@@ -24,6 +24,7 @@ This file is part of the iText (R) project.
24
24
25
25
import com .itextpdf .bouncycastleconnector .BouncyCastleFactoryCreator ;
26
26
import com .itextpdf .commons .bouncycastle .IBouncyCastleFactory ;
27
+ import com .itextpdf .commons .bouncycastle .crypto .fips .AbstractFipsUnapprovedOperationError ;
27
28
import com .itextpdf .commons .bouncycastle .operator .AbstractOperatorCreationException ;
28
29
import com .itextpdf .commons .bouncycastle .pkcs .AbstractPKCSException ;
29
30
import com .itextpdf .io .font .constants .StandardFonts ;
@@ -116,7 +117,13 @@ public void encryptWithCertificateStandard128() throws IOException, InterruptedE
116
117
AbstractPKCSException , AbstractOperatorCreationException {
117
118
String filename = "encryptWithCertificateStandard128.pdf" ;
118
119
int encryptionType = EncryptionConstants .STANDARD_ENCRYPTION_128 ;
119
- encryptWithCertificate (filename , encryptionType , CompressionConstants .DEFAULT_COMPRESSION );
120
+ if (FACTORY .isInApprovedOnlyMode ()) {
121
+ // RSA PKCS1.5 encryption disallowed
122
+ Assert .assertThrows (AbstractFipsUnapprovedOperationError .class ,
123
+ () -> encryptWithCertificate (filename , encryptionType , CompressionConstants .DEFAULT_COMPRESSION ));
124
+ } else {
125
+ encryptWithCertificate (filename , encryptionType , CompressionConstants .DEFAULT_COMPRESSION );
126
+ }
120
127
}
121
128
122
129
@ Test
@@ -126,7 +133,13 @@ public void encryptWithCertificateStandard40() throws IOException, InterruptedEx
126
133
AbstractPKCSException , AbstractOperatorCreationException {
127
134
String filename = "encryptWithCertificateStandard40.pdf" ;
128
135
int encryptionType = EncryptionConstants .STANDARD_ENCRYPTION_40 ;
129
- encryptWithCertificate (filename , encryptionType , CompressionConstants .DEFAULT_COMPRESSION );
136
+ if (FACTORY .isInApprovedOnlyMode ()) {
137
+ // RSA PKCS1.5 encryption disallowed
138
+ Assert .assertThrows (AbstractFipsUnapprovedOperationError .class ,
139
+ () -> encryptWithCertificate (filename , encryptionType , CompressionConstants .DEFAULT_COMPRESSION ));
140
+ } else {
141
+ encryptWithCertificate (filename , encryptionType , CompressionConstants .DEFAULT_COMPRESSION );
142
+ }
130
143
}
131
144
132
145
@ Test
@@ -136,7 +149,13 @@ public void encryptWithCertificateStandard128NoCompression() throws IOException,
136
149
GeneralSecurityException , AbstractPKCSException , AbstractOperatorCreationException {
137
150
String filename = "encryptWithCertificateStandard128NoCompression.pdf" ;
138
151
int encryptionType = EncryptionConstants .STANDARD_ENCRYPTION_128 ;
139
- encryptWithCertificate (filename , encryptionType , CompressionConstants .NO_COMPRESSION );
152
+ if (FACTORY .isInApprovedOnlyMode ()) {
153
+ // RSA PKCS1.5 encryption disallowed
154
+ Assert .assertThrows (AbstractFipsUnapprovedOperationError .class ,
155
+ () -> encryptWithCertificate (filename , encryptionType , CompressionConstants .NO_COMPRESSION ));
156
+ } else {
157
+ encryptWithCertificate (filename , encryptionType , CompressionConstants .NO_COMPRESSION );
158
+ }
140
159
}
141
160
142
161
@ Test
@@ -146,7 +165,13 @@ public void encryptWithCertificateStandard40NoCompression() throws IOException,
146
165
GeneralSecurityException , AbstractPKCSException , AbstractOperatorCreationException {
147
166
String filename = "encryptWithCertificateStandard40NoCompression.pdf" ;
148
167
int encryptionType = EncryptionConstants .STANDARD_ENCRYPTION_40 ;
149
- encryptWithCertificate (filename , encryptionType , CompressionConstants .NO_COMPRESSION );
168
+ if (FACTORY .isInApprovedOnlyMode ()) {
169
+ // RSA PKCS1.5 encryption disallowed
170
+ Assert .assertThrows (AbstractFipsUnapprovedOperationError .class ,
171
+ () -> encryptWithCertificate (filename , encryptionType , CompressionConstants .NO_COMPRESSION ));
172
+ } else {
173
+ encryptWithCertificate (filename , encryptionType , CompressionConstants .NO_COMPRESSION );
174
+ }
150
175
}
151
176
152
177
@ Test
@@ -156,7 +181,13 @@ public void encryptWithCertificateAes128() throws IOException, InterruptedExcept
156
181
AbstractPKCSException , AbstractOperatorCreationException {
157
182
String filename = "encryptWithCertificateAes128.pdf" ;
158
183
int encryptionType = EncryptionConstants .ENCRYPTION_AES_128 ;
159
- encryptWithCertificate (filename , encryptionType , CompressionConstants .DEFAULT_COMPRESSION );
184
+ if (FACTORY .isInApprovedOnlyMode ()) {
185
+ // RSA PKCS1.5 encryption disallowed
186
+ Assert .assertThrows (AbstractFipsUnapprovedOperationError .class ,
187
+ () -> encryptWithCertificate (filename , encryptionType , CompressionConstants .DEFAULT_COMPRESSION ));
188
+ } else {
189
+ encryptWithCertificate (filename , encryptionType , CompressionConstants .DEFAULT_COMPRESSION );
190
+ }
160
191
}
161
192
162
193
@ Test
@@ -166,7 +197,13 @@ public void encryptWithCertificateAes256() throws IOException, InterruptedExcept
166
197
AbstractPKCSException , AbstractOperatorCreationException {
167
198
String filename = "encryptWithCertificateAes256.pdf" ;
168
199
int encryptionType = EncryptionConstants .ENCRYPTION_AES_256 ;
169
- encryptWithCertificate (filename , encryptionType , CompressionConstants .DEFAULT_COMPRESSION );
200
+ if (FACTORY .isInApprovedOnlyMode ()) {
201
+ // RSA PKCS1.5 encryption disallowed
202
+ Assert .assertThrows (AbstractFipsUnapprovedOperationError .class ,
203
+ () -> encryptWithCertificate (filename , encryptionType , CompressionConstants .DEFAULT_COMPRESSION ));
204
+ } else {
205
+ encryptWithCertificate (filename , encryptionType , CompressionConstants .DEFAULT_COMPRESSION );
206
+ }
170
207
}
171
208
172
209
@ Test
@@ -176,7 +213,13 @@ public void encryptWithCertificateAes128NoCompression() throws IOException, Inte
176
213
GeneralSecurityException , AbstractPKCSException , AbstractOperatorCreationException {
177
214
String filename = "encryptWithCertificateAes128NoCompression.pdf" ;
178
215
int encryptionType = EncryptionConstants .ENCRYPTION_AES_128 ;
179
- encryptWithCertificate (filename , encryptionType , CompressionConstants .NO_COMPRESSION );
216
+ if (FACTORY .isInApprovedOnlyMode ()) {
217
+ // RSA PKCS1.5 encryption disallowed
218
+ Assert .assertThrows (AbstractFipsUnapprovedOperationError .class ,
219
+ () -> encryptWithCertificate (filename , encryptionType , CompressionConstants .NO_COMPRESSION ));
220
+ } else {
221
+ encryptWithCertificate (filename , encryptionType , CompressionConstants .NO_COMPRESSION );
222
+ }
180
223
}
181
224
182
225
@ Test
@@ -186,7 +229,13 @@ public void encryptWithCertificateAes256NoCompression() throws IOException, Inte
186
229
GeneralSecurityException , AbstractPKCSException , AbstractOperatorCreationException {
187
230
String filename = "encryptWithCertificateAes256NoCompression.pdf" ;
188
231
int encryptionType = EncryptionConstants .ENCRYPTION_AES_256 ;
189
- encryptWithCertificate (filename , encryptionType , CompressionConstants .NO_COMPRESSION );
232
+ if (FACTORY .isInApprovedOnlyMode ()) {
233
+ // RSA PKCS1.5 encryption disallowed
234
+ Assert .assertThrows (AbstractFipsUnapprovedOperationError .class ,
235
+ () -> encryptWithCertificate (filename , encryptionType , CompressionConstants .NO_COMPRESSION ));
236
+ } else {
237
+ encryptWithCertificate (filename , encryptionType , CompressionConstants .NO_COMPRESSION );
238
+ }
190
239
}
191
240
192
241
@ Test
0 commit comments