| 1 | // |
| 2 | // Copyright (c) SAS Institute Inc. |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
| 16 | |
| 17 | // PKCS#7 is a specification for signing or encrypting data using ASN.1 |
| 18 | // structures. It is also known as CMS (cryptographic message syntax) and is |
| 19 | // discussed in RFC 2315, RFC 3369, RFC 3852, and RFC 5652. |
| 20 | // |
| 21 | // This package implements signature operations needed for creating and |
| 22 | // validating signature technologies based on PKCS#7 including Java and |
| 23 | // Microsoft Authenticode |
| 24 | package pkcs7 |
| 25 | |
| 26 | import ( |
| 27 | "crypto/x509/pkix" |
| 28 | "encoding/asn1" |
| 29 | "math/big" |
| 30 | ) |
| 31 | |
| 32 | var ( |
| 33 | OidData = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 7, 1} |
| 34 | OidSignedData = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 7, 2} |
| 35 | OidAttributeContentType = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 3} |
| 36 | OidAttributeMessageDigest = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 4} |
| 37 | OidAttributeSigningTime = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 5} |
| 38 | ) |
| 39 | |
| 40 | const MimeType = "application/pkcs7-mime" |
| 41 | |
| 42 | type ContentInfo struct { |
| 43 | Raw asn1.RawContent |
| 44 | ContentType asn1.ObjectIdentifier |
| 45 | } |
| 46 | |
| 47 | type ContentInfoSignedData struct { |
| 48 | ContentType asn1.ObjectIdentifier |
| 49 | Content SignedData `asn1:"explicit,optional,tag:0"` |
| 50 | } |
| 51 | |
| 52 | type SignedData struct { |
| 53 | Version int `asn1:"default:1"` |
| 54 | DigestAlgorithmIdentifiers []pkix.AlgorithmIdentifier `asn1:"set"` |
| 55 | ContentInfo ContentInfo `` |
| 56 | Certificates RawCertificates `asn1:"optional,tag:0"` |
| 57 | CRLs []pkix.CertificateList `asn1:"optional,tag:1"` |
| 58 | SignerInfos []SignerInfo `asn1:"set"` |
| 59 | } |
| 60 | |
| 61 | type RawCertificates []asn1.RawValue |
| 62 | |
| 63 | type Attribute struct { |
| 64 | Type asn1.ObjectIdentifier |
| 65 | Values asn1.RawValue |
| 66 | } |
| 67 | |
| 68 | type AttributeList []Attribute |
| 69 | |
| 70 | type SignerInfo struct { |
| 71 | RawContent asn1.RawContent |
| 72 | |
| 73 | Version int `asn1:"default:1"` |
| 74 | IssuerAndSerialNumber IssuerAndSerial `` |
| 75 | DigestAlgorithm pkix.AlgorithmIdentifier `` |
| 76 | AuthenticatedAttributes AttributeList `asn1:"optional,tag:0"` |
| 77 | DigestEncryptionAlgorithm pkix.AlgorithmIdentifier `` |
| 78 | EncryptedDigest []byte `` |
| 79 | UnauthenticatedAttributes AttributeList `asn1:"optional,tag:1"` |
| 80 | } |
| 81 | |
| 82 | type IssuerAndSerial struct { |
| 83 | IssuerName asn1.RawValue |
| 84 | SerialNumber *big.Int |
| 85 | } |