1. The question
libweida carries an identity as PEM, bytes or a path (weida_identity_from_pem, _from_pem_file(s)), hands it back as an owned weida_pem, names a trusted key as sha256: text and a presented chain as DER certificates (weida_incoming_meta_peer_chain_cert). Every language package sits on that boundary (0046), and every platform has its own types for keys and certificates.
So the question is: which forms does each package take and give for key material, and where do keys that cannot leave a platform store fit.
2. The evidence
The Rust API. Identity::from_pem, from_pem_files, from_pem_file and to_pem read and write PEM; Trust::and_anchor and and_anchor_file take PEM; PeerChain::certs yields DER, leaf first; a key is named by its Fingerprint, sha256: over the SubjectPublicKeyInfo. The key inside an Identity is kept in zeroizing storage, and to_pem's output is the caller's to wipe.
Per platform.
- Node:
crypto.KeyObjectexports a private key as PKCS#8 PEM (export({ type: "pkcs8", format: "pem" }));crypto.X509Certificategives PEM (toString()) and DER (raw) and is built from either. - Java and Android:
KeyStore(PKCS#12 on disk),PrivateKey.getEncoded()(PKCS#8 DER for an exportable key) andX509Certificate.getEncoded()(DER). - Erlang:
public_key:pem_decode/1andpem_encode/1;ssltakescertfile,keyfile,cacertfile, orcert(DER),key({Type, DER}) andcacerts(DER) in memory. - Go:
tls.CertificateholdsCertificate [][]byte(DER) and aPrivateKeythatx509.MarshalPKCS8PrivateKeyexports when it is an*ecdsa.PrivateKey,*rsa.PrivateKeyored25519.PrivateKey;x509.CertPoolcannot be enumerated, so its certificates cannot be handed on. - Python:
ssl.SSLContext.load_cert_chain(certfile, keyfile)takes paths; libraries pass bytes;cryptographyhas certificate and private-key objects that serialize to PEM.
3. The options
A. PEM only at every package surface. Loses: users hand-write PEM conversions where their platform already has a key or certificate type.
B. Each package maps its platform's types onto the ABI's PEM and DER. Loses: one conversion layer per package, written in that package's language.
C. DER and platform-specific entry points in the ABI. Loses: N formats in one boundary, each tested in Rust for a caller that is not Rust.
4. The decision
B, under these rules.
- The ABI carries PEM in (bytes or a path), an owned
weida_pemout, DER for a presented chain, andsha256:text for keys. It gains no platform format. - A package accepts its platform's types plus bytes and paths, and converts in the package. A platform private key is exported as PKCS#8.
- Key material a package gives out is a byte buffer the caller can wipe: JS
Uint8Array, Javabyte[], Go[]byte, Pythonbytearray. Erlang binaries cannot be wiped, and the Erlang package says so. - A presented chain is the platform's certificate type where its standard library has one, otherwise DER.
| Language | Identity in | Anchors | Out | Presented chain |
|---|---|---|---|---|
| JS | Identity.from({ cert: X509Certificate | X509Certificate[] | Bytes, key: KeyObject | Bytes }), fromPem, fromPemFile(s) | X509Certificate | Bytes, a file | certificatePem(): string, toPem(): Uint8Array, certificates(): X509Certificate[] | X509Certificate[] |
| JVM/Android | Identity.from(PrivateKey, X509Certificate...), Identity.fromKeyStore(KeyStore, alias, char[] password), PEM bytes and paths | X509Certificate, bytes, a path | toPem(): byte[], certificates(): X509Certificate[] | X509Certificate[] |
| Erlang/Elixir | ssl-style options: certfile/keyfile, cert (DER or a list), key ({Type, DER}) | cacertfile, cacerts | PEM binary | [DER binary] |
| Go | IdentityFromTLS(tls.Certificate) (the key must be *ecdsa.PrivateKey, *rsa.PrivateKey or ed25519.PrivateKey; any other crypto.Signer is case 2), PEM bytes and paths | []*x509.Certificate, PEM, a path; never x509.CertPool | ToPEM() []byte, TLSCertificate() (tls.Certificate, error) | []*x509.Certificate |
| Python | paths in load_cert_chain's shape, bytes, and cryptography certificates and private keys when installed | bytes, a path | to_pem() -> bytearray | list[bytes] (DER) |
Case 2, keys that never leave their store (Secure Enclave, Android Keystore, TPM, PKCS#11), is outside this note: such a key has no PKCS#8 to export. Its shape is a signer handle whose signature requests are a queue (0045 decision 10), proposal #17.
5. Follow-ups
- Plan B: Python (proposal #15).
- Plan C: JVM/Android, Erlang/Elixir and Go (proposal #16).
- Case 2: a signer handle in the ABI (proposal #17).