verifyTimeStampToken function
Verifies token against stampedData - the exact bytes whose digest the
token should attest to (the signature value for a signature timestamp,
the signed byte ranges for a document timestamp). Confirms the embedded
MessageImprint matches and the TSA's CMS signature is cryptographically
valid against its embedded certificate. Trust in the TSA certificate is
the caller's to establish (via a trust store) and is out of scope here.
Implementation
TimeStampVerification verifyTimeStampToken(
TimeStampToken token, List<int> stampedData) {
final hash = hashForDigestOid(token.messageImprint.hashAlgorithmOid);
if (hash == null) {
return TimeStampVerification(
imprintMatches: false,
signatureValid: false,
genTime: token.genTime,
problem: 'unsupported imprint digest '
'${token.messageImprint.hashAlgorithmOid}',
);
}
final digest = hash.convert(stampedData).bytes;
final imprintMatches = _bytesEqual(digest, token.messageImprint.hashedMessage);
// The token's CMS signs the TSTInfo (the eContent), via signed attributes.
final verification = cmsVerify(token.cms, token.signer, token.cms.eContent!);
return TimeStampVerification(
imprintMatches: imprintMatches,
signatureValid: verification.signatureValid && verification.digestMatches,
genTime: token.genTime,
problem: verification.problem,
);
}