/** * Get a code point iterator for a UTF-8 encoded byte array. * * @param bytes the array * @return the code point iterator */ public static CodePointIterator ofUtf8Bytes(final byte[] bytes) { return ofUtf8Bytes(bytes, 0, bytes.length); }
/** * <p>A default public key in its PEM format used to validate the signature of tokens without <code>kid</code> header parameter. * * <p>If not provided, the validator will not validate signatures. * * @param publicKeyPem the public key in its PEM format * @return this instance */ public Builder publicKey(byte[] publicKeyPem) { Iterator<PemEntry<?>> pemEntryIterator = Pem.parsePemContent(CodePointIterator.ofUtf8Bytes(publicKeyPem)); PublicKey publicKey = pemEntryIterator.next().tryCast(PublicKey.class); if (publicKey == null) { throw log.tokenRealmJwtInvalidPublicKeyPem(); } this.publicKey = publicKey; return this; }
private static Password createSimpleDigestPassword(String algorithm, int prefixSize, byte[] userPassword) throws InvalidKeySpecException { int length = userPassword.length - prefixSize; byte[] digest = CodePointIterator.ofUtf8Bytes(userPassword, prefixSize, length).base64Decode().drain(); return SimpleDigestPassword.createRaw(algorithm, digest); }
private static Password createSaltedSimpleDigestPassword(String algorithm, int prefixSize, byte[] userPassword) throws InvalidKeySpecException { int length = userPassword.length - prefixSize; byte[] decoded = CodePointIterator.ofUtf8Bytes(userPassword, prefixSize, length).base64Decode().drain(); int digestLength = expectedDigestLengthBytes(algorithm); int saltLength = decoded.length - digestLength; if (saltLength < 1) { throw log.insufficientDataToFormDigestAndSalt(); } byte[] digest = new byte[digestLength]; byte[] salt = new byte[saltLength]; System.arraycopy(decoded, 0, digest, 0, digestLength); System.arraycopy(decoded, digestLength, salt, 0, saltLength); return SaltedSimpleDigestPassword.createRaw(algorithm, digest, salt); }
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); } }
private static Password createCryptBasedPassword(byte[] userPassword) throws InvalidKeySpecException { if (userPassword.length != 20) { throw log.insufficientDataToFormDigestAndSalt(); } final int lo = ModularCrypt.MOD_CRYPT.decode(userPassword[7] & 0xff); final int hi = ModularCrypt.MOD_CRYPT.decode(userPassword[8] & 0xff); if (lo == -1 || hi == -1) { throw log.invalidSalt((char) lo, (char) hi); } short salt = (short) (lo | hi << 6); byte[] hash = CodePointIterator.ofUtf8Bytes(userPassword, 9, 11).base64Decode(ModularCrypt.MOD_CRYPT, false).drain(); return UnixDESCryptPassword.createRaw(ALGORITHM_CRYPT_DES, salt, hash); }
throw saslPlain.mechMessageTooLong().toSaslException(); CodePointIterator i = CodePointIterator.ofUtf8Bytes(response); String authorizationId; String loginName;
private static Password createBsdCryptBasedPassword(byte[] userPassword) throws InvalidKeySpecException { if (userPassword.length != 27) { throw log.insufficientDataToFormDigestAndSalt(); } int b0 = ModularCrypt.MOD_CRYPT.decode(userPassword[8] & 0xff); int b1 = ModularCrypt.MOD_CRYPT.decode(userPassword[9] & 0xff); int b2 = ModularCrypt.MOD_CRYPT.decode(userPassword[10] & 0xff); int b3 = ModularCrypt.MOD_CRYPT.decode(userPassword[11] & 0xff); if (b0 == -1 || b1 == -1 || b2 == -1 || b3 == -1) { throw log.invalidRounds((char) b0, (char) b1, (char) b2, (char) b3); } int iterationCount = b0 | b1 << 6 | b2 << 12 | b3 << 18; b0 = ModularCrypt.MOD_CRYPT.decode(userPassword[12] & 0xff); b1 = ModularCrypt.MOD_CRYPT.decode(userPassword[13] & 0xff); b2 = ModularCrypt.MOD_CRYPT.decode(userPassword[14] & 0xff); b3 = ModularCrypt.MOD_CRYPT.decode(userPassword[15] & 0xff); if (b0 == -1 || b1 == -1 || b2 == -1 || b3 == -1) { throw log.invalidSalt((char) b0, (char) b1, (char) b2, (char) b3); } int salt = b0 | b1 << 6 | b2 << 12 | b3 << 18; byte[] hash = CodePointIterator.ofUtf8Bytes(userPassword, 16, 11).base64Decode(ModularCrypt.MOD_CRYPT, false).drain(); return BSDUnixDESCryptPassword.createRaw(ALGORITHM_BSD_CRYPT_DES, hash, salt, iterationCount); }
final CodePointIterator cpi = CodePointIterator.ofUtf8Bytes(challenge); final CodePointIterator di = cpi.delimitedBy(' '); final String otp;
protected byte[] evaluateMessage(final int state, final byte[] response) throws SaslException { switch (state) { case ST_CHALLENGE: { final CodePointIterator cpi = CodePointIterator.ofUtf8Bytes(response); final CodePointIterator di = cpi.delimitedBy(0); final CodePointIterator cpi = CodePointIterator.ofUtf8Bytes(response); final CodePointIterator di = cpi.delimitedBy(':'); final String responseType = di.drainToString().toLowerCase(Locale.ENGLISH);
/** * Get a code point iterator for a UTF-8 encoded byte array. * * @param bytes the array * @return the code point iterator */ public static CodePointIterator ofUtf8Bytes(final byte[] bytes) { return ofUtf8Bytes(bytes, 0, bytes.length); }
/** * Get a code point iterator for a UTF-8 encoded byte array. * * @param bytes the array * @return the code point iterator */ public static CodePointIterator ofUtf8Bytes(final byte[] bytes) { return ofUtf8Bytes(bytes, 0, bytes.length); }
private static Password createSimpleDigestPassword(String algorithm, int prefixSize, byte[] userPassword) throws InvalidKeySpecException { int length = userPassword.length - prefixSize; byte[] digest = CodePointIterator.ofUtf8Bytes(userPassword, prefixSize, length).base64Decode().drain(); return SimpleDigestPassword.createRaw(algorithm, digest); }
private static Password createSimpleDigestPassword(String algorithm, int prefixSize, byte[] userPassword) throws InvalidKeySpecException { int length = userPassword.length - prefixSize; byte[] digest = CodePointIterator.ofUtf8Bytes(userPassword, prefixSize, length).base64Decode().drain(); return SimpleDigestPassword.createRaw(algorithm, digest); }
private static Password createSimpleDigestPassword(String algorithm, int prefixSize, byte[] userPassword) throws InvalidKeySpecException { int length = userPassword.length - prefixSize; byte[] digest = CodePointIterator.ofUtf8Bytes(userPassword, prefixSize, length).base64Decode().drain(); return SimpleDigestPassword.createRaw(algorithm, digest); }
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); } }
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); } }
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); } }
private static Password createCryptBasedPassword(byte[] userPassword) throws InvalidKeySpecException { if (userPassword.length != 20) { throw log.insufficientDataToFormDigestAndSalt(); } final int lo = ModularCrypt.MOD_CRYPT.decode(userPassword[7] & 0xff); final int hi = ModularCrypt.MOD_CRYPT.decode(userPassword[8] & 0xff); if (lo == -1 || hi == -1) { throw log.invalidSalt((char) lo, (char) hi); } short salt = (short) (lo | hi << 6); byte[] hash = CodePointIterator.ofUtf8Bytes(userPassword, 9, 11).base64Decode(ModularCrypt.MOD_CRYPT, false).drain(); return UnixDESCryptPassword.createRaw(ALGORITHM_CRYPT_DES, salt, hash); }
private static Password createCryptBasedPassword(byte[] userPassword) throws InvalidKeySpecException { if (userPassword.length != 20) { throw log.insufficientDataToFormDigestAndSalt(); } final int lo = ModularCrypt.MOD_CRYPT.decode(userPassword[7] & 0xff); final int hi = ModularCrypt.MOD_CRYPT.decode(userPassword[8] & 0xff); if (lo == -1 || hi == -1) { throw log.invalidSalt((char) lo, (char) hi); } short salt = (short) (lo | hi << 6); byte[] hash = CodePointIterator.ofUtf8Bytes(userPassword, 9, 11).base64Decode(ModularCrypt.MOD_CRYPT, false).drain(); return UnixDESCryptPassword.createRaw(ALGORITHM_CRYPT_DES, salt, hash); }