Verify RFC 3161 trusted timestamp

前端 未结 3 1245
故里飘歌
故里飘歌 2020-12-23 15:31

In my build process, I want to include a timestamp from an RFC-3161-compliant TSA. At run time, the code will verify this timestamp, preferably without the assistance of a

3条回答
  •  独厮守ぢ
    2020-12-23 15:59

    I am not sure to understand why you want to rebuild the data structure signed in the response. Actually if you want to extract the signed data from the time-stamp server response you can do this:

    var tsr = GetTimestamp(hashToTimestamp, nonce, "http://some.rfc3161-compliant.server");
    var tst = tsr.TimeStampToken;
    var tsi = tst.TimeStampInfo;
    var signature = // Get the signature
    var certificate = // Get the signer certificate
    var signedData = tsi.GetEncoded(); // Similar to tsi.TstInfo.GetEncoded();
    VerifySignature(signedData, signature, certificate)
    

    If you want to rebuild the data structure, you need to create a new Org.BouncyCastle.Asn1.Tsp.TstInfo instance (tsi.TstInfo is a Org.BouncyCastle.Asn1.Tsp.TstInfo object) with all elements contained in the response.

    In RFC 3161 the signed data structure is defined as this ASN.1 sequence:

    TSTInfo ::= SEQUENCE  {
       version                      INTEGER  { v1(1) },
       policy                       TSAPolicyId,
       messageImprint               MessageImprint,
         -- MUST have the same value as the similar field in
         -- TimeStampReq
       serialNumber                 INTEGER,
        -- Time-Stamping users MUST be ready to accommodate integers
        -- up to 160 bits.
       genTime                      GeneralizedTime,
       accuracy                     Accuracy                 OPTIONAL,
       ordering                     BOOLEAN             DEFAULT FALSE,
       nonce                        INTEGER                  OPTIONAL,
         -- MUST be present if the similar field was present
         -- in TimeStampReq.  In that case it MUST have the same value.
       tsa                          [0] GeneralName          OPTIONAL,
       extensions                   [1] IMPLICIT Extensions   OPTIONAL  }
    

提交回复
热议问题