/** * Get a byte iterator over the UTF-8 encoding of this code point iterator. * * @return the byte iterator */ public ByteIterator asUtf8() { return asUtf8(false); }
private byte[] createErrorMessage() { JsonObjectBuilder objectBuilder = Json.createObjectBuilder(); objectBuilder.add("status", "invalid_token"); Object asDiscoveryUrl = serverConfig.get(CONFIG_OPENID_CONFIGURATION_URL); if (asDiscoveryUrl != null) { objectBuilder.add(CONFIG_OPENID_CONFIGURATION_URL, asDiscoveryUrl.toString()); } return ByteIterator.ofBytes(objectBuilder.build().toString().getBytes()).base64Encode().asUtf8().drain(); } }
private static String getEncodedJson(JsonObject jsonObject) { return CodePointIterator.ofString(jsonObject.toString()).asUtf8().base64Encode(BASE64_URL, false).drainToString(); }
private static byte[] mask(final String algorithm, final char[] initialKeyMaterial, final int iterationCount, final byte[] salt, final char[] chars) throws InvalidKeySpecException { final Cipher cipher = getCipher(algorithm, initialKeyMaterial, iterationCount, salt, Cipher.ENCRYPT_MODE); try { return cipher.doFinal(CodePointIterator.ofChars(chars).asUtf8().drain()); } catch (IllegalBlockSizeException | BadPaddingException e) { throw new InvalidKeySpecException(e); } }
private static void composeCryptBasedPassword(ByteArrayOutputStream out, UnixDESCryptPassword password) throws IOException { out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() >> 6 & 0x3f)); out.write(ByteIterator.ofBytes(password.getHash()).base64Encode(ModularCrypt.MOD_CRYPT, false).asUtf8().drain()); }
if (ALGORITHM_SIMPLE_DIGEST_MD5.equals(algorithm)) { out.write(new byte[] { '{', 'm', 'd', '5', '}' }); out.write(ByteIterator.ofBytes(((SimpleDigestPassword)password).getDigest()).base64Encode().asUtf8().drain()); } else if (ALGORITHM_SIMPLE_DIGEST_SHA_1.equals(algorithm)) { out.write(new byte[]{'{','s','h','a','}'}); out.write(ByteIterator.ofBytes(((SimpleDigestPassword)password).getDigest()).base64Encode().asUtf8().drain()); } else if (ALGORITHM_SIMPLE_DIGEST_SHA_256.equals(algorithm)) { out.write(new byte[]{'{','s','h','a','2','5','6','}'}); out.write(ByteIterator.ofBytes(((SimpleDigestPassword)password).getDigest()).base64Encode().asUtf8().drain()); } else if (ALGORITHM_SIMPLE_DIGEST_SHA_384.equals(algorithm)) { out.write(new byte[]{'{','s','h','a','3','8','4','}'}); out.write(ByteIterator.ofBytes(((SimpleDigestPassword)password).getDigest()).base64Encode().asUtf8().drain()); } else if (ALGORITHM_SIMPLE_DIGEST_SHA_512.equals(algorithm)) { out.write(new byte[]{'{','s','h','a','5','1','2','}'}); out.write(ByteIterator.ofBytes(((SimpleDigestPassword)password).getDigest()).base64Encode().asUtf8().drain()); } else if (ALGORITHM_PASSWORD_SALT_DIGEST_MD5.equals(algorithm)) { out.write(new byte[]{'{','s','m','d','5','}'}); composeCryptBasedPassword(out, (UnixDESCryptPassword) password); } else if (ALGORITHM_CLEAR.equals(algorithm)) { return CodePointIterator.ofChars(((ClearPassword)password).getPassword()).asUtf8().drain(); } else { return null;
private JsonObject extractClaims(String encodedClaims) throws RealmUnavailableException { try { Base64.Decoder urlDecoder = Base64.getUrlDecoder(); CodePointIterator decodedClaims = CodePointIterator.ofUtf8Bytes(urlDecoder.decode(encodedClaims)); return Json.createReader(decodedClaims.asUtf8().asInputStream()).readObject(); } catch (Exception cause) { throw log.tokenRealmJwtParseFailed(cause); } }
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Content-Length", String.valueOf(params.length)); connection.setRequestProperty("Authorization", "Basic " + CodePointIterator.ofString(clientId + ":" + clientSecret).asUtf8().base64Encode().drainToString());
private static void composeBsdCryptBasedPassword(ByteArrayOutputStream out, BSDUnixDESCryptPassword password) throws IOException { out.write(ModularCrypt.MOD_CRYPT.encode(password.getIterationCount() & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getIterationCount() >> 6 & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getIterationCount() >> 12 & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getIterationCount() >> 18 & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() >> 6 & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() >> 12 & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() >> 18 & 0x3f)); out.write(ByteIterator.ofBytes(password.getHash()).base64Encode(ModularCrypt.MOD_CRYPT, false).asUtf8().drain()); }
public void store(final String credentialAlias, final Credential credential, final CredentialStore.ProtectionParameter protectionParameter) throws CredentialStoreException, UnsupportedCredentialTypeException { if (! modifiable) { throw log.nonModifiableCredentialStore("store"); } if (protectionParameter != null) { throw log.invalidProtectionParameter(protectionParameter); } // Vault can only store clear passwords; let's check out the type first. final char[] chars = credential.castAndApply(PasswordCredential.class, c -> c.getPassword().castAndApply(ClearPassword.class, ClearPassword::getPassword)); if (chars == null) { throw log.unsupportedCredentialType(credential.getClass()); } byte[] encoded; try { final Cipher cipher = Cipher.getInstance(adminKey.getAlgorithm()); cipher.init(Cipher.ENCRYPT_MODE, adminKey); encoded = cipher.doFinal(CodePointIterator.ofChars(chars).asUtf8().drain()); } catch (NoSuchAlgorithmException | IllegalBlockSizeException | BadPaddingException | NoSuchPaddingException | InvalidKeyException e) { throw log.cannotWriteCredentialToStore(e); } synchronized (data) { data.put(credentialAlias, encoded); } }
/** * Get the key authorization string for this challenge. * * @param account the ACME account information to use (must not be {@code null}) * @return the key authorization string for this challenge * @throws AcmeException if the key authorization string cannot be determined */ public String getKeyAuthorization(AcmeAccount account) throws AcmeException { Assert.checkNotNullParam("account", account); JsonObject jwk = getJwk(account.getPublicKey(), account.getAlgHeader()); byte[] jwkWithoutWhitespace = CodePointIterator.ofString(jwk.toString()).skip(Character::isWhitespace).skipCrLf().asUtf8().drain(); try { MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); messageDigest.update(jwkWithoutWhitespace); byte[] jwkThumbprint = messageDigest.digest(); return token + "." + base64UrlEncode(jwkThumbprint); } catch (NoSuchAlgorithmException e) { throw acme.unableToDetermineKeyAuthorizationString(e); } }
private static byte[] encodeClearPasswordSpec(ClearPasswordSpec keySpec) throws InvalidKeySpecException { byte[] passwordBytes = CodePointIterator.ofChars(keySpec.getEncodedPassword()).asUtf8().drain(); return new ByteStringBuilder().append(CLEAR_PASSWORD_SPEC_ID).append(passwordBytes).toArray(); }
private static byte[] composeDigestSalt(SaltedSimpleDigestPassword password) { return ByteIterator.ofBytes(new ByteStringBuilder() .append(password.getDigest()) .append(password.getSalt()) .toArray() ).base64Encode().asUtf8().drain(); }
final byte[] response = CodePointIterator.ofString(path).asUtf8(true).drain(); setNegotiationState(PROCESS_RESPONSE_STATE); return response;
final byte[] bytes; if (authorizationId != null) { bytes = CodePointIterator.ofString(authorizationId).asUtf8(true).drain(); } else { bytes = new byte[] { UTF8NUL };
private byte[] createErrorMessage() { JsonObjectBuilder objectBuilder = Json.createObjectBuilder(); objectBuilder.add("status", "invalid_token"); Object asDiscoveryUrl = serverConfig.get(CONFIG_OPENID_CONFIGURATION_URL); if (asDiscoveryUrl != null) { objectBuilder.add(CONFIG_OPENID_CONFIGURATION_URL, asDiscoveryUrl.toString()); } return ByteIterator.ofBytes(objectBuilder.build().toString().getBytes()).base64Encode().asUtf8().drain(); } }
private static byte[] mask(final String algorithm, final char[] initialKeyMaterial, final int iterationCount, final byte[] salt, final char[] chars) throws InvalidKeySpecException { final Cipher cipher = getCipher(algorithm, initialKeyMaterial, iterationCount, salt, Cipher.ENCRYPT_MODE); try { return cipher.doFinal(CodePointIterator.ofChars(chars).asUtf8().drain()); } catch (IllegalBlockSizeException | BadPaddingException e) { throw new InvalidKeySpecException(e); } }
private static void composeCryptBasedPassword(ByteArrayOutputStream out, UnixDESCryptPassword password) throws IOException { out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() >> 6 & 0x3f)); out.write(ByteIterator.ofBytes(password.getHash()).base64Encode(ModularCrypt.MOD_CRYPT, false).asUtf8().drain()); }
private static void composeBsdCryptBasedPassword(ByteArrayOutputStream out, BSDUnixDESCryptPassword password) throws IOException { out.write(ModularCrypt.MOD_CRYPT.encode(password.getIterationCount() & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getIterationCount() >> 6 & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getIterationCount() >> 12 & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getIterationCount() >> 18 & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() >> 6 & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() >> 12 & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() >> 18 & 0x3f)); out.write(ByteIterator.ofBytes(password.getHash()).base64Encode(ModularCrypt.MOD_CRYPT, false).asUtf8().drain()); }
private static byte[] composeDigestSalt(SaltedSimpleDigestPassword password) { return ByteIterator.ofBytes(new ByteStringBuilder() .append(password.getDigest()) .append(password.getSalt()) .toArray() ).base64Encode().asUtf8().drain(); }