| 1 | package pkcs7scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.14 bytes/" |
| 5 | "cryptoscip-go gomod github.com/golang/go/src go1.14 crypto/" |
| 6 | "crypto/subtlescip-go gomod github.com/golang/go/src go1.14 `crypto/subtle`/" |
| 7 | "crypto/x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/" |
| 8 | "crypto/x509/pkixscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/" |
| 9 | "encoding/asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/" |
| 10 | "errorsscip-go gomod github.com/golang/go/src go1.14 errors/" |
| 11 | "fmtscip-go gomod github.com/golang/go/src go1.14 fmt/" |
| 12 | "timescip-go gomod github.com/golang/go/src go1.14 time/" |
| 13 | ) |
| 14 | |
| 15 | // Verify is a wrapper around VerifyWithChain() that initializes an empty |
| 16 | // trust store, effectively disabling certificate verification when validating |
| 17 | // a signature. |
| 18 | func (p7 *PKCS7scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#) Verifyscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Verify().() (err error) { |
| 19 | return p7.VerifyWithChainscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#VerifyWithChain().(nil) |
| 20 | } |
| 21 | |
| 22 | // VerifyWithChain checks the signatures of a PKCS7 object. |
| 23 | // |
| 24 | // If truststore is not nil, it also verifies the chain of trust of |
| 25 | // the end-entity signer cert to one of the roots in the |
| 26 | // truststore. When the PKCS7 object includes the signing time |
| 27 | // authenticated attr verifies the chain at that time and UTC now |
| 28 | // otherwise. |
| 29 | func (p7 *PKCS7scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#) VerifyWithChainscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#VerifyWithChain().(truststore *x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.CertPoolscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/CertPool#) (err error) { |
| 30 | if len(p7.Signersscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Signers.) == 0 { |
| 31 | return errorsscip-go gomod github.com/golang/go/src go1.14 errors/.Newscip-go gomod github.com/golang/go/src go1.14 errors/New().("pkcs7: Message has no signers") |
| 32 | } |
| 33 | for _, signer := range p7.Signersscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Signers. { |
| 34 | if err := verifySignaturescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/verifySignature().(p7, signer, truststore); err != nil { |
| 35 | return err |
| 36 | } |
| 37 | } |
| 38 | return nil |
| 39 | } |
| 40 | |
| 41 | // VerifyWithChainAtTime checks the signatures of a PKCS7 object. |
| 42 | // |
| 43 | // If truststore is not nil, it also verifies the chain of trust of |
| 44 | // the end-entity signer cert to a root in the truststore at |
| 45 | // currentTime. It does not use the signing time authenticated |
| 46 | // attribute. |
| 47 | func (p7 *PKCS7scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#) VerifyWithChainAtTimescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#VerifyWithChainAtTime().(truststore *x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.CertPoolscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/CertPool#, currentTime timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#) (err error) { |
| 48 | if len(p7.Signersscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Signers.) == 0 { |
| 49 | return errorsscip-go gomod github.com/golang/go/src go1.14 errors/.Newscip-go gomod github.com/golang/go/src go1.14 errors/New().("pkcs7: Message has no signers") |
| 50 | } |
| 51 | for _, signer := range p7.Signersscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Signers. { |
| 52 | if err := verifySignatureAtTimescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/verifySignatureAtTime().(p7, signer, truststore, currentTime); err != nil { |
| 53 | return err |
| 54 | } |
| 55 | } |
| 56 | return nil |
| 57 | } |
| 58 | |
| 59 | // SigningTimeNotValidError is returned when the signing time attribute |
| 60 | // falls outside of the signer certificate validity. |
| 61 | type SigningTimeNotValidErrorscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError# struct { |
| 62 | SigningTimescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError#SigningTime. timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time# |
| 63 | NotBeforescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError#NotBefore. timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time# // NotBefore of signer |
| 64 | NotAfterscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError#NotAfter. timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time# // NotAfter of signer |
| 65 | } |
| 66 | |
| 67 | func (e *SigningTimeNotValidErrorscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError#) Errorscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError#Error().() string { |
| 68 | return fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.14 fmt/Sprintf().("pkcs7: signing time %q is outside of certificate validity %q to %q", |
| 69 | e.SigningTimescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError#SigningTime..Formatscip-go gomod github.com/golang/go/src go1.14 time/Time#Format().(timescip-go gomod github.com/golang/go/src go1.14 time/.RFC3339scip-go gomod github.com/golang/go/src go1.14 time/RFC3339.), |
| 70 | e.NotBeforescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError#NotBefore..Formatscip-go gomod github.com/golang/go/src go1.14 time/Time#Format().(timescip-go gomod github.com/golang/go/src go1.14 time/.RFC3339scip-go gomod github.com/golang/go/src go1.14 time/RFC3339.), |
| 71 | e.NotAfterscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError#NotAfter..Formatscip-go gomod github.com/golang/go/src go1.14 time/Time#Format().(timescip-go gomod github.com/golang/go/src go1.14 time/.RFC3339scip-go gomod github.com/golang/go/src go1.14 time/RFC3339.)) |
| 72 | } |
| 73 | |
| 74 | func verifySignatureAtTimescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/verifySignatureAtTime().(p7 *PKCS7scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#, signer signerInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#, truststore *x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.CertPoolscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/CertPool#, currentTime timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#) (err error) { |
| 75 | signedData := p7.Contentscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Content. |
| 76 | ee := getCertFromCertsByIssuerAndSerialscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/getCertFromCertsByIssuerAndSerial().(p7.Certificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Certificates., signer.IssuerAndSerialNumberscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#IssuerAndSerialNumber.) |
| 77 | if ee == nil { |
| 78 | return errorsscip-go gomod github.com/golang/go/src go1.14 errors/.Newscip-go gomod github.com/golang/go/src go1.14 errors/New().("pkcs7: No certificate for signer") |
| 79 | } |
| 80 | if len(signer.AuthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#AuthenticatedAttributes.) > 0 { |
| 81 | // TODO(fullsailor): First check the content type match |
| 82 | var ( |
| 83 | digest []byte |
| 84 | signingTime timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time# |
| 85 | ) |
| 86 | err := unmarshalAttributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/unmarshalAttribute().(signer.AuthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#AuthenticatedAttributes., OIDAttributeMessageDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDAttributeMessageDigest., &digest) |
| 87 | if err != nil { |
| 88 | return err |
| 89 | } |
| 90 | hash, err := getHashForOIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/getHashForOID().(signer.DigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#DigestAlgorithm..Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.) |
| 91 | if err != nil { |
| 92 | return err |
| 93 | } |
| 94 | computed, err := calculateHashscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/calculateHash().(p7.Hasherscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Hasher., hash, p7.Contentscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Content.) |
| 95 | if err != nil { |
| 96 | return err |
| 97 | } |
| 98 | if subtlescip-go gomod github.com/golang/go/src go1.14 `crypto/subtle`/.ConstantTimeComparescip-go gomod github.com/golang/go/src go1.14 `crypto/subtle`/ConstantTimeCompare().(digest, computed) != 1 { |
| 99 | return &MessageDigestMismatchErrorscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/MessageDigestMismatchError#{ |
| 100 | ExpectedDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/MessageDigestMismatchError#ExpectedDigest.: digest, |
| 101 | ActualDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/MessageDigestMismatchError#ActualDigest.: computed, |
| 102 | } |
| 103 | } |
| 104 | signedData, err = marshalAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/marshalAttributes().(signer.AuthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#AuthenticatedAttributes.) |
| 105 | if err != nil { |
| 106 | return err |
| 107 | } |
| 108 | err = unmarshalAttributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/unmarshalAttribute().(signer.AuthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#AuthenticatedAttributes., OIDAttributeSigningTimescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDAttributeSigningTime., &signingTime) |
| 109 | if err == nil { |
| 110 | // signing time found, performing validity check |
| 111 | if signingTime.Afterscip-go gomod github.com/golang/go/src go1.14 time/Time#After().(ee.NotAfterscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#NotAfter.) || signingTime.Beforescip-go gomod github.com/golang/go/src go1.14 time/Time#Before().(ee.NotBeforescip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#NotBefore.) { |
| 112 | return &SigningTimeNotValidErrorscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError#{ |
| 113 | SigningTimescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError#SigningTime.: signingTime, |
| 114 | NotBeforescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError#NotBefore.: ee.NotBeforescip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#NotBefore., |
| 115 | NotAfterscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError#NotAfter.: ee.NotAfterscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#NotAfter., |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | if truststore != nil { |
| 121 | _, err = verifyCertChainscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/verifyCertChain().(ee, p7.Certificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Certificates., truststore, currentTime) |
| 122 | if err != nil { |
| 123 | return err |
| 124 | } |
| 125 | } |
| 126 | sigalg, err := getSignatureAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/getSignatureAlgorithm().(signer.DigestEncryptionAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#DigestEncryptionAlgorithm., signer.DigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#DigestAlgorithm.) |
| 127 | if err != nil { |
| 128 | return err |
| 129 | } |
| 130 | return ee.CheckSignaturescip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#CheckSignature().(sigalg, signedData, signer.EncryptedDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#EncryptedDigest.) |
| 131 | } |
| 132 | |
| 133 | func verifySignaturescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/verifySignature().(p7 *PKCS7scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#, signer signerInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#, truststore *x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.CertPoolscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/CertPool#) (err error) { |
| 134 | signedData := p7.Contentscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Content. |
| 135 | ee := getCertFromCertsByIssuerAndSerialscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/getCertFromCertsByIssuerAndSerial().(p7.Certificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Certificates., signer.IssuerAndSerialNumberscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#IssuerAndSerialNumber.) |
| 136 | if ee == nil { |
| 137 | return errorsscip-go gomod github.com/golang/go/src go1.14 errors/.Newscip-go gomod github.com/golang/go/src go1.14 errors/New().("pkcs7: No certificate for signer") |
| 138 | } |
| 139 | signingTime := timescip-go gomod github.com/golang/go/src go1.14 time/.Nowscip-go gomod github.com/golang/go/src go1.14 time/Now().().UTCscip-go gomod github.com/golang/go/src go1.14 time/Time#UTC().() |
| 140 | if len(signer.AuthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#AuthenticatedAttributes.) > 0 { |
| 141 | // TODO(fullsailor): First check the content type match |
| 142 | var digest []byte |
| 143 | err := unmarshalAttributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/unmarshalAttribute().(signer.AuthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#AuthenticatedAttributes., OIDAttributeMessageDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDAttributeMessageDigest., &digest) |
| 144 | if err != nil { |
| 145 | return err |
| 146 | } |
| 147 | hash, err := getHashForOIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/getHashForOID().(signer.DigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#DigestAlgorithm..Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.) |
| 148 | if err != nil { |
| 149 | return err |
| 150 | } |
| 151 | computed, err := calculateHashscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/calculateHash().(p7.Hasherscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Hasher., hash, p7.Contentscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Content.) |
| 152 | if err != nil { |
| 153 | return err |
| 154 | } |
| 155 | if subtlescip-go gomod github.com/golang/go/src go1.14 `crypto/subtle`/.ConstantTimeComparescip-go gomod github.com/golang/go/src go1.14 `crypto/subtle`/ConstantTimeCompare().(digest, computed) != 1 { |
| 156 | return &MessageDigestMismatchErrorscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/MessageDigestMismatchError#{ |
| 157 | ExpectedDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/MessageDigestMismatchError#ExpectedDigest.: digest, |
| 158 | ActualDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/MessageDigestMismatchError#ActualDigest.: computed, |
| 159 | } |
| 160 | } |
| 161 | signedData, err = marshalAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/marshalAttributes().(signer.AuthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#AuthenticatedAttributes.) |
| 162 | if err != nil { |
| 163 | return err |
| 164 | } |
| 165 | err = unmarshalAttributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/unmarshalAttribute().(signer.AuthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#AuthenticatedAttributes., OIDAttributeSigningTimescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDAttributeSigningTime., &signingTime) |
| 166 | if err == nil { |
| 167 | // signing time found, performing validity check |
| 168 | if signingTime.Afterscip-go gomod github.com/golang/go/src go1.14 time/Time#After().(ee.NotAfterscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#NotAfter.) || signingTime.Beforescip-go gomod github.com/golang/go/src go1.14 time/Time#Before().(ee.NotBeforescip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#NotBefore.) { |
| 169 | return &SigningTimeNotValidErrorscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError#{ |
| 170 | SigningTimescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError#SigningTime.: signingTime, |
| 171 | NotBeforescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError#NotBefore.: ee.NotBeforescip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#NotBefore., |
| 172 | NotAfterscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SigningTimeNotValidError#NotAfter.: ee.NotAfterscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#NotAfter., |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | if truststore != nil { |
| 178 | _, err = verifyCertChainscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/verifyCertChain().(ee, p7.Certificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Certificates., truststore, signingTime) |
| 179 | if err != nil { |
| 180 | return err |
| 181 | } |
| 182 | } |
| 183 | sigalg, err := getSignatureAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/getSignatureAlgorithm().(signer.DigestEncryptionAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#DigestEncryptionAlgorithm., signer.DigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#DigestAlgorithm.) |
| 184 | if err != nil { |
| 185 | return err |
| 186 | } |
| 187 | return ee.CheckSignaturescip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#CheckSignature().(sigalg, signedData, signer.EncryptedDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#EncryptedDigest.) |
| 188 | } |
| 189 | |
| 190 | // GetOnlySigner returns an x509.Certificate for the first signer of the signed |
| 191 | // data payload. If there are more or less than one signer, nil is returned |
| 192 | func (p7 *PKCS7scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#) GetOnlySignerscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#GetOnlySigner().() *x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate# { |
| 193 | if len(p7.Signersscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Signers.) != 1 { |
| 194 | return nil |
| 195 | } |
| 196 | signer := p7.Signersscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Signers.[0] |
| 197 | return getCertFromCertsByIssuerAndSerialscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/getCertFromCertsByIssuerAndSerial().(p7.Certificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Certificates., signer.IssuerAndSerialNumberscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#IssuerAndSerialNumber.) |
| 198 | } |
| 199 | |
| 200 | // UnmarshalSignedAttribute decodes a single attribute from the signer info |
| 201 | func (p7 *PKCS7scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#) UnmarshalSignedAttributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#UnmarshalSignedAttribute().(attributeType asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#, out interface{}) error { |
| 202 | sd, ok := p7.rawscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#raw..(signedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#) |
| 203 | if !ok { |
| 204 | return errorsscip-go gomod github.com/golang/go/src go1.14 errors/.Newscip-go gomod github.com/golang/go/src go1.14 errors/New().("pkcs7: payload is not signedData content") |
| 205 | } |
| 206 | if len(sd.SignerInfosscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#SignerInfos.) < 1 { |
| 207 | return errorsscip-go gomod github.com/golang/go/src go1.14 errors/.Newscip-go gomod github.com/golang/go/src go1.14 errors/New().("pkcs7: payload has no signers") |
| 208 | } |
| 209 | attributes := sd.SignerInfosscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#SignerInfos.[0].AuthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#AuthenticatedAttributes. |
| 210 | return unmarshalAttributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/unmarshalAttribute().(attributes, attributeType, out) |
| 211 | } |
| 212 | |
| 213 | func parseSignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/parseSignedData().(data []byte) (*PKCS7scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#, error) { |
| 214 | var sd signedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData# |
| 215 | asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.Unmarshalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/Unmarshal().(data, &sd) |
| 216 | certs, err := sd.Certificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#Certificates..Parsescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/rawCertificates#Parse().() |
| 217 | if err != nil { |
| 218 | return nil, err |
| 219 | } |
| 220 | // fmt.Printf("--> Signed Data Version %d\n", sd.Version) |
| 221 | |
| 222 | var compound asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.RawValuescip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue# |
| 223 | var content unsignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/unsignedData# |
| 224 | |
| 225 | // The Content.Bytes maybe empty on PKI responses. |
| 226 | if len(sd.ContentInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#ContentInfo..Contentscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo#Content..Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Bytes.) > 0 { |
| 227 | if _, err := asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.Unmarshalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/Unmarshal().(sd.ContentInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#ContentInfo..Contentscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo#Content..Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Bytes., &compound); err != nil { |
| 228 | return nil, err |
| 229 | } |
| 230 | } |
| 231 | // Compound octet string |
| 232 | if compound.IsCompoundscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#IsCompound. { |
| 233 | if compound.Tagscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Tag. == 4 { |
| 234 | for len(compound.Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Bytes.) > 0 { |
| 235 | var cdata asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.RawValuescip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue# |
| 236 | if _, err = asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.Unmarshalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/Unmarshal().(compound.Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Bytes., &cdata); err != nil { |
| 237 | return nil, err |
| 238 | } |
| 239 | content = append(content, cdata.Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Bytes....) |
| 240 | compound.Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Bytes. = compound.Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Bytes.[len(cdata.FullBytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#FullBytes.):] |
| 241 | } |
| 242 | } else { |
| 243 | content = compound.Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Bytes. |
| 244 | } |
| 245 | } else { |
| 246 | // assuming this is tag 04 |
| 247 | content = compound.Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Bytes. |
| 248 | } |
| 249 | return &PKCS7scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#{ |
| 250 | Contentscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Content.: content, |
| 251 | Certificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Certificates.: certs, |
| 252 | CRLsscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#CRLs.: sd.CRLsscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#CRLs., |
| 253 | Signersscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#Signers.: sd.SignerInfosscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#SignerInfos., |
| 254 | rawscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/PKCS7#raw.: sd}, nil |
| 255 | } |
| 256 | |
| 257 | // verifyCertChain takes an end-entity certs, a list of potential intermediates and a |
| 258 | // truststore, and built all potential chains between the EE and a trusted root. |
| 259 | // |
| 260 | // When verifying chains that may have expired, currentTime can be set to a past date |
| 261 | // to allow the verification to pass. If unset, currentTime is set to the current UTC time. |
| 262 | func verifyCertChainscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/verifyCertChain().(ee *x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#, certs []*x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#, truststore *x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.CertPoolscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/CertPool#, currentTime timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#) (chains [][]*x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#, err error) { |
| 263 | intermediates := x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.NewCertPoolscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/NewCertPool().() |
| 264 | for _, intermediate := range certs { |
| 265 | intermediates.AddCertscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/CertPool#AddCert().(intermediate) |
| 266 | } |
| 267 | verifyOptions := x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.VerifyOptionsscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/VerifyOptions#{ |
| 268 | Rootsscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/VerifyOptions#Roots.: truststore, |
| 269 | Intermediatesscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/VerifyOptions#Intermediates.: intermediates, |
| 270 | KeyUsagesscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/VerifyOptions#KeyUsages.: []x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.ExtKeyUsagescip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/ExtKeyUsage#{x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.ExtKeyUsageAnyscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/ExtKeyUsageAny.}, |
| 271 | CurrentTimescip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/VerifyOptions#CurrentTime.: currentTime, |
| 272 | } |
| 273 | chains, err = ee.Verifyscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#Verify().(verifyOptions) |
| 274 | if err != nil { |
| 275 | return chains, fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("pkcs7: failed to verify certificate chain: %v", err) |
| 276 | } |
| 277 | return |
| 278 | } |
| 279 | |
| 280 | // MessageDigestMismatchError is returned when the signer data digest does not |
| 281 | // match the computed digest for the contained content |
| 282 | type MessageDigestMismatchErrorscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/MessageDigestMismatchError# struct { |
| 283 | ExpectedDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/MessageDigestMismatchError#ExpectedDigest. []byte |
| 284 | ActualDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/MessageDigestMismatchError#ActualDigest. []byte |
| 285 | } |
| 286 | |
| 287 | func (err *MessageDigestMismatchErrorscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/MessageDigestMismatchError#) Errorscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/MessageDigestMismatchError#Error().() string { |
| 288 | return fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.14 fmt/Sprintf().("pkcs7: Message digest mismatch\n\tExpected: %X\n\tActual : %X", err.ExpectedDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/MessageDigestMismatchError#ExpectedDigest., err.ActualDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/MessageDigestMismatchError#ActualDigest.) |
| 289 | } |
| 290 | |
| 291 | func getSignatureAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/getSignatureAlgorithm().(digestEncryption, digest pkixscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/.AlgorithmIdentifierscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#) (x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.SignatureAlgorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/SignatureAlgorithm#, error) { |
| 292 | switch { |
| 293 | case digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmECDSASHA1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmECDSASHA1.): |
| 294 | return x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.ECDSAWithSHA1scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/ECDSAWithSHA1., nil |
| 295 | case digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmECDSASHA256scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmECDSASHA256.): |
| 296 | return x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.ECDSAWithSHA256scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/ECDSAWithSHA256., nil |
| 297 | case digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmECDSASHA384scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmECDSASHA384.): |
| 298 | return x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.ECDSAWithSHA384scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/ECDSAWithSHA384., nil |
| 299 | case digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmECDSASHA512scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmECDSASHA512.): |
| 300 | return x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.ECDSAWithSHA512scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/ECDSAWithSHA512., nil |
| 301 | case digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDEncryptionAlgorithmRSAscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDEncryptionAlgorithmRSA.), |
| 302 | digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDEncryptionAlgorithmRSASHA1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDEncryptionAlgorithmRSASHA1.), |
| 303 | digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDEncryptionAlgorithmRSASHA256scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDEncryptionAlgorithmRSASHA256.), |
| 304 | digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDEncryptionAlgorithmRSASHA384scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDEncryptionAlgorithmRSASHA384.), |
| 305 | digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDEncryptionAlgorithmRSASHA512scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDEncryptionAlgorithmRSASHA512.): |
| 306 | switch { |
| 307 | case digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmSHA1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmSHA1.), digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDEncryptionAlgorithmRSASHA1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDEncryptionAlgorithmRSASHA1.): |
| 308 | return x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.SHA1WithRSAscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/SHA1WithRSA., nil |
| 309 | case digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmSHA256scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmSHA256.), digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDEncryptionAlgorithmRSASHA256scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDEncryptionAlgorithmRSASHA256.): |
| 310 | return x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.SHA256WithRSAscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/SHA256WithRSA., nil |
| 311 | case digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmSHA384scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmSHA384.), digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDEncryptionAlgorithmRSASHA384scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDEncryptionAlgorithmRSASHA384.): |
| 312 | return x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.SHA384WithRSAscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/SHA384WithRSA., nil |
| 313 | case digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmSHA512scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmSHA512.), digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDEncryptionAlgorithmRSASHA512scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDEncryptionAlgorithmRSASHA512.): |
| 314 | return x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.SHA512WithRSAscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/SHA512WithRSA., nil |
| 315 | default: |
| 316 | return -1, fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("pkcs7: unsupported digest %q for encryption algorithm %q", |
| 317 | digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Stringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#String().(), digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Stringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#String().()) |
| 318 | } |
| 319 | case digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmDSAscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmDSA.), |
| 320 | digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmDSASHA1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmDSASHA1.): |
| 321 | switch { |
| 322 | case digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmSHA1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmSHA1.): |
| 323 | return x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.DSAWithSHA1scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/DSAWithSHA1., nil |
| 324 | case digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmSHA256scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmSHA256.): |
| 325 | return x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.DSAWithSHA256scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/DSAWithSHA256., nil |
| 326 | default: |
| 327 | return -1, fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("pkcs7: unsupported digest %q for encryption algorithm %q", |
| 328 | digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Stringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#String().(), digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Stringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#String().()) |
| 329 | } |
| 330 | case digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDEncryptionAlgorithmECDSAP256scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDEncryptionAlgorithmECDSAP256.), |
| 331 | digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDEncryptionAlgorithmECDSAP384scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDEncryptionAlgorithmECDSAP384.), |
| 332 | digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDEncryptionAlgorithmECDSAP521scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDEncryptionAlgorithmECDSAP521.): |
| 333 | switch { |
| 334 | case digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmSHA1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmSHA1.): |
| 335 | return x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.ECDSAWithSHA1scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/ECDSAWithSHA1., nil |
| 336 | case digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmSHA256scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmSHA256.): |
| 337 | return x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.ECDSAWithSHA256scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/ECDSAWithSHA256., nil |
| 338 | case digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmSHA384scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmSHA384.): |
| 339 | return x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.ECDSAWithSHA384scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/ECDSAWithSHA384., nil |
| 340 | case digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmSHA512scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmSHA512.): |
| 341 | return x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.ECDSAWithSHA512scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/ECDSAWithSHA512., nil |
| 342 | default: |
| 343 | return -1, fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("pkcs7: unsupported digest %q for encryption algorithm %q", |
| 344 | digest.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Stringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#String().(), digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Stringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#String().()) |
| 345 | } |
| 346 | default: |
| 347 | return -1, fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("pkcs7: unsupported algorithm %q", |
| 348 | digestEncryption.Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm..Stringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#String().()) |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | func getCertFromCertsByIssuerAndSerialscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/getCertFromCertsByIssuerAndSerial().(certs []*x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#, ias issuerAndSerialscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/issuerAndSerial#) *x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate# { |
| 353 | for _, cert := range certs { |
| 354 | if isCertMatchForIssuerAndSerialscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/isCertMatchForIssuerAndSerial().(cert, ias) { |
| 355 | return cert |
| 356 | } |
| 357 | } |
| 358 | return nil |
| 359 | } |
| 360 | |
| 361 | func unmarshalAttributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/unmarshalAttribute().(attrs []attributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attribute#, attributeType asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#, out interface{}) error { |
| 362 | for _, attr := range attrs { |
| 363 | if attr.Typescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attribute#Type..Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(attributeType) { |
| 364 | _, err := asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.Unmarshalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/Unmarshal().(attr.Valuescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attribute#Value..Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Bytes., out) |
| 365 | return err |
| 366 | } |
| 367 | } |
| 368 | return errorsscip-go gomod github.com/golang/go/src go1.14 errors/.Newscip-go gomod github.com/golang/go/src go1.14 errors/New().("pkcs7: attribute type not in attributes") |
| 369 | } |
| 370 | |
| 371 | func calculateHashscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/calculateHash().(hasher Hasherscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/Hasher#, hashFunc cryptoscip-go gomod github.com/golang/go/src go1.14 crypto/.Hashscip-go gomod github.com/golang/go/src go1.14 crypto/Hash#, content []byte) (computed []byte, err error) { |
| 372 | if hasher != nil { |
| 373 | computed, err = hasher.Hashscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/Hasher#Hash.(hashFunc, bytesscip-go gomod github.com/golang/go/src go1.14 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.14 bytes/NewReader().(content)) |
| 374 | } else { |
| 375 | if !hashFunc.Availablescip-go gomod github.com/golang/go/src go1.14 crypto/Hash#Available().() { |
| 376 | return nil, fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("hash function %v not available", hashFunc) |
| 377 | } |
| 378 | |
| 379 | h := hashFunc.Newscip-go gomod github.com/golang/go/src go1.14 crypto/Hash#New().() |
| 380 | _, _ = h.Writescip-go gomod github.com/golang/go/src go1.14 io/Writer#Write().(content) |
| 381 | computed = h.Sumscip-go gomod github.com/golang/go/src go1.14 hash/Hash#Sum().(nil) |
| 382 | } |
| 383 | |
| 384 | return |
| 385 | } |