| 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/dsascip-go gomod github.com/golang/go/src go1.14 `crypto/dsa`/" |
| 7 | "crypto/randscip-go gomod github.com/golang/go/src go1.14 `crypto/rand`/" |
| 8 | "crypto/x509scip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/" |
| 9 | "crypto/x509/pkixscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/" |
| 10 | "encoding/asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/" |
| 11 | "errorsscip-go gomod github.com/golang/go/src go1.14 errors/" |
| 12 | "fmtscip-go gomod github.com/golang/go/src go1.14 fmt/" |
| 13 | "math/bigscip-go gomod github.com/golang/go/src go1.14 `math/big`/" |
| 14 | "syncscip-go gomod github.com/golang/go/src go1.14 sync/" |
| 15 | "timescip-go gomod github.com/golang/go/src go1.14 time/" |
| 16 | ) |
| 17 | |
| 18 | func initscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/init().() { |
| 19 | defaultMessageDigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/defaultMessageDigestAlgorithm..oidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/defaultMessageDigestAlgorithm:oid. = OIDDigestAlgorithmSHA1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmSHA1. |
| 20 | } |
| 21 | |
| 22 | var defaultMessageDigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/defaultMessageDigestAlgorithm. struct { |
| 23 | syncscip-go gomod github.com/golang/go/src go1.14 sync/.RWMutexscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex# |
| 24 | oidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/defaultMessageDigestAlgorithm:oid. 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# |
| 25 | } |
| 26 | |
| 27 | // SetDefaultDigestAlgorithm sets the default digest algorithm |
| 28 | // to be used for signing operations on [SignedData]. |
| 29 | // |
| 30 | // This must be called before creating a new instance of [SignedData] |
| 31 | // using [NewSignedData]. |
| 32 | // |
| 33 | // When this function is not called, the default digest algorithm is SHA1. |
| 34 | func SetDefaultDigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SetDefaultDigestAlgorithm().(d 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#) error { |
| 35 | defaultMessageDigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/defaultMessageDigestAlgorithm..Lockscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#Lock().() |
| 36 | defer defaultMessageDigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/defaultMessageDigestAlgorithm..Unlockscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#Unlock().() |
| 37 | |
| 38 | switch { |
| 39 | case d.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.), |
| 40 | d.Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(OIDDigestAlgorithmSHA224scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDDigestAlgorithmSHA224.), d.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.), |
| 41 | d.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.), d.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.), |
| 42 | d.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.), d.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.), |
| 43 | d.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.), d.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.), |
| 44 | d.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.), d.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.): |
| 45 | break |
| 46 | default: |
| 47 | return fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("unsupported message digest algorithm %v", d) |
| 48 | } |
| 49 | |
| 50 | defaultMessageDigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/defaultMessageDigestAlgorithm..oidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/defaultMessageDigestAlgorithm:oid. = d |
| 51 | |
| 52 | return nil |
| 53 | } |
| 54 | |
| 55 | func defaultMessageDigestAlgorithmOIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/defaultMessageDigestAlgorithmOID().() 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# { |
| 56 | defaultMessageDigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/defaultMessageDigestAlgorithm..RLockscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#RLock().() |
| 57 | defer defaultMessageDigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/defaultMessageDigestAlgorithm..RUnlockscip-go gomod github.com/golang/go/src go1.14 sync/RWMutex#RUnlock().() |
| 58 | |
| 59 | return defaultMessageDigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/defaultMessageDigestAlgorithm..oidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/defaultMessageDigestAlgorithm:oid. |
| 60 | } |
| 61 | |
| 62 | // SignedData is an opaque data structure for creating signed data payloads |
| 63 | type SignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData# struct { |
| 64 | sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd. signedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData# |
| 65 | certsscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#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# |
| 66 | datascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#data., messageDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#messageDigest. []byte |
| 67 | digestOidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#digestOid. 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# |
| 68 | encryptionOidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#encryptionOid. 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# |
| 69 | } |
| 70 | |
| 71 | // NewSignedData takes data and initializes a PKCS7 SignedData struct that is |
| 72 | // ready to be signed via AddSigner. The digest algorithm is set to SHA1 by default |
| 73 | // and can be changed by calling SetDigestAlgorithm. |
| 74 | func NewSignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/NewSignedData().(data []byte) (*SignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#, error) { |
| 75 | content, err := asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.Marshalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/Marshal().(data) |
| 76 | if err != nil { |
| 77 | return nil, err |
| 78 | } |
| 79 | ci := contentInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo#{ |
| 80 | ContentTypescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo#ContentType.: OIDDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDData., |
| 81 | Contentscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo#Content.: 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#{Classscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Class.: 2, Tagscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Tag.: 0, Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Bytes.: content, IsCompoundscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#IsCompound.: true}, |
| 82 | } |
| 83 | sd := signedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#{ |
| 84 | ContentInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#ContentInfo.: ci, |
| 85 | Versionscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#Version.: 1, |
| 86 | } |
| 87 | return &SignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#{sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd.: sd, datascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#data.: data, digestOidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#digestOid.: defaultMessageDigestAlgorithmOIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/defaultMessageDigestAlgorithmOID().()}, nil |
| 88 | } |
| 89 | |
| 90 | // SignerInfoConfig are optional values to include when adding a signer |
| 91 | type SignerInfoConfigscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignerInfoConfig# struct { |
| 92 | ExtraSignedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignerInfoConfig#ExtraSignedAttributes. []Attributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/Attribute# |
| 93 | ExtraUnsignedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignerInfoConfig#ExtraUnsignedAttributes. []Attributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/Attribute# |
| 94 | } |
| 95 | |
| 96 | type signedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData# struct { |
| 97 | Versionscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#Version. int `asn1:"default:1"` |
| 98 | DigestAlgorithmIdentifiersscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#DigestAlgorithmIdentifiers. []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# `asn1:"set"` |
| 99 | ContentInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#ContentInfo. contentInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo# |
| 100 | Certificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#Certificates. rawCertificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/rawCertificates# `asn1:"optional,tag:0"` |
| 101 | CRLsscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#CRLs. []pkixscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/.CertificateListscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/CertificateList# `asn1:"optional,tag:1"` |
| 102 | SignerInfosscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#SignerInfos. []signerInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo# `asn1:"set"` |
| 103 | } |
| 104 | |
| 105 | type signerInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo# struct { |
| 106 | Versionscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#Version. int `asn1:"default:1"` |
| 107 | IssuerAndSerialNumberscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#IssuerAndSerialNumber. issuerAndSerialscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/issuerAndSerial# |
| 108 | DigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#DigestAlgorithm. 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# |
| 109 | AuthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#AuthenticatedAttributes. []attributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attribute# `asn1:"optional,omitempty,tag:0"` |
| 110 | DigestEncryptionAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#DigestEncryptionAlgorithm. 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# |
| 111 | EncryptedDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#EncryptedDigest. []byte |
| 112 | UnauthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#UnauthenticatedAttributes. []attributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attribute# `asn1:"optional,omitempty,tag:1"` |
| 113 | } |
| 114 | |
| 115 | type attributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attribute# struct { |
| 116 | Typescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attribute#Type. 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# |
| 117 | Valuescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attribute#Value. 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# `asn1:"set"` |
| 118 | } |
| 119 | |
| 120 | func marshalAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/marshalAttributes().(attrs []attributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attribute#) ([]byte, error) { |
| 121 | encodedAttributes, err := asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.Marshalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/Marshal().(struct { |
| 122 | A []attributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attribute# `asn1:"set"` |
| 123 | }{A: attrs}) |
| 124 | if err != nil { |
| 125 | return nil, err |
| 126 | } |
| 127 | |
| 128 | // Remove the leading sequence octets |
| 129 | var raw 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# |
| 130 | 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().(encodedAttributes, &raw) |
| 131 | return raw.Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Bytes., nil |
| 132 | } |
| 133 | |
| 134 | type rawCertificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/rawCertificates# struct { |
| 135 | Rawscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/rawCertificates#Raw. asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.RawContentscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawContent# |
| 136 | } |
| 137 | |
| 138 | type issuerAndSerialscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/issuerAndSerial# struct { |
| 139 | IssuerNamescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/issuerAndSerial#IssuerName. 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# |
| 140 | SerialNumberscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/issuerAndSerial#SerialNumber. *bigscip-go gomod github.com/golang/go/src go1.14 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int# |
| 141 | } |
| 142 | |
| 143 | // SetDigestAlgorithm sets the digest algorithm to be used in the signing process. |
| 144 | // |
| 145 | // This should be called before adding signers |
| 146 | func (sd *SignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#) SetDigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#SetDigestAlgorithm().(d 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#) { |
| 147 | sd.digestOidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#digestOid. = d |
| 148 | } |
| 149 | |
| 150 | // SetEncryptionAlgorithm sets the encryption algorithm to be used in the signing process. |
| 151 | // |
| 152 | // This should be called before adding signers |
| 153 | func (sd *SignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#) SetEncryptionAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#SetEncryptionAlgorithm().(d 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#) { |
| 154 | sd.encryptionOidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#encryptionOid. = d |
| 155 | } |
| 156 | |
| 157 | // AddSigner is a wrapper around AddSignerChain() that adds a signer without any parent. |
| 158 | func (sd *SignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#) AddSignerscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#AddSigner().(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#, pkey cryptoscip-go gomod github.com/golang/go/src go1.14 crypto/.PrivateKeyscip-go gomod github.com/golang/go/src go1.14 crypto/PrivateKey#, config SignerInfoConfigscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignerInfoConfig#) error { |
| 159 | var parents []*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# |
| 160 | return sd.AddSignerChainscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#AddSignerChain().(ee, pkey, parents, config) |
| 161 | } |
| 162 | |
| 163 | // AddSignerChain signs attributes about the content and adds certificates |
| 164 | // and signers infos to the Signed Data. The certificate and private key |
| 165 | // of the end-entity signer are used to issue the signature, and any |
| 166 | // parent of that end-entity that need to be added to the list of |
| 167 | // certifications can be specified in the parents slice. |
| 168 | // |
| 169 | // The signature algorithm used to hash the data is the one of the end-entity |
| 170 | // certificate. |
| 171 | func (sd *SignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#) AddSignerChainscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#AddSignerChain().(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#, pkey cryptoscip-go gomod github.com/golang/go/src go1.14 crypto/.PrivateKeyscip-go gomod github.com/golang/go/src go1.14 crypto/PrivateKey#, parents []*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#, config SignerInfoConfigscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignerInfoConfig#) error { |
| 172 | // Following RFC 2315, 9.2 SignerInfo type, the distinguished name of |
| 173 | // the issuer of the end-entity signer is stored in the issuerAndSerialNumber |
| 174 | // section of the SignedData.SignerInfo, alongside the serial number of |
| 175 | // the end-entity. |
| 176 | var ias issuerAndSerialscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/issuerAndSerial# |
| 177 | ias.SerialNumberscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/issuerAndSerial#SerialNumber. = ee.SerialNumberscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#SerialNumber. |
| 178 | if len(parents) == 0 { |
| 179 | // no parent, the issuer is the end-entity cert itself |
| 180 | ias.IssuerNamescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/issuerAndSerial#IssuerName. = 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#{FullBytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#FullBytes.: ee.RawIssuerscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#RawIssuer.} |
| 181 | } else { |
| 182 | err := verifyPartialChainscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/verifyPartialChain().(ee, parents) |
| 183 | if err != nil { |
| 184 | return err |
| 185 | } |
| 186 | // the first parent is the issuer |
| 187 | ias.IssuerNamescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/issuerAndSerial#IssuerName. = 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#{FullBytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#FullBytes.: parents[0].RawSubjectscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#RawSubject.} |
| 188 | } |
| 189 | sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd..DigestAlgorithmIdentifiersscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#DigestAlgorithmIdentifiers. = append(sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd..DigestAlgorithmIdentifiersscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#DigestAlgorithmIdentifiers., |
| 190 | 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#{Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.: sd.digestOidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#digestOid.}, |
| 191 | ) |
| 192 | hash, err := getHashForOIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/getHashForOID().(sd.digestOidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#digestOid.) |
| 193 | if err != nil { |
| 194 | return err |
| 195 | } |
| 196 | h := hash.Newscip-go gomod github.com/golang/go/src go1.14 crypto/Hash#New().() |
| 197 | h.Writescip-go gomod github.com/golang/go/src go1.14 io/Writer#Write().(sd.datascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#data.) |
| 198 | sd.messageDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#messageDigest. = h.Sumscip-go gomod github.com/golang/go/src go1.14 hash/Hash#Sum().(nil) |
| 199 | encryptionOid, err := getOIDForEncryptionAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/getOIDForEncryptionAlgorithm().(pkey, sd.digestOidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#digestOid.) |
| 200 | if err != nil { |
| 201 | return err |
| 202 | } |
| 203 | attrs := &attributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attributes#{} |
| 204 | attrs.Addscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attributes#Add().(OIDAttributeContentTypescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDAttributeContentType., sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd..ContentInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#ContentInfo..ContentTypescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo#ContentType.) |
| 205 | attrs.Addscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attributes#Add().(OIDAttributeMessageDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDAttributeMessageDigest., sd.messageDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#messageDigest.) |
| 206 | attrs.Addscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attributes#Add().(OIDAttributeSigningTimescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDAttributeSigningTime., 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().()) |
| 207 | for _, attr := range config.ExtraSignedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignerInfoConfig#ExtraSignedAttributes. { |
| 208 | attrs.Addscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attributes#Add().(attr.Typescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/Attribute#Type., attr.Valuescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/Attribute#Value.) |
| 209 | } |
| 210 | finalAttrs, err := attrs.ForMarshallingscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attributes#ForMarshalling().() |
| 211 | if err != nil { |
| 212 | return err |
| 213 | } |
| 214 | unsignedAttrs := &attributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attributes#{} |
| 215 | for _, attr := range config.ExtraUnsignedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignerInfoConfig#ExtraUnsignedAttributes. { |
| 216 | unsignedAttrs.Addscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attributes#Add().(attr.Typescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/Attribute#Type., attr.Valuescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/Attribute#Value.) |
| 217 | } |
| 218 | finalUnsignedAttrs, err := unsignedAttrs.ForMarshallingscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attributes#ForMarshalling().() |
| 219 | if err != nil { |
| 220 | return err |
| 221 | } |
| 222 | // create signature of signed attributes |
| 223 | signature, err := signAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signAttributes().(finalAttrs, pkey, hash) |
| 224 | if err != nil { |
| 225 | return err |
| 226 | } |
| 227 | signer := signerInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#{ |
| 228 | AuthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#AuthenticatedAttributes.: finalAttrs, |
| 229 | UnauthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#UnauthenticatedAttributes.: finalUnsignedAttrs, |
| 230 | DigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#DigestAlgorithm.: 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#{Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.: sd.digestOidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#digestOid.}, |
| 231 | DigestEncryptionAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#DigestEncryptionAlgorithm.: 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#{Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.: encryptionOid}, |
| 232 | IssuerAndSerialNumberscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#IssuerAndSerialNumber.: ias, |
| 233 | EncryptedDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#EncryptedDigest.: signature, |
| 234 | Versionscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#Version.: 1, |
| 235 | } |
| 236 | sd.certsscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#certs. = append(sd.certsscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#certs., ee) |
| 237 | if len(parents) > 0 { |
| 238 | sd.certsscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#certs. = append(sd.certsscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#certs., parents...) |
| 239 | } |
| 240 | sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd..SignerInfosscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#SignerInfos. = append(sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd..SignerInfosscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#SignerInfos., signer) |
| 241 | return nil |
| 242 | } |
| 243 | |
| 244 | // SignWithoutAttr issues a signature on the content of the pkcs7 SignedData. |
| 245 | // Unlike AddSigner/AddSignerChain, it calculates the digest on the data alone |
| 246 | // and does not include any signed attributes like timestamp and so on. |
| 247 | // |
| 248 | // This function is needed to sign old Android APKs, something you probably |
| 249 | // shouldn't do unless you're maintaining backward compatibility for old |
| 250 | // applications. |
| 251 | func (sd *SignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#) SignWithoutAttrscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#SignWithoutAttr().(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#, pkey cryptoscip-go gomod github.com/golang/go/src go1.14 crypto/.PrivateKeyscip-go gomod github.com/golang/go/src go1.14 crypto/PrivateKey#, config SignerInfoConfigscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignerInfoConfig#) error { |
| 252 | var signature []byte |
| 253 | sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd..DigestAlgorithmIdentifiersscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#DigestAlgorithmIdentifiers. = append(sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd..DigestAlgorithmIdentifiersscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#DigestAlgorithmIdentifiers., 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#{Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.: sd.digestOidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#digestOid.}) |
| 254 | hash, err := getHashForOIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/getHashForOID().(sd.digestOidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#digestOid.) |
| 255 | if err != nil { |
| 256 | return err |
| 257 | } |
| 258 | h := hash.Newscip-go gomod github.com/golang/go/src go1.14 crypto/Hash#New().() |
| 259 | h.Writescip-go gomod github.com/golang/go/src go1.14 io/Writer#Write().(sd.datascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#data.) |
| 260 | sd.messageDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#messageDigest. = h.Sumscip-go gomod github.com/golang/go/src go1.14 hash/Hash#Sum().(nil) |
| 261 | switch pkey := pkey.(type) { |
| 262 | case *dsascip-go gomod github.com/golang/go/src go1.14 `crypto/dsa`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.14 `crypto/dsa`/PrivateKey#: |
| 263 | // dsa doesn't implement crypto.Signer so we make a special case |
| 264 | // https://github.com/golang/go/issues/27889 |
| 265 | r, s, err := dsascip-go gomod github.com/golang/go/src go1.14 `crypto/dsa`/.Signscip-go gomod github.com/golang/go/src go1.14 `crypto/dsa`/Sign().(randscip-go gomod github.com/golang/go/src go1.14 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.14 `crypto/rand`/Reader., pkey, sd.messageDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#messageDigest.) |
| 266 | if err != nil { |
| 267 | return err |
| 268 | } |
| 269 | signature, err = asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.Marshalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/Marshal().(dsaSignaturescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/dsaSignature#{r, s}) |
| 270 | if err != nil { |
| 271 | return err |
| 272 | } |
| 273 | default: |
| 274 | key, ok := pkey.(cryptoscip-go gomod github.com/golang/go/src go1.14 crypto/.Signerscip-go gomod github.com/golang/go/src go1.14 crypto/Signer#) |
| 275 | if !ok { |
| 276 | 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: private key does not implement crypto.Signer") |
| 277 | } |
| 278 | signature, err = key.Signscip-go gomod github.com/golang/go/src go1.14 crypto/Signer#Sign().(randscip-go gomod github.com/golang/go/src go1.14 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.14 `crypto/rand`/Reader., sd.messageDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#messageDigest., hash) |
| 279 | if err != nil { |
| 280 | return err |
| 281 | } |
| 282 | } |
| 283 | var ias issuerAndSerialscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/issuerAndSerial# |
| 284 | ias.SerialNumberscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/issuerAndSerial#SerialNumber. = ee.SerialNumberscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#SerialNumber. |
| 285 | // no parent, the issue is the end-entity cert itself |
| 286 | ias.IssuerNamescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/issuerAndSerial#IssuerName. = 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#{FullBytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#FullBytes.: ee.RawIssuerscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#RawIssuer.} |
| 287 | if sd.encryptionOidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#encryptionOid. == nil { |
| 288 | // if the encryption algorithm wasn't set by SetEncryptionAlgorithm, |
| 289 | // infer it from the digest algorithm |
| 290 | sd.encryptionOidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#encryptionOid., err = getOIDForEncryptionAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/getOIDForEncryptionAlgorithm().(pkey, sd.digestOidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#digestOid.) |
| 291 | } |
| 292 | if err != nil { |
| 293 | return err |
| 294 | } |
| 295 | signer := signerInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#{ |
| 296 | DigestAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#DigestAlgorithm.: 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#{Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.: sd.digestOidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#digestOid.}, |
| 297 | DigestEncryptionAlgorithmscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#DigestEncryptionAlgorithm.: 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#{Algorithmscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.: sd.encryptionOidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#encryptionOid.}, |
| 298 | IssuerAndSerialNumberscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#IssuerAndSerialNumber.: ias, |
| 299 | EncryptedDigestscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#EncryptedDigest.: signature, |
| 300 | Versionscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#Version.: 1, |
| 301 | } |
| 302 | // create signature of signed attributes |
| 303 | sd.certsscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#certs. = append(sd.certsscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#certs., ee) |
| 304 | sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd..SignerInfosscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#SignerInfos. = append(sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd..SignerInfosscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#SignerInfos., signer) |
| 305 | return nil |
| 306 | } |
| 307 | |
| 308 | func (si *signerInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#) SetUnauthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#SetUnauthenticatedAttributes().(extraUnsignedAttrs []Attributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/Attribute#) error { |
| 309 | unsignedAttrs := &attributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attributes#{} |
| 310 | for _, attr := range extraUnsignedAttrs { |
| 311 | unsignedAttrs.Addscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attributes#Add().(attr.Typescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/Attribute#Type., attr.Valuescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/Attribute#Value.) |
| 312 | } |
| 313 | finalUnsignedAttrs, err := unsignedAttrs.ForMarshallingscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attributes#ForMarshalling().() |
| 314 | if err != nil { |
| 315 | return err |
| 316 | } |
| 317 | |
| 318 | si.UnauthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#UnauthenticatedAttributes. = finalUnsignedAttrs |
| 319 | |
| 320 | return nil |
| 321 | } |
| 322 | |
| 323 | // AddCertificate adds the certificate to the payload. Useful for parent certificates |
| 324 | func (sd *SignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#) AddCertificatescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#AddCertificate().(cert *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#) { |
| 325 | sd.certsscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#certs. = append(sd.certsscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#certs., cert) |
| 326 | } |
| 327 | |
| 328 | // Detach removes content from the signed data struct to make it a detached signature. |
| 329 | // This must be called right before Finish() |
| 330 | func (sd *SignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#) Detachscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#Detach().() { |
| 331 | sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd..ContentInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#ContentInfo. = contentInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo#{ContentTypescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo#ContentType.: OIDDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDData.} |
| 332 | } |
| 333 | |
| 334 | // GetSignedData returns the private Signed Data |
| 335 | func (sd *SignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#) GetSignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#GetSignedData().() *signedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData# { |
| 336 | return &sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd. |
| 337 | } |
| 338 | |
| 339 | // Finish marshals the content and its signers |
| 340 | func (sd *SignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#) Finishscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#Finish().() ([]byte, error) { |
| 341 | sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd..Certificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#Certificates. = marshalCertificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/marshalCertificates().(sd.certsscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#certs.) |
| 342 | inner, err := asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.Marshalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/Marshal().(sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd.) |
| 343 | if err != nil { |
| 344 | return nil, err |
| 345 | } |
| 346 | outer := contentInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo#{ |
| 347 | ContentTypescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo#ContentType.: OIDSignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDSignedData., |
| 348 | Contentscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo#Content.: 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#{Classscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Class.: 2, Tagscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Tag.: 0, Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Bytes.: inner, IsCompoundscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#IsCompound.: true}, |
| 349 | } |
| 350 | return asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.Marshalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/Marshal().(outer) |
| 351 | } |
| 352 | |
| 353 | // RemoveAuthenticatedAttributes removes authenticated attributes from signedData |
| 354 | // similar to OpenSSL's PKCS7_NOATTR or -noattr flags |
| 355 | func (sd *SignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#) RemoveAuthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#RemoveAuthenticatedAttributes().() { |
| 356 | for i := range sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd..SignerInfosscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#SignerInfos. { |
| 357 | sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd..SignerInfosscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#SignerInfos.[i].AuthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#AuthenticatedAttributes. = nil |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | // RemoveUnauthenticatedAttributes removes unauthenticated attributes from signedData |
| 362 | func (sd *SignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#) RemoveUnauthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#RemoveUnauthenticatedAttributes().() { |
| 363 | for i := range sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd..SignerInfosscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#SignerInfos. { |
| 364 | sd.sdscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/SignedData#sd..SignerInfosscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#SignerInfos.[i].UnauthenticatedAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signerInfo#UnauthenticatedAttributes. = nil |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | // verifyPartialChain checks that a given cert is issued by the first parent in the list, |
| 369 | // then continue down the path. It doesn't require the last parent to be a root CA, |
| 370 | // or to be trusted in any truststore. It simply verifies that the chain provided, albeit |
| 371 | // partial, makes sense. |
| 372 | func verifyPartialChainscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/verifyPartialChain().(cert *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#, parents []*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#) error { |
| 373 | if len(parents) == 0 { |
| 374 | return fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("pkcs7: zero parents provided to verify the signature of certificate %q", cert.Subjectscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#Subject..CommonNamescip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/Name#CommonName.) |
| 375 | } |
| 376 | err := cert.CheckSignatureFromscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#CheckSignatureFrom().(parents[0]) |
| 377 | if err != nil { |
| 378 | return fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("pkcs7: certificate signature from parent is invalid: %v", err) |
| 379 | } |
| 380 | if len(parents) == 1 { |
| 381 | // there is no more parent to check, return |
| 382 | return nil |
| 383 | } |
| 384 | return verifyPartialChainscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/verifyPartialChain().(parents[0], parents[1:]) |
| 385 | } |
| 386 | |
| 387 | func cert2issuerAndSerialscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/cert2issuerAndSerial().(cert *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#) (issuerAndSerialscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/issuerAndSerial#, error) { |
| 388 | var ias issuerAndSerialscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/issuerAndSerial# |
| 389 | // The issuer RDNSequence has to match exactly the sequence in the certificate |
| 390 | // We cannot use cert.Issuer.ToRDNSequence() here since it mangles the sequence |
| 391 | ias.IssuerNamescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/issuerAndSerial#IssuerName. = 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#{FullBytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#FullBytes.: cert.RawIssuerscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#RawIssuer.} |
| 392 | ias.SerialNumberscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/issuerAndSerial#SerialNumber. = cert.SerialNumberscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#SerialNumber. |
| 393 | |
| 394 | return ias, nil |
| 395 | } |
| 396 | |
| 397 | // signs the DER encoded form of the attributes with the private key |
| 398 | func signAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signAttributes().(attrs []attributescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/attribute#, pkey cryptoscip-go gomod github.com/golang/go/src go1.14 crypto/.PrivateKeyscip-go gomod github.com/golang/go/src go1.14 crypto/PrivateKey#, digestAlg cryptoscip-go gomod github.com/golang/go/src go1.14 crypto/.Hashscip-go gomod github.com/golang/go/src go1.14 crypto/Hash#) ([]byte, error) { |
| 399 | attrBytes, err := marshalAttributesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/marshalAttributes().(attrs) |
| 400 | if err != nil { |
| 401 | return nil, err |
| 402 | } |
| 403 | h := digestAlg.Newscip-go gomod github.com/golang/go/src go1.14 crypto/Hash#New().() |
| 404 | h.Writescip-go gomod github.com/golang/go/src go1.14 io/Writer#Write().(attrBytes) |
| 405 | hash := h.Sumscip-go gomod github.com/golang/go/src go1.14 hash/Hash#Sum().(nil) |
| 406 | |
| 407 | // dsa doesn't implement crypto.Signer so we make a special case |
| 408 | // https://github.com/golang/go/issues/27889 |
| 409 | switch pkey := pkey.(type) { |
| 410 | case *dsascip-go gomod github.com/golang/go/src go1.14 `crypto/dsa`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.14 `crypto/dsa`/PrivateKey#: |
| 411 | r, s, err := dsascip-go gomod github.com/golang/go/src go1.14 `crypto/dsa`/.Signscip-go gomod github.com/golang/go/src go1.14 `crypto/dsa`/Sign().(randscip-go gomod github.com/golang/go/src go1.14 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.14 `crypto/rand`/Reader., pkey, hash) |
| 412 | if err != nil { |
| 413 | return nil, err |
| 414 | } |
| 415 | return asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.Marshalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/Marshal().(dsaSignaturescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/dsaSignature#{r, s}) |
| 416 | } |
| 417 | |
| 418 | key, ok := pkey.(cryptoscip-go gomod github.com/golang/go/src go1.14 crypto/.Signerscip-go gomod github.com/golang/go/src go1.14 crypto/Signer#) |
| 419 | if !ok { |
| 420 | return nil, errorsscip-go gomod github.com/golang/go/src go1.14 errors/.Newscip-go gomod github.com/golang/go/src go1.14 errors/New().("pkcs7: private key does not implement crypto.Signer") |
| 421 | } |
| 422 | return key.Signscip-go gomod github.com/golang/go/src go1.14 crypto/Signer#Sign().(randscip-go gomod github.com/golang/go/src go1.14 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.14 `crypto/rand`/Reader., hash, digestAlg) |
| 423 | } |
| 424 | |
| 425 | type dsaSignaturescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/dsaSignature# struct { |
| 426 | Rscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/dsaSignature#R., Sscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/dsaSignature#S. *bigscip-go gomod github.com/golang/go/src go1.14 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int# |
| 427 | } |
| 428 | |
| 429 | // concats and wraps the certificates in the RawValue structure |
| 430 | func marshalCertificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/marshalCertificates().(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#) rawCertificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/rawCertificates# { |
| 431 | var buf bytesscip-go gomod github.com/golang/go/src go1.14 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.14 bytes/Buffer# |
| 432 | for _, cert := range certs { |
| 433 | buf.Writescip-go gomod github.com/golang/go/src go1.14 bytes/Buffer#Write().(cert.Rawscip-go gomod github.com/golang/go/src go1.14 `crypto/x509`/Certificate#Raw.) |
| 434 | } |
| 435 | rawCerts, _ := marshalCertificateBytesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/marshalCertificateBytes().(buf.Bytesscip-go gomod github.com/golang/go/src go1.14 bytes/Buffer#Bytes().()) |
| 436 | return rawCerts |
| 437 | } |
| 438 | |
| 439 | // Even though, the tag & length are stripped out during marshalling the |
| 440 | // RawContent, we have to encode it into the RawContent. If its missing, |
| 441 | // then `asn1.Marshal()` will strip out the certificate wrapper instead. |
| 442 | func marshalCertificateBytesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/marshalCertificateBytes().(certs []byte) (rawCertificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/rawCertificates#, error) { |
| 443 | var val = 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#{Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Bytes.: certs, Classscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Class.: 2, Tagscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Tag.: 0, IsCompoundscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#IsCompound.: true} |
| 444 | b, err := asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.Marshalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/Marshal().(val) |
| 445 | if err != nil { |
| 446 | return rawCertificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/rawCertificates#{}, err |
| 447 | } |
| 448 | return rawCertificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/rawCertificates#{Rawscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/rawCertificates#Raw.: b}, nil |
| 449 | } |
| 450 | |
| 451 | // DegenerateCertificate creates a signed data structure containing only the |
| 452 | // provided certificate or certificate chain. |
| 453 | func DegenerateCertificatescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/DegenerateCertificate().(cert []byte) ([]byte, error) { |
| 454 | rawCert, err := marshalCertificateBytesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/marshalCertificateBytes().(cert) |
| 455 | if err != nil { |
| 456 | return nil, err |
| 457 | } |
| 458 | emptyContent := contentInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo#{ContentTypescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo#ContentType.: OIDDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDData.} |
| 459 | sd := signedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#{ |
| 460 | Versionscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#Version.: 1, |
| 461 | ContentInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#ContentInfo.: emptyContent, |
| 462 | Certificatesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#Certificates.: rawCert, |
| 463 | CRLsscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/signedData#CRLs.: []pkixscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/.CertificateListscip-go gomod github.com/golang/go/src go1.14 `crypto/x509/pkix`/CertificateList#{}, |
| 464 | } |
| 465 | content, err := asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.Marshalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/Marshal().(sd) |
| 466 | if err != nil { |
| 467 | return nil, err |
| 468 | } |
| 469 | signedContent := contentInfoscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo#{ |
| 470 | ContentTypescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo#ContentType.: OIDSignedDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/OIDSignedData., |
| 471 | Contentscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7`/contentInfo#Content.: 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#{Classscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Class.: 2, Tagscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Tag.: 0, Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#Bytes.: content, IsCompoundscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/RawValue#IsCompound.: true}, |
| 472 | } |
| 473 | return asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.Marshalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/Marshal().(signedContent) |
| 474 | } |