Skip to content
Open
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 @@ -55,6 +55,7 @@ protected KeyStoreOptionsBase() {
*/
protected KeyStoreOptionsBase(KeyStoreOptionsBase other) {
super();
this.provider = other.provider;
this.type = other.type;
this.password = other.password;
this.path = other.path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public KeyStoreHelper(KeyStore ks, String password, String aliasPassword) throws
// It's a private key
continue;
}
if (key.getFormat() == null) {
// Hardware security module key, not extractable
continue;
}
X509KeyManager mgr = new X509KeyManager() {
@Override
public String[] getClientAliases(String s, Principal[] principals) {
Expand Down Expand Up @@ -254,10 +258,14 @@ public static KeyStore loadKeyStore(String type, String provider, String passwor
if (!ks.containsAlias(alias)) {
throw new IllegalArgumentException("alias does not exist in the keystore: " + alias);
}
List<String> ksAliases = Collections.list(ks.aliases());
for (String ksAlias : ksAliases) {
if (!alias.equals(ksAlias)) {
ks.deleteEntry(ksAlias);
// HSM keys are not extractable to memory. Deleting an entry from the HSM-KeyStore removes the actual entry from the store
// This PKCS11 check prevents it
if (!type.equalsIgnoreCase("PKCS11")) {
List<String> ksAliases = Collections.list(ks.aliases());
for (String ksAlias : ksAliases) {
if (!alias.equals(ksAlias)) {
ks.deleteEntry(ksAlias);
}
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions vertx-core/src/test/java/io/vertx/tests/security/KeyStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,26 @@ private void testTrustStore(KeyStoreHelper helper) throws Exception {
TrustManager[] keyManagers = helper.getTrustMgrs((VertxInternal) vertx);
assertTrue(keyManagers.length > 0);
}
@Test
public void testCopyKeyStoreOptions() {
KeyStoreOptions options = new KeyStoreOptions();
options.setPassword("secret");
options.setPath("/path/to/keystore.p12");
options.setValue(Buffer.buffer("dummy"));
options.setType("PKCS11");
options.setProvider("SunPKCS11-hsm");
options.setAlias("server-key");
options.setAliasPassword("key-secret");
KeyStoreOptions copy = new KeyStoreOptions(options);
assertEquals("secret", copy.getPassword());
assertEquals("/path/to/keystore.p12", copy.getPath());
assertEquals(Buffer.buffer("dummy"), copy.getValue());
assertEquals("PKCS11", copy.getType());
assertEquals("SunPKCS11-hsm", copy.getProvider());
assertEquals("server-key", copy.getAlias());
assertEquals("key-secret", copy.getAliasPassword());
}


/*
@Test
Expand Down