final String algorithm = ModularCrypt.identifyAlgorithm(c); if (algorithm == null) { throw log.noAlgorithmForPassword(alias); pw = ModularCrypt.decode(c); } catch (InvalidKeySpecException e) { throw log.noAlgorithmForPassword(alias);
final int algorithmId = doIdentifyAlgorithm(cryptString); switch (algorithmId) { case A_CRYPT_MD5: { return parseUnixMD5CryptPasswordString(cryptString); return parseBCryptPasswordString(cryptString); return parseUnixSHA256CryptPasswordString(cryptString); return parseUnixSHA512CryptPasswordString(cryptString); return parseSunUnixMD5CryptPasswordString(ALGORITHM_SUN_CRYPT_MD5, cryptString); return parseSunUnixMD5CryptPasswordString(ALGORITHM_SUN_CRYPT_MD5_BARE_SALT, cryptString); return parseBSDUnixDESCryptPasswordString(cryptString); return parseUnixDESCryptPasswordString(cryptString);
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(); } } }
/** * Attempt to identify the algorithm used by the given crypt string password. * * @param chars the password crypt string characters * @return the algorithm name, or {@code null} if no algorithm could be guessed */ public static String identifyAlgorithm(char[] chars) { return getAlgorithmNameString(doIdentifyAlgorithm(chars)); }
/** * Decode the given string and creates a {@link Password} instance. * * @param cryptString the string representing the encoded format of the password * @return a {@link Password} instance created from the given string * @throws InvalidKeySpecException if the given password is not supported or could be decoded */ public static Password decode(String cryptString) throws InvalidKeySpecException { Assert.checkNotNullParam("cryptString", cryptString); return decode(cryptString.toCharArray()); }
/** * Encode the given {@link Password} to a string. * * @param password the password to encode * @return a string representing the encoded password * @throws InvalidKeySpecException if the given password is not supported or could be encoded */ public static String encodeAsString(Password password) throws InvalidKeySpecException { return getCryptStringToBuilder(password).toString(); }
int idx = lastIndexOf(chars, '$'); if (idx > 0) { if (chars[idx - 1] == '$') {
} else { format = MCF_FORMAT; passwordString = ModularCrypt.encodeAsString(password);
private void parsePassword(final List<Credential> credentials, final XMLStreamReader streamReader) throws XMLStreamException, RealmUnavailableException { parseCredential(streamReader, (algorithm, format, text) -> { try { if (BASE64_FORMAT.equals(format)) { if (algorithm == null) { throw ElytronMessages.log.fileSystemRealmMissingAttribute("algorithm", path, streamReader.getLocation().getLineNumber(), name); } byte[] passwordBytes = CodePointIterator.ofChars(text.toCharArray()).base64Decode().drain(); PasswordFactory passwordFactory = PasswordFactory.getInstance(algorithm); PasswordSpec passwordSpec = BasicPasswordSpecEncoding.decode(passwordBytes); if (passwordSpec != null) { credentials.add(new PasswordCredential(passwordFactory.generatePassword(passwordSpec))); } else { throw ElytronMessages.log.fileSystemRealmInvalidPasswordAlgorithm(algorithm, path, streamReader.getLocation().getLineNumber(), name); } } else if (MCF_FORMAT.equals(format)) { credentials.add(new PasswordCredential(ModularCrypt.decode(text))); } else { throw ElytronMessages.log.fileSystemRealmInvalidPasswordFormat(format, path, streamReader.getLocation().getLineNumber(), name); } } catch (InvalidKeySpecException | NoSuchAlgorithmException e) { throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), name); } }); }
/** * Attempt to identify the algorithm used by the given crypt string password. * * @param chars the password crypt string characters * @return the algorithm name, or {@code null} if no algorithm could be guessed */ public static String identifyAlgorithm(char[] chars) { return getAlgorithmNameString(doIdentifyAlgorithm(chars)); }
/** * Encode the given {@link Password} to a char array. * * @param password the password to encode * @return a char array representing the encoded password * @throws InvalidKeySpecException if the given password is not supported or could be encoded */ public static char[] encode(Password password) throws InvalidKeySpecException { StringBuilder b = getCryptStringToBuilder(password); char[] chars = new char[b.length()]; b.getChars(0, b.length(), chars, 0); return chars; }
int idx = lastIndexOf(chars, '$'); if (idx > 0) { if (chars[idx - 1] == '$') {
} else { format = MCF_FORMAT; passwordString = ModularCrypt.encodeAsString(password);
final int algorithmId = doIdentifyAlgorithm(cryptString); switch (algorithmId) { case A_CRYPT_MD5: { return parseUnixMD5CryptPasswordString(cryptString); return parseBCryptPasswordString(cryptString); return parseUnixSHA256CryptPasswordString(cryptString); return parseUnixSHA512CryptPasswordString(cryptString); return parseSunUnixMD5CryptPasswordString(ALGORITHM_SUN_CRYPT_MD5, cryptString); return parseSunUnixMD5CryptPasswordString(ALGORITHM_SUN_CRYPT_MD5_BARE_SALT, cryptString); return parseBSDUnixDESCryptPasswordString(cryptString); return parseUnixDESCryptPasswordString(cryptString);
if (s != null) { final char[] chars = s.toCharArray(); final String identified = ModularCrypt.identifyAlgorithm(chars); if (identified != null) { try { Password modularCryptPassword = ModularCrypt.decode(chars); if (log.isTraceEnabled()) { log.tracef("Key Mapper: Password credential created using Modular Crypt algorithm [%s]", identified);
/** * Decode the given string and creates a {@link Password} instance. * * @param cryptString the string representing the encoded format of the password * @return a {@link Password} instance created from the given string * @throws InvalidKeySpecException if the given password is not supported or could be decoded */ public static Password decode(String cryptString) throws InvalidKeySpecException { Assert.checkNotNullParam("cryptString", cryptString); return decode(cryptString.toCharArray()); }
/** * Attempt to identify the algorithm used by the given crypt string password. * * @param chars the password crypt string characters * @return the algorithm name, or {@code null} if no algorithm could be guessed */ public static String identifyAlgorithm(char[] chars) { return getAlgorithmNameString(doIdentifyAlgorithm(chars)); }
/** * Encode the given {@link Password} to a string. * * @param password the password to encode * @return a string representing the encoded password * @throws InvalidKeySpecException if the given password is not supported or could be encoded */ public static String encodeAsString(Password password) throws InvalidKeySpecException { return getCryptStringToBuilder(password).toString(); }
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(); } } }
int idx = lastIndexOf(chars, '$'); if (idx > 0) { if (chars[idx - 1] == '$') {