Debian Codegraph @

lib/pkcs9/pkcs7.go

raw symbols SCIP
1 //
2 // Copyright (c) SAS Institute Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 package pkcs9scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/
18
19 import (
20 "bytesscip-go gomod github.com/golang/go/src go1.18 bytes/"
21 "contextscip-go gomod github.com/golang/go/src go1.18 context/"
22 "cryptoscip-go gomod github.com/golang/go/src go1.18 crypto/"
23 "crypto/x509scip-go gomod github.com/golang/go/src go1.18 `crypto/x509`/"
24 "errorsscip-go gomod github.com/golang/go/src go1.18 errors/"
25 "fmtscip-go gomod github.com/golang/go/src go1.18 fmt/"
26 "timescip-go gomod github.com/golang/go/src go1.18 time/"
27
28 "github.com/sassoftware/relic/v7/lib/pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/"
29 "github.com/sassoftware/relic/v7/lib/x509toolsscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/x509tools`/"
30 )
31
32 func TimestampAndMarshalscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampAndMarshal().(ctx contextscip-go gomod github.com/golang/go/src go1.18 context/.Contextscip-go gomod github.com/golang/go/src go1.18 context/Context#, psd *pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.ContentInfoSignedDatascip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/ContentInfoSignedData#, timestamper Timestamperscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/Timestamper#, authenticode bool) (*TimestampedSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#, error) {
33 if timestamper != nil {
34 signerInfo := &psd.Contentscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/ContentInfoSignedData#Content..SignerInfosscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignedData#SignerInfos.[0]
35 hash, err := x509toolsscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/x509tools`/.PkixDigestToHashEscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/x509tools`/PkixDigestToHashE().(signerInfo.DigestAlgorithmscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignerInfo#DigestAlgorithm.)
36 if err != nil {
37 return nil, err
38 }
39 token, err := timestamper.Timestampscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/Timestamper#Timestamp.(ctx, &Requestscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/Request#{EncryptedDigestscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/Request#EncryptedDigest.: signerInfo.EncryptedDigestscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignerInfo#EncryptedDigest., Hashscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/Request#Hash.: hash})
40 if err != nil {
41 return nil, err
42 }
43 if authenticode {
44 err = AddStampToSignedAuthenticodescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/AddStampToSignedAuthenticode().(signerInfo, *token)
45 } else {
46 err = AddStampToSignedDatascip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/AddStampToSignedData().(signerInfo, *token)
47 }
48 if err != nil {
49 return nil, err
50 }
51 }
52 verified, err := psd.Contentscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/ContentInfoSignedData#Content..Verifyscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignedData#Verify().(nil, false)
53 if err != nil {
54 return nil, fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("pkcs7: failed signature self-check: %w", err)
55 }
56 ts, err := VerifyOptionalTimestampscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/VerifyOptionalTimestamp().(verified)
57 if err != nil {
58 return nil, fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("pkcs7: failed signature self-check: %w", err)
59 }
60 blob, err := psd.Marshalscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/ContentInfoSignedData#Marshal().()
61 if err != nil {
62 return nil, err
63 }
64 ts.Rawscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#Raw. = blob
65 return &ts, err
66 }
67
68 // Attach a RFC 3161 timestamp to a PKCS#7 SignerInfo
69 func AddStampToSignedDatascip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/AddStampToSignedData().(signerInfo *pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.SignerInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignerInfo#, token pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.ContentInfoSignedDatascip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/ContentInfoSignedData#) error {
70 return signerInfo.UnauthenticatedAttributesscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignerInfo#UnauthenticatedAttributes..Addscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/AttributeList#Add().(OidAttributeTimeStampTokenscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/OidAttributeTimeStampToken., token)
71 }
72
73 // Attach a RFC 3161 timestamp to a PKCS#7 SignerInfo using the OID for authenticode signatures
74 func AddStampToSignedAuthenticodescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/AddStampToSignedAuthenticode().(signerInfo *pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.SignerInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignerInfo#, token pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.ContentInfoSignedDatascip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/ContentInfoSignedData#) error {
75 return signerInfo.UnauthenticatedAttributesscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignerInfo#UnauthenticatedAttributes..Addscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/AttributeList#Add().(OidSpcTimeStampTokenscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/OidSpcTimeStampToken., token)
76 }
77
78 // Validated timestamp token
79 type CounterSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature# struct {
80 pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.Signaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature#Signature.
81 Hashscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature#Hash. cryptoscip-go gomod github.com/golang/go/src go1.18 crypto/.Hashscip-go gomod github.com/golang/go/src go1.18 crypto/Hash#
82 SigningTimescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature#SigningTime. timescip-go gomod github.com/golang/go/src go1.18 time/.Timescip-go gomod github.com/golang/go/src go1.18 time/Time#
83 }
84
85 // Validated signature containing a optional timestamp token
86 type TimestampedSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature# struct {
87 pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.Signaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#Signature.
88 CounterSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#CounterSignature. *CounterSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature#
89 Rawscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#Raw. []byte
90 }
91
92 // Look for a timestamp (counter-signature or timestamp token) in the
93 // UnauthenticatedAttributes of the given already-validated signature and check
94 // its integrity. The certificate chain is not checked; call VerifyChain() on
95 // the result to validate it fully. Returns nil if no timestamp is present.
96 func VerifyPkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/VerifyPkcs7().(sig pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.Signaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#) (*CounterSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature#, error) {
97 var tst pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.ContentInfoSignedDatascip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/ContentInfoSignedData#
98 // check several OIDs for timestamp tokens
99 err := sig.SignerInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#SignerInfo..UnauthenticatedAttributesscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignerInfo#UnauthenticatedAttributes..GetOnescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/AttributeList#GetOne().(OidAttributeTimeStampTokenscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/OidAttributeTimeStampToken., &tst)
100 if _, ok := err.(pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.ErrNoAttributescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/ErrNoAttribute#); ok {
101 err = sig.SignerInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#SignerInfo..UnauthenticatedAttributesscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignerInfo#UnauthenticatedAttributes..GetOnescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/AttributeList#GetOne().(OidSpcTimeStampTokenscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/OidSpcTimeStampToken., &tst)
102 }
103 var imprintHash cryptoscip-go gomod github.com/golang/go/src go1.18 crypto/.Hashscip-go gomod github.com/golang/go/src go1.18 crypto/Hash#
104 if err == nil {
105 // timestamptoken is a fully nested signedData containing a TSTInfo
106 // that digests the parent signature blob
107 return Verifyscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/Verify().(&tst, sig.SignerInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#SignerInfo..EncryptedDigestscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignerInfo#EncryptedDigest., sig.Intermediatesscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#Intermediates.)
108 } else if _, ok := err.(pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.ErrNoAttributescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/ErrNoAttribute#); ok {
109 tsi := new(pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.SignerInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignerInfo#)
110 if err := sig.SignerInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#SignerInfo..UnauthenticatedAttributesscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignerInfo#UnauthenticatedAttributes..GetOnescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/AttributeList#GetOne().(OidAttributeCounterSignscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/OidAttributeCounterSign., tsi); err != nil {
111 if _, ok := err.(pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.ErrNoAttributescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/ErrNoAttribute#); ok {
112 return nil, nil
113 }
114 return nil, err
115 }
116 // counterSignature is simply a signerinfo. The certificate chain is
117 // included in the parent structure, and the timestamp signs the
118 // signature blob from the parent signerinfo
119 imprintHash, _ = x509toolsscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/x509tools`/.PkixDigestToHashscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/x509tools`/PkixDigestToHash().(sig.SignerInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#SignerInfo..DigestAlgorithmscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignerInfo#DigestAlgorithm.)
120 return finishVerifyscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/finishVerify().(tsi, sig.SignerInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#SignerInfo..EncryptedDigestscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignerInfo#EncryptedDigest., sig.Intermediatesscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#Intermediates., imprintHash, tsi, nil)
121 }
122 return nil, err
123 }
124
125 // Look for a timestamp token or counter-signature in the given signature and
126 // return a structure that can be used to validate the signature's certificate
127 // chain. If no timestamp is present, then the current time will be used when
128 // validating the chain.
129 func VerifyOptionalTimestampscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/VerifyOptionalTimestamp().(sig pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.Signaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#) (TimestampedSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#, error) {
130 tsig := TimestampedSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#{Signaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#Signature.: sig}
131 ts, err := VerifyPkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/VerifyPkcs7().(sig)
132 if err != nil {
133 return tsig, err
134 }
135 tsig.CounterSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#CounterSignature. = ts
136 return tsig, nil
137 }
138
139 // Verify that the timestamp token has a valid certificate chain
140 func (cs CounterSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature#) VerifyChainscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature#VerifyChain().(roots *x509scip-go gomod github.com/golang/go/src go1.18 `crypto/x509`/.CertPoolscip-go gomod github.com/golang/go/src go1.18 `crypto/x509`/CertPool#, extraCerts []*x509scip-go gomod github.com/golang/go/src go1.18 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.18 `crypto/x509`/Certificate#) error {
141 return cs.Signaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature#Signature..VerifyChainscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#VerifyChain().(roots, extraCerts, x509scip-go gomod github.com/golang/go/src go1.18 `crypto/x509`/.ExtKeyUsageTimeStampingscip-go gomod github.com/golang/go/src go1.18 `crypto/x509`/ExtKeyUsageTimeStamping., cs.SigningTimescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature#SigningTime.)
142 }
143
144 // Verify the certificate chain of a PKCS#7 signature. If the signature has a
145 // valid timestamp token attached, then the timestamp is used for validating
146 // the primary signature's chain, making the signature valid after the
147 // certificates have expired.
148 func (sig TimestampedSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#) VerifyChainscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#VerifyChain().(roots *x509scip-go gomod github.com/golang/go/src go1.18 `crypto/x509`/.CertPoolscip-go gomod github.com/golang/go/src go1.18 `crypto/x509`/CertPool#, extraCerts []*x509scip-go gomod github.com/golang/go/src go1.18 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.18 `crypto/x509`/Certificate#, usage x509scip-go gomod github.com/golang/go/src go1.18 `crypto/x509`/.ExtKeyUsagescip-go gomod github.com/golang/go/src go1.18 `crypto/x509`/ExtKeyUsage#) error {
149 var signingTime timescip-go gomod github.com/golang/go/src go1.18 time/.Timescip-go gomod github.com/golang/go/src go1.18 time/Time#
150 if sig.CounterSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#CounterSignature. != nil {
151 if err := sig.CounterSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#CounterSignature..VerifyChainscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature#VerifyChain().(roots, extraCerts); err != nil {
152 return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("validating timestamp: %w", err)
153 }
154 signingTime = sig.CounterSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#CounterSignature..SigningTimescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature#SigningTime.
155 }
156 return sig.Signaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#Signature..VerifyChainscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#VerifyChain().(roots, extraCerts, usage, signingTime)
157 }
158
159 // Verify a non-RFC-3161 timestamp token against the given encrypted digest
160 // from the primary signature.
161 func VerifyMicrosoftTokenscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/VerifyMicrosoftToken().(token *pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.ContentInfoSignedDatascip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/ContentInfoSignedData#, encryptedDigest []byte) (*CounterSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature#, error) {
162 sig, err := token.Contentscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/ContentInfoSignedData#Content..Verifyscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignedData#Verify().(nil, false)
163 if err != nil {
164 return nil, err
165 }
166 content, err := token.Contentscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/ContentInfoSignedData#Content..ContentInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignedData#ContentInfo..Bytesscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/ContentInfo#Bytes().()
167 if err != nil {
168 return nil, err
169 }
170 if !bytesscip-go gomod github.com/golang/go/src go1.18 bytes/.Equalscip-go gomod github.com/golang/go/src go1.18 bytes/Equal().(content, encryptedDigest) {
171 return nil, errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("timestamp does not match the enclosing signature")
172 }
173 hash, _ := x509toolsscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/x509tools`/.PkixDigestToHashscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/x509tools`/PkixDigestToHash().(sig.SignerInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#SignerInfo..DigestAlgorithmscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignerInfo#DigestAlgorithm.)
174 signingTime, err := sig.SignerInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#SignerInfo..SigningTimescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/SignerInfo#SigningTime().()
175 if err != nil {
176 return nil, err
177 }
178 return &CounterSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature#{
179 Signaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature#Signature.: sig,
180 Hashscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature#Hash.: hash,
181 SigningTimescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/CounterSignature#SigningTime.: signingTime,
182 }, nil
183 }