Skip to content

Commit dc3d7a6

Browse files
committed
JCE: zero WolfSSLKeyStore PKCS8 private key buffer after native check
1 parent 570faa4 commit dc3d7a6

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/main/java/com/wolfssl/provider/jce/WolfSSLKeyStore.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,11 +1459,14 @@ private void checkCertificateChainMatchesPrivateKey(
14591459
if (pkcs8Key == null || pkcs8Key.length == 0) {
14601460
throw new KeyStoreException("Bad PrivateKey PKCS#8 encoding");
14611461
}
1462-
1463-
match = X509CheckPrivateKey(derCert, pkcs8Key);
1464-
if (!match) {
1465-
throw new KeyStoreException("X509Certificate does not match " +
1466-
"provided private key");
1462+
try {
1463+
match = X509CheckPrivateKey(derCert, pkcs8Key);
1464+
if (!match) {
1465+
throw new KeyStoreException("X509Certificate does not match " +
1466+
"provided private key");
1467+
}
1468+
} finally {
1469+
Arrays.fill(pkcs8Key, (byte)0);
14671470
}
14681471
}
14691472

@@ -1986,7 +1989,7 @@ else if (entry.getValue() instanceof WKSSecretKey) {
19861989

19871990
log("KeyStore successfully stored to OutputStream");
19881991

1989-
return;
1992+
return;
19901993
}
19911994

19921995
/**

0 commit comments

Comments
 (0)