@Test public void hashMismatch() throws Exception { thrown.expectError(ErrorCodes.X_MALFORMED_SIGNATURE); TimeStampToken token = getTimestampFromFile("valid"); byte[] stampedData = getBytesFromFile("stamped-data"); stampedData[42] = 0x01; TimestampVerifier.verify(token, stampedData, null); }
public static void verify(TimeStampToken tsToken, byte[] stampedData, List<X509Certificate> tspCerts) throws Exception { String thatHash = encodeBase64(calculateDigest( tsToken.getTimeStampInfo().getHashAlgorithm(), stampedData)); String thisHash = encodeBase64( tsToken.getTimeStampInfo().getMessageImprintDigest()); if (!thisHash.equals(thatHash)) { throw new CodedException(X_MALFORMED_SIGNATURE, "Timestamp hashes do not match"); } verify(tsToken, tspCerts); }
TimestampVerifier { public static void verify(TimeStampToken tsToken, byte[] stampedData, List<X509Certificate> tspCerts) throws Exception { String thatHash = encodeBase64(calculateDigest( tsToken.getTimeStampInfo().getHashAlgorithm(), stampedData)); String thisHash = encodeBase64( tsToken.getTimeStampInfo().getMessageImprintDigest()); if (!thisHash.equals(thatHash)) { throw new CodedException(X_MALFORMED_SIGNATURE, "Timestamp hashes do not match"); } verify(tsToken, tspCerts); } }
TimestampVerifier { public static void verify(TimeStampToken tsToken, byte[] stampedData, List<X509Certificate> tspCerts) throws Exception { String thatHash = encodeBase64(calculateDigest( tsToken.getTimeStampInfo().getHashAlgorithm(), stampedData)); String thisHash = encodeBase64( tsToken.getTimeStampInfo().getMessageImprintDigest()); if (!thisHash.equals(thatHash)) { throw new CodedException(X_MALFORMED_SIGNATURE, "Timestamp hashes do not match"); } verify(tsToken, tspCerts); } private  TimestampVerifier(); }
TimestampVerifier { public static void verify(TimeStampToken tsToken, byte[] stampedData, List<X509Certificate> tspCerts) throws Exception { String thatHash = encodeBase64(calculateDigest( tsToken.getTimeStampInfo().getHashAlgorithm(), stampedData)); String thisHash = encodeBase64( tsToken.getTimeStampInfo().getMessageImprintDigest()); if (!thisHash.equals(thatHash)) { throw new CodedException(X_MALFORMED_SIGNATURE, "Timestamp hashes do not match"); } verify(tsToken, tspCerts); } private  TimestampVerifier(); static void verify(TimeStampToken tsToken,
            byte[] stampedData, List<X509Certificate> tspCerts); static void verify(TimeStampToken tsToken,
            List<X509Certificate> tspCerts); static X509Certificate getSignerCertificate(
            TimeStampToken tsToken, List<X509Certificate> tspCerts); }
TimestampVerifier { public static void verify(TimeStampToken tsToken, byte[] stampedData, List<X509Certificate> tspCerts) throws Exception { String thatHash = encodeBase64(calculateDigest( tsToken.getTimeStampInfo().getHashAlgorithm(), stampedData)); String thisHash = encodeBase64( tsToken.getTimeStampInfo().getMessageImprintDigest()); if (!thisHash.equals(thatHash)) { throw new CodedException(X_MALFORMED_SIGNATURE, "Timestamp hashes do not match"); } verify(tsToken, tspCerts); } private  TimestampVerifier(); static void verify(TimeStampToken tsToken,
            byte[] stampedData, List<X509Certificate> tspCerts); static void verify(TimeStampToken tsToken,
            List<X509Certificate> tspCerts); static X509Certificate getSignerCertificate(
            TimeStampToken tsToken, List<X509Certificate> tspCerts);  }