Most .der and .cer files hold an X.509 certificate, the
structure defined for the internet by RFC 5280. Some hold a revocation list, a key
(PKCS #8 or PKCS #1) or a PKCS #7 bundle instead; the first SEQUENCE’s contents tell
them apart. This page gives the certificate and CRL structures; the encoding itself is
on the encoding rules page.
Sources: RFC 5280 (sections 4, 5 and the ASN.1 modules in Appendix A) for the structures, attribute, extension, key purpose and reason values; RFC 4055 for the RSA OIDs, RFC 5480 and RFC 5758 for the elliptic-curve ones, RFC 8410 for Ed25519.
Certificate
Certificate ::= SEQUENCE {
tbsCertificate TBSCertificate,
signatureAlgorithm AlgorithmIdentifier,
signatureValue BIT STRING } -- named "signature" in RFC 5280
| Field of TBSCertificate | Encoding | Meaning |
|---|---|---|
version | [0] EXPLICIT INTEGER, default 0 | 0 v1, 1 v2, 2 v3. Certificates with extensions are v3. |
serialNumber | INTEGER | Unique per issuer; positive, at most 20 octets. |
signature | AlgorithmIdentifier | The signature algorithm; must match signatureAlgorithm. |
issuer | Name | Who signed it. See names. |
validity | SEQUENCE of two Times | notBefore and notAfter: UTCTime up to 2049, GeneralizedTime from 2050 (UTCTime years 50–99 mean 1950–1999). GeneralizedTime here has no fractional seconds. A notAfter of 99991231235959Z means no well-defined expiry. |
subject | Name | Whom the certificate is for. |
subjectPublicKeyInfo | SEQUENCE { AlgorithmIdentifier, BIT STRING } | The public key and its algorithm. |
issuerUniqueID | [1] IMPLICIT BIT STRING, optional | v2 and later; rarely used. |
subjectUniqueID | [2] IMPLICIT BIT STRING, optional | v2 and later; rarely used. |
extensions | [3] EXPLICIT SEQUENCE OF Extension, optional | v3. Each Extension is { extnID OID, critical BOOLEAN default false, extnValue OCTET STRING holding the DER of the extension’s value }. |
An AlgorithmIdentifier is a SEQUENCE of an OID and optional parameters. Common
ones: 1.2.840.113549.1.1.1 RSA, 1.2.840.113549.1.1.11
SHA-256 with RSA, 1.2.840.113549.1.1.10 RSASSA-PSS,
1.2.840.10045.2.1 elliptic-curve public key,
1.2.840.10045.4.3.2 ECDSA with SHA-256, 1.3.101.112
Ed25519.
Names
A Name is a SEQUENCE OF RelativeDistinguishedName, each a SET OF { type OID, value }.
RFC 5280 requires CAs to encode DirectoryString values as PrintableString or
UTF8String, except that a CA’s or CRL issuer’s subject must match the encoding it uses
in the issuer field of what it issues. The OIDs below are under
id-at (2.5.4), except domain component and the e-mail
address, which RFC 5280 keeps only for legacy implementations.
| Attribute | Short name | OID |
|---|---|---|
| Common name | CN | 2.5.4.3 |
| Surname | SN | 2.5.4.4 |
| Serial number | – | 2.5.4.5 |
| Country | C | 2.5.4.6 |
| Locality | L | 2.5.4.7 |
| State or province | ST | 2.5.4.8 |
| Organisation | O | 2.5.4.10 |
| Organisational unit | OU | 2.5.4.11 |
| Title | – | 2.5.4.12 |
| Name (generic) | – | 2.5.4.41 |
| Given name | – | 2.5.4.42 |
| Initials | – | 2.5.4.43 |
| Generation qualifier | – | 2.5.4.44 |
| DN qualifier | – | 2.5.4.46 |
| Pseudonym | – | 2.5.4.65 |
| Domain component | DC | 0.9.2342.19200300.100.1.25 |
| Email address (legacy) | – | 1.2.840.113549.1.9.1 |
Extensions
| OID | Extension | Value |
|---|---|---|
2.5.29.9 | Subject directory attributes | Attributes of the subject. |
2.5.29.14 | Subject key identifier | An OCTET STRING identifying this public key. |
2.5.29.15 | Key usage | A BIT STRING; see key usage. |
2.5.29.17 | Subject alternative name | GeneralNames: the host names, addresses or e-mail addresses covered. |
2.5.29.18 | Issuer alternative name | GeneralNames. |
2.5.29.19 | Basic constraints | SEQUENCE { cA BOOLEAN default false, pathLenConstraint INTEGER optional }. |
2.5.29.30 | Name constraints | Permitted and excluded subtrees of names for certificates below a CA. |
2.5.29.31 | CRL distribution points | Where to fetch revocation lists. |
2.5.29.32 | Certificate policies | Policy OIDs, with qualifiers; 2.5.29.32.0 is any policy. |
2.5.29.33 | Policy mappings | Pairs of issuer and subject policy OIDs. |
2.5.29.35 | Authority key identifier | Identifies the issuer’s key, usually by its subject key identifier. |
2.5.29.36 | Policy constraints | Requirements on explicit policies below a CA. |
2.5.29.37 | Extended key usage | A list of key purpose OIDs; see key purposes. |
2.5.29.46 | Freshest CRL | Where to fetch delta CRLs. |
2.5.29.54 | Inhibit anyPolicy | Certificates after which “any policy” stops counting. |
1.3.6.1.5.5.7.1.1 | Authority information access | How to reach the issuer: …48.1 OCSP responder, …48.2 CA issuers (the issuer’s certificate). |
1.3.6.1.5.5.7.1.11 | Subject information access | Services of the subject: …48.3 time stamping, …48.5 CA repository. |
Two more extensions are defined by RFC 5280 and appear in older certificates:
2.5.29.16 private key usage period (see below) and, as a CRL entry
extension, 2.5.29.23 hold instruction code (an OID).
Arcs behind the extension OIDs
| Name | OID | Used for |
|---|---|---|
id-ce | 2.5.29 | Standard certificate and CRL extensions (the table above) |
id-pkix | 1.3.6.1.5.5.7 | Root of the four arcs below |
id-pe | 1.3.6.1.5.5.7.1 | Private extensions: .1 authority information access, .11 subject information access |
id-qt | 1.3.6.1.5.5.7.2 | Policy qualifier types: .1 id-qt-cps (CPS pointer), .2 id-qt-unotice (user notice) |
id-kp | 1.3.6.1.5.5.7.3 | Key purposes (see below) |
id-ad | 1.3.6.1.5.5.7.48 | Access methods: .1 OCSP, .2 CA issuers, .3 time stamping, .5 CA repository |
id-holdinstruction | 2.2.840.10040.2 | Hold instruction codes: .1 none (deprecated), .2 call issuer, .3 reject |
Extension values in ASN.1
The module is RFC 5280 Appendix A.2 (implicit tags). The bytes inside an
extnValue OCTET STRING are the DER of these types. In DER a component
equal to its DEFAULT is left out (a BasicConstraints with
cA false has no boolean), and a named bit list drops trailing zero bits.
When a nameConstraints value uses a uniformResourceIdentifier it holds a
host name or domain, not a URI.
-- key identifiers
AuthorityKeyIdentifier ::= SEQUENCE {
keyIdentifier [0] KeyIdentifier OPTIONAL,
authorityCertIssuer [1] GeneralNames OPTIONAL,
authorityCertSerialNumber [2] CertificateSerialNumber OPTIONAL }
-- authorityCertIssuer and authorityCertSerialNumber: both or neither
KeyIdentifier ::= OCTET STRING
SubjectKeyIdentifier ::= KeyIdentifier
PrivateKeyUsagePeriod ::= SEQUENCE {
notBefore [0] GeneralizedTime OPTIONAL,
notAfter [1] GeneralizedTime OPTIONAL } -- at least one present
-- policies
CertificatePolicies ::= SEQUENCE SIZE (1..MAX) OF PolicyInformation
PolicyInformation ::= SEQUENCE {
policyIdentifier CertPolicyId,
policyQualifiers SEQUENCE SIZE (1..MAX) OF PolicyQualifierInfo OPTIONAL }
CertPolicyId ::= OBJECT IDENTIFIER
PolicyQualifierInfo ::= SEQUENCE {
policyQualifierId OBJECT IDENTIFIER, -- id-qt-cps or id-qt-unotice
qualifier ANY DEFINED BY policyQualifierId }
CPSuri ::= IA5String
UserNotice ::= SEQUENCE {
noticeRef NoticeReference OPTIONAL,
explicitText DisplayText OPTIONAL }
NoticeReference ::= SEQUENCE {
organization DisplayText,
noticeNumbers SEQUENCE OF INTEGER }
DisplayText ::= CHOICE {
ia5String IA5String (SIZE (1..200)),
visibleString VisibleString (SIZE (1..200)),
bmpString BMPString (SIZE (1..200)),
utf8String UTF8String (SIZE (1..200)) }
PolicyMappings ::= SEQUENCE SIZE (1..MAX) OF SEQUENCE {
issuerDomainPolicy CertPolicyId,
subjectDomainPolicy CertPolicyId }
PolicyConstraints ::= SEQUENCE {
requireExplicitPolicy [0] SkipCerts OPTIONAL,
inhibitPolicyMapping [1] SkipCerts OPTIONAL }
SkipCerts ::= INTEGER (0..MAX)
InhibitAnyPolicy ::= SkipCerts
-- names
GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName
AnotherName ::= SEQUENCE {
type-id OBJECT IDENTIFIER,
value [0] EXPLICIT ANY DEFINED BY type-id }
EDIPartyName ::= SEQUENCE {
nameAssigner [0] DirectoryString OPTIONAL,
partyName [1] DirectoryString }
SubjectDirectoryAttributes ::= SEQUENCE SIZE (1..MAX) OF Attribute
Attribute ::= SEQUENCE {
type OBJECT IDENTIFIER,
values SET OF AttributeValue } -- at least one value
BasicConstraints ::= SEQUENCE {
cA BOOLEAN DEFAULT FALSE,
pathLenConstraint INTEGER (0..MAX) OPTIONAL }
NameConstraints ::= SEQUENCE {
permittedSubtrees [0] GeneralSubtrees OPTIONAL,
excludedSubtrees [1] GeneralSubtrees OPTIONAL }
GeneralSubtrees ::= SEQUENCE SIZE (1..MAX) OF GeneralSubtree
GeneralSubtree ::= SEQUENCE {
base GeneralName,
minimum [0] BaseDistance DEFAULT 0,
maximum [1] BaseDistance OPTIONAL }
BaseDistance ::= INTEGER (0..MAX)
-- revocation distribution
CRLDistributionPoints ::= SEQUENCE SIZE (1..MAX) OF DistributionPoint
FreshestCRL ::= CRLDistributionPoints
DistributionPoint ::= SEQUENCE {
distributionPoint [0] DistributionPointName OPTIONAL,
reasons [1] ReasonFlags OPTIONAL,
cRLIssuer [2] GeneralNames OPTIONAL }
DistributionPointName ::= CHOICE {
fullName [0] GeneralNames,
nameRelativeToCRLIssuer [1] RelativeDistinguishedName }
ReasonFlags ::= BIT STRING {
unused (0), keyCompromise (1), cACompromise (2), affiliationChanged (3),
superseded (4), cessationOfOperation (5), certificateHold (6),
privilegeWithdrawn (7), aACompromise (8) }
-- usage and access
ExtKeyUsageSyntax ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId
KeyPurposeId ::= OBJECT IDENTIFIER
AuthorityInfoAccessSyntax ::= SEQUENCE SIZE (1..MAX) OF AccessDescription
SubjectInfoAccessSyntax ::= SEQUENCE SIZE (1..MAX) OF AccessDescription
AccessDescription ::= SEQUENCE {
accessMethod OBJECT IDENTIFIER,
accessLocation GeneralName }
-- CRL and CRL entry extensions
CRLNumber ::= INTEGER (0..MAX)
BaseCRLNumber ::= CRLNumber -- delta CRL indicator
IssuingDistributionPoint ::= SEQUENCE {
distributionPoint [0] DistributionPointName OPTIONAL,
onlyContainsUserCerts [1] BOOLEAN DEFAULT FALSE,
onlyContainsCACerts [2] BOOLEAN DEFAULT FALSE,
onlySomeReasons [3] ReasonFlags OPTIONAL,
indirectCRL [4] BOOLEAN DEFAULT FALSE,
onlyContainsAttributeCerts [5] BOOLEAN DEFAULT FALSE }
-- at most one of the three onlyContains... flags may be TRUE
CRLReason ::= ENUMERATED {
unspecified (0), keyCompromise (1), cACompromise (2), affiliationChanged (3),
superseded (4), cessationOfOperation (5), certificateHold (6),
removeFromCRL (8), privilegeWithdrawn (9), aACompromise (10) }
CertificateIssuer ::= GeneralNames
HoldInstructionCode ::= OBJECT IDENTIFIER
InvalidityDate ::= GeneralizedTime
Unknown bits, enumerated values and trailing elements inside a non-critical extension
are ignored; a critical extension that holds unexpected values makes the whole
certificate or CRL unacceptable (RFC 5280 Appendix B). The ReasonFlags bit numbers
differ from the CRLReason values: there is no removeFromCRL bit, and
privilegeWithdrawn is bit 7 but reason 9.
GeneralName
A CHOICE told apart by its context tag: [0] otherName,
[1] rfc822Name (e-mail address, IA5String), [2] dNSName
(IA5String), [3] x400Address, [4] directoryName (Name),
[5] ediPartyName, [6] uniformResourceIdentifier (IA5String),
[7] iPAddress (OCTET STRING of 4 or 16 bytes, or 8 or 32 with a mask in
name constraints), [8] registeredID (OID).
Key usage bits
| Bit | Name |
|---|---|
| 0 | digitalSignature |
| 1 | nonRepudiation (now contentCommitment) |
| 2 | keyEncipherment |
| 3 | dataEncipherment |
| 4 | keyAgreement |
| 5 | keyCertSign |
| 6 | cRLSign |
| 7 | encipherOnly |
| 8 | decipherOnly |
Bit 0 is the most significant bit of the first content octet after the unused-bits count.
Key purposes
| OID | Purpose |
|---|---|
1.3.6.1.5.5.7.3.1 | TLS server authentication |
1.3.6.1.5.5.7.3.2 | TLS client authentication |
1.3.6.1.5.5.7.3.3 | Code signing |
1.3.6.1.5.5.7.3.4 | E-mail protection |
1.3.6.1.5.5.7.3.8 | Time stamping |
1.3.6.1.5.5.7.3.9 | OCSP signing |
2.5.29.37.0 | Any extended key usage |
Certificate revocation lists
CertificateList ::= SEQUENCE {
tbsCertList TBSCertList,
signatureAlgorithm AlgorithmIdentifier,
signatureValue BIT STRING }
TBSCertList ::= SEQUENCE {
version INTEGER OPTIONAL, -- 1 (v2) if present
signature AlgorithmIdentifier,
issuer Name,
thisUpdate Time,
nextUpdate Time OPTIONAL,
revokedCertificates SEQUENCE OF SEQUENCE {
userCertificate INTEGER, -- serial number
revocationDate Time,
crlEntryExtensions Extensions OPTIONAL } OPTIONAL,
crlExtensions [0] EXPLICIT Extensions OPTIONAL }
| OID | CRL extension |
|---|---|
2.5.29.20 | CRL number |
2.5.29.27 | Delta CRL indicator (critical) |
2.5.29.28 | Issuing distribution point (critical) |
2.5.29.35, .18, .46, 1.3.6.1.5.5.7.1.1 | Authority key identifier, issuer alternative name, freshest CRL, authority information access |
2.5.29.21 | Entry: reason code |
2.5.29.24 | Entry: invalidity date |
2.5.29.29 | Entry: certificate issuer (critical) |
| Reason code | Meaning |
|---|---|
| 0 | unspecified |
| 1 | keyCompromise |
| 2 | cACompromise |
| 3 | affiliationChanged |
| 4 | superseded |
| 5 | cessationOfOperation |
| 6 | certificateHold |
| 7 | not used |
| 8 | removeFromCRL |
| 9 | privilegeWithdrawn |
| 10 | aACompromise |