Search in sources :

Example 1 with ArchiveTimeStamp

use of com.github.zhenwei.pkix.util.asn1.tsp.ArchiveTimeStamp in project LinLong-Java by zhenwei1108.

the class ERSArchiveTimeStampGenerator method generateArchiveTimeStamp.

public ERSArchiveTimeStamp generateArchiveTimeStamp(TimeStampResponse tspResponse) throws TSPException, ERSException {
    PartialHashtree[] reducedHashTree = getPartialHashtrees();
    byte[] rootHash = rootNodeCalculator.computeRootHash(digCalc, reducedHashTree);
    TSTInfo tstInfo = tspResponse.getTimeStampToken().getTimeStampInfo().toASN1Structure();
    if (!tstInfo.getMessageImprint().getHashAlgorithm().equals(digCalc.getAlgorithmIdentifier())) {
        throw new ERSException("time stamp imprint for wrong algorithm");
    }
    if (!Arrays.areEqual(tstInfo.getMessageImprint().getHashedMessage(), rootHash)) {
        throw new ERSException("time stamp imprint for wrong root hash");
    }
    ArchiveTimeStamp ats;
    if (reducedHashTree.length == 1) {
        // just include the TimeStamp
        ats = new ArchiveTimeStamp(null, null, tspResponse.getTimeStampToken().toCMSSignedData().toASN1Structure());
    } else {
        ats = new ArchiveTimeStamp(digCalc.getAlgorithmIdentifier(), reducedHashTree, tspResponse.getTimeStampToken().toCMSSignedData().toASN1Structure());
    }
    return new ERSArchiveTimeStamp(ats, digCalc, rootNodeCalculator);
}
Also used : TSTInfo(com.github.zhenwei.pkix.util.asn1.tsp.TSTInfo) ArchiveTimeStamp(com.github.zhenwei.pkix.util.asn1.tsp.ArchiveTimeStamp) PartialHashtree(com.github.zhenwei.pkix.util.asn1.tsp.PartialHashtree)

Aggregations

ArchiveTimeStamp (com.github.zhenwei.pkix.util.asn1.tsp.ArchiveTimeStamp)1 PartialHashtree (com.github.zhenwei.pkix.util.asn1.tsp.PartialHashtree)1 TSTInfo (com.github.zhenwei.pkix.util.asn1.tsp.TSTInfo)1