21
21
import org .bouncycastle .asn1 .x509 .GeneralName ;
22
22
import org .bouncycastle .asn1 .x509 .GeneralNames ;
23
23
import org .bouncycastle .cert .X509CertificateHolder ;
24
+ import org .bouncycastle .openssl .PEMDecryptorProvider ;
24
25
import org .bouncycastle .openssl .PEMEncryptedKeyPair ;
25
26
import org .bouncycastle .openssl .PEMParser ;
26
27
import org .bouncycastle .pkcs .PKCS10CertificationRequest ;
50
51
import org .hamcrest .Matchers ;
51
52
import org .junit .After ;
52
53
import org .junit .BeforeClass ;
54
+ import org .mockito .Mockito ;
53
55
54
56
import javax .net .ssl .KeyManagerFactory ;
55
57
import javax .net .ssl .TrustManagerFactory ;
@@ -349,6 +351,16 @@ public void testGeneratingSignedPemCertificates() throws Exception {
349
351
PEMParser pemParser = new PEMParser (reader );
350
352
Object parsed = pemParser .readObject ();
351
353
assertThat (parsed , instanceOf (PEMEncryptedKeyPair .class ));
354
+ // Verify we are using AES encryption
355
+ final PEMDecryptorProvider pemDecryptorProvider = Mockito .mock (PEMDecryptorProvider .class );
356
+ try {
357
+ ((PEMEncryptedKeyPair ) parsed ).decryptKeyPair (pemDecryptorProvider );
358
+ } catch (Exception e ) {
359
+ // Catch error thrown by the empty mock, we are only interested in the argument passed in
360
+ }
361
+ finally {
362
+ Mockito .verify (pemDecryptorProvider ).get ("AES-128-CBC" );
363
+ }
352
364
char [] zeroChars = new char [caInfo .password .length ];
353
365
Arrays .fill (zeroChars , (char ) 0 );
354
366
assertArrayEquals (zeroChars , caInfo .password );
@@ -368,7 +380,13 @@ public void testGeneratingSignedPemCertificates() throws Exception {
368
380
assertTrue (Files .exists (zipRoot .resolve (filename )));
369
381
final Path cert = zipRoot .resolve (filename + "/" + filename + ".crt" );
370
382
assertTrue (Files .exists (cert ));
371
- assertTrue (Files .exists (zipRoot .resolve (filename + "/" + filename + ".key" )));
383
+ Path keyFile = zipRoot .resolve (filename + "/" + filename + ".key" );
384
+ assertTrue (Files .exists (keyFile ));
385
+ if (keyPassword != null ) {
386
+ assertTrue (Files .readString (keyFile ).contains ("DEK-Info: AES-128-CBC" ));
387
+ } else {
388
+ assertFalse (Files .readString (keyFile ).contains ("DEK-Info:" ));
389
+ }
372
390
final Path p12 = zipRoot .resolve (filename + "/" + filename + ".p12" );
373
391
try (InputStream input = Files .newInputStream (cert )) {
374
392
X509Certificate certificate = readX509Certificate (input );
0 commit comments