8236671: NullPointerException in JKS keystore
Reviewed-by: hchao, xuelei
This commit is contained in:
parent
e9370a13b6
commit
276a1bf767
@ -293,7 +293,7 @@ public final class JceKeyStore extends KeyStoreSpi {
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new KeyStoreException(e.getMessage());
|
||||
throw new KeyStoreException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -281,6 +281,9 @@ public abstract class JavaKeyStore extends KeyStoreSpi {
|
||||
if (!(key instanceof java.security.PrivateKey)) {
|
||||
throw new KeyStoreException("Cannot store non-PrivateKeys");
|
||||
}
|
||||
if (password == null) {
|
||||
throw new KeyStoreException("password can't be null");
|
||||
}
|
||||
try {
|
||||
synchronized(entries) {
|
||||
KeyEntry entry = new KeyEntry();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -40,7 +40,7 @@ import java.util.Base64;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8048621 8133090 8167371
|
||||
* @bug 8048621 8133090 8167371 8236671
|
||||
* @summary Test basic operations with keystores (jks, jceks, pkcs12)
|
||||
* @author Yu-Ching Valerie PENG
|
||||
*/
|
||||
@ -163,6 +163,17 @@ public class TestKeyStoreBasic {
|
||||
// create an empty key store
|
||||
ks.load(null, null);
|
||||
|
||||
// unit test - test with null password
|
||||
try {
|
||||
ks.setKeyEntry(ALIAS_HEAD, privateKey, null,
|
||||
new Certificate[] { cert });
|
||||
} catch (KeyStoreException e) {
|
||||
if (!e.getMessage().contains("password can\'t be null")) {
|
||||
throw new RuntimeException("Unexpected message:" + e.getMessage());
|
||||
}
|
||||
// expected
|
||||
}
|
||||
|
||||
// store the secret keys
|
||||
for (int j = 0; j < numEntries; j++) {
|
||||
ks.setKeyEntry(ALIAS_HEAD + j, privateKey, PASSWDK,
|
||||
|
Loading…
x
Reference in New Issue
Block a user