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 Key engineGetKey(final String alias, final char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException { final HashMap<String, PasswordEntry> map = pwRef.get(); if (map == null) return null; final PasswordEntry key = map.get(alias); if (key == null) return null; if (password != null) { throw log.invalidKeyStoreEntryPassword(alias); } return key.getPassword(); }
public void engineStore(final OutputStream stream, final char[] password) throws IOException, NoSuchAlgorithmException, CertificateException { final HashMap<String, PasswordEntry> map = pwRef.get(); if (map != null) { final OutputStreamWriter osw = new OutputStreamWriter(stream, StandardCharsets.UTF_8); final BufferedWriter bw = new BufferedWriter(osw); for (Map.Entry<String, PasswordEntry> entry : map.entrySet()) { final PasswordEntry passwordEntry = entry.getValue(); final Password pw = passwordEntry.getPassword(); final char[] chars; final String alias = entry.getKey(); try { chars = ModularCrypt.encode(pw); } catch (InvalidKeySpecException e) { throw log.keyStoreFailedToTranslate(alias, e); } bw.write(alias.replaceAll("([\\\\:])", "\\$1")); bw.write(':'); bw.write(chars); bw.write('\n'); // ensure that a broken file ends on a whole entry bw.flush(); } } }
public KeyStore.Entry engineGetEntry(final String alias, final KeyStore.ProtectionParameter protParam) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException { final KeyStore.Entry entry = delegate.getEntry(alias, protParam); if (entry instanceof KeyStore.SecretKeyEntry) { final SecretKey secretKey = ((KeyStore.SecretKeyEntry) entry).getSecretKey(); if ("password".equals(secretKey.getAlgorithm())) { return new PasswordEntry(decoded(secretKey)); } } return entry; }
public void engineSetEntry(final String alias, final KeyStore.Entry entry, final KeyStore.ProtectionParameter protParam) throws KeyStoreException { if (entry instanceof PasswordEntry) try { delegate.setEntry(alias, new KeyStore.SecretKeyEntry(encoded(((PasswordEntry) entry).getPassword())), protParam); } catch (InvalidKeyException e) { throw new KeyStoreException(e); }else { delegate.setEntry(alias, entry, protParam); } }
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); }
private static char[] keyStoreCredentialToPassword(ExceptionSupplier<KeyStore.Entry, ConfigXMLParseException> keyStoreCredential, Supplier<Provider[]> providers) throws GeneralSecurityException, ConfigXMLParseException { final KeyStore.Entry entry = keyStoreCredential == null ? null : keyStoreCredential.get(); if (entry instanceof PasswordEntry) { Password password = ((PasswordEntry) entry).getPassword(); final PasswordFactory passwordFactory = PasswordFactory.getInstance(password.getAlgorithm(), providers); password = passwordFactory.translate(password); final ClearPasswordSpec spec = passwordFactory.getKeySpec(password, ClearPasswordSpec.class); return spec.getEncodedPassword(); } else if (entry instanceof KeyStore.SecretKeyEntry) { final SecretKey secretKey = ((KeyStore.SecretKeyEntry) entry).getSecretKey(); final SecretKeyFactory instance = SecretKeyFactory.getInstance(secretKey.getAlgorithm()); final SecretKeySpec keySpec = (SecretKeySpec) instance.getKeySpec(secretKey, SecretKeySpec.class); final byte[] encoded = keySpec.getEncoded(); return encoded == null ? null : new String(encoded, StandardCharsets.UTF_8).toCharArray(); } else { return null; } }
throw log.noAlgorithmForPassword(alias); map.put(alias, new PasswordEntry(pw)); while (ch != '\n') { ch = forceReadCP(br);
final PasswordEntry passwordEntry = (PasswordEntry) entry; if (credentialType.isAssignableFrom(PasswordCredential.class)) { credential = new PasswordCredential(passwordEntry.getPassword()); } else { return null;
if (keyStoreCredential != null) throw reader.unexpectedElement(); ExceptionSupplier<Password, ConfigXMLParseException> credential = parseClearPassword(reader, providers); keyStoreCredential = () -> new PasswordEntry(credential.get()); break; throw new ConfigXMLParseException(xmlLog.couldNotObtainCredential(), reader); return new PasswordEntry(passwordCredential.getPassword()); } catch (IOException e) { throw xmlLog.xmlFailedToCreateCredential(nestedLocation, e);
/** * Convert a key store entry into a credential object. * * @param keyStoreEntry the key store entry to convert (must not be {@code null}) * @return the corresponding credential, or {@code null} if the entry type is unrecognized */ static Credential fromKeyStoreEntry(KeyStore.Entry keyStoreEntry) { Assert.checkNotNullParam("keyStoreEntry", keyStoreEntry); if (keyStoreEntry instanceof PasswordEntry) { return new PasswordCredential(((PasswordEntry) keyStoreEntry).getPassword()); } else if (keyStoreEntry instanceof KeyStore.PrivateKeyEntry) { return new X509CertificateChainPrivateCredential(((KeyStore.PrivateKeyEntry) keyStoreEntry).getPrivateKey(), X500.asX509CertificateArray(((KeyStore.PrivateKeyEntry) keyStoreEntry).getCertificateChain())); } else if (keyStoreEntry instanceof KeyStore.TrustedCertificateEntry) { return new X509CertificateChainPublicCredential((X509Certificate) ((KeyStore.TrustedCertificateEntry) keyStoreEntry).getTrustedCertificate()); } else if (keyStoreEntry instanceof KeyStore.SecretKeyEntry) { return new SecretKeyCredential(((KeyStore.SecretKeyEntry) keyStoreEntry).getSecretKey()); } else { return null; } } }
if (keyStoreCredential != null) throw reader.unexpectedElement(); ExceptionSupplier<Password, ConfigXMLParseException> credential = parseClearPassword(reader, providers); keyStoreCredential = () -> new PasswordEntry(credential.get()); break; throw new ConfigXMLParseException(xmlLog.couldNotObtainCredential(), reader); return new PasswordEntry(passwordCredential.getPassword()); } catch (IOException e) { throw xmlLog.xmlFailedToCreateCredential(nestedLocation, e);
final KeyStore.Entry entry = entryFactory.get(); if (entry instanceof PasswordEntry) try { final Password password = ((PasswordEntry) entry).getPassword(); final PasswordFactory passwordFactory1 = PasswordFactory.getInstance(password.getAlgorithm(), providersSupplier); final ClearPasswordSpec passwordSpec = passwordFactory1.getKeySpec(password, ClearPasswordSpec.class);
@ManagedBean(name = "entry") @ViewScoped public class PasswordEntryBean implements Serializable { //other attributes... private PasswordEntry passwordEntry; private PasswordEntry passwordEntryV; private PasswordEntry conPasswordEntry; //<editor-fold defaultstate="collapsed" desc="CONSTRUCTORS"> public PasswordEntryBean() { passwordEntry = new PasswordEntry(); passwordEntryV = new PasswordEntry(); conPasswordEntry = new PasswordEntry(); } //getters and setters... }
public Key engineGetKey(final String alias, final char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException { final HashMap<String, PasswordEntry> map = pwRef.get(); if (map == null) return null; final PasswordEntry key = map.get(alias); if (key == null) return null; if (password != null) { throw log.invalidKeyStoreEntryPassword(alias); } return key.getPassword(); }
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 Key engineGetKey(final String alias, final char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException { final HashMap<String, PasswordEntry> map = pwRef.get(); if (map == null) return null; final PasswordEntry key = map.get(alias); if (key == null) return null; if (password != null) { throw log.invalidKeyStoreEntryPassword(alias); } return key.getPassword(); }
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 Key engineGetKey(final String alias, final char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException { final HashMap<String, PasswordEntry> map = pwRef.get(); if (map == null) return null; final PasswordEntry key = map.get(alias); if (key == null) return null; if (password != null) { throw log.invalidKeyStoreEntryPassword(alias); } return key.getPassword(); }
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); } }