abla/crypto/x509

Generated from source.

Import with import "abla/crypto/x509".

Source: abla/crypto/x509/entry.ab

X509Attribute (class)

class X509Attribute(val oid: string, val tag: int, val value: string)

Holds an attribute's dotted object identifier, ASN.1 tag, and encoded value.

X509Name (class)

class X509Name(
    val der: string,
    val rdns: array<array<X509Attribute>>,
    val canonical: string,
    val commonName: string
)

A distinguished name: its DER, its relative distinguished names (each a set of attributes), and a canonical form that two names have in common exactly when RFC 5280 (7.1) says they match (case and spaces ignored in text).

x509EmptyName (fun)

fun x509EmptyName(): X509Name

Returns an empty distinguished name with no relative names or encoded bytes.

X509GeneralName (class)

class X509GeneralName(val kind: int, val value: string, val name: X509Name)

One GeneralName: kind is its context tag number (1 e-mail, 2 DNS, 4 directory, 6 URI, 7 IP address, 0 other), value the name as text, the address bytes (a constraint's, address then mask), or a directory name's canonical form.

X509Certificate (class)

class X509Certificate(
    val ok: bool,
    val error: string,
    val der: string,
    val tbs: string,
    val version: int,
    val serial: string,
    val signatureOid: string,
    val signatureParameters: string,
    val signature: string,
    val issuer: X509Name,
    val subject: X509Name,
    /** Seconds since 1970-01-01 UTC. */
    val notBefore: int,
    val notAfter: int,
    val keyOid: string,
    val keyParameters: string,
    val keyBits: string,
    val spki: string,
    val hasBasicConstraints: bool,
    val isCa: bool,
    /** The pathLenConstraint, or -1. */
    val pathLength: int,
    /** The keyUsage bits (bit n of the BIT STRING as 1 << n), or -1 with no extension. */
    val keyUsage: int,
    val hasExtendedKeyUsage: bool,
    val extendedKeyUsage: array<string>,
    val hasAltNames: bool,
    val altNamesCritical: bool,
    val altNames: array<X509GeneralName>,
    val hasNameConstraints: bool,
    val permitted: array<X509GeneralName>,
    val excluded: array<X509GeneralName>,
    val subjectKeyId: string,
    val authorityKeyId: string,
    /** The OID of the first critical extension this code does not know, or "". */
    val unknownCritical: string,
    /** The leaf promises an OCSP staple (the TLS Feature extension of RFC 7633 lists status_request): a client that checks revocation refuses it without one. */
    val mustStaple: bool = false
)

Holds parsed certificate fields, with a false success flag and error text when decoding fails.

X509Certificate.selfIssued (method)

fun selfIssued(): bool

Returns true if the canonical subject and issuer names match.

X509_KEY_DIGITAL_SIGNATURE (val)

val X509_KEY_DIGITAL_SIGNATURE

Key usage bit permitting digital signatures.

X509_KEY_NON_REPUDIATION (val)

val X509_KEY_NON_REPUDIATION

Key usage bit for content commitment.

X509_KEY_ENCIPHERMENT (val)

val X509_KEY_ENCIPHERMENT

Key usage bit permitting encipherment of other keys.

X509_KEY_DATA_ENCIPHERMENT (val)

val X509_KEY_DATA_ENCIPHERMENT

Key usage bit permitting direct encipherment of application data.

X509_KEY_AGREEMENT (val)

val X509_KEY_AGREEMENT

Key usage bit permitting key agreement.

X509_KEY_CERT_SIGN (val)

val X509_KEY_CERT_SIGN

Key usage bit permitting certificate signing.

X509_KEY_CRL_SIGN (val)

val X509_KEY_CRL_SIGN

Key usage bit permitting certificate revocation list signing.

X509_OID_SERVER_AUTH (val)

val X509_OID_SERVER_AUTH

Extended key usage identifier for TLS server authentication.

X509_OID_CLIENT_AUTH (val)

val X509_OID_CLIENT_AUTH

Extended key usage identifier for TLS client authentication.

X509_OID_ANY_EKU (val)

val X509_OID_ANY_EKU

Extended key usage identifier allowing any purpose.

x509Failed (fun)

fun x509Failed(error: string): X509Certificate

Returns a failed certificate result carrying the supplied error.

x509OidText (fun)

fun x509OidText(der: string, item: DerItem): string

An OID's dotted text, or "" if its bytes are not a well formed one.

x509ParseDer (fun)

fun x509ParseDer(der: string): X509Certificate

The certificate in der: check ok and error.

X509PemResult (class)

class X509PemResult(val certificates: array<X509Certificate>, val skipped: int)

All the certificates in a PEM text; the ones that do not parse are left out, and counted in the second result.

x509ParsePem (fun)

fun x509ParsePem(text: string): X509PemResult

Returns the certificates from PEM blocks together with the count of skipped invalid blocks.

X509TrustStore (class)

class X509TrustStore(val certificates: array<X509Certificate>)

Holds certificates that can serve as trust anchors during chain validation.

x509TrustStoreFromPem (fun)

fun x509TrustStoreFromPem(text: string): X509TrustStore

Returns a trust store containing the successfully parsed certificates from a PEM bundle.

x509TrustStoreFromFile (fun)

fun x509TrustStoreFromFile(path: string): X509TrustStore?

Returns the store parsed from a PEM file, or null if the path does not exist.

x509TrustStoreFromDerRecords (fun)

fun x509TrustStoreFromDerRecords(records: string): X509TrustStore

The store of certificates given as DER records, each a 32-bit little-endian length and the certificate (what the Windows runtime's system call 4006 returns for the system's root store); a record that does not parse is skipped.

x509SystemBundlePaths (fun)

fun x509SystemBundlePaths(): array<string>

Where the system keeps its CA bundle: the usual places of Debian, Red Hat, SUSE, Alpine, FreeBSD and macOS.

x509SystemTrustStore (fun)

fun x509SystemTrustStore(): X509TrustStore

The first system bundle that exists and holds a certificate, or an empty store.

x509CheckSignature (fun)

fun x509CheckSignature(cert: X509Certificate, issuer: X509Certificate): string

The reason cert's signature does not verify under the public key of issuer, or "" if it does.

x509VerifySignedBytes (fun)

fun x509VerifySignedBytes(der: string, algorithm: DerItem, signed: string, signature: string, issuer: X509Certificate): string

The reason a signature over the bytes signed does not verify under the public key of issuer, or "" if it does; the algorithm is the AlgorithmIdentifier algorithm of der (as in a certificate's or an OCSP response's signatureAlgorithm), and the same algorithms are accepted as for a certificate (SHA-2 RSA PKCS#1 and PSS, ECDSA P-256 and P-384, Ed25519; SHA-1 and MD5 are not).

x509IpBytes (fun)

fun x509IpBytes(host: string): string

The bytes of an IPv4 dotted quad or an IPv6 address in text, or "" if host is not an IP address.

x509DnsMatches (fun)

fun x509DnsMatches(pattern: string, host: string): bool

Whether a dNSName pattern of a certificate (lower case) matches the lower case host: labels equal, the pattern's first label may be a lone *, which stands for exactly one label, and only when the pattern has at least three labels (no *.com).

x509MatchesHost (fun)

fun x509MatchesHost(cert: X509Certificate, host: string): bool

Whether the certificate is valid for host (a DNS name or an IP address): only the subjectAltName counts.

X509Options (class)

class X509Options(
    /** The host name the leaf must be valid for; "" skips the check. */
    val hostname: string,
    /** The time of validation, seconds since 1970. Required: this module reads no clock. */
    val now: int,
    /** The longest path, leaf and trust anchor included. */
    val maximumDepth: int = 8,
    /** 0: a server's certificate (extended key usage serverAuth), 1: a client's. */
    val usage: int = 0
)

Sets the name, validation time, path depth, and key-use constraints for chain verification.

X509Verification (class)

class X509Verification(val ok: bool, val error: string, val path: array<X509Certificate>, val kind: int = 0)

kind says why a failed verification failed, for a caller that must tell causes apart without reading error: X509_FAILURE_OTHER, X509_FAILURE_UNKNOWN_AUTHORITY (no path to a trusted anchor), X509_FAILURE_MALFORMED (the leaf does not parse) or X509_FAILURE_EXPIRED (a certificate of the path is not yet valid or has expired).

X509_FAILURE_OTHER (val)

val X509_FAILURE_OTHER

Validation failure category for errors outside the named categories.

X509_FAILURE_UNKNOWN_AUTHORITY (val)

val X509_FAILURE_UNKNOWN_AUTHORITY

Validation failure category for a chain without a trusted issuer.

X509_FAILURE_EXPIRED (val)

val X509_FAILURE_EXPIRED

Validation failure category for a certificate outside its permitted lifetime.

X509_FAILURE_MALFORMED (val)

val X509_FAILURE_MALFORMED

Validation failure category for a malformed certificate or chain.

x509ValidatePath (fun)

fun x509ValidatePath(path: array<X509Certificate>, options: X509Options): string

The reason the path (leaf first, trust anchor last) is not valid, or "". Signatures are checked as it is built.

x509Verify (fun)

fun x509Verify(chain: array<string>, store: X509TrustStore, options: X509Options): X509Verification

Validates a server's chain (DER certificates, the leaf first; the others in any order, extras ignored): builds a path to a certificate in store, checks it and the leaf's host name.

Built from Abla v0.2.79 source ba5d6b7d. Examples and generated signatures follow that source revision.