使用 openssl ts ( https://www.openssl.org/docs/man1.1.0/man1/openssl-ts.html ) 我可以创建 TS 查询、回复、从回复中提取令牌并验证令牌(如果我有签名证书DER 格式)的 RFC3161 格式,如下所示: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.
问题一:
为什么这只需要信任锚(=自签名)证书而不是整个链到 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(在链接规范中指定)(最好不首先将其转换为人类可读的形式)?