Example usage for org.bouncycastle.tsp TimeStampTokenInfo toASN1Structure

List of usage examples for org.bouncycastle.tsp TimeStampTokenInfo toASN1Structure

Introduction

In this page you can find the example usage for org.bouncycastle.tsp TimeStampTokenInfo toASN1Structure.

Prototype

public TSTInfo toASN1Structure() 

Source Link

Usage

From source file:com.itextpdf.signatures.PdfPKCS7.java

License:Open Source License

/**
 * Verify the digest.//from  ww w . jav  a2s .  c  o m
 *
 * @return <CODE>true</CODE> if the signature checks out, <CODE>false</CODE> otherwise
 * @throws SignatureException                     on error
 * @throws java.security.GeneralSecurityException
 */
public boolean verify() throws GeneralSecurityException {
    if (verified)
        return verifyResult;
    if (isTsp) {
        TimeStampTokenInfo info = timeStampToken.getTimeStampInfo();
        MessageImprint imprint = info.toASN1Structure().getMessageImprint();
        byte[] md = messageDigest.digest();
        byte[] imphashed = imprint.getHashedMessage();
        verifyResult = Arrays.equals(md, imphashed);
    } else {
        if (sigAttr != null || sigAttrDer != null) {
            final byte[] msgDigestBytes = messageDigest.digest();
            boolean verifyRSAdata = true;
            // Stefan Santesson fixed a bug, keeping the code backward compatible
            boolean encContDigestCompare = false;
            if (RSAdata != null) {
                verifyRSAdata = Arrays.equals(msgDigestBytes, RSAdata);
                encContDigest.update(RSAdata);
                encContDigestCompare = Arrays.equals(encContDigest.digest(), digestAttr);
            }
            boolean absentEncContDigestCompare = Arrays.equals(msgDigestBytes, digestAttr);
            boolean concludingDigestCompare = absentEncContDigestCompare || encContDigestCompare;
            boolean sigVerify = verifySigAttributes(sigAttr) || verifySigAttributes(sigAttrDer);
            verifyResult = concludingDigestCompare && sigVerify && verifyRSAdata;
        } else {
            if (RSAdata != null)
                sig.update(messageDigest.digest());
            verifyResult = sig.verify(digest);
        }
    }
    verified = true;
    return verifyResult;
}

From source file:com.itextpdf.signatures.PdfPKCS7.java

License:Open Source License

/**
 * Checks if the timestamp refers to this document.
 *
 * @return true if it checks false otherwise
 * @throws GeneralSecurityException on error
 *//*from   w  ww .jav  a2  s.  c  o  m*/
public boolean verifyTimestampImprint() throws GeneralSecurityException {
    if (timeStampToken == null)
        return false;
    TimeStampTokenInfo info = timeStampToken.getTimeStampInfo();
    MessageImprint imprint = info.toASN1Structure().getMessageImprint();
    String algOID = info.getHashAlgorithm().getAlgorithm().getId();
    byte[] md = SignUtils.getMessageDigest(DigestAlgorithms.getDigest(algOID)).digest(digest);
    byte[] imphashed = imprint.getHashedMessage();
    return Arrays.equals(md, imphashed);
}

From source file:com.itextpdf.text.pdf.security.PdfPKCS7.java

License:Open Source License

/**
 * Checks if the timestamp refers to this document.
 * @return true if it checks false otherwise
 * @throws GeneralSecurityException on error
 * @since   2.1.6//from   w w  w.ja  v a 2  s .  c o m
 */
public boolean verifyTimestampImprint() throws GeneralSecurityException {
    if (timeStampToken == null)
        return false;
    TimeStampTokenInfo info = timeStampToken.getTimeStampInfo();
    MessageImprint imprint = info.toASN1Structure().getMessageImprint();
    String algOID = info.getMessageImprintAlgOID().getId();
    byte[] md = new BouncyCastleDigest().getMessageDigest(DigestAlgorithms.getDigest(algOID)).digest(digest);
    byte[] imphashed = imprint.getHashedMessage();
    boolean res = Arrays.equals(md, imphashed);
    return res;
}