private static SecretKey encoded(final Password password) throws InvalidKeyException { if (password instanceof ClearPassword) { return new SecretKeySpec(new String(((ClearPassword)password).getPassword()).getBytes(StandardCharsets.UTF_8), "password"); } else { throw ElytronMessages.log.invalidKeyUnknownUnknownPasswordTypeOrAlgorithm(); } }
private static Password createClearPassword(int skip, byte[] userPassword) { if (skip != 0) userPassword = Arrays.copyOfRange(userPassword, skip, userPassword.length); return ClearPassword.createRaw(ALGORITHM_CLEAR, new String(userPassword, StandardCharsets.UTF_8).toCharArray()); }
password = credential.getPassword(ClearPassword.class); if (password == null) throw log.couldNotObtainCredential(); charPassword = password.getPassword(); } catch (Exception e) { throw log.couldNotObtainCredentialWithCause(e); } finally { try { if (password != null) password.destroy(); } catch (DestroyFailedException e){ log.credentialDestroyingFailed(e); password = credential.getPassword(ClearPassword.class); if (password == null) throw log.couldNotObtainCredential(); charPassword = password.getPassword(); } catch (Exception e) { throw log.obtainingDirContextCredentialFromAuthenticationContextFailed(e); } finally { try { if (password != null) password.destroy(); } catch (DestroyFailedException e){ log.credentialDestroyingFailed(e);
ClearPasswordImpl(ClearPassword clearPassword) { password = clearPassword.getPassword().clone(); }
private static Password decoded(final SecretKey key) { return ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, new String(key.getEncoded(), StandardCharsets.UTF_8).toCharArray()); }
password = credential.getPassword(ClearPassword.class); if (password == null) throw log.couldNotObtainCredential(); charPassword = password.getPassword(); } catch (Exception e) { throw log.couldNotObtainCredentialWithCause(e); } finally { try { if (password != null) password.destroy(); } catch (DestroyFailedException e){ log.credentialDestroyingFailed(e); password = credential.getPassword(ClearPassword.class); if (password == null) throw log.couldNotObtainCredential(); charPassword = password.getPassword(); } catch (Exception e) { throw log.obtainingDirContextCredentialFromAuthenticationContextFailed(e); } finally { try { if (password != null) password.destroy(); } catch (DestroyFailedException e){ log.credentialDestroyingFailed(e);
@Override public String apply(CredentialSource sharedSecretSource) { try { PasswordCredential credential = sharedSecretSource.getCredential(PasswordCredential.class); ClearPassword password = credential.getPassword(ClearPassword.class); return String.valueOf(password.getPassword()); } catch (IOException e) { throw new IllegalArgumentException(e); } } };
/** * Create a new configuration which is the same as this configuration, but which uses the given password to authenticate. * * @param password the password to use * @return the new configuration */ public AuthenticationConfiguration usePassword(char[] password) { return usePassword(password == null ? null : ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, password)); }
password = credential.getPassword(ClearPassword.class); if (password == null) throw log.couldNotObtainCredential(); charPassword = password.getPassword(); } catch (Exception e) { throw log.couldNotObtainCredentialWithCause(e); } finally { try { if (password != null) password.destroy(); } catch (DestroyFailedException e){ log.credentialDestroyingFailed(e); password = credential.getPassword(ClearPassword.class); if (password == null) throw log.couldNotObtainCredential(); charPassword = password.getPassword(); } catch (Exception e) { throw log.obtainingDirContextCredentialFromAuthenticationContextFailed(e); } finally { try { if (password != null) password.destroy(); } catch (DestroyFailedException e){ log.credentialDestroyingFailed(e);
public final String getPassword() { if (credentialSourceSupplier != null) { try { return new String( credentialSourceSupplier.get().getCredential(PasswordCredential.class).getPassword(ClearPassword.class).getPassword()); } catch (Exception e) { throw ConnectorLogger.DEPLOYMENT_CONNECTOR_LOGGER.invalidCredentialSourceSupplier(e); } } return this.password; }
/** * Create a new configuration which is the same as this configuration, but which uses the given password to authenticate. * * @param password the password to use * @return the new configuration */ public AuthenticationConfiguration usePassword(String password) { return usePassword(password == null ? null : ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, password.toCharArray())); }
password = credential.getPassword(ClearPassword.class); if (password == null) throw log.couldNotObtainCredential(); charPassword = password.getPassword(); } catch (Exception e) { throw log.couldNotObtainCredentialWithCause(e); } finally { try { if (password != null) password.destroy(); } catch (DestroyFailedException e){ log.credentialDestroyingFailed(e); password = credential.getPassword(ClearPassword.class); if (password == null) throw log.couldNotObtainCredential(); charPassword = password.getPassword(); } catch (Exception e) { throw log.obtainingDirContextCredentialFromAuthenticationContextFailed(e); } finally { try { if (password != null) password.destroy(); } catch (DestroyFailedException e){ log.credentialDestroyingFailed(e);
public Credentials getCredentials() { ExceptionSupplier<CredentialSource, Exception> credentialSourceSupplier = credentialSourceSupplierInjector.getOptionalValue(); if (credentialSourceSupplier != null) { try { CredentialSource credentialSource = credentialSourceSupplier.get(); if (credentialSource == null) { return credentials; } char[] password = credentialSource.getCredential(PasswordCredential.class).getPassword(ClearPassword.class).getPassword(); return new Credentials(credentials.getUsername(), new String(password)); } catch (Exception e) { throw new RuntimeException(e); } } else { return credentials; } }
Object writeReplace() { return ClearPassword.createRaw(getAlgorithm(), password); }
@Override public SingleSignOnSessionFactory get() { KeyStore store = this.keyStore.get(); String alias = this.keyAlias; CredentialSource source = this.credentialSource.get(); try { if (!store.containsAlias(alias)) { throw UndertowLogger.ROOT_LOGGER.missingKeyStoreEntry(alias); } if (!store.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) { throw UndertowLogger.ROOT_LOGGER.keyStoreEntryNotPrivate(alias); } PasswordCredential credential = source.getCredential(PasswordCredential.class); if (credential == null) { throw UndertowLogger.ROOT_LOGGER.missingCredential(source.toString()); } ClearPassword password = credential.getPassword(ClearPassword.class); if (password == null) { throw UndertowLogger.ROOT_LOGGER.credentialNotClearPassword(credential.toString()); } KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) store.getEntry(alias, new KeyStore.PasswordProtection(password.getPassword())); KeyPair keyPair = new KeyPair(entry.getCertificate().getPublicKey(), entry.getPrivateKey()); Optional<SSLContext> context = Optional.ofNullable(this.sslContext).map(dependency -> dependency.get()); return new DefaultSingleSignOnSessionFactory(this.manager.get(), keyPair, connection -> context.ifPresent(ctx -> connection.setSSLSocketFactory(ctx.getSocketFactory()))); } catch (GeneralSecurityException | IOException e) { throw new IllegalArgumentException(e); } } }
public <C extends Credential> C getCredential(final Class<C> credentialType, final String algorithmName, final AlgorithmParameterSpec parameterSpec) throws IOException { if (PasswordCredential.class.isAssignableFrom(credentialType) && (algorithmName == null || algorithmName.equals(ClearPassword.ALGORITHM_CLEAR)) && parameterSpec == null) { try { final PasswordCallback passwordCallback = new PasswordCallback("Password", false); callbackHandler.handle(new Callback[] { passwordCallback }); final char[] chars = passwordCallback.getPassword(); return chars == null ? null : credentialType.cast(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, chars))); } catch (UnsupportedCallbackException e) { // fall out and try CredentialCallback } } try { final CredentialCallback credentialCallback = new CredentialCallback(credentialType, algorithmName, parameterSpec); callbackHandler.handle(new Callback[] { credentialCallback }); return credentialCallback.getCredential(credentialType, algorithmName, parameterSpec); } catch (UnsupportedCallbackException e) { // no credentials can be acquired; fall out } return null; } }
composeCryptBasedPassword(out, (UnixDESCryptPassword) password); } else if (ALGORITHM_CLEAR.equals(algorithm)) { return CodePointIterator.ofChars(((ClearPassword)password).getPassword()).asUtf8().drain(); } else { return null;
public <C extends Credential> C retrieve(final String credentialAlias, final Class<C> credentialType, final String credentialAlgorithm, final AlgorithmParameterSpec parameterSpec, final CredentialStore.ProtectionParameter protectionParameter) throws CredentialStoreException { if (protectionParameter != null) { throw log.invalidProtectionParameter(protectionParameter); } if (! credentialType.isAssignableFrom(PasswordCredential.class)) { return null; } if (credentialAlgorithm != null && ! credentialAlgorithm.equals(ClearPassword.ALGORITHM_CLEAR)) { return null; } if (parameterSpec != null) { return null; } final byte[] bytes; synchronized (data) { bytes = data.get(credentialAlias); } // decode final byte[] decoded; try { final Cipher cipher = Cipher.getInstance(adminKey.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, adminKey); decoded = cipher.doFinal(bytes); } catch (NoSuchAlgorithmException | IllegalBlockSizeException | BadPaddingException | NoSuchPaddingException | InvalidKeyException e) { throw log.cannotAcquireCredentialFromStore(e); } return credentialType.cast(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, new String(decoded, StandardCharsets.UTF_8).toCharArray()))); }
@Override public CipherAuthToken apply(String authValue) { KeyStore store = this.keyStore.get(); String alias = this.keyAlias; try { if (!store.containsAlias(alias)) { throw JGroupsLogger.ROOT_LOGGER.keyEntryNotFound(alias); } if (!store.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) { throw JGroupsLogger.ROOT_LOGGER.unexpectedKeyStoreEntryType(alias, KeyStore.PrivateKeyEntry.class.getSimpleName()); } PasswordCredential credential = this.keyCredentialSource.get().getCredential(PasswordCredential.class); if (credential == null) { throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource(); } ClearPassword password = credential.getPassword(ClearPassword.class); if (password == null) { throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource(); } KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) store.getEntry(alias, new KeyStore.PasswordProtection(password.getPassword())); KeyPair pair = new KeyPair(entry.getCertificate().getPublicKey(), entry.getPrivateKey()); Cipher cipher = Cipher.getInstance(this.transformation); return new CipherAuthToken(cipher, pair, authValue.getBytes(StandardCharsets.UTF_8)); } catch (GeneralSecurityException | IOException e) { throw new IllegalArgumentException(e); } } }
return credentialType.cast(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, line.toCharArray()))); } finally {