1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Package pkix contains shared, low level structures used for ASN.1 parsing
6 // and serialization of X.509 certificates, CRL and OCSP.
11 "github.com/google/certificate-transparency/go/asn1"
17 // AlgorithmIdentifier represents the ASN.1 structure of the same name. See RFC
18 // 5280, section 4.1.1.2.
19 type AlgorithmIdentifier struct {
20 Algorithm asn1.ObjectIdentifier
21 Parameters asn1.RawValue `asn1:"optional"`
24 type RDNSequence []RelativeDistinguishedNameSET
26 type RelativeDistinguishedNameSET []AttributeTypeAndValue
28 // AttributeTypeAndValue mirrors the ASN.1 structure of the same name in
29 // http://tools.ietf.org/html/rfc5280#section-4.1.2.4
30 type AttributeTypeAndValue struct {
31 Type asn1.ObjectIdentifier
35 // Extension represents the ASN.1 structure of the same name. See RFC
37 type Extension struct {
38 Id asn1.ObjectIdentifier
39 Critical bool `asn1:"optional"`
43 // Name represents an X.509 distinguished name. This only includes the common
44 // elements of a DN. Additional elements in the name are ignored.
46 Country, Organization, OrganizationalUnit []string
47 Locality, Province []string
48 StreetAddress, PostalCode []string
49 SerialNumber, CommonName string
51 Names []AttributeTypeAndValue
54 func (n *Name) FillFromRDNSequence(rdns *RDNSequence) {
55 for _, rdn := range *rdns {
60 n.Names = append(n.Names, atv)
61 value, ok := atv.Value.(string)
67 if len(t) == 4 && t[0] == 2 && t[1] == 5 && t[2] == 4 {
72 n.SerialNumber = value
74 n.Country = append(n.Country, value)
76 n.Locality = append(n.Locality, value)
78 n.Province = append(n.Province, value)
80 n.StreetAddress = append(n.StreetAddress, value)
82 n.Organization = append(n.Organization, value)
84 n.OrganizationalUnit = append(n.OrganizationalUnit, value)
86 n.PostalCode = append(n.PostalCode, value)
93 oidCountry = []int{2, 5, 4, 6}
94 oidOrganization = []int{2, 5, 4, 10}
95 oidOrganizationalUnit = []int{2, 5, 4, 11}
96 oidCommonName = []int{2, 5, 4, 3}
97 oidSerialNumber = []int{2, 5, 4, 5}
98 oidLocality = []int{2, 5, 4, 7}
99 oidProvince = []int{2, 5, 4, 8}
100 oidStreetAddress = []int{2, 5, 4, 9}
101 oidPostalCode = []int{2, 5, 4, 17}
104 // appendRDNs appends a relativeDistinguishedNameSET to the given RDNSequence
105 // and returns the new value. The relativeDistinguishedNameSET contains an
106 // attributeTypeAndValue for each of the given values. See RFC 5280, A.1, and
107 // search for AttributeTypeAndValue.
108 func appendRDNs(in RDNSequence, values []string, oid asn1.ObjectIdentifier) RDNSequence {
109 if len(values) == 0 {
113 s := make([]AttributeTypeAndValue, len(values))
114 for i, value := range values {
122 func (n Name) ToRDNSequence() (ret RDNSequence) {
123 ret = appendRDNs(ret, n.Country, oidCountry)
124 ret = appendRDNs(ret, n.Organization, oidOrganization)
125 ret = appendRDNs(ret, n.OrganizationalUnit, oidOrganizationalUnit)
126 ret = appendRDNs(ret, n.Locality, oidLocality)
127 ret = appendRDNs(ret, n.Province, oidProvince)
128 ret = appendRDNs(ret, n.StreetAddress, oidStreetAddress)
129 ret = appendRDNs(ret, n.PostalCode, oidPostalCode)
130 if len(n.CommonName) > 0 {
131 ret = appendRDNs(ret, []string{n.CommonName}, oidCommonName)
133 if len(n.SerialNumber) > 0 {
134 ret = appendRDNs(ret, []string{n.SerialNumber}, oidSerialNumber)
140 // CertificateList represents the ASN.1 structure of the same name. See RFC
141 // 5280, section 5.1. Use Certificate.CheckCRLSignature to verify the
143 type CertificateList struct {
144 TBSCertList TBSCertificateList
145 SignatureAlgorithm AlgorithmIdentifier
146 SignatureValue asn1.BitString
149 // HasExpired reports whether now is past the expiry time of certList.
150 func (certList *CertificateList) HasExpired(now time.Time) bool {
151 return now.After(certList.TBSCertList.NextUpdate)
154 // TBSCertificateList represents the ASN.1 structure of the same name. See RFC
155 // 5280, section 5.1.
156 type TBSCertificateList struct {
158 Version int `asn1:"optional,default:2"`
159 Signature AlgorithmIdentifier
163 RevokedCertificates []RevokedCertificate `asn1:"optional"`
164 Extensions []Extension `asn1:"tag:0,optional,explicit"`
167 // RevokedCertificate represents the ASN.1 structure of the same name. See RFC
168 // 5280, section 5.1.
169 type RevokedCertificate struct {
170 SerialNumber *big.Int
171 RevocationTime time.Time
172 Extensions []Extension `asn1:"optional"`