/** * Initialisation if a supplied key is defined in the properties. This supplied key must be in a keystore which * can be generated using the keystoreGenerator file in demos. The keystore must be on the classpath to find it. */ protected void readSecretKeyFromKeystore() throws Exception { // must not use default keystore type - as it does not support secret keys KeyStore store=KeyStore.getInstance(keystore_type != null? keystore_type : KeyStore.getDefaultType()); if(key_password == null && store_password != null) { key_password=store_password; log.debug("%s: key_password used is same as store_password", local_addr); } try (InputStream inputStream = getKeyStoreSource()) { store.load(inputStream, store_password.toCharArray()); } // loaded keystore - get the key if (!store.entryInstanceOf(alias, KeyStore.SecretKeyEntry.class)) { throw new Exception("Key '" + alias + "' from keystore " + keystore_name + " is not a secret key"); } KeyStore.SecretKeyEntry entry = (KeyStore.SecretKeyEntry) store.getEntry(alias, new KeyStore.PasswordProtection(key_password.toCharArray())); if (entry == null) { throw new Exception("Key '" + alias + "' not found in keystore " + keystore_name); } this.setKeyStoreEntry(entry); }
@Override public void init() throws Exception { if (this.secret_key == null) { readSecretKeyFromKeystore(); } super.init(); }
@Override public void setKeyStoreEntry(KeyStore.SecretKeyEntry entry) { this.setSecretKey(entry.getSecretKey()); }
/** * Initialisation if a supplied key is defined in the properties. This supplied key must be in a keystore which * can be generated using the keystoreGenerator file in demos. The keystore must be on the classpath to find it. */ protected void readSecretKeyFromKeystore() throws Exception { // must not use default keystore type - as it does not support secret keys KeyStore store=KeyStore.getInstance(keystore_type != null? keystore_type : KeyStore.getDefaultType()); if(key_password == null && store_password != null) { key_password=store_password; log.debug("%s: key_password used is same as store_password", local_addr); } try (InputStream inputStream = getKeyStoreSource()) { store.load(inputStream, store_password.toCharArray()); } // loaded keystore - get the key if (!store.entryInstanceOf(alias, KeyStore.SecretKeyEntry.class)) { throw new Exception("Key '" + alias + "' from keystore " + keystore_name + " is not a secret key"); } KeyStore.SecretKeyEntry entry = (KeyStore.SecretKeyEntry) store.getEntry(alias, new KeyStore.PasswordProtection(key_password.toCharArray())); if (entry == null) { throw new Exception("Key '" + alias + "' not found in keystore " + keystore_name); } this.setKeyStoreEntry(entry); }
@Override public void init() throws Exception { if (this.secret_key == null) { readSecretKeyFromKeystore(); } super.init(); }
@Override public void setKeyStoreEntry(KeyStore.SecretKeyEntry entry) { this.setSecretKey(entry.getSecretKey()); }