@@ -28,6 +28,7 @@ This file is part of the iText (R) project.
28
28
import com .itextpdf .kernel .exceptions .KernelExceptionMessageConstant ;
29
29
import com .itextpdf .kernel .exceptions .PdfException ;
30
30
import com .itextpdf .kernel .geom .Rectangle ;
31
+ import com .itextpdf .kernel .logs .KernelLogMessageConstant ;
31
32
import com .itextpdf .kernel .mac .MacProperties .MacDigestAlgorithm ;
32
33
import com .itextpdf .kernel .pdf .EncryptionConstants ;
33
34
import com .itextpdf .kernel .pdf .PdfDocument ;
@@ -40,6 +41,8 @@ This file is part of the iText (R) project.
40
41
import com .itextpdf .kernel .utils .CompareTool ;
41
42
import com .itextpdf .test .AssertUtil ;
42
43
import com .itextpdf .test .ExtendedITextTest ;
44
+ import com .itextpdf .test .annotations .LogMessage ;
45
+ import com .itextpdf .test .annotations .LogMessages ;
43
46
44
47
import java .io .IOException ;
45
48
import java .security .PrivateKey ;
@@ -62,7 +65,6 @@ public class MacIntegrityProtectorReadingAndRewritingTest extends ExtendedITextT
62
65
63
66
@ BeforeAll
64
67
public static void beforeClass () {
65
- Assumptions .assumeTrue ("BC" .equals (PROVIDER_NAME ));
66
68
createOrClearDestinationFolder (DESTINATION_FOLDER );
67
69
Security .addProvider (BouncyCastleFactoryCreator .getFactory ().getProvider ());
68
70
}
@@ -73,6 +75,8 @@ public static void afterClass() {
73
75
}
74
76
75
77
@ Test
78
+ @ LogMessages (messages = @ LogMessage (messageTemplate = KernelLogMessageConstant .MD5_IS_NOT_FIPS_COMPLIANT ,
79
+ ignore = true ))
76
80
public void appendModeTest () throws IOException , InterruptedException {
77
81
String fileName = "appendModeTest.pdf" ;
78
82
String outputFileName = DESTINATION_FOLDER + fileName ;
@@ -88,6 +92,8 @@ public void appendModeTest() throws IOException, InterruptedException {
88
92
}
89
93
90
94
@ Test
95
+ @ LogMessages (messages = @ LogMessage (messageTemplate = KernelLogMessageConstant .MD5_IS_NOT_FIPS_COMPLIANT ,
96
+ ignore = true ))
91
97
public void preserveEncryptionTest () throws IOException , InterruptedException {
92
98
String fileName = "preserveEncryptionTest.pdf" ;
93
99
String outputFileName = DESTINATION_FOLDER + fileName ;
@@ -104,6 +110,8 @@ public void preserveEncryptionTest() throws IOException, InterruptedException {
104
110
}
105
111
106
112
@ Test
113
+ @ LogMessages (messages = @ LogMessage (messageTemplate = KernelLogMessageConstant .MD5_IS_NOT_FIPS_COMPLIANT ,
114
+ ignore = true ))
107
115
public void writerPropertiesTest () throws IOException , InterruptedException {
108
116
String fileName = "writerPropertiesTest.pdf" ;
109
117
String outputFileName = DESTINATION_FOLDER + fileName ;
@@ -123,6 +131,8 @@ public void writerPropertiesTest() throws IOException, InterruptedException {
123
131
}
124
132
125
133
@ Test
134
+ @ LogMessages (messages = @ LogMessage (messageTemplate = KernelLogMessageConstant .MD5_IS_NOT_FIPS_COMPLIANT ,
135
+ ignore = true ))
126
136
public void macShouldNotBePreservedWithEncryptionTest () throws IOException , InterruptedException {
127
137
String fileName = "macShouldNotBePreservedWithEncryptionTest.pdf" ;
128
138
String outputFileName = DESTINATION_FOLDER + fileName ;
@@ -139,6 +149,8 @@ public void macShouldNotBePreservedWithEncryptionTest() throws IOException, Inte
139
149
}
140
150
141
151
@ Test
152
+ @ LogMessages (messages = @ LogMessage (messageTemplate = KernelLogMessageConstant .MD5_IS_NOT_FIPS_COMPLIANT ,
153
+ ignore = true ))
142
154
public void macShouldNotBePreservedTest () throws IOException , InterruptedException {
143
155
String fileName = "macShouldNotBePreservedTest.pdf" ;
144
156
String outputFileName = DESTINATION_FOLDER + fileName ;
@@ -154,6 +166,8 @@ public void macShouldNotBePreservedTest() throws IOException, InterruptedExcepti
154
166
}
155
167
156
168
@ Test
169
+ @ LogMessages (messages = @ LogMessage (messageTemplate = KernelLogMessageConstant .MD5_IS_NOT_FIPS_COMPLIANT ,
170
+ ignore = true ))
157
171
public void invalidMacTokenTest () {
158
172
String fileName = "invalidMacTokenTest.pdf" ;
159
173
String outputFileName = DESTINATION_FOLDER + fileName ;
@@ -168,7 +182,14 @@ public void invalidMacTokenTest() {
168
182
}
169
183
170
184
@ Test
185
+ @ LogMessages (messages = @ LogMessage (messageTemplate = KernelLogMessageConstant .MD5_IS_NOT_FIPS_COMPLIANT ,
186
+ ignore = true ))
171
187
public void invalidPublicKeyMacProtectedDocumentTest () throws Exception {
188
+ try {
189
+ BouncyCastleFactoryCreator .getFactory ().isEncryptionFeatureSupported (0 , true );
190
+ } catch (Exception ignored ) {
191
+ Assumptions .assumeTrue (false );
192
+ }
172
193
String fileName = "invalidPublicKeyMacProtectedDocumentTest.pdf" ;
173
194
String outputFileName = DESTINATION_FOLDER + fileName ;
174
195
@@ -188,59 +209,76 @@ public void invalidPublicKeyMacProtectedDocumentTest() throws Exception {
188
209
}
189
210
190
211
@ Test
212
+ @ LogMessages (messages = @ LogMessage (messageTemplate = KernelLogMessageConstant .MD5_IS_NOT_FIPS_COMPLIANT ,
213
+ ignore = true ))
191
214
public void readSignedMacProtectedDocumentWithoutAttributeTest () {
192
215
String message = Assertions .assertThrows (PdfException .class , () -> {
193
- try (PdfDocument pdfDoc = new PdfDocument (new PdfReader (SOURCE_FOLDER + "signedMacProtectedDocWithoutAttribute.pdf" ,
216
+ try (PdfDocument ignored = new PdfDocument (new PdfReader (SOURCE_FOLDER + "signedMacProtectedDocWithoutAttribute.pdf" ,
194
217
new ReaderProperties ().setPassword (PASSWORD )))) {
195
218
}
196
219
}).getMessage ();
197
220
Assertions .assertEquals (KernelExceptionMessageConstant .MAC_ATTRIBUTE_NOT_SPECIFIED , message );
198
221
}
199
222
200
223
@ Test
224
+ @ LogMessages (messages = @ LogMessage (messageTemplate = KernelLogMessageConstant .MD5_IS_NOT_FIPS_COMPLIANT ,
225
+ ignore = true ))
201
226
public void macProtectionStrippedTest () {
202
227
String message = Assertions .assertThrows (PdfException .class , () -> {
203
- try (PdfDocument pdfDoc = new PdfDocument (new PdfReader (SOURCE_FOLDER + "macProtectionStrippedTest.pdf" ,
228
+ try (PdfDocument ignored = new PdfDocument (new PdfReader (SOURCE_FOLDER + "macProtectionStrippedTest.pdf" ,
204
229
new ReaderProperties ().setPassword (PASSWORD )))) {
205
230
}
206
231
}).getMessage ();
207
232
Assertions .assertEquals (KernelExceptionMessageConstant .MAC_PERMS_WITHOUT_MAC , message );
208
233
}
209
234
210
235
@ Test
236
+ @ LogMessages (messages = @ LogMessage (messageTemplate = KernelLogMessageConstant .MD5_IS_NOT_FIPS_COMPLIANT ,
237
+ ignore = true ))
211
238
public void readSignedMacProtectedDocumentTest () {
212
239
AssertUtil .doesNotThrow (() -> {
213
- try (PdfDocument pdfDoc = new PdfDocument (new PdfReader (SOURCE_FOLDER + "signedMacProtectedDocument.pdf" ,
240
+ try (PdfDocument ignored = new PdfDocument (new PdfReader (SOURCE_FOLDER + "signedMacProtectedDocument.pdf" ,
214
241
new ReaderProperties ().setPassword (PASSWORD )))) {
215
242
}
216
243
});
217
244
}
218
245
219
246
@ Test
247
+ @ LogMessages (messages = @ LogMessage (messageTemplate = KernelLogMessageConstant .MD5_IS_NOT_FIPS_COMPLIANT ,
248
+ ignore = true ))
220
249
public void readThirdPartyMacProtectedDocumentTest () {
221
250
AssertUtil .doesNotThrow (() -> {
222
- try (PdfDocument pdfDoc = new PdfDocument (new PdfReader (SOURCE_FOLDER + "thirdPartyMacProtectedDocument.pdf" ,
251
+ try (PdfDocument ignored = new PdfDocument (new PdfReader (SOURCE_FOLDER + "thirdPartyMacProtectedDocument.pdf" ,
223
252
new ReaderProperties ().setPassword (PASSWORD )))) {
224
253
}
225
254
});
226
255
}
227
256
228
257
@ Test
258
+ @ LogMessages (messages = @ LogMessage (messageTemplate = KernelLogMessageConstant .MD5_IS_NOT_FIPS_COMPLIANT ,
259
+ ignore = true ))
229
260
public void readThirdPartyPublicKeyMacProtectedDocumentTest () throws Exception {
261
+ try {
262
+ BouncyCastleFactoryCreator .getFactory ().isEncryptionFeatureSupported (0 , true );
263
+ } catch (Exception ignored ) {
264
+ Assumptions .assumeTrue (false );
265
+ }
230
266
PrivateKey privateKey = MacIntegrityProtectorCreationTest .getPrivateKey (CERTS_SRC + "keyForEncryption.pem" );
231
267
Certificate certificate = CryptoUtil .readPublicCertificate (
232
268
FileUtil .getInputStreamForFile (CERTS_SRC + "certForEncryption.crt" ));
233
269
AssertUtil .doesNotThrow (() -> {
234
- try (PdfDocument pdfDoc = new PdfDocument (new PdfReader (SOURCE_FOLDER + "thirdPartyPublicKeyMacProtectedDocument.pdf" ,
270
+ try (PdfDocument ignored = new PdfDocument (new PdfReader (SOURCE_FOLDER + "thirdPartyPublicKeyMacProtectedDocument.pdf" ,
235
271
new ReaderProperties ().setPublicKeySecurityParams (certificate , privateKey , PROVIDER_NAME , null )))) {
236
272
}
237
273
});
238
274
}
239
275
240
276
@ Test
277
+ @ LogMessages (messages = @ LogMessage (messageTemplate = KernelLogMessageConstant .MD5_IS_NOT_FIPS_COMPLIANT ,
278
+ ignore = true ))
241
279
public void readMacProtectedPdf1_7 () {
242
280
AssertUtil .doesNotThrow (() -> {
243
- try (PdfDocument pdfDoc = new PdfDocument (new PdfReader (SOURCE_FOLDER + "macProtectedDocumentPdf1_7.pdf" ,
281
+ try (PdfDocument ignored = new PdfDocument (new PdfReader (SOURCE_FOLDER + "macProtectedDocumentPdf1_7.pdf" ,
244
282
new ReaderProperties ().setPassword (PASSWORD )))) {
245
283
}
246
284
});
0 commit comments