public AliasFilter remove(final String alias) { return new AliasFilter(this) { @Override public boolean test(String t) { if (alias.equals(t)) { return false; } else { return previous.test(t); } } }; }
@Override public void engineSetKeyEntry(String alias, Key key, char[] password, Certificate[] chain) throws KeyStoreException { super.engineSetKeyEntry(alias, key, password, chain); modified = true; }
@Override public void engineStore(OutputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException { super.engineStore(stream, password); modified = false; }
/** * Performs the same action as {@link #load(InputStream, char[])} except a {@link LoadKey} is returned that can be used to revert the load. * * @param inputStream the stream to load from or {@code null} * @param password the password used to protect the contents of the {@link KeyStore} or {@code null} * @return a {@link LoadKey} that can be used to revert the load and restore the previous {@link KeyStore} state * @throws NoSuchAlgorithmException if the keystore cannot be read due to a missing algorithm * @throws CertificateException if the keystore cannot be read due to a certificate problem * @throws IOException if the keystore cannot be read due to an I/O problem */ public LoadKey revertibleLoad(final InputStream inputStream, final char[] password) throws NoSuchAlgorithmException, CertificateException, IOException { KeyStore current = keyStoreSpi.getCurrentKeyStore(); if (current == null) { throw log.reversibleLoadNotPossible(); } load(inputStream, password); return new LoadKey(current); }
public void engineSetKeyEntry(final String alias, final Key key, final char[] password, final Certificate[] chain) throws KeyStoreException { if (key instanceof Password) { engineSetEntry(alias, new PasswordEntry((Password) key), password == null ? null : new KeyStore.PasswordProtection(password)); } else { delegate.setKeyEntry(alias, key, password, chain); } }
public void engineSetKeyEntry(final String alias, final Key key, final char[] password, final Certificate[] chain) throws KeyStoreException { if (password != null) { throw new KeyStoreException(log.invalidKeyStoreEntryPassword(alias)); } if (key instanceof Password) { engineSetEntry(alias, new PasswordEntry((Password) key), null); } throw log.invalidKeyStoreEntryType(alias, PasswordEntry.class, Key.class); }
/** * Create a new {@code AtomicLoadKeyStore} wrapping a {@link KeyStore} or the specified type, obtained from the supplied {@link Provider}. * * @param type the type of the {@link KeyStore} to wrap * @param provider the {@link Provider} to use to create the {@link KeyStore} instance. * @return the new {@link AtomicLoadKeyStore} instance */ public static AtomicLoadKeyStore newInstance(final String type, final Provider provider) { AtomicLoadKeyStoreSpi keyStoreSpi = new AtomicLoadKeyStoreSpi(() -> KeyStore.getInstance(type, provider)); ElytronMessages.tls.tracef("AtomicLoadKeyStore creating: type = %s, provider = %s", type, provider); return new AtomicLoadKeyStore(keyStoreSpi, provider, type); }
@Override public void engineLoad(InputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException { if (initialised) { super.engineLoad(stream, password); modified = false; } else { // Skip the first initialisation as we are deliberately getting initialised flags set. initialised = true; } }
/** * Mark this as being modified, this can be used where the delegate is delibaratly modified outside this wrapper. */ public void setModified(final boolean modified) { keyStoreSpi.setModified(modified); }
@Override public void engineSetCertificateEntry(String alias, Certificate cert) throws KeyStoreException { super.engineSetCertificateEntry(alias, cert); modified = true; }
/** * Atomically evert the keystore to a previous state. * * @param key the load key */ public void revert(LoadKey key) { keyStoreSpi.restoreKeyStore(key.keyStore); }
/** * Identify if the KeyStore has been modified through this implementation since the last call to save or load. * * @return {@code true} if the {@link KeyStore} has been modified, {@code false} otherwise. */ public boolean isModified() { return keyStoreSpi.isModified(); }
@Override public void engineDeleteEntry(String alias) throws KeyStoreException { super.engineDeleteEntry(alias); modified = true; }
public static Builder builder() { return new Builder(); }
@Override public String engineGetCertificateAlias(Certificate cert) { String alias = super.engineGetCertificateAlias(cert); return alias != null ? aliasPredicate.test(alias) ? alias : null : null; }
@Override public void engineSetKeyEntry(String alias, byte[] key, Certificate[] chain) throws KeyStoreException { getKeyStore().setKeyEntry(alias, key, chain); }
private static int forceReadCP(Reader r) throws IOException { final int i = readCP(r); if (i == -1) { throw log.unexpectedEof(); } return i; }
/** * Construct a new instance. * * @param delegate the delegate {@code KeyStore} (must not be {@code null}) */ public WrappingPasswordKeyStore(final KeyStore delegate) { super(new WrappingPasswordKeyStoreSpiImpl(delegate), delegate.getProvider(), delegate.getType()); } }
public AliasFilter add(final String alias) { return new AliasFilter(this) { @Override public boolean test(String t) { if (alias.equals(t)) { return true; } else { return previous.test(t); } } }; }
@Override public void engineSetKeyEntry(String alias, byte[] key, Certificate[] chain) throws KeyStoreException { super.engineSetKeyEntry(alias, key, chain); modified = true; }