Files
LithosAnanake/include/starkernel/x509_ed25519.h
T
Robert Allan JamesandClaude Sonnet 5 431bcb1f34 Milestone 6: root CA generated, snakeoil intermediate embedded, DER parser
Root CA + snakeoil intermediate generated entirely offline
(/home/rajames/CLionProjects/lithosananke-ca/, outside this repo,
private keys chmod 600) per this milestone's own requirement: Ed25519,
root self-signed 20-year validity, intermediate real-CA-signed
(CA:TRUE, pathlen:0), chain verified via openssl.

Snakeoil intermediate embedded as a capsule (capsules/pki/
snakeoil-intermediate.der) -- confirmed the font-capsule precedent
needed zero new infrastructure, any non-.4th file under capsules/
embeds verbatim already.

New x509_ed25519.c: a from-scratch, narrow DER walker (not general
ASN.1/X.509, per this milestone's design decision) extracting the raw
Ed25519 pubkey from a cert's SubjectPublicKeyInfo -- handles the
optional v3 version field, verifies the AlgorithmIdentifier OID is
Ed25519 rather than assuming, handles both DER length forms. Verified
against ground truth: the extracted key from the real embedded cert
matches openssl's own reported pubkey byte-for-byte; refusal path
checked against truncated/garbage/empty/wrong-algorithm (real RSA cert)
input. Compiles clean on all three architectures.

Still open: mkcapsule signing step, wiring ed25519_verify() into
capsule_birth.c's three validate call sites (landing warn-only first,
per decision -- a bug here could stop every capsule from birthing,
including Mama's own, on all three arches), and the BLOCK_MAP.md
signature-status column. Documented in FABRIC-3.md.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U14ET9CWAtbQMbYqomKgXd
2026-08-26 20:55:05 -04:00

31 lines
1.3 KiB
C

/*
* x509_ed25519.h -- extract a raw Ed25519 public key from a DER-encoded
* X.509 certificate's SubjectPublicKeyInfo (RFC 8410).
*
* Deliberately NOT a general ASN.1/X.509 parser (Milestone 6 decision,
* FABRIC-2.md): walks exactly as far into the DER structure as needed
* to reach SubjectPublicKeyInfo, verifies its AlgorithmIdentifier OID is
* Ed25519 (1.3.101.112) and rejects anything else, then returns the raw
* 32-byte key from the trailing BIT STRING. No signature verification,
* no chain validation, no extension parsing -- this only answers "what
* public key does this cert claim to hold," matching exactly what
* ed25519_verify() needs as input.
*
* Freestanding C99, no libc beyond memcmp/memcpy (already provided by
* src/starkernel/vm/host/shim.c in the kernel build).
*/
#ifndef STARKERNEL_X509_ED25519_H
#define STARKERNEL_X509_ED25519_H
#include <stdint.h>
#include <stddef.h>
/* Returns 0 on success (pubkey_out[32] filled), -1 on any malformed
* encoding, unexpected structure, or non-Ed25519 algorithm. Never
* faults on malformed input -- every DER length/tag is bounds-checked
* against der_len before use. */
int x509_extract_ed25519_pubkey(const uint8_t *der, size_t der_len,
uint8_t pubkey_out[32]);
#endif /* STARKERNEL_X509_ED25519_H */