【问题标题】:OpenSSL: how to extract certificates and token status from RFC3161 timestamping reply?OpenSSL:如何从 RFC3161 时间戳回复中提取证书和令牌状态?
【发布时间】:2024-01-21 15:54:01
【问题描述】:

使用 openssl ts (https://www.openssl.org/docs/man1.1.0/man1/openssl-ts.html) 我可以创建 TS 查询、回复、从回复中提取令牌并验证此处指定的 RFC3161 格式的令牌(如果我有 DER 格式的签名证书):https://www.ietf.org/rfc/rfc3161.txt

要获得令牌,我可以这样做:

openssl ts -query -digest 899ba3d9f777e2a74bdd34302bc06cb3f7a46ac1f565ee128f79fd5dab99d68b -sha256 \
| curl -s -H "Content-Type: application/timestamp-query" -H "Accept: application/timestamp-reply" --data-binary @- https://freetsa.org/tsr > response.tsr
openssl ts -reply -in response.tsr -token_out -out token.tk

我还可以使用人类可读的形式打印响应 openssl ts -reply -in response.tsr -text

要验证令牌,我需要提供参数

-CAfile trusted_certs.pem
The name of the file containing a set of trusted self-signed CA certificates in PEM format.
The file should contain one or more certificates in PEM format.

问题 1:

为什么这只需要信任锚(=自签名)证书而不是整个链到 TSA 证书(或者 -verify 仅适用于证书链已包含在令牌中的令牌) ?

问题 2:

-cert
The TSA is expected to include its signing certificate in the response.

如果我在第一个 openssl 调用中指定 -cert 参数,则 token.tk 将更长,并且还包含用于对其进行签名的证书。如何从 token.tk 中提取该证书?

问题 3:

当我请求响应以包含证书时,我很惊讶 token.tk 变得更长(我假设只有 response.tsr 变得更长,而不是令牌本身),因为规范指定 TimeStampToken 像这样:

   A TimeStampToken is as follows.  It is defined as a ContentInfo
   ([CMS]) and SHALL encapsulate a signed data content type.

   TimeStampToken ::= ContentInfo
     -- contentType is id-signedData ([CMS])
     -- content is SignedData ([CMS])

   The fields of type EncapsulatedContentInfo of the SignedData
   construct have the following meanings:

   eContentType is an object identifier that uniquely specifies the
   content type.  For a time-stamp token it is defined as:

   id-ct-TSTInfo  OBJECT IDENTIFIER ::= { iso(1) member-body(2)
   us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) ct(1) 4}

   eContent is the content itself, carried as an octet string.
   The eContent SHALL be the DER-encoded value of TSTInfo.

   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  }

那么,签名证书存储在哪里?它是扩展名吗?还是它是 ContentType 标识符的一部分?

问题 4:

如果我确实指定了 -cert 参数,我如何从 token.tk 中提取文件 token_stripped.tk,以便 token_stripped.tk 与我创建没有 -cert 参数的请求相同?

问题 5:

如何从 response.tsr 中提取 PKIStatus(在链接规范中指定)(最好不先将其转换为人类可读的形式)?

【问题讨论】:

    标签: openssl timestamp rfc3161


    【解决方案1】:

    回答我自己的问题:

    问题一:

    为什么这只需要信任锚(=自签名)证书 而不是整个链到 TSA 证书(或 -verify 仅适用于证书链已用于的令牌 包含在令牌中)?

    它确实需要它,但如果令牌已经包含嵌入的整个信任链,则不需要它。否则,必须使用 -untrusted 参数提供它

    问题 2:

    -cert
    The TSA is expected to include its signing certificate in the response.
    

    如果我在第一个 openssl 调用中指定 -cert 参数,那么 token.tk 会更长,并且还包含之前的证书 用来签名的。如何从 token.tk 中提取该证书?

    以下调用提取嵌入的证书:

    penssl pkcs7 -inform DER -in tokenfile.tst -print_certs -outform PEM -out certificatechain.pem
    

    问题 3:

    我很惊讶 token.tk 在我请求响应时变长了 包括证书(我会假设只有 response.tsr 到 变得更长,而不是令牌本身

    TstInfo 实际上保持相同的长度,但时间戳标记不是 TstInfo,而是包装 CMS ContentInfo,并且证书(符合规范)作为签名属性嵌入到该 ContentInfo 对象中。

    问题 4:

    如果我确实指定了 -cert 参数,我如何提取文件 token_stripped.tk from token.tk,这样token_stripped.tk是一样的 好像我会在没有 -cert 参数的情况下创建请求?

    由于证书嵌入在签名属性中而不是未签名属性中,因此无法从包含证书链的证书中生成有效的剥离令牌。

    问题 5:

    如何提取 PKIStatus(如链接中指定的 规范)来自 response.tsr (最好不先转换 它以人类可读的形式)?

    除了使用 openssl cli 解析人类可读的表单之外,我没有找到其他方法

    【讨论】:

      最近更新 更多