Skip to content

Commit

Permalink
8236671: NullPointerException in JKS keystore
Browse files Browse the repository at this point in the history
Reviewed-by: clanger
Backport-of: 276a1bf
  • Loading branch information
TheRealMDoerr committed Jul 21, 2021
1 parent 240ef44 commit 44ef6fe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public void engineSetKeyEntry(String alias, Key key, char[] password,
}

} catch (Exception e) {
throw new KeyStoreException(e.getMessage());
throw new KeyStoreException(e.getMessage(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ public void engineSetKeyEntry(String alias, Key key, char[] password,
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();
Expand Down
15 changes: 13 additions & 2 deletions test/jdk/java/security/KeyStore/TestKeyStoreBasic.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2015, 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
Expand Down Expand Up @@ -40,7 +40,7 @@

/*
* @test
* @bug 8048621 8133090 8167371
* @bug 8048621 8133090 8167371 8236671
* @summary Test basic operations with keystores (jks, jceks, pkcs12)
* @author Yu-Ching Valerie PENG
*/
Expand Down Expand Up @@ -181,6 +181,17 @@ public void runTest(String provider) throws Exception {
// 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,
Expand Down

1 comment on commit 44ef6fe

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.