Attribute certificates

The RFC 5755 attribute-certificate producing side. pki.attrcert.sign builds an AttributeCertificateInfo binding a Holder to a set of privilege attributes (role, clearance, group, ...) over a validity window, signs it with an Attribute Authority's private key, and emits an AttributeCertificate that pki.schema.attrcert.parse accepts and re-validates byte for byte. Unlike a public-key certificate an attribute certificate is never self-signed -- the holder has no key, so the issuing AA is always a distinct signer. Parsing lives at pki.schema.attrcert.parse.

pki.attrcert.sign

since 0.3.2 experimental
pki.attrcert.sign(spec, issuer, opts?) -> Promise<Buffer|string>

Build, sign, and DER-encode an RFC 5755 attribute certificate as an Attribute Authority. spec describes the certificate -- holder (exactly one form: entityName, baseCertificateID, fromCertificate to bind a public-key certificate's identity, or objectDigestInfo), notBeforeTime / notAfterTime (Dates -> GeneralizedTime), an optional serialNumber (positive, <= 20 octets; a random 20-octet serial is generated when omitted), attributes (an object of the sec. 4.4 privilege syntaxes -- role / clearance / group / chargingIdentity / accessIdentity / authenticationInfo -- or an array of pre-encoded Attribute DER), and optional extensions (an object of auditIdentity / targetInformation / noRevAvail / aaControls / acProxying / authorityKeyIdentifier, or an array of pre-encoded Extension DER). issuer is the signing AA -- { cert, key } (the AA certificate DER/PEM and its private key) or { name, publicKey, key } (an explicit issuer DN, AA SPKI DER, and key); an attribute certificate is never self-signed. The signature algorithm is resolved from the AA key (RSA PKCS#1 v1.5 or PSS, ECDSA, EdDSA, ML-DSA, SLH-DSA, or a composite arm), and the signature is verified under the AA public key before the certificate is returned. Returns DER, or a PEM ATTRIBUTE CERTIFICATE with opts.pem. Malformed input throws a typed AttrCertError. The AA certificate's own profile (RFC 5755 sec. 4.5) and validity are a verification-layer concern -- validate the AA certificate with pki.path.validate before trusting the attribute certificate. Parsing is pki.schema.attrcert.parse.

Options

- `pem` (boolean) -- return a PEM `ATTRIBUTE CERTIFICATE` string instead of DER.
- `pss` (boolean) -- sign an RSA key with RSASSA-PSS rather than PKCS#1 v1.5.
- `digestAlgorithm` (string) -- override the message digest where the algorithm permits a choice.

Example

async function example() {
  var ac = await pki.attrcert.sign(
    { holder: { entityName: { directoryName: "CN=Alice" } },
      notBeforeTime: new Date("2026-01-01T00:00:00Z"), notAfterTime: new Date("2027-01-01T00:00:00Z"),
      attributes: { role: { roleName: { uniformResourceIdentifier: "urn:role:admin" } } } },
    { cert: signerCertDer, key: signerKeyPkcs8 });
  pki.schema.attrcert.parse(ac).attributes[0].type;   // the role attribute OID
}
example();

References

  • spec RFC 5755
  • defends forged-attribute-certificate (CWE-347)