@@ -24,6 +24,7 @@ This file is part of the iText (R) project.
2424
2525import com .itextpdf .bouncycastleconnector .BouncyCastleFactoryCreator ;
2626import com .itextpdf .commons .bouncycastle .IBouncyCastleFactory ;
27+ import com .itextpdf .commons .bouncycastle .crypto .fips .AbstractFipsUnapprovedOperationError ;
2728import com .itextpdf .commons .bouncycastle .operator .AbstractOperatorCreationException ;
2829import com .itextpdf .commons .bouncycastle .pkcs .AbstractPKCSException ;
2930import com .itextpdf .io .font .constants .StandardFonts ;
@@ -116,7 +117,13 @@ public void encryptWithCertificateStandard128() throws IOException, InterruptedE
116117 AbstractPKCSException , AbstractOperatorCreationException {
117118 String filename = "encryptWithCertificateStandard128.pdf" ;
118119 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+ }
120127 }
121128
122129 @ Test
@@ -126,7 +133,13 @@ public void encryptWithCertificateStandard40() throws IOException, InterruptedEx
126133 AbstractPKCSException , AbstractOperatorCreationException {
127134 String filename = "encryptWithCertificateStandard40.pdf" ;
128135 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+ }
130143 }
131144
132145 @ Test
@@ -136,7 +149,13 @@ public void encryptWithCertificateStandard128NoCompression() throws IOException,
136149 GeneralSecurityException , AbstractPKCSException , AbstractOperatorCreationException {
137150 String filename = "encryptWithCertificateStandard128NoCompression.pdf" ;
138151 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+ }
140159 }
141160
142161 @ Test
@@ -146,7 +165,13 @@ public void encryptWithCertificateStandard40NoCompression() throws IOException,
146165 GeneralSecurityException , AbstractPKCSException , AbstractOperatorCreationException {
147166 String filename = "encryptWithCertificateStandard40NoCompression.pdf" ;
148167 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+ }
150175 }
151176
152177 @ Test
@@ -156,7 +181,13 @@ public void encryptWithCertificateAes128() throws IOException, InterruptedExcept
156181 AbstractPKCSException , AbstractOperatorCreationException {
157182 String filename = "encryptWithCertificateAes128.pdf" ;
158183 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+ }
160191 }
161192
162193 @ Test
@@ -166,7 +197,13 @@ public void encryptWithCertificateAes256() throws IOException, InterruptedExcept
166197 AbstractPKCSException , AbstractOperatorCreationException {
167198 String filename = "encryptWithCertificateAes256.pdf" ;
168199 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+ }
170207 }
171208
172209 @ Test
@@ -176,7 +213,13 @@ public void encryptWithCertificateAes128NoCompression() throws IOException, Inte
176213 GeneralSecurityException , AbstractPKCSException , AbstractOperatorCreationException {
177214 String filename = "encryptWithCertificateAes128NoCompression.pdf" ;
178215 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+ }
180223 }
181224
182225 @ Test
@@ -186,7 +229,13 @@ public void encryptWithCertificateAes256NoCompression() throws IOException, Inte
186229 GeneralSecurityException , AbstractPKCSException , AbstractOperatorCreationException {
187230 String filename = "encryptWithCertificateAes256NoCompression.pdf" ;
188231 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+ }
190239 }
191240
192241 @ Test
0 commit comments