Search in sources :

Example 1 with JwtHeader

use of org.xdi.oxauth.model.jwt.JwtHeader in project oxAuth by GluuFederation.

the class JwtState method headerToJSONObject.

protected JSONObject headerToJSONObject() throws InvalidJwtException {
    JwtHeader jwtHeader = new JwtHeader();
    jwtHeader.setType(type);
    if (keyEncryptionAlgorithm != null && blockEncryptionAlgorithm != null) {
        jwtHeader.setAlgorithm(keyEncryptionAlgorithm);
        jwtHeader.setEncryptionMethod(blockEncryptionAlgorithm);
    } else {
        jwtHeader.setAlgorithm(signatureAlgorithm);
    }
    jwtHeader.setKeyId(keyId);
    return jwtHeader.toJsonObject();
}
Also used : JwtHeader(org.xdi.oxauth.model.jwt.JwtHeader)

Example 2 with JwtHeader

use of org.xdi.oxauth.model.jwt.JwtHeader in project oxAuth by GluuFederation.

the class JwtAuthorizationRequest method headerToJSONObject.

protected JSONObject headerToJSONObject() throws InvalidJwtException {
    JwtHeader jwtHeader = new JwtHeader();
    jwtHeader.setType(type);
    if (keyEncryptionAlgorithm != null && blockEncryptionAlgorithm != null) {
        jwtHeader.setAlgorithm(keyEncryptionAlgorithm);
        jwtHeader.setEncryptionMethod(blockEncryptionAlgorithm);
    } else {
        jwtHeader.setAlgorithm(signatureAlgorithm);
    }
    jwtHeader.setKeyId(keyId);
    return jwtHeader.toJsonObject();
}
Also used : JwtHeader(org.xdi.oxauth.model.jwt.JwtHeader)

Example 3 with JwtHeader

use of org.xdi.oxauth.model.jwt.JwtHeader in project oxAuth by GluuFederation.

the class AbstractJweDecrypter method decrypt.

@Override
public Jwe decrypt(String encryptedJwe) throws InvalidJweException {
    try {
        if (StringUtils.isBlank(encryptedJwe)) {
            return null;
        }
        String[] jweParts = encryptedJwe.split("\\.");
        if (jweParts.length != 5) {
            throw new InvalidJwtException("Invalid JWS format.");
        }
        String encodedHeader = jweParts[0];
        String encodedEncryptedKey = jweParts[1];
        String encodedInitializationVector = jweParts[2];
        String encodedCipherText = jweParts[3];
        String encodedIntegrityValue = jweParts[4];
        Jwe jwe = new Jwe();
        jwe.setEncodedHeader(encodedHeader);
        jwe.setEncodedEncryptedKey(encodedEncryptedKey);
        jwe.setEncodedInitializationVector(encodedInitializationVector);
        jwe.setEncodedCiphertext(encodedCipherText);
        jwe.setEncodedIntegrityValue(encodedIntegrityValue);
        jwe.setHeader(new JwtHeader(encodedHeader));
        keyEncryptionAlgorithm = KeyEncryptionAlgorithm.fromName(jwe.getHeader().getClaimAsString(JwtHeaderName.ALGORITHM));
        blockEncryptionAlgorithm = BlockEncryptionAlgorithm.fromName(jwe.getHeader().getClaimAsString(JwtHeaderName.ENCRYPTION_METHOD));
        byte[] contentMasterKey = decryptEncryptionKey(encodedEncryptedKey);
        byte[] initializationVector = Base64Util.base64urldecode(encodedInitializationVector);
        byte[] authenticationTag = Base64Util.base64urldecode(encodedIntegrityValue);
        byte[] additionalAuthenticatedData = jwe.getAdditionalAuthenticatedData().getBytes(Util.UTF8_STRING_ENCODING);
        String plainText = decryptCipherText(encodedCipherText, contentMasterKey, initializationVector, authenticationTag, additionalAuthenticatedData);
        jwe.setClaims(new JwtClaims(plainText));
        return jwe;
    } catch (InvalidJwtException e) {
        throw new InvalidJweException(e);
    } catch (UnsupportedEncodingException e) {
        throw new InvalidJweException(e);
    }
}
Also used : InvalidJwtException(org.xdi.oxauth.model.exception.InvalidJwtException) JwtHeader(org.xdi.oxauth.model.jwt.JwtHeader) JwtClaims(org.xdi.oxauth.model.jwt.JwtClaims) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidJweException(org.xdi.oxauth.model.exception.InvalidJweException)

Aggregations

JwtHeader (org.xdi.oxauth.model.jwt.JwtHeader)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvalidJweException (org.xdi.oxauth.model.exception.InvalidJweException)1 InvalidJwtException (org.xdi.oxauth.model.exception.InvalidJwtException)1 JwtClaims (org.xdi.oxauth.model.jwt.JwtClaims)1