Java Code Examples for com.sun.org.apache.xml.internal.security.algorithms.MessageDigestAlgorithm

The following examples show how to use com.sun.org.apache.xml.internal.security.algorithms.MessageDigestAlgorithm. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: jdk1.8-source-analysis   Source File: Reference.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns {@link MessageDigestAlgorithm}
 *
 *
 * @return {@link MessageDigestAlgorithm}
 *
 * @throws XMLSignatureException
 */
public MessageDigestAlgorithm getMessageDigestAlgorithm() throws XMLSignatureException {
    if (digestMethodElem == null) {
        return null;
    }

    String uri = digestMethodElem.getAttributeNS(null, Constants._ATT_ALGORITHM);

    if (uri == null) {
        return null;
    }

    if (secureValidation && MessageDigestAlgorithm.ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5.equals(uri)) {
        Object exArgs[] = { uri };

        throw new XMLSignatureException("signature.signatureAlgorithm", exArgs);
    }

    return MessageDigestAlgorithm.getInstance(this.doc, uri);
}
 
Example 2
Source Project: jdk1.8-source-analysis   Source File: Reference.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 3
Source Project: jdk1.8-source-analysis   Source File: IntegrityHmac.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Proxy method for {@link java.security.Signature#verify(byte[])}
 * which is executed on the internal {@link java.security.Signature} object.
 *
 * @param signature
 * @return true if the signature is correct
 * @throws XMLSignatureException
 */
protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
    try {
        if (this.HMACOutputLengthSet && this.HMACOutputLength < getDigestLength()) {
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "HMACOutputLength must not be less than " + getDigestLength());
            }
            Object[] exArgs = { String.valueOf(getDigestLength()) };
            throw new XMLSignatureException("algorithms.HMACOutputLengthMin", exArgs);
        } else {
            byte[] completeResult = this.macAlgorithm.doFinal();
            return MessageDigestAlgorithm.isEqual(completeResult, signature);
        }
    } catch (IllegalStateException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
 
Example 4
Source Project: dragonwell8_jdk   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns {@link MessageDigestAlgorithm}
 *
 *
 * @return {@link MessageDigestAlgorithm}
 *
 * @throws XMLSignatureException
 */
public MessageDigestAlgorithm getMessageDigestAlgorithm() throws XMLSignatureException {
    if (digestMethodElem == null) {
        return null;
    }

    String uri = digestMethodElem.getAttributeNS(null, Constants._ATT_ALGORITHM);

    if (uri == null) {
        return null;
    }

    if (secureValidation && MessageDigestAlgorithm.ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5.equals(uri)) {
        Object exArgs[] = { uri };

        throw new XMLSignatureException("signature.signatureAlgorithm", exArgs);
    }

    return MessageDigestAlgorithm.getInstance(this.doc, uri);
}
 
Example 5
Source Project: dragonwell8_jdk   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 6
/**
 * Proxy method for {@link java.security.Signature#verify(byte[])}
 * which is executed on the internal {@link java.security.Signature} object.
 *
 * @param signature
 * @return true if the signature is correct
 * @throws XMLSignatureException
 */
protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
    try {
        if (this.HMACOutputLengthSet && this.HMACOutputLength < getDigestLength()) {
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "HMACOutputLength must not be less than " + getDigestLength());
            }
            Object[] exArgs = { String.valueOf(getDigestLength()) };
            throw new XMLSignatureException("algorithms.HMACOutputLengthMin", exArgs);
        } else {
            byte[] completeResult = this.macAlgorithm.doFinal();
            return MessageDigestAlgorithm.isEqual(completeResult, signature);
        }
    } catch (IllegalStateException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
 
Example 7
Source Project: jdk8u-jdk   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns {@link MessageDigestAlgorithm}
 *
 *
 * @return {@link MessageDigestAlgorithm}
 *
 * @throws XMLSignatureException
 */
public MessageDigestAlgorithm getMessageDigestAlgorithm() throws XMLSignatureException {
    if (digestMethodElem == null) {
        return null;
    }

    String uri = digestMethodElem.getAttributeNS(null, Constants._ATT_ALGORITHM);

    if (uri == null) {
        return null;
    }

    if (secureValidation && MessageDigestAlgorithm.ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5.equals(uri)) {
        Object exArgs[] = { uri };

        throw new XMLSignatureException("signature.signatureAlgorithm", exArgs);
    }

    return MessageDigestAlgorithm.getInstance(this.doc, uri);
}
 
Example 8
Source Project: TencentKona-8   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 9
Source Project: TencentKona-8   Source File: IntegrityHmac.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Proxy method for {@link java.security.Signature#verify(byte[])}
 * which is executed on the internal {@link java.security.Signature} object.
 *
 * @param signature
 * @return true if the signature is correct
 * @throws XMLSignatureException
 */
protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
    try {
        if (this.HMACOutputLengthSet && this.HMACOutputLength < getDigestLength()) {
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "HMACOutputLength must not be less than " + getDigestLength());
            }
            Object[] exArgs = { String.valueOf(getDigestLength()) };
            throw new XMLSignatureException("algorithms.HMACOutputLengthMin", exArgs);
        } else {
            byte[] completeResult = this.macAlgorithm.doFinal();
            return MessageDigestAlgorithm.isEqual(completeResult, signature);
        }
    } catch (IllegalStateException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
 
Example 10
Source Project: jdk8u60   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns {@link MessageDigestAlgorithm}
 *
 *
 * @return {@link MessageDigestAlgorithm}
 *
 * @throws XMLSignatureException
 */
public MessageDigestAlgorithm getMessageDigestAlgorithm() throws XMLSignatureException {
    if (digestMethodElem == null) {
        return null;
    }

    String uri = digestMethodElem.getAttributeNS(null, Constants._ATT_ALGORITHM);

    if (uri == null) {
        return null;
    }

    if (secureValidation && MessageDigestAlgorithm.ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5.equals(uri)) {
        Object exArgs[] = { uri };

        throw new XMLSignatureException("signature.signatureAlgorithm", exArgs);
    }

    return MessageDigestAlgorithm.getInstance(this.doc, uri);
}
 
Example 11
Source Project: jdk8u60   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 12
Source Project: jdk8u-dev-jdk   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 13
Source Project: jdk8u60   Source File: IntegrityHmac.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Proxy method for {@link java.security.Signature#verify(byte[])}
 * which is executed on the internal {@link java.security.Signature} object.
 *
 * @param signature
 * @return true if the signature is correct
 * @throws XMLSignatureException
 */
protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
    try {
        if (this.HMACOutputLengthSet && this.HMACOutputLength < getDigestLength()) {
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "HMACOutputLength must not be less than " + getDigestLength());
            }
            Object[] exArgs = { String.valueOf(getDigestLength()) };
            throw new XMLSignatureException("algorithms.HMACOutputLengthMin", exArgs);
        } else {
            byte[] completeResult = this.macAlgorithm.doFinal();
            return MessageDigestAlgorithm.isEqual(completeResult, signature);
        }
    } catch (IllegalStateException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
 
Example 14
Source Project: JDKSourceCode1.8   Source File: Reference.java    License: MIT License 6 votes vote down vote up
/**
 * Returns {@link MessageDigestAlgorithm}
 *
 *
 * @return {@link MessageDigestAlgorithm}
 *
 * @throws XMLSignatureException
 */
public MessageDigestAlgorithm getMessageDigestAlgorithm() throws XMLSignatureException {
    if (digestMethodElem == null) {
        return null;
    }

    String uri = digestMethodElem.getAttributeNS(null, Constants._ATT_ALGORITHM);

    if (uri == null) {
        return null;
    }

    if (secureValidation && MessageDigestAlgorithm.ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5.equals(uri)) {
        Object exArgs[] = { uri };

        throw new XMLSignatureException("signature.signatureAlgorithm", exArgs);
    }

    return MessageDigestAlgorithm.getInstance(this.doc, uri);
}
 
Example 15
Source Project: JDKSourceCode1.8   Source File: Reference.java    License: MIT License 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 16
Source Project: JDKSourceCode1.8   Source File: IntegrityHmac.java    License: MIT License 6 votes vote down vote up
/**
 * Proxy method for {@link java.security.Signature#verify(byte[])}
 * which is executed on the internal {@link java.security.Signature} object.
 *
 * @param signature
 * @return true if the signature is correct
 * @throws XMLSignatureException
 */
protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
    try {
        if (this.HMACOutputLengthSet && this.HMACOutputLength < getDigestLength()) {
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "HMACOutputLength must not be less than " + getDigestLength());
            }
            Object[] exArgs = { String.valueOf(getDigestLength()) };
            throw new XMLSignatureException("algorithms.HMACOutputLengthMin", exArgs);
        } else {
            byte[] completeResult = this.macAlgorithm.doFinal();
            return MessageDigestAlgorithm.isEqual(completeResult, signature);
        }
    } catch (IllegalStateException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
 
Example 17
Source Project: openjdk-jdk8u   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns {@link MessageDigestAlgorithm}
 *
 *
 * @return {@link MessageDigestAlgorithm}
 *
 * @throws XMLSignatureException
 */
public MessageDigestAlgorithm getMessageDigestAlgorithm() throws XMLSignatureException {
    if (digestMethodElem == null) {
        return null;
    }

    String uri = digestMethodElem.getAttributeNS(null, Constants._ATT_ALGORITHM);

    if (uri == null) {
        return null;
    }

    if (secureValidation && MessageDigestAlgorithm.ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5.equals(uri)) {
        Object exArgs[] = { uri };

        throw new XMLSignatureException("signature.signatureAlgorithm", exArgs);
    }

    return MessageDigestAlgorithm.getInstance(this.doc, uri);
}
 
Example 18
Source Project: openjdk-jdk8u   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 19
Source Project: jdk8u-jdk   Source File: IntegrityHmac.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Proxy method for {@link java.security.Signature#verify(byte[])}
 * which is executed on the internal {@link java.security.Signature} object.
 *
 * @param signature
 * @return true if the signature is correct
 * @throws XMLSignatureException
 */
protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
    try {
        if (this.HMACOutputLengthSet && this.HMACOutputLength < getDigestLength()) {
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "HMACOutputLength must not be less than " + getDigestLength());
            }
            Object[] exArgs = { String.valueOf(getDigestLength()) };
            throw new XMLSignatureException("algorithms.HMACOutputLengthMin", exArgs);
        } else {
            byte[] completeResult = this.macAlgorithm.doFinal();
            return MessageDigestAlgorithm.isEqual(completeResult, signature);
        }
    } catch (IllegalStateException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
 
Example 20
/**
 * Returns {@link MessageDigestAlgorithm}
 *
 *
 * @return {@link MessageDigestAlgorithm}
 *
 * @throws XMLSignatureException
 */
public MessageDigestAlgorithm getMessageDigestAlgorithm() throws XMLSignatureException {
    if (digestMethodElem == null) {
        return null;
    }

    String uri = digestMethodElem.getAttributeNS(null, Constants._ATT_ALGORITHM);

    if (uri == null) {
        return null;
    }

    if (secureValidation && MessageDigestAlgorithm.ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5.equals(uri)) {
        Object exArgs[] = { uri };

        throw new XMLSignatureException("signature.signatureAlgorithm", exArgs);
    }

    return MessageDigestAlgorithm.getInstance(this.doc, uri);
}
 
Example 21
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 22
/**
 * Proxy method for {@link java.security.Signature#verify(byte[])}
 * which is executed on the internal {@link java.security.Signature} object.
 *
 * @param signature
 * @return true if the signature is correct
 * @throws XMLSignatureException
 */
protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
    try {
        if (this.HMACOutputLengthSet && this.HMACOutputLength < getDigestLength()) {
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "HMACOutputLength must not be less than " + getDigestLength());
            }
            Object[] exArgs = { String.valueOf(getDigestLength()) };
            throw new XMLSignatureException("algorithms.HMACOutputLengthMin", exArgs);
        } else {
            byte[] completeResult = this.macAlgorithm.doFinal();
            return MessageDigestAlgorithm.isEqual(completeResult, signature);
        }
    } catch (IllegalStateException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
 
Example 23
Source Project: jdk8u-jdk   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 24
Source Project: openjdk-jdk9   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 25
Source Project: openjdk-jdk9   Source File: IntegrityHmac.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Proxy method for {@link java.security.Signature#verify(byte[])}
 * which is executed on the internal {@link java.security.Signature} object.
 *
 * @param signature
 * @return true if the signature is correct
 * @throws XMLSignatureException
 */
protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
    try {
        if (this.HMACOutputLengthSet && this.HMACOutputLength < getDigestLength()) {
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "HMACOutputLength must not be less than " + getDigestLength());
            }
            Object[] exArgs = { String.valueOf(getDigestLength()) };
            throw new XMLSignatureException("algorithms.HMACOutputLengthMin", exArgs);
        } else {
            byte[] completeResult = this.macAlgorithm.doFinal();
            return MessageDigestAlgorithm.isEqual(completeResult, signature);
        }
    } catch (IllegalStateException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
 
Example 26
Source Project: jdk8u-jdk   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 27
Source Project: jdk8u-jdk   Source File: IntegrityHmac.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Proxy method for {@link java.security.Signature#verify(byte[])}
 * which is executed on the internal {@link java.security.Signature} object.
 *
 * @param signature
 * @return true if the signature is correct
 * @throws XMLSignatureException
 */
protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
    try {
        if (this.HMACOutputLengthSet && this.HMACOutputLength < getDigestLength()) {
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "HMACOutputLength must not be less than " + getDigestLength());
            }
            Object[] exArgs = { String.valueOf(getDigestLength()) };
            throw new XMLSignatureException("algorithms.HMACOutputLengthMin", exArgs);
        } else {
            byte[] completeResult = this.macAlgorithm.doFinal();
            return MessageDigestAlgorithm.isEqual(completeResult, signature);
        }
    } catch (IllegalStateException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
 
Example 28
Source Project: hottub   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns {@link MessageDigestAlgorithm}
 *
 *
 * @return {@link MessageDigestAlgorithm}
 *
 * @throws XMLSignatureException
 */
public MessageDigestAlgorithm getMessageDigestAlgorithm() throws XMLSignatureException {
    if (digestMethodElem == null) {
        return null;
    }

    String uri = digestMethodElem.getAttributeNS(null, Constants._ATT_ALGORITHM);

    if (uri == null) {
        return null;
    }

    if (secureValidation && MessageDigestAlgorithm.ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5.equals(uri)) {
        Object exArgs[] = { uri };

        throw new XMLSignatureException("signature.signatureAlgorithm", exArgs);
    }

    return MessageDigestAlgorithm.getInstance(this.doc, uri);
}
 
Example 29
Source Project: hottub   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 30
Source Project: hottub   Source File: IntegrityHmac.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Proxy method for {@link java.security.Signature#verify(byte[])}
 * which is executed on the internal {@link java.security.Signature} object.
 *
 * @param signature
 * @return true if the signature is correct
 * @throws XMLSignatureException
 */
protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
    try {
        if (this.HMACOutputLengthSet && this.HMACOutputLength < getDigestLength()) {
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "HMACOutputLength must not be less than " + getDigestLength());
            }
            Object[] exArgs = { String.valueOf(getDigestLength()) };
            throw new XMLSignatureException("algorithms.HMACOutputLengthMin", exArgs);
        } else {
            byte[] completeResult = this.macAlgorithm.doFinal();
            return MessageDigestAlgorithm.isEqual(completeResult, signature);
        }
    } catch (IllegalStateException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}