Recursive AI

onecrypto fix: moving assets to post-quantum cryptography

All onecrypto docs

onecrypto scan finds the quantum-vulnerable assets and prints a command for each; onecrypto fix runs it.

onecrypto fix <verb> <file> [--to TARGET] [options]
onecrypto fix --from scan.json [options]       # every finding of 'scan --json'

Dry run by default. Without --apply the command checks everything it can without writing (keys load, recipients suit, the original verifies) and reports what it would do. With --apply the results go beside the input as <name>.pq.<ext> (or to --out, a directory or the principal file name). An existing file is never overwritten, a private key is written with mode 0600, and the original is never touched. A fix that fails writes nothing: streamed output goes to <name>.partial and is deleted on any error.

Targets. ml-dsa-44|65|87, ml-dsa-65-ed25519 (composite), ml-kem-512|768|1024, x25519-ml-kem-768, x448-ml-kem-1024, ed25519 (the names the scan prints). Without --to the crypto policy decides (CryptoPolicy.NewSignatureSuite and NewKemSuite): --policy standard (default) composite ML-DSA-65 with Ed25519 for signatures and ML-KEM-768 with X25519 for encryption; --policy cnsa2 ML-DSA-87 and ML-KEM-1024. In OpenPGP the same choice means the RFC 9980 profiles (ML-DSA-65 with Ed25519 and ML-KEM-768 with X25519; ML-DSA-87 with Ed448 and ML-KEM-1024 with X448 under cnsa2). A signature target for an encryption certificate (or the reverse) is refused. New keys are generated on OneCrypto's own implementations and written as unencrypted PKCS #8 (RFC 9881 and RFC 9935 seed form).

reissue

For a certificate, a certification request or a bare private key.

InputWith --ca and --ca-keyWithout
CertificateNew certificate for a new key, issued by the CASelf-issued: a new self-signed certificate. Otherwise a PKCS #10 request (RFC 2986) for the same subject and extensions
Encryption certificate (key usage keyEncipherment only)Issued by the CAOnly the key: a KEM key cannot sign a request, so there is no proof of possession to put in one. Enrol the public key with a protocol that proves possession another way
RequestNew request, new keythe same
Private keyNew keythe same

Carried over (RFC 5280 §4.1–4.2): subject, subject alternative names, basic constraints (CA flag and path length), extended key usage, certificate policies, name constraints, policy mappings and constraints, inhibit anyPolicy, subject information access, and any extension this library does not know. Key usage is narrowed to what the new algorithm may carry (signing and certificate signing for ML-DSA; keyEncipherment for ML-KEM). Renewed: serial, validity (the new one starts at --at, default now, and keeps the old length, shortened if the CA certificate ends sooner, and says so), subject and authority key identifiers, and authority information access and CRL distribution points, which the issuing CA writes. Embedded SCTs are dropped. The old certificate stays valid until it expires or is revoked.

ACME renewal is not part of this command; it arrives with the ACME client. Use the request it writes.

re-sign

CMS and S/MIME SignedData (attached or detached, DER or PEM), OpenPGP signatures and signed PDFs.

The original is verified first, and an invalid one is refused (InvalidOriginal): CMS through the structured verifier at --at; OpenPGP against --verify-cert; PDF by its byte-range, digest and signature checks (trust in the signer's chain is reported but does not block, because the fix has no anchors). --force REASON signs anyway and writes the reason into the report. The content is always the original octets, never a re-encoding.

FormatWhat happens to the old signature
CMSKept: the new SignerInfo, its digest algorithm and its certificates are added (RFC 5652 §5.1, §5.3); the old SignerInfos are copied byte for byte. --replace writes the new signer only
OpenPGP detachedKept: the old signature packets then the new (a signature file may hold several, RFC 9580 §10.3.2.1). --replace writes the new one only
OpenPGP cleartext and inline-signedReplaced: those formats carry one set of signatures
PDFKept: a new signature is appended as an incremental update (ISO 32000-2 §12.8); the old bytes do not change, so the old signatures still verify. --replace does not apply

The new signer is --signer-cert with --signer-key (OpenPGP: --signer-key, a secret key file). With neither, a CMS or PDF fix makes a new key for the old signer's subject, issued by --ca when given and self-signed otherwise; it says which, because whoever verifies has to trust a self-signed signer directly. --tsa URL time-stamps the new signature (RFC 3161): the only network access of the command.

re-encrypt

CMS EnvelopedData and AuthEnvelopedData (DER or PEM) and OpenPGP messages. --key opens the old message, each --recipient is a new recipient's certificate. The output is encrypted to the new recipients only.

  • CMS: ML-KEM and composite ML-KEM recipients get a KEMRecipientInfo (RFC 9629, RFC 9936); X25519/ECDH recipients a key agreement; RSA recipients key transport. At least one recipient must be post-quantum, or the new message is no safer and the fix refuses. The kind stays (EnvelopedData stays AES-CBC, AuthEnvelopedData stays AES-GCM); the encapsulated content type is carried over unchanged, so a signed-then-enveloped message stays signed inside.
  • OpenPGP: the recipient certificates decide the packets (PKESK v3/v6, SEIPD v1/v2, RFC 9980 for post-quantum subkeys). Only the encryption layer changes: the packets inside it (one-pass signatures, literal data, signatures, compression) are carried over as they were, so a signed-and-encrypted message stays signed and its signatures verify against the same keys.
  • Streaming: decryption feeds encryption through a 1 MiB buffer on a second thread, so memory is flat whatever the size, and the plaintext exists nowhere else. Decryption writes to a stream and encryption reads from one, so one side must run apart from the other; a dedicated thread is used rather than a pooled one because it blocks for the whole message, and the buffer is cleared when the fix ends (a pipe from System.IO.Pipelines would keep the plaintext in pooled arrays that are not cleared).
  • Fail closed: a wrong key (WrongKey), a failed authentication tag or padding check (IntegrityFailure) or any other failure to open the original stops the fix with a typed error and no output file. An authenticated original (AuthEnvelopedData, SEIPD) releases no plaintext before its checks; a CBC-only original cannot be checked before its last block (RFC 5652 §6.3), which is why the output is a temporary file that is deleted on failure.

rotate

  • OpenSSH keys: RSA, DSA and ECDSA keys move to Ed25519 (PROTOCOL.key format), keeping the comment; --new-passphrase-file protects the new file. OpenSSH has no post-quantum host or user key type, so this is as far as an SSH key can go, and the report says so. The session key exchange (mlkem768x25519-sha256) is the part that already protects against a recording. Files: <name>.pq and <name>.pq.pub.
  • OpenPGP keys (secret key file; --password-file for a protected one):
    • x25519-ml-kem-768 (the default; x448-ml-kem-1024 under --policy cnsa2) adds a post-quantum encryption subkey to the existing key (RFC 9980 appendix A.2): the identity, certifications and signing key stay. Files: <name>.pq<ext> (the secret key with the subkey) and <name>.pq.pub<ext> (the certificate to publish). A key that already has one is reported and left alone.
    • ml-dsa-65 or ml-dsa-87 makes a new key (RFC 9980 profiles) with the same User IDs, certified by the old key, and writes the old key's revocation certificate without applying it (<name>.pq.revocation<ext>): revoking is yours to decide once everyone has the new key.

Whole fix lists

onecrypto scan --json > scan.json, then onecrypto fix --from scan.json --ca ca.pem --ca-key ca.key ... runs each finding with the keys and options given. A finding the supplied keys cannot serve (a re-encryption without --key, a location inside an archive or a mail store, a line of a key list) comes back refused with the missing input named; the rest still run. reconfigure (TLS endpoints) has nothing to run.

Exit status

0 everything ran, 1 something was refused, 2 bad usage.

Library

CertificateFix.Reissue, CmsFix.ReSign and CmsFix.ReEncrypt, SshFix.Rotate take objects and return a FixResult (files by role, and report lines: written, kept, skipped with a reason). Fix.Run(request, handlers) and Fix.ApplyList(findings, template, handlers) work on files; PgpFixHandler (.OpenPgp) and PdfFixHandler (.Pdf) are the handlers for their packages. Nothing reads the clock: every request carries Now.

Checked against

tools/fix/interop.sh runs each verb through the tool and reads the results with OpenSSL (x509, verify, req -verify, cms -verify, cms -decrypt), ssh-keygen and pdfsig; tests/OneCrypto.Fix.Tests round-trips every finding class of the scan corpus (scan, fix, scan again).