Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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