Search in sources :

Example 1 with DigestVerifier

use of org.apache.cxf.rs.security.httpsignature.DigestVerifier in project cxf by apache.

the class AbstractSignatureInFilter method verifyDigest.

protected byte[] verifyDigest(MultivaluedMap<String, String> headers, InputStream entityStream) {
    byte[] messageBody = null;
    if (!enabled) {
        return messageBody;
    }
    // configuration to require that the digest is signed (and hence present)
    if (entityStream != null && headers.containsKey("Digest")) {
        LOG.fine("Digesting message body");
        try {
            messageBody = IOUtils.readBytesFromStream(entityStream);
        } catch (IOException e) {
            throw new DigestFailureException("failed to validate the digest", e);
        }
        DigestVerifier digestVerifier = new DigestVerifier();
        try {
            digestVerifier.inspectDigest(messageBody, headers);
        } catch (DigestFailureException | DifferentDigestsException | MissingDigestException ex) {
            Message message = PhaseInterceptorChain.getCurrentMessage();
            if (MessageUtils.isRequestor(message)) {
                throw ex;
            }
            throw new BadRequestException(ex);
        }
    }
    LOG.fine("Finished digest message verification process");
    return messageBody;
}
Also used : Message(org.apache.cxf.message.Message) DigestFailureException(org.apache.cxf.rs.security.httpsignature.exception.DigestFailureException) BadRequestException(javax.ws.rs.BadRequestException) IOException(java.io.IOException) MissingDigestException(org.apache.cxf.rs.security.httpsignature.exception.MissingDigestException) DifferentDigestsException(org.apache.cxf.rs.security.httpsignature.exception.DifferentDigestsException) DigestVerifier(org.apache.cxf.rs.security.httpsignature.DigestVerifier)

Aggregations

IOException (java.io.IOException)1 BadRequestException (javax.ws.rs.BadRequestException)1 Message (org.apache.cxf.message.Message)1 DigestVerifier (org.apache.cxf.rs.security.httpsignature.DigestVerifier)1 DifferentDigestsException (org.apache.cxf.rs.security.httpsignature.exception.DifferentDigestsException)1 DigestFailureException (org.apache.cxf.rs.security.httpsignature.exception.DigestFailureException)1 MissingDigestException (org.apache.cxf.rs.security.httpsignature.exception.MissingDigestException)1