| 1 | // Package timestamp implements the Time-Stamp Protocol (TSP) as specified in |
| 2 | // RFC3161 (Internet X.509 Public Key Infrastructure Time-Stamp Protocol (TSP)). |
| 3 | package timestampscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/ |
| 4 | |
| 5 | import ( |
| 6 | "cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/" |
| 7 | "crypto/randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/" |
| 8 | "crypto/x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/" |
| 9 | "crypto/x509/pkixscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/" |
| 10 | "encoding/asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/" |
| 11 | "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/" |
| 12 | "ioscip-go gomod github.com/golang/go/src go1.16 io/" |
| 13 | "math/bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/" |
| 14 | "strconvscip-go gomod github.com/golang/go/src go1.16 strconv/" |
| 15 | "stringsscip-go gomod github.com/golang/go/src go1.16 strings/" |
| 16 | "timescip-go gomod github.com/golang/go/src go1.16 time/" |
| 17 | |
| 18 | "github.com/digitorus/pkcs7scip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/" |
| 19 | ) |
| 20 | |
| 21 | // FailureInfo contains the failure details of an Time-Stamp request. See |
| 22 | // https://tools.ietf.org/html/rfc3161#section-2.4.2 |
| 23 | type FailureInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/FailureInfo# int |
| 24 | |
| 25 | const ( |
| 26 | // UnknownFailureInfo mean that no known failure info was provided |
| 27 | UnknownFailureInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/UnknownFailureInfo. FailureInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/FailureInfo# = -1 |
| 28 | // BadAlgorithm defines an unrecognized or unsupported Algorithm Identifier |
| 29 | BadAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/BadAlgorithm. FailureInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/FailureInfo# = 0 |
| 30 | // BadRequest indicates that the transaction not permitted or supported |
| 31 | BadRequestscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/BadRequest. FailureInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/FailureInfo# = 2 |
| 32 | // BadDataFormat means tha data submitted has the wrong format |
| 33 | BadDataFormatscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/BadDataFormat. FailureInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/FailureInfo# = 5 |
| 34 | // TimeNotAvailable indicates that TSA's time source is not available |
| 35 | TimeNotAvailablescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/TimeNotAvailable. FailureInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/FailureInfo# = 14 |
| 36 | // UnacceptedPolicy indicates that the requested TSA policy is not supported |
| 37 | // by the TSA |
| 38 | UnacceptedPolicyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/UnacceptedPolicy. FailureInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/FailureInfo# = 15 |
| 39 | // UnacceptedExtension indicates that the requested extension is not supported |
| 40 | // by the TSA |
| 41 | UnacceptedExtensionscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/UnacceptedExtension. FailureInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/FailureInfo# = 16 |
| 42 | // AddInfoNotAvailable means that the information requested could not be |
| 43 | // understood or is not available |
| 44 | AddInfoNotAvailablescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/AddInfoNotAvailable. FailureInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/FailureInfo# = 17 |
| 45 | // SystemFailure indicates that the request cannot be handled due to system |
| 46 | // failure |
| 47 | SystemFailurescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/SystemFailure. FailureInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/FailureInfo# = 25 |
| 48 | ) |
| 49 | |
| 50 | func (f FailureInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/FailureInfo#) Stringscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/FailureInfo#String().() string { |
| 51 | switch f { |
| 52 | case BadAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/BadAlgorithm.: |
| 53 | return "unrecognized or unsupported Algorithm Identifier" |
| 54 | case BadRequestscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/BadRequest.: |
| 55 | return "transaction not permitted or supported" |
| 56 | case BadDataFormatscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/BadDataFormat.: |
| 57 | return "the data submitted has the wrong format" |
| 58 | case TimeNotAvailablescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/TimeNotAvailable.: |
| 59 | return "the TSA's time source is not available" |
| 60 | case UnacceptedPolicyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/UnacceptedPolicy.: |
| 61 | return "the requested TSA policy is not supported by the TSA" |
| 62 | case UnacceptedExtensionscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/UnacceptedExtension.: |
| 63 | return "the requested extension is not supported by the TSA" |
| 64 | case AddInfoNotAvailablescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/AddInfoNotAvailable.: |
| 65 | return "the additional information requested could not be understood or is not available" |
| 66 | case SystemFailurescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/SystemFailure.: |
| 67 | return "the request cannot be handled due to system failure" |
| 68 | default: |
| 69 | return "unknown failure" |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // Status contains the status of an Time-Stamp request. See |
| 74 | // https://tools.ietf.org/html/rfc3161#section-2.4.2 |
| 75 | type Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Status# int |
| 76 | |
| 77 | const ( |
| 78 | // Granted PKIStatus contains the value zero a TimeStampToken, as requested, |
| 79 | // is present. |
| 80 | Grantedscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Granted. Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Status# = 0 |
| 81 | // GrantedWithMods PKIStatus contains the value one a TimeStampToken, with |
| 82 | // modifications, is present. |
| 83 | GrantedWithModsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/GrantedWithMods. Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Status# = 1 |
| 84 | // Rejection PKIStatus |
| 85 | Rejectionscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Rejection. Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Status# = 2 |
| 86 | // Waiting PKIStatus |
| 87 | Waitingscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Waiting. Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Status# = 3 |
| 88 | // RevocationWarning PKIStatus |
| 89 | RevocationWarningscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RevocationWarning. Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Status# = 4 |
| 90 | // RevocationNotification PKIStatus |
| 91 | RevocationNotificationscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RevocationNotification. Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Status# = 5 |
| 92 | ) |
| 93 | |
| 94 | func (s Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Status#) Stringscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Status#String().() string { |
| 95 | switch s { |
| 96 | case Grantedscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Granted.: |
| 97 | return "the request is granted" |
| 98 | case GrantedWithModsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/GrantedWithMods.: |
| 99 | return "the request is granted with modifications" |
| 100 | case Rejectionscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Rejection.: |
| 101 | return "the request is rejected" |
| 102 | case Waitingscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Waiting.: |
| 103 | return "the request is waiting" |
| 104 | case RevocationWarningscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RevocationWarning.: |
| 105 | return "revocation is imminent" |
| 106 | case RevocationNotificationscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RevocationNotification.: |
| 107 | return "revocation has occurred" |
| 108 | default: |
| 109 | return "unknown status: " + strconvscip-go gomod github.com/golang/go/src go1.16 strconv/.Itoascip-go gomod github.com/golang/go/src go1.16 strconv/Itoa().(int(s)) |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // ParseError results from an invalid Time-Stamp request or response. |
| 114 | type ParseErrorscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/ParseError# string |
| 115 | |
| 116 | func (p ParseErrorscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/ParseError#) Errorscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/ParseError#Error().() string { |
| 117 | return string(p) |
| 118 | } |
| 119 | |
| 120 | // Request represents an Time-Stamp request. See |
| 121 | // https://tools.ietf.org/html/rfc3161#section-2.4.1 |
| 122 | type Requestscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request# struct { |
| 123 | HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#HashAlgorithm. cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.Hashscip-go gomod github.com/golang/go/src go1.16 crypto/Hash# |
| 124 | HashedMessagescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#HashedMessage. []byte |
| 125 | |
| 126 | // Certificates indicates if the TSA needs to return the signing certificate |
| 127 | // and optionally any other certificates of the chain as part of the response. |
| 128 | Certificatesscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#Certificates. bool |
| 129 | |
| 130 | // The TSAPolicyOID field, if provided, indicates the TSA policy under |
| 131 | // which the TimeStampToken SHOULD be provided |
| 132 | TSAPolicyOIDscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#TSAPolicyOID. asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/ObjectIdentifier# |
| 133 | |
| 134 | // The nonce, if provided, allows the client to verify the timeliness of |
| 135 | // the response. |
| 136 | Noncescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#Nonce. *bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int# |
| 137 | |
| 138 | // Extensions contains raw X.509 extensions from the Extensions field of the |
| 139 | // Time-Stamp request. When parsing requests, this can be used to extract |
| 140 | // non-critical extensions that are not parsed by this package. When |
| 141 | // marshaling OCSP requests, the Extensions field is ignored, see |
| 142 | // ExtraExtensions. |
| 143 | Extensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#Extensions. []pkixscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/.Extensionscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/Extension# |
| 144 | |
| 145 | // ExtraExtensions contains extensions to be copied, raw, into any marshaled |
| 146 | // OCSP response (in the singleExtensions field). Values override any |
| 147 | // extensions that would otherwise be produced based on the other fields. The |
| 148 | // ExtraExtensions field is not populated when parsing Time-Stamp requests, |
| 149 | // see Extensions. |
| 150 | ExtraExtensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#ExtraExtensions. []pkixscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/.Extensionscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/Extension# |
| 151 | } |
| 152 | |
| 153 | // ParseRequest parses an timestamp request in DER form. |
| 154 | func ParseRequestscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/ParseRequest().(bytes []byte) (*Requestscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#, error) { |
| 155 | var err error |
| 156 | var rest []byte |
| 157 | var req requestscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/request# |
| 158 | |
| 159 | if rest, err = asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.Unmarshalscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/Unmarshal().(bytes, &req); err != nil { |
| 160 | return nil, err |
| 161 | } |
| 162 | if len(rest) > 0 { |
| 163 | return nil, ParseErrorscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/ParseError#("trailing data in Time-Stamp request") |
| 164 | } |
| 165 | |
| 166 | if len(req.MessageImprintscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/request#MessageImprint..HashedMessagescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/messageImprint#HashedMessage.) == 0 { |
| 167 | return nil, ParseErrorscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/ParseError#("Time-Stamp request contains no hashed message") |
| 168 | } |
| 169 | |
| 170 | hashFunc := getHashAlgorithmFromOIDscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/getHashAlgorithmFromOID().(req.MessageImprintscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/request#MessageImprint..HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/messageImprint#HashAlgorithm..Algorithmscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.) |
| 171 | if hashFunc == cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.Hashscip-go gomod github.com/golang/go/src go1.16 crypto/Hash#(0) { |
| 172 | return nil, ParseErrorscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/ParseError#("Time-Stamp request uses unknown hash function") |
| 173 | } |
| 174 | |
| 175 | return &Requestscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#{ |
| 176 | HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#HashAlgorithm.: hashFunc, |
| 177 | HashedMessagescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#HashedMessage.: req.MessageImprintscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/request#MessageImprint..HashedMessagescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/messageImprint#HashedMessage., |
| 178 | Certificatesscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#Certificates.: req.CertReqscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/request#CertReq., |
| 179 | Noncescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#Nonce.: req.Noncescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/request#Nonce., |
| 180 | TSAPolicyOIDscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#TSAPolicyOID.: req.ReqPolicyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/request#ReqPolicy., |
| 181 | Extensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#Extensions.: req.Extensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/request#Extensions., |
| 182 | }, nil |
| 183 | } |
| 184 | |
| 185 | // Marshal marshals the Time-Stamp request to ASN.1 DER encoded form. |
| 186 | func (req *Requestscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#) Marshalscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#Marshal().() ([]byte, error) { |
| 187 | request := requestscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/request#{ |
| 188 | Versionscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/request#Version.: 1, |
| 189 | MessageImprintscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/request#MessageImprint.: messageImprintscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/messageImprint#{ |
| 190 | HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/messageImprint#HashAlgorithm.: pkixscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/.AlgorithmIdentifierscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/AlgorithmIdentifier#{ |
| 191 | Algorithmscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.: getOIDFromHashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/getOIDFromHashAlgorithm().(req.HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#HashAlgorithm.), |
| 192 | Parametersscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/AlgorithmIdentifier#Parameters.: asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.RawValuescip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#{ |
| 193 | Tagscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#Tag.: 5, /* ASN.1 NULL */ |
| 194 | }, |
| 195 | }, |
| 196 | HashedMessagescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/messageImprint#HashedMessage.: req.HashedMessagescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#HashedMessage., |
| 197 | }, |
| 198 | CertReqscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/request#CertReq.: req.Certificatesscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#Certificates., |
| 199 | Extensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/request#Extensions.: req.ExtraExtensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#ExtraExtensions., |
| 200 | } |
| 201 | |
| 202 | if req.TSAPolicyOIDscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#TSAPolicyOID. != nil { |
| 203 | request.ReqPolicyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/request#ReqPolicy. = req.TSAPolicyOIDscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#TSAPolicyOID. |
| 204 | } |
| 205 | if req.Noncescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#Nonce. != nil { |
| 206 | request.Noncescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/request#Nonce. = req.Noncescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#Nonce. |
| 207 | } |
| 208 | reqBytes, err := asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.Marshalscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/Marshal().(request) |
| 209 | if err != nil { |
| 210 | return nil, err |
| 211 | } |
| 212 | return reqBytes, nil |
| 213 | } |
| 214 | |
| 215 | // Timestamp represents an Time-Stamp. See: |
| 216 | // https://tools.ietf.org/html/rfc3161#section-2.4.1 |
| 217 | type Timestampscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp# struct { |
| 218 | // Timestamp token part of raw ASN.1 DER content. |
| 219 | RawTokenscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#RawToken. []byte |
| 220 | |
| 221 | HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#HashAlgorithm. cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.Hashscip-go gomod github.com/golang/go/src go1.16 crypto/Hash# |
| 222 | HashedMessagescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#HashedMessage. []byte |
| 223 | |
| 224 | Timescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Time. timescip-go gomod github.com/golang/go/src go1.16 time/.Timescip-go gomod github.com/golang/go/src go1.16 time/Time# |
| 225 | Accuracyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Accuracy. timescip-go gomod github.com/golang/go/src go1.16 time/.Durationscip-go gomod github.com/golang/go/src go1.16 time/Duration# |
| 226 | SerialNumberscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#SerialNumber. *bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int# |
| 227 | Policyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Policy. asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/ObjectIdentifier# |
| 228 | Orderingscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Ordering. bool |
| 229 | Noncescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Nonce. *bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int# |
| 230 | Qualifiedscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Qualified. bool |
| 231 | |
| 232 | Certificatesscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Certificates. []*x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate# |
| 233 | |
| 234 | // If set to true, includes TSA certificate in timestamp response |
| 235 | AddTSACertificatescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#AddTSACertificate. bool |
| 236 | |
| 237 | // Extensions contains raw X.509 extensions from the Extensions field of the |
| 238 | // Time-Stamp. When parsing time-stamps, this can be used to extract |
| 239 | // non-critical extensions that are not parsed by this package. When |
| 240 | // marshaling time-stamps, the Extensions field is ignored, see |
| 241 | // ExtraExtensions. |
| 242 | Extensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Extensions. []pkixscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/.Extensionscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/Extension# |
| 243 | |
| 244 | // ExtraExtensions contains extensions to be copied, raw, into any marshaled |
| 245 | // Time-Stamp response. Values override any extensions that would otherwise |
| 246 | // be produced based on the other fields. The ExtraExtensions field is not |
| 247 | // populated when parsing Time-Stamp responses, see Extensions. |
| 248 | ExtraExtensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#ExtraExtensions. []pkixscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/.Extensionscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/Extension# |
| 249 | } |
| 250 | |
| 251 | // ParseResponse parses an Time-Stamp response in DER form containing a |
| 252 | // TimeStampToken. |
| 253 | // |
| 254 | // Invalid signatures or parse failures will result in a ParseError. Error |
| 255 | // responses will result in a ResponseError. |
| 256 | func ParseResponsescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/ParseResponse().(bytes []byte) (*Timestampscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#, error) { |
| 257 | var err error |
| 258 | var rest []byte |
| 259 | var resp responsescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/response# |
| 260 | |
| 261 | if rest, err = asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.Unmarshalscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/Unmarshal().(bytes, &resp); err != nil { |
| 262 | return nil, err |
| 263 | } |
| 264 | if len(rest) > 0 { |
| 265 | return nil, ParseErrorscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/ParseError#("trailing data in Time-Stamp response") |
| 266 | } |
| 267 | |
| 268 | if resp.Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/response#Status..Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/pkiStatusInfo#Status. > 0 { |
| 269 | var fis string |
| 270 | fi := resp.Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/response#Status..FailureInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/pkiStatusInfo#FailureInfo().() |
| 271 | if fi != UnknownFailureInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/UnknownFailureInfo. { |
| 272 | fis = fi.Stringscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/FailureInfo#String().() |
| 273 | } |
| 274 | return nil, fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("%s: %s (%v)", |
| 275 | resp.Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/response#Status..Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/pkiStatusInfo#Status..Stringscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Status#String().(), |
| 276 | stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Joinscip-go gomod github.com/golang/go/src go1.16 strings/Join().(resp.Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/response#Status..StatusStringscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/pkiStatusInfo#StatusString., ","), |
| 277 | fis) |
| 278 | } |
| 279 | |
| 280 | if len(resp.TimeStampTokenscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/response#TimeStampToken..Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#Bytes.) == 0 { |
| 281 | return nil, ParseErrorscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/ParseError#("no pkcs7 data in Time-Stamp response") |
| 282 | } |
| 283 | |
| 284 | return Parsescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Parse().(resp.TimeStampTokenscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/response#TimeStampToken..FullBytesscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#FullBytes.) |
| 285 | } |
| 286 | |
| 287 | // Parse parses an Time-Stamp in DER form. If the time-stamp contains a |
| 288 | // certificate then the signature over the response is checked. |
| 289 | // |
| 290 | // Invalid signatures or parse failures will result in a ParseError. Error |
| 291 | // responses will result in a ResponseError. |
| 292 | func Parsescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Parse().(bytes []byte) (*Timestampscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#, error) { |
| 293 | var addTSACertificate bool |
| 294 | p7, err := pkcs7scip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/.Parsescip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/Parse().(bytes) |
| 295 | if err != nil { |
| 296 | return nil, err |
| 297 | } |
| 298 | |
| 299 | if len(p7.Certificatesscip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/PKCS7#Certificates.) > 0 { |
| 300 | if err = p7.Verifyscip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/PKCS7#Verify().(); err != nil { |
| 301 | return nil, err |
| 302 | } |
| 303 | addTSACertificate = true |
| 304 | } else { |
| 305 | addTSACertificate = false |
| 306 | } |
| 307 | |
| 308 | var inf tstInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo# |
| 309 | if _, err = asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.Unmarshalscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/Unmarshal().(p7.Contentscip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/PKCS7#Content., &inf); err != nil { |
| 310 | return nil, err |
| 311 | } |
| 312 | |
| 313 | if len(inf.MessageImprintscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#MessageImprint..HashedMessagescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/messageImprint#HashedMessage.) == 0 { |
| 314 | return nil, ParseErrorscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/ParseError#("Time-Stamp response contains no hashed message") |
| 315 | } |
| 316 | |
| 317 | ret := &Timestampscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#{ |
| 318 | RawTokenscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#RawToken.: bytes, |
| 319 | HashedMessagescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#HashedMessage.: inf.MessageImprintscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#MessageImprint..HashedMessagescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/messageImprint#HashedMessage., |
| 320 | Timescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Time.: inf.Timescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Time., |
| 321 | Accuracyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Accuracy.: timescip-go gomod github.com/golang/go/src go1.16 time/.Durationscip-go gomod github.com/golang/go/src go1.16 time/Duration#((timescip-go gomod github.com/golang/go/src go1.16 time/.Secondscip-go gomod github.com/golang/go/src go1.16 time/Second. * timescip-go gomod github.com/golang/go/src go1.16 time/.Durationscip-go gomod github.com/golang/go/src go1.16 time/Duration#(inf.Accuracyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Accuracy..Secondsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/accuracy#Seconds.)) + |
| 322 | (timescip-go gomod github.com/golang/go/src go1.16 time/.Millisecondscip-go gomod github.com/golang/go/src go1.16 time/Millisecond. * timescip-go gomod github.com/golang/go/src go1.16 time/.Durationscip-go gomod github.com/golang/go/src go1.16 time/Duration#(inf.Accuracyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Accuracy..Millisecondsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/accuracy#Milliseconds.)) + |
| 323 | (timescip-go gomod github.com/golang/go/src go1.16 time/.Microsecondscip-go gomod github.com/golang/go/src go1.16 time/Microsecond. * timescip-go gomod github.com/golang/go/src go1.16 time/.Durationscip-go gomod github.com/golang/go/src go1.16 time/Duration#(inf.Accuracyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Accuracy..Microsecondsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/accuracy#Microseconds.))), |
| 324 | SerialNumberscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#SerialNumber.: inf.SerialNumberscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#SerialNumber., |
| 325 | Policyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Policy.: inf.Policyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Policy., |
| 326 | Orderingscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Ordering.: inf.Orderingscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Ordering., |
| 327 | Noncescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Nonce.: inf.Noncescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Nonce., |
| 328 | Certificatesscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Certificates.: p7.Certificatesscip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/PKCS7#Certificates., |
| 329 | AddTSACertificatescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#AddTSACertificate.: addTSACertificate, |
| 330 | Extensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Extensions.: inf.Extensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Extensions., |
| 331 | } |
| 332 | |
| 333 | ret.HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#HashAlgorithm. = getHashAlgorithmFromOIDscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/getHashAlgorithmFromOID().(inf.MessageImprintscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#MessageImprint..HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/messageImprint#HashAlgorithm..Algorithmscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.) |
| 334 | if ret.HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#HashAlgorithm. == cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.Hashscip-go gomod github.com/golang/go/src go1.16 crypto/Hash#(0) { |
| 335 | return nil, ParseErrorscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/ParseError#("Time-Stamp response uses unknown hash function") |
| 336 | } |
| 337 | |
| 338 | if oidInExtensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/oidInExtensions().(asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/ObjectIdentifier#{1, 3, 6, 1, 5, 5, 7, 1, 3}, inf.Extensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Extensions.) { |
| 339 | ret.Qualifiedscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Qualified. = true |
| 340 | } |
| 341 | return ret, nil |
| 342 | } |
| 343 | |
| 344 | // RequestOptions contains options for constructing timestamp requests. |
| 345 | type RequestOptionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions# struct { |
| 346 | // Hash contains the hash function that should be used when |
| 347 | // constructing the timestamp request. If zero, SHA-256 will be used. |
| 348 | Hashscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#Hash. cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.Hashscip-go gomod github.com/golang/go/src go1.16 crypto/Hash# |
| 349 | |
| 350 | // Certificates sets Request.Certificates |
| 351 | Certificatesscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#Certificates. bool |
| 352 | |
| 353 | // The TSAPolicyOID field, if provided, indicates the TSA policy under |
| 354 | // which the TimeStampToken SHOULD be provided |
| 355 | TSAPolicyOIDscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#TSAPolicyOID. asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/ObjectIdentifier# |
| 356 | |
| 357 | // The nonce, if provided, allows the client to verify the timeliness of |
| 358 | // the response. |
| 359 | Noncescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#Nonce. *bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int# |
| 360 | } |
| 361 | |
| 362 | func (opts *RequestOptionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#) hashscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#hash().() cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.Hashscip-go gomod github.com/golang/go/src go1.16 crypto/Hash# { |
| 363 | if opts == nil || opts.Hashscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#Hash. == 0 { |
| 364 | return cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.SHA256scip-go gomod github.com/golang/go/src go1.16 crypto/SHA256. |
| 365 | } |
| 366 | return opts.Hashscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#Hash. |
| 367 | } |
| 368 | |
| 369 | // CreateRequest returns a DER-encoded, timestamp request for the status of cert. If |
| 370 | // opts is nil then sensible defaults are used. |
| 371 | func CreateRequestscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/CreateRequest().(r ioscip-go gomod github.com/golang/go/src go1.16 io/.Readerscip-go gomod github.com/golang/go/src go1.16 io/Reader#, opts *RequestOptionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#) ([]byte, error) { |
| 372 | hashFunc := opts.hashscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#hash().() |
| 373 | |
| 374 | if !hashFunc.Availablescip-go gomod github.com/golang/go/src go1.16 crypto/Hash#Available().() { |
| 375 | return nil, x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.ErrUnsupportedAlgorithmscip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/ErrUnsupportedAlgorithm. |
| 376 | } |
| 377 | h := opts.hashscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#hash().().Newscip-go gomod github.com/golang/go/src go1.16 crypto/Hash#New().() |
| 378 | |
| 379 | b := make([]byte, h.Sizescip-go gomod github.com/golang/go/src go1.16 hash/Hash#Size().()) |
| 380 | for { |
| 381 | n, err := r.Readscip-go gomod github.com/golang/go/src go1.16 io/Reader#Read().(b) |
| 382 | if err == ioscip-go gomod github.com/golang/go/src go1.16 io/.EOFscip-go gomod github.com/golang/go/src go1.16 io/EOF. { |
| 383 | break |
| 384 | } |
| 385 | |
| 386 | _, err = h.Writescip-go gomod github.com/golang/go/src go1.16 io/Writer#Write().(b[:n]) |
| 387 | if err != nil { |
| 388 | return nil, fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("failed to create hash") |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | req := &Requestscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#{ |
| 393 | HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#HashAlgorithm.: opts.hashscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#hash().(), |
| 394 | HashedMessagescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#HashedMessage.: h.Sumscip-go gomod github.com/golang/go/src go1.16 hash/Hash#Sum().(nil), |
| 395 | } |
| 396 | if opts != nil { |
| 397 | req.Certificatesscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#Certificates. = opts.Certificatesscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#Certificates. |
| 398 | } |
| 399 | if opts != nil && opts.TSAPolicyOIDscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#TSAPolicyOID. != nil { |
| 400 | req.TSAPolicyOIDscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#TSAPolicyOID. = opts.TSAPolicyOIDscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#TSAPolicyOID. |
| 401 | } |
| 402 | if opts != nil && opts.Noncescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#Nonce. != nil { |
| 403 | req.Noncescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#Nonce. = opts.Noncescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/RequestOptions#Nonce. |
| 404 | } |
| 405 | return req.Marshalscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Request#Marshal().() |
| 406 | } |
| 407 | |
| 408 | // CreateResponseWithOpts returns a DER-encoded timestamp response with the specified contents. |
| 409 | // The fields in the response are populated as follows: |
| 410 | // |
| 411 | // The responder cert is used to populate the responder's name field, and the |
| 412 | // certificate itself is provided alongside the timestamp response signature. |
| 413 | func (t *Timestampscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#) CreateResponseWithOptsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#CreateResponseWithOpts().(signingCert *x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#, priv cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.Signerscip-go gomod github.com/golang/go/src go1.16 crypto/Signer#, opts cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.SignerOptsscip-go gomod github.com/golang/go/src go1.16 crypto/SignerOpts#) ([]byte, error) { |
| 414 | messageImprint := getMessageImprintscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/getMessageImprint().(t.HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#HashAlgorithm., t.HashedMessagescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#HashedMessage.) |
| 415 | |
| 416 | tsaSerialNumber, err := generateTSASerialNumberscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/generateTSASerialNumber().() |
| 417 | if err != nil { |
| 418 | return nil, err |
| 419 | } |
| 420 | tstInfo, err := t.populateTSTInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#populateTSTInfo().(messageImprint, t.Policyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Policy., tsaSerialNumber, signingCert) |
| 421 | if err != nil { |
| 422 | return nil, err |
| 423 | } |
| 424 | signature, err := t.generateSignedDatascip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#generateSignedData().(tstInfo, priv, signingCert, opts) |
| 425 | if err != nil { |
| 426 | return nil, err |
| 427 | } |
| 428 | timestampRes := responsescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/response#{ |
| 429 | Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/response#Status.: pkiStatusInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/pkiStatusInfo#{ |
| 430 | Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/pkiStatusInfo#Status.: Grantedscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Granted., |
| 431 | }, |
| 432 | TimeStampTokenscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/response#TimeStampToken.: asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.RawValuescip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#{FullBytesscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#FullBytes.: signature}, |
| 433 | } |
| 434 | tspResponseBytes, err := asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.Marshalscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/Marshal().(timestampRes) |
| 435 | if err != nil { |
| 436 | return nil, err |
| 437 | } |
| 438 | return tspResponseBytes, nil |
| 439 | } |
| 440 | |
| 441 | // CreateResponse returns a DER-encoded timestamp response with the specified contents. |
| 442 | // The fields in the response are populated as follows: |
| 443 | // |
| 444 | // The responder cert is used to populate the responder's name field, and the |
| 445 | // certificate itself is provided alongside the timestamp response signature. |
| 446 | // |
| 447 | // This function is equivalent to CreateResponseWithOpts, using a SHA256 hash. |
| 448 | // |
| 449 | // Deprecated: Use CreateResponseWithOpts instead. |
| 450 | func (t *Timestampscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#) CreateResponsescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#CreateResponse().(signingCert *x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#, priv cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.Signerscip-go gomod github.com/golang/go/src go1.16 crypto/Signer#) ([]byte, error) { |
| 451 | return t.CreateResponseWithOptsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#CreateResponseWithOpts().(signingCert, priv, cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.SHA256scip-go gomod github.com/golang/go/src go1.16 crypto/SHA256.) |
| 452 | } |
| 453 | |
| 454 | // CreateErrorResponse is used to create response other than granted and granted with mod status |
| 455 | func CreateErrorResponsescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/CreateErrorResponse().(pkiStatus Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Status#, pkiFailureInfo FailureInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/FailureInfo#) ([]byte, error) { |
| 456 | var bs asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.BitStringscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/BitString# |
| 457 | setFlagscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/setFlag().(&bs, int(pkiFailureInfo)) |
| 458 | |
| 459 | timestampRes := responsescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/response#{ |
| 460 | Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/response#Status.: pkiStatusInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/pkiStatusInfo#{ |
| 461 | Statusscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/pkiStatusInfo#Status.: pkiStatus, |
| 462 | FailInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/pkiStatusInfo#FailInfo.: bs, |
| 463 | }, |
| 464 | } |
| 465 | tspResponseBytes, err := asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.Marshalscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/Marshal().(timestampRes) |
| 466 | if err != nil { |
| 467 | return nil, err |
| 468 | } |
| 469 | return tspResponseBytes, nil |
| 470 | } |
| 471 | |
| 472 | func setFlagscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/setFlag().(bs *asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.BitStringscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/BitString#, i int) { |
| 473 | for l := len(bs.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/BitString#Bytes.); l < 4; l++ { |
| 474 | (*bs).Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/BitString#Bytes. = append((*bs).Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/BitString#Bytes., byte(0)) |
| 475 | (*bs).BitLengthscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/BitString#BitLength. = len((*bs).Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/BitString#Bytes.) * 8 |
| 476 | } |
| 477 | b := i / 8 |
| 478 | p := uint(7 - (i - 8*b)) |
| 479 | (*bs).Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/BitString#Bytes.[b] = (*bs).Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/BitString#Bytes.[b] | (1 << p) |
| 480 | bs.BitLengthscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/BitString#BitLength. = asn1BitLengthscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/asn1BitLength().(bs.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/BitString#Bytes.) |
| 481 | bs.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/BitString#Bytes. = bs.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/BitString#Bytes.[0 : (bs.BitLengthscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/BitString#BitLength./8)+1] |
| 482 | } |
| 483 | |
| 484 | func getMessageImprintscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/getMessageImprint().(hashAlgorithm cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.Hashscip-go gomod github.com/golang/go/src go1.16 crypto/Hash#, hashedMessage []byte) messageImprintscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/messageImprint# { |
| 485 | messageImprint := messageImprintscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/messageImprint#{ |
| 486 | HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/messageImprint#HashAlgorithm.: pkixscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/.AlgorithmIdentifierscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/AlgorithmIdentifier#{ |
| 487 | Algorithmscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.: getOIDFromHashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/getOIDFromHashAlgorithm().(hashAlgorithm), |
| 488 | Parametersscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/AlgorithmIdentifier#Parameters.: asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.NullRawValuescip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/NullRawValue., |
| 489 | }, |
| 490 | HashedMessagescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/messageImprint#HashedMessage.: hashedMessage, |
| 491 | } |
| 492 | return messageImprint |
| 493 | } |
| 494 | |
| 495 | func generateTSASerialNumberscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/generateTSASerialNumber().() (*bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#, error) { |
| 496 | randomBytes := make([]byte, 20) |
| 497 | _, err := randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/.Readscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/Read().(randomBytes) |
| 498 | if err != nil { |
| 499 | return nil, err |
| 500 | } |
| 501 | serialNumber := bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.NewIntscip-go gomod github.com/golang/go/src go1.16 `math/big`/NewInt().(0) |
| 502 | serialNumber = serialNumber.SetBytesscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#SetBytes().(randomBytes) |
| 503 | return serialNumber, nil |
| 504 | } |
| 505 | |
| 506 | func (t *Timestampscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#) populateTSTInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#populateTSTInfo().(messageImprint messageImprintscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/messageImprint#, policyOID asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/ObjectIdentifier#, tsaSerialNumber *bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#, tsaCert *x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#) ([]byte, error) { |
| 507 | dirGeneralName, err := asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.Marshalscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/Marshal().(asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.RawValuescip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#{Tagscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#Tag.: 4, Classscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#Class.: 2, IsCompoundscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#IsCompound.: true, Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#Bytes.: tsaCert.RawSubjectscip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#RawSubject.}) |
| 508 | if err != nil { |
| 509 | return nil, err |
| 510 | } |
| 511 | tstInfo := tstInfoscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#{ |
| 512 | Versionscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Version.: 1, |
| 513 | Policyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Policy.: policyOID, |
| 514 | MessageImprintscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#MessageImprint.: messageImprint, |
| 515 | SerialNumberscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#SerialNumber.: tsaSerialNumber, |
| 516 | Timescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Time.: t.Timescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Time., |
| 517 | TSAscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#TSA.: asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.RawValuescip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#{Tagscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#Tag.: 0, Classscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#Class.: 2, IsCompoundscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#IsCompound.: true, Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#Bytes.: dirGeneralName}, |
| 518 | Orderingscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Ordering.: t.Orderingscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Ordering., |
| 519 | } |
| 520 | if t.Noncescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Nonce. != nil { |
| 521 | tstInfo.Noncescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Nonce. = t.Noncescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Nonce. |
| 522 | } |
| 523 | if t.Accuracyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Accuracy. != 0 { |
| 524 | if t.Accuracyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Accuracy. < timescip-go gomod github.com/golang/go/src go1.16 time/.Microsecondscip-go gomod github.com/golang/go/src go1.16 time/Microsecond. { |
| 525 | // Round up to 1 microsecond if accuracy is lower than 1 microsecond but greater than 0 nanosecond |
| 526 | tstInfo.Accuracyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Accuracy..Microsecondsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/accuracy#Microseconds. = 1 |
| 527 | } else { |
| 528 | seconds := t.Accuracyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Accuracy..Truncatescip-go gomod github.com/golang/go/src go1.16 time/Duration#Truncate().(timescip-go gomod github.com/golang/go/src go1.16 time/.Secondscip-go gomod github.com/golang/go/src go1.16 time/Second.) |
| 529 | tstInfo.Accuracyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Accuracy..Secondsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/accuracy#Seconds. = int64(seconds.Secondsscip-go gomod github.com/golang/go/src go1.16 time/Duration#Seconds().()) |
| 530 | ms := (t.Accuracyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Accuracy. - seconds).Truncatescip-go gomod github.com/golang/go/src go1.16 time/Duration#Truncate().(timescip-go gomod github.com/golang/go/src go1.16 time/.Millisecondscip-go gomod github.com/golang/go/src go1.16 time/Millisecond.) |
| 531 | if ms != 0 { |
| 532 | tstInfo.Accuracyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Accuracy..Millisecondsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/accuracy#Milliseconds. = int64(ms.Millisecondsscip-go gomod github.com/golang/go/src go1.16 time/Duration#Milliseconds().()) |
| 533 | } |
| 534 | microSeconds := (t.Accuracyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Accuracy. - seconds - ms).Truncatescip-go gomod github.com/golang/go/src go1.16 time/Duration#Truncate().(timescip-go gomod github.com/golang/go/src go1.16 time/.Microsecondscip-go gomod github.com/golang/go/src go1.16 time/Microsecond.) |
| 535 | if microSeconds != 0 { |
| 536 | tstInfo.Accuracyscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Accuracy..Microsecondsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/accuracy#Microseconds. = int64(microSeconds.Microsecondsscip-go gomod github.com/golang/go/src go1.16 time/Duration#Microseconds().()) |
| 537 | } |
| 538 | } |
| 539 | } |
| 540 | if len(t.ExtraExtensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#ExtraExtensions.) != 0 { |
| 541 | tstInfo.Extensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Extensions. = t.ExtraExtensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#ExtraExtensions. |
| 542 | } |
| 543 | if t.Qualifiedscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Qualified. && !oidInExtensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/oidInExtensions().(asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/ObjectIdentifier#{1, 3, 6, 1, 5, 5, 7, 1, 3}, t.ExtraExtensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#ExtraExtensions.) { |
| 544 | qcStatements := []qcStatementscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/qcStatement#{{ |
| 545 | StatementIDscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/qcStatement#StatementID.: asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/ObjectIdentifier#{0, 4, 0, 19422, 1, 1}, |
| 546 | }} |
| 547 | asn1QcStats, err := asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.Marshalscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/Marshal().(qcStatements) |
| 548 | if err != nil { |
| 549 | return nil, err |
| 550 | } |
| 551 | tstInfo.Extensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Extensions. = append(tstInfo.Extensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/tstInfo#Extensions., pkixscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/.Extensionscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/Extension#{ |
| 552 | Idscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/Extension#Id.: []int{1, 3, 6, 1, 5, 5, 7, 1, 3}, |
| 553 | Valuescip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/Extension#Value.: asn1QcStats, |
| 554 | Criticalscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/Extension#Critical.: false, |
| 555 | }) |
| 556 | } |
| 557 | tstInfoBytes, err := asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.Marshalscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/Marshal().(tstInfo) |
| 558 | if err != nil { |
| 559 | return nil, err |
| 560 | } |
| 561 | return tstInfoBytes, nil |
| 562 | } |
| 563 | |
| 564 | func (t *Timestampscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#) populateSigningCertificateV2Extscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#populateSigningCertificateV2Ext().(certificate *x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#) ([]byte, error) { |
| 565 | if !t.HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#HashAlgorithm..Availablescip-go gomod github.com/golang/go/src go1.16 crypto/Hash#Available().() { |
| 566 | return nil, x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.ErrUnsupportedAlgorithmscip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/ErrUnsupportedAlgorithm. |
| 567 | } |
| 568 | if t.HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#HashAlgorithm..HashFuncscip-go gomod github.com/golang/go/src go1.16 crypto/Hash#HashFunc().() == cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.SHA1scip-go gomod github.com/golang/go/src go1.16 crypto/SHA1. { |
| 569 | return nil, fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("for SHA1 use ESSCertID instead of ESSCertIDv2") |
| 570 | } |
| 571 | |
| 572 | h := t.HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#HashAlgorithm..HashFuncscip-go gomod github.com/golang/go/src go1.16 crypto/Hash#HashFunc().().Newscip-go gomod github.com/golang/go/src go1.16 crypto/Hash#New().() |
| 573 | _, err := h.Writescip-go gomod github.com/golang/go/src go1.16 io/Writer#Write().(certificate.Rawscip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#Raw.) |
| 574 | if err != nil { |
| 575 | return nil, fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("failed to create hash") |
| 576 | } |
| 577 | |
| 578 | var hashAlg pkixscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/.AlgorithmIdentifierscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/AlgorithmIdentifier# |
| 579 | |
| 580 | // HashAlgorithm defaults to SHA256 |
| 581 | if t.HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#HashAlgorithm..HashFuncscip-go gomod github.com/golang/go/src go1.16 crypto/Hash#HashFunc().() != cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.SHA256scip-go gomod github.com/golang/go/src go1.16 crypto/SHA256. { |
| 582 | hashAlg = pkixscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/.AlgorithmIdentifierscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/AlgorithmIdentifier#{ |
| 583 | Algorithmscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.: hashOIDsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/hashOIDs.[t.HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#HashAlgorithm..HashFuncscip-go gomod github.com/golang/go/src go1.16 crypto/Hash#HashFunc().()], |
| 584 | Parametersscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/AlgorithmIdentifier#Parameters.: asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.NullRawValuescip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/NullRawValue., |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | signingCertificateV2 := signingCertificateV2scip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/signingCertificateV2#{ |
| 589 | Certsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/signingCertificateV2#Certs.: []essCertIDv2scip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/essCertIDv2#{{ |
| 590 | HashAlgorithmscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/essCertIDv2#HashAlgorithm.: hashAlg, |
| 591 | CertHashscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/essCertIDv2#CertHash.: h.Sumscip-go gomod github.com/golang/go/src go1.16 hash/Hash#Sum().(nil), |
| 592 | IssuerSerialscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/essCertIDv2#IssuerSerial.: issuerAndSerialscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/issuerAndSerial#{ |
| 593 | IssuerNamescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/issuerAndSerial#IssuerName.: generalNamesscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/generalNames#{ |
| 594 | Namescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/generalNames#Name.: asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.RawValuescip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#{Tagscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#Tag.: 4, Classscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#Class.: 2, IsCompoundscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#IsCompound.: true, Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#Bytes.: certificate.RawIssuerscip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#RawIssuer.}, |
| 595 | }, |
| 596 | SerialNumberscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/issuerAndSerial#SerialNumber.: certificate.SerialNumberscip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#SerialNumber., |
| 597 | }, |
| 598 | }}, |
| 599 | } |
| 600 | signingCertV2Bytes, err := asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.Marshalscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/Marshal().(signingCertificateV2) |
| 601 | if err != nil { |
| 602 | return nil, err |
| 603 | } |
| 604 | return signingCertV2Bytes, nil |
| 605 | } |
| 606 | |
| 607 | // digestAlgorithmToOID converts the hash func to the corresponding OID. |
| 608 | // This should have parity with [pkcs7.getHashForOID]. |
| 609 | func digestAlgorithmToOIDscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/digestAlgorithmToOID().(hash cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.Hashscip-go gomod github.com/golang/go/src go1.16 crypto/Hash#) (asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/ObjectIdentifier#, error) { |
| 610 | switch hash { |
| 611 | case cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.SHA1scip-go gomod github.com/golang/go/src go1.16 crypto/SHA1.: |
| 612 | return pkcs7scip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/.OIDDigestAlgorithmSHA1scip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/OIDDigestAlgorithmSHA1., nil |
| 613 | case cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.SHA256scip-go gomod github.com/golang/go/src go1.16 crypto/SHA256.: |
| 614 | return pkcs7scip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/.OIDDigestAlgorithmSHA256scip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/OIDDigestAlgorithmSHA256., nil |
| 615 | case cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.SHA384scip-go gomod github.com/golang/go/src go1.16 crypto/SHA384.: |
| 616 | return pkcs7scip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/.OIDDigestAlgorithmSHA384scip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/OIDDigestAlgorithmSHA384., nil |
| 617 | case cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.SHA512scip-go gomod github.com/golang/go/src go1.16 crypto/SHA512.: |
| 618 | return pkcs7scip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/.OIDDigestAlgorithmSHA512scip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/OIDDigestAlgorithmSHA512., nil |
| 619 | } |
| 620 | return nil, pkcs7scip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/.ErrUnsupportedAlgorithmscip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/ErrUnsupportedAlgorithm. |
| 621 | } |
| 622 | |
| 623 | func (t *Timestampscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#) generateSignedDatascip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#generateSignedData().(tstInfo []byte, signer cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.Signerscip-go gomod github.com/golang/go/src go1.16 crypto/Signer#, certificate *x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#, opts cryptoscip-go gomod github.com/golang/go/src go1.16 crypto/.SignerOptsscip-go gomod github.com/golang/go/src go1.16 crypto/SignerOpts#) ([]byte, error) { |
| 624 | signedData, err := pkcs7scip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/.NewSignedDatascip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/NewSignedData().(tstInfo) |
| 625 | if err != nil { |
| 626 | return nil, err |
| 627 | } |
| 628 | |
| 629 | alg, err := digestAlgorithmToOIDscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/digestAlgorithmToOID().(opts.HashFuncscip-go gomod github.com/golang/go/src go1.16 crypto/SignerOpts#HashFunc().()) |
| 630 | if err != nil { |
| 631 | return nil, err |
| 632 | } |
| 633 | signedData.SetDigestAlgorithmscip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/SignedData#SetDigestAlgorithm().(alg) |
| 634 | signedData.SetContentTypescip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/SignedData#SetContentType().(asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/ObjectIdentifier#{1, 2, 840, 113549, 1, 9, 16, 1, 4}) |
| 635 | signedData.GetSignedDatascip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/SignedData#GetSignedData().().Versionscip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/signedData#Version. = 3 |
| 636 | |
| 637 | signingCertV2Bytes, err := t.populateSigningCertificateV2Extscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#populateSigningCertificateV2Ext().(certificate) |
| 638 | if err != nil { |
| 639 | return nil, err |
| 640 | } |
| 641 | |
| 642 | signerInfoConfig := pkcs7scip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/.SignerInfoConfigscip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/SignerInfoConfig#{ |
| 643 | ExtraSignedAttributesscip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/SignerInfoConfig#ExtraSignedAttributes.: []pkcs7scip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/.Attributescip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/Attribute#{ |
| 644 | { |
| 645 | Typescip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/Attribute#Type.: asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/ObjectIdentifier#{1, 2, 840, 113549, 1, 9, 16, 2, 47}, |
| 646 | Valuescip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/Attribute#Value.: asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.RawValuescip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#{FullBytesscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/RawValue#FullBytes.: signingCertV2Bytes}, |
| 647 | }, |
| 648 | }, |
| 649 | } |
| 650 | if !t.AddTSACertificatescip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#AddTSACertificate. { |
| 651 | signerInfoConfig.SkipCertificatesscip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/SignerInfoConfig#SkipCertificates. = true |
| 652 | } |
| 653 | |
| 654 | if len(t.Certificatesscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Certificates.) > 0 { |
| 655 | err = signedData.AddSignerChainscip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/SignedData#AddSignerChain().(certificate, signer, t.Certificatesscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/Timestamp#Certificates., signerInfoConfig) |
| 656 | } else { |
| 657 | err = signedData.AddSignerscip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/SignedData#AddSigner().(certificate, signer, signerInfoConfig) |
| 658 | } |
| 659 | if err != nil { |
| 660 | return nil, err |
| 661 | } |
| 662 | |
| 663 | signature, err := signedData.Finishscip-go gomod github.com/digitorus/pkcs7 e76b763bdc49 `github.com/digitorus/pkcs7`/SignedData#Finish().() |
| 664 | if err != nil { |
| 665 | return nil, err |
| 666 | } |
| 667 | return signature, nil |
| 668 | } |
| 669 | |
| 670 | // copied from crypto/x509 package |
| 671 | // oidNotInExtensions reports whether an extension with the given oid exists in |
| 672 | // extensions. |
| 673 | func oidInExtensionsscip-go gomod github.com/digitorus/timestamp . `github.com/digitorus/timestamp`/oidInExtensions().(oid asn1scip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/ObjectIdentifier#, extensions []pkixscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/.Extensionscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/Extension#) bool { |
| 674 | for _, e := range extensions { |
| 675 | if e.Idscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/Extension#Id..Equalscip-go gomod github.com/golang/go/src go1.16 `encoding/asn1`/ObjectIdentifier#Equal().(oid) { |
| 676 | return true |
| 677 | } |
| 678 | } |
| 679 | return false |
| 680 | } |