Search in sources :

Example 6 with JweDecryptionOutput

use of org.apache.cxf.rs.security.jose.jwe.JweDecryptionOutput in project cxf by apache.

the class JweJsonClientResponseFilter method filter.

@Override
public void filter(ClientRequestContext req, ClientResponseContext res) throws IOException {
    if (isMethodWithNoContent(req.getMethod()) || isCheckEmptyStream() && !res.hasEntity()) {
        return;
    }
    JweDecryptionOutput out = decrypt(res.getEntityStream());
    byte[] bytes = out.getContent();
    res.setEntityStream(new ByteArrayInputStream(bytes));
    res.getHeaders().putSingle("Content-Length", Integer.toString(bytes.length));
    String ct = JoseUtils.checkContentType(out.getHeaders().getContentType(), getDefaultMediaType());
    if (ct != null) {
        res.getHeaders().putSingle("Content-Type", ct);
    }
    if (super.isValidateHttpHeaders()) {
        super.validateHttpHeadersIfNeeded(res.getHeaders(), out.getHeaders());
    }
}
Also used : JweDecryptionOutput(org.apache.cxf.rs.security.jose.jwe.JweDecryptionOutput) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 7 with JweDecryptionOutput

use of org.apache.cxf.rs.security.jose.jwe.JweDecryptionOutput in project cxf by apache.

the class BookStore method getRecipientText.

private String getRecipientText(JweJsonConsumer consumer, String recipientPropLoc, String recipientKid) {
    Message message = JAXRSUtils.getCurrentMessage();
    Properties recipientProps = JweUtils.loadJweProperties(message, recipientPropLoc);
    JsonWebKey recipientKey = JwkUtils.loadJwkSet(message, recipientProps, null).getKey(recipientKid);
    ContentAlgorithm contentEncryptionAlgorithm = JweUtils.getContentEncryptionAlgorithm(recipientProps);
    JweDecryptionProvider jweRecipient = JweUtils.createJweDecryptionProvider(recipientKey, contentEncryptionAlgorithm);
    JweDecryptionOutput jweRecipientOutput = consumer.decryptWith(jweRecipient, Collections.singletonMap("kid", recipientKid));
    return jweRecipientOutput.getContentText();
}
Also used : JweDecryptionOutput(org.apache.cxf.rs.security.jose.jwe.JweDecryptionOutput) Message(org.apache.cxf.message.Message) ContentAlgorithm(org.apache.cxf.rs.security.jose.jwa.ContentAlgorithm) JsonWebKey(org.apache.cxf.rs.security.jose.jwk.JsonWebKey) JweDecryptionProvider(org.apache.cxf.rs.security.jose.jwe.JweDecryptionProvider) Properties(java.util.Properties)

Example 8 with JweDecryptionOutput

use of org.apache.cxf.rs.security.jose.jwe.JweDecryptionOutput in project cxf by apache.

the class AbstractJweJsonDecryptingFilter method decrypt.

protected JweDecryptionOutput decrypt(InputStream is) throws IOException {
    JweJsonConsumer c = new JweJsonConsumer(new String(IOUtils.readBytesFromStream(is), StandardCharsets.UTF_8));
    JweDecryptionProvider theProvider = getInitializedDecryptionProvider(c.getProtectedHeader());
    JweJsonEncryptionEntry entry = c.getJweDecryptionEntry(theProvider, recipientProperties);
    if (entry == null) {
        throw new JweException(JweException.Error.INVALID_JSON_JWE);
    }
    JweDecryptionOutput out = c.decryptWith(theProvider, entry);
    JAXRSUtils.getCurrentMessage().put(JweJsonConsumer.class, c);
    JAXRSUtils.getCurrentMessage().put(JweJsonEncryptionEntry.class, entry);
    return out;
}
Also used : JweDecryptionOutput(org.apache.cxf.rs.security.jose.jwe.JweDecryptionOutput) JweException(org.apache.cxf.rs.security.jose.jwe.JweException) JweJsonConsumer(org.apache.cxf.rs.security.jose.jwe.JweJsonConsumer) JweDecryptionProvider(org.apache.cxf.rs.security.jose.jwe.JweDecryptionProvider) JweJsonEncryptionEntry(org.apache.cxf.rs.security.jose.jwe.JweJsonEncryptionEntry)

Example 9 with JweDecryptionOutput

use of org.apache.cxf.rs.security.jose.jwe.JweDecryptionOutput in project cxf by apache.

the class JweClientResponseFilter method filter.

@Override
public void filter(ClientRequestContext req, ClientResponseContext res) throws IOException {
    if (isMethodWithNoContent(req.getMethod()) || isCheckEmptyStream() && !res.hasEntity()) {
        return;
    }
    JweDecryptionOutput out = decrypt(res.getEntityStream());
    byte[] bytes = out.getContent();
    res.setEntityStream(new ByteArrayInputStream(bytes));
    res.getHeaders().putSingle("Content-Length", Integer.toString(bytes.length));
    String ct = JoseUtils.checkContentType(out.getHeaders().getContentType(), getDefaultMediaType());
    if (ct != null) {
        res.getHeaders().putSingle("Content-Type", ct);
    }
    if (super.isValidateHttpHeaders()) {
        super.validateHttpHeadersIfNeeded(res.getHeaders(), out.getHeaders());
    }
}
Also used : JweDecryptionOutput(org.apache.cxf.rs.security.jose.jwe.JweDecryptionOutput) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 10 with JweDecryptionOutput

use of org.apache.cxf.rs.security.jose.jwe.JweDecryptionOutput in project cxf by apache.

the class JweJsonContainerRequestFilter method filter.

@Override
public void filter(ContainerRequestContext context) throws IOException {
    if (isMethodWithNoContent(context.getMethod()) || isCheckEmptyStream() && !context.hasEntity()) {
        return;
    }
    try {
        JweDecryptionOutput out = decrypt(context.getEntityStream());
        byte[] bytes = out.getContent();
        context.setEntityStream(new ByteArrayInputStream(bytes));
        context.getHeaders().putSingle("Content-Length", Integer.toString(bytes.length));
        String ct = JoseUtils.checkContentType(out.getHeaders().getContentType(), getDefaultMediaType());
        if (ct != null) {
            context.getHeaders().putSingle("Content-Type", ct);
        }
        if (super.isValidateHttpHeaders()) {
            super.validateHttpHeadersIfNeeded(context.getHeaders(), out.getHeaders());
        }
    } catch (JweException ex) {
        context.abortWith(JAXRSUtils.toResponse(400));
        return;
    }
}
Also used : JweDecryptionOutput(org.apache.cxf.rs.security.jose.jwe.JweDecryptionOutput) JweException(org.apache.cxf.rs.security.jose.jwe.JweException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

JweDecryptionOutput (org.apache.cxf.rs.security.jose.jwe.JweDecryptionOutput)12 JweDecryptionProvider (org.apache.cxf.rs.security.jose.jwe.JweDecryptionProvider)7 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Properties (java.util.Properties)4 JweJwtCompactConsumer (org.apache.cxf.rs.security.jose.jwe.JweJwtCompactConsumer)4 JwsJwtCompactConsumer (org.apache.cxf.rs.security.jose.jws.JwsJwtCompactConsumer)4 KeyStore (java.security.KeyStore)3 JwtToken (org.apache.cxf.rs.security.jose.jwt.JwtToken)3 SignatureProperties (org.apache.cxf.sts.SignatureProperties)3 StaticSTSProperties (org.apache.cxf.sts.StaticSTSProperties)3 EncryptionProperties (org.apache.cxf.sts.service.EncryptionProperties)3 JWTTokenProvider (org.apache.cxf.sts.token.provider.jwt.JWTTokenProvider)3 Crypto (org.apache.wss4j.common.crypto.Crypto)3 Merlin (org.apache.wss4j.common.crypto.Merlin)3 JweCompactConsumer (org.apache.cxf.rs.security.jose.jwe.JweCompactConsumer)2 JweException (org.apache.cxf.rs.security.jose.jwe.JweException)2 Message (org.apache.cxf.message.Message)1 ContentAlgorithm (org.apache.cxf.rs.security.jose.jwa.ContentAlgorithm)1 JweHeaders (org.apache.cxf.rs.security.jose.jwe.JweHeaders)1 JweJsonConsumer (org.apache.cxf.rs.security.jose.jwe.JweJsonConsumer)1