C509

C509 CBOR-encoded certificates (draft-ietf-cose-cbor-encoded-cert). A compact CBOR re-encoding of an X.509 v3 certificate: a deterministic-CBOR array of exactly 11 elements (10 TBS fields + the issuer signature). Two modes -- c509CertificateType 2 = natively-signed C509, 3 = a CBOR re-encoding of a DER X.509 certificate that inverts byte-for-byte to the original DER (so the original signature still verifies). It decodes CBOR, not DER, so it is reached by an explicit pki.schema.c509.parse call and is NOT auto-routed by pki.schema.parse.

pki.schema.c509.parse

since 0.2.30 experimental
pki.schema.c509.parse(bytes) -> { certificateType, serialNumber, serialNumberHex, ... }

Decode a C509 certificate (draft-ietf-cose-cbor-encoded-cert) from its deterministic-CBOR bytes. Returns the decoded fields (c509CertificateType 2 native or 3 re-encoded); a malformed shape throws a typed C509Error carrying the inner cbor/asn1 fault as .cause. It decodes CBOR, not DER, so it is reached by an explicit call and is not auto-routed by pki.schema.parse. The type-2 signedData and the raw signature are surfaced RAW (a native verifier hashes them without re-serialization).

Example

// the RFC 7925 profiled certificate from draft-ietf-cose-cbor-encoded-cert Appendix A.1 (type 3)
var bytes = Buffer.from(
  "8b03" + "4301f50d" + "00" + "6b52464320746573742043" + "41" + "1a63b0cd00" + "1a6955b900" +
  "d830460123456789ab" + "01" + "5821feb1216ab96e5b3b3340f5bdf02e693f16213a04525ed44450b1019c2dfd3838ab" +
  "01" + "5840d4320b1d6849e309219d30037e138166f2508247dddae76ccceea55053c108e90d551f6d60106f1abb484cfbe6256c178e4ac3314ea19191e8b607da5ae3bda16",
  "hex");
var c = pki.schema.c509.parse(bytes);
c.certificateType; // 3

References

pki.schema.c509.encode

since 0.3.4 experimental
pki.schema.c509.encode(input[, opts]) -> Buffer

Encode a C509 certificate to its deterministic-CBOR bytes -- the producing-side inverse of pki.schema.c509.parse. input is either a DER X.509 v3 certificate (a Buffer or PEM string), which is forward-transformed to a **type-3** C509 (a compact CBOR re-encoding whose signature is copied from the source and re-expressed as a fixed-width r||s, so parse(encode(der)).reconstructedDer reproduces the original DER byte for byte and the original signature still verifies), or a pki.schema.c509.parse result object, which is re-emitted to its native deterministic-CBOR array. The emission is canonical deterministic CBOR (RFC 8949 sec. 4.2) -- shortest-form heads, definite lengths, sorted map keys, and the registry integer shorthand for every registered algorithm / attribute / extension. It is signing-free (a byte transform, like pki.ct.encodeSctList); a shape outside the covered set throws a typed C509Error.

The fixed-width ECDSA r||s is sized by the ISSUER's signing curve, which a leaf certificate does not carry. It is resolved authoritatively (never a magnitude guess, and matching issuer/subject Names are not taken as proof of self-signing): from opts.issuerCurve, or from the RFC 5480 standard digest<->curve pairing the signature algorithm implies. A certificate signed with a non-standard digest/curve pairing (its r/s wider than the digest's standard curve) fails closed -- supply the issuer curve via opts.issuerCurve.

Options

- `issuerCurve` (string) -- the ISSUER's ECDSA signing curve "P-256" / "P-384" / "P-521" (or the OID
  names prime256v1 / secp384r1 / secp521r1); authoritative, overrides the resolution above. Consulted
  only for the DER -> type-3 path; ignored when re-emitting a parse result.

Example

var cbor = pki.schema.c509.encode(signerCertDer);   // a DER cert -> a compact type-3 C509
pki.schema.c509.parse(cbor).certificateType;        // 3

References