Skip to content

crypt: crypto-agility + post-quantum KEX for master/minion auth - #71035

Open
dwoz wants to merge 9 commits into
saltstack:3008.xfrom
dwoz:wip/crypto-agility-3008x
Open

dwoz wants to merge 9 commits into
saltstack:3008.xfrom
dwoz:wip/crypto-agility-3008x

Conversation

@dwoz

@dwoz dwoz commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Delivers the crypto-agility roadmap raised in Discord 11/26 end-to-end: non-RSA identity keys, forward-secret ephemeral key exchange, and post-quantum hybrid KEX. All opt-in; 3008.x defaults unchanged.

What ships

Algorithm catalog (salt/crypt.py)

  • OAEP-SHA256/384/512, PKCS1v15-SHA256/384/512, PSS-SHA256/384/512 for the existing RSA paths.
  • ED25519-NONE as a non-RSA signing algorithm.
  • X25519-HKDF-SHA256 — authenticated ephemeral KEX. Full forward secrecy on every auth.
  • X25519-MLKEM768-HKDF-SHA256 — post-quantum hybrid. Addresses harvest-now-decrypt-later. Requires cryptography>=46.

Polymorphic key classes
PrivateKey / PublicKey dispatch across RSA + Ed25519; cross-family algorithm IDs rejected. gen_keys(keysize, key_type=...) dispatcher. New key_type config opt (default rsa).

Full handshake wiring

  • Minion (AsyncAuth): minion_sign_in_payload emits ephemeral + signs it (proof-of-possession of long-term key); _decrypt_aes_kex verifies the master's transcript sig, derives via HKDF-SHA256, AEAD-unwraps aes + session. Legacy RSA-OAEP token path untouched.
  • Master (AuthFuncs): _kex_master_reply_fields helper verifies minion ephemeral sig, calls kex_master_reply. Both async (_auth_impl) and sync (_auth_impl_sync) paths branch on enc_algo in KEX_ALGORITHMS.

Config validation
Config-load rejects key_type=ed25519 + non-KEX encryption_algorithm (the auth-reply X9.31 digest sig path can't sign under Ed25519).

Security properties of the KEX path

  • Forward secrecy: AES session key is derived from an ephemeral exchange; compromise of the master's long-term identity key does NOT allow decryption of previously-recorded traffic.
  • MITM resistance: Master signs its ephemeral pub + AEAD-wrapped blob hashes under its long-term identity key. Minion signs its own ephemeral for proof-of-possession.
  • Context binding: HKDF info and AEAD aad both include minion_id || nonce || sha256(master_long_term_pub) || sha256(minion_long_term_pub) || sha256(mlkem_ct). Prevents UKS and cross-session replay.
  • PQ hybrid: ML-KEM-768 shared secret concatenated with X25519 shared secret before HKDF. Break in either primitive alone is survivable; only break in both recovers the session key.

Compatibility

  • All new algorithm IDs are opt-in. 3008.x defaults remain OAEP-SHA1 / PKCS1v15-SHA1 / rsa.
  • A new minion configured for a KEX algorithm against an old master fails cleanly at first auth; the master never understands the new algorithm.
  • Hybrid PQ algorithm gated by HAS_MLKEM so older cryptography builds still import.
  • Ed25519 keys serialize as PKCS8 PEM (not BEGIN RSA PRIVATE KEY); downstream code that pattern-matches PEM headers should be audited (tracked as follow-up).

Tracks: #71034 (PQ roadmap issue).

Test plan

  • tests/pytests/unit/crypt/test_key_types.py — 18 unit tests covering gen_keys/sign/verify for Ed25519, cross-family rejection, RSA-PSS round-trip, OAEP-SHA256 round-trip, KEX round-trip (X25519 + hybrid), KEX tamper detection, minion-side proof-of-possession, ed25519-requires-KEX config validation.
  • tests/pytests/unit/crypt/test_kex_integration.py — 4 tests driving the full flow through AsyncAuth.minion_sign_in_payload + AsyncAuth.decrypt_aes against a simulated master, parametrized on both KEX algorithms, tamper + missing-field guards.
  • Existing tests/pytests/unit/test_crypt.py (35 pass, 6 skip) unchanged.
  • Full CI green.
  • Interop: new master ↔ old minion, old master ↔ new minion (fallback to RSA-OAEP), new master ↔ new minion with each KEX algorithm.

@dwoz
dwoz requested a review from a team as a code owner December 5, 2026 22:34
@dwoz dwoz added the test:full Run the full test suite label Dec 5, 2026
@dwoz dwoz added this to the Argon v3008.7 milestone Dec 5, 2026
dwoz added a commit to dwoz/salt that referenced this pull request Dec 5, 2026
@dwoz dwoz changed the title crypt: additive crypto-agility primitives (Ed25519 + X25519 KEX) crypt: crypto-agility + post-quantum KEX for master/minion auth Dec 6, 2026
CI failed on Photon OS 4/5 FIPS runs with:
  cryptography.exceptions.UnsupportedAlgorithm:
  X25519 is not supported by this version of OpenSSL.

The underlying issue is container-level: the Photon FIPS CI image
bundles a pre-3.5 OpenSSL FIPS provider that excludes Curve25519-based
algorithms. OpenSSL 3.5's FIPS module (FIPS 140-3 cert saltstack#4985) does
cover X25519, so the "FIPS mode disables X25519" assumption is already
becoming outdated.

Rather than skip arbitrarily on FIPS_TESTRUN (which would stay wrong
once the container is refreshed), add a runtime probe:

- salt.crypt.x25519_available() -- attempt X25519 key generation,
  return True/False. Used by both the config-load validator and the
  test-skip markers so both respond to actual OpenSSL capability.
- apply_minion_config / apply_master_config raise
  SaltConfigurationError with a clear "update OpenSSL or pick RSA OAEP"
  message when a KEX algorithm is configured but X25519 isn't available.
- tests/pytests/unit/crypt/test_key_types.py: individual
  @skip_if_no_x25519 markers on the 8 KEX-exercising tests.
- tests/pytests/unit/crypt/test_kex_integration.py: module-level
  pytestmark since every test uses X25519.
- New test_config_load_rejects_kex_when_x25519_unavailable covers the
  config-load error path (skips when X25519 IS available).

Local run: 88 passed, 12 skipped (the new skip plus pre-existing
FIPS-related skips). When the Photon CI container ships OpenSSL >= 3.5
FIPS, these tests begin running automatically.
dwoz added 3 commits December 5, 2026 23:03
Standalone X25519 is not FIPS-approved (NIST policy, unchanged across
OpenSSL 3.5.x FIPS provider revisions). That leaves FIPS fleets with
only the legacy RSA-OAEP path even though the bundled OpenSSL 3.5.8
FIPS provider exposes both Ed25519 identity keys and ML-KEM-768.

Add a third KEX variant with no X25519 dependency:

- MLKEM768-HKDF-SHA256 -- minion generates ML-KEM-768 keypair, sends
  pub; master encapsulates against it, returns ciphertext + the master
  ephemeral is the ciphertext itself. HKDF-SHA256 derives the AES-256
  session key from the single shared secret. AEAD-wrap aes + session
  under that key, master-ephemeral + wrap hashes signed under the
  long-term identity. Same transcript-sig / AEAD-aad construction as
  the other KEX variants.

- New KEX_ALGORITHMS_REQUIRING_X25519 tuple separates variants that
  depend on standalone X25519 from the pure-ML-KEM path. Config
  validator only refuses when the configured algorithm actually
  requires X25519 and the probe fails; MLKEM768-HKDF-SHA256 gets its
  own ML-KEM availability probe.

- Runtime probe mlkem768_available() mirrors x25519_available(): tries
  to actually generate a keypair rather than rely on the import-time
  HAS_MLKEM flag, so FIPS providers that expose only a subset report
  accurately.

- New kex_master_reply branch for pure-ML-KEM: master_ephemeral is just
  the ciphertext (1088B), no X25519 pub prepended. Minion-consume mirror
  decaps against the stored ML-KEM private; no ECDH step.

Unlocks ``key_type=ed25519`` + KEX for FIPS fleets (Ed25519 is
FIPS-approved in 3.5.8; was previously only pairable with the
X25519-based KEX algorithms).

Tests: new test_kex_mlkem768_only_roundtrip. 89 pass / 12 skip.
NSA's December 2026 PQC-transition press release points at CNSA 2.0
for all new NSS acquisitions after 2027-01-01. CNSA 2.0 requires
Category-5 PQ primitives: ML-KEM-1024 for key establishment, ML-DSA-87
for signatures, SHA-384+ for hashing, AES-256 for symmetric. This
commit brings salt's auth protocol into compliance with that profile.

ML-DSA (FIPS 204) signatures and identity keys:
- MLDSA44-NONE / MLDSA65-NONE / MLDSA87-NONE signing_algorithm values
  covering NIST Categories 2 / 3 / 5. MLDSA87-NONE is the CNSA 2.0
  requirement.
- KEY_TYPE_MLDSA44 / 65 / 87 identity key types; all serialize as PKCS8
  PEM like Ed25519. Single-shot sign() / verify() -- hash and
  randomization are baked into the FIPS 204 construction.
- PrivateKey / PublicKey dispatch extended to recognize ML-DSA
  instances; cross-family algorithm IDs refused as with Ed25519.
- gen_keys(key_type=mldsa87, ...) via _generate_private_key dispatcher;
  PKCS8 PEM shared with Ed25519's non-traditional path.
- Config validator enforces key_type <-> signing_algorithm pairing
  across all non-RSA identity types, not just Ed25519.

MLKEM1024-HKDF-SHA384 KEX:
- Mirror of MLKEM768-HKDF-SHA256 but at Category-5 security + SHA-384
  derivation. Larger ciphertext (1568B) and public key (1568B).
- New _kex_hash() selector: SHA-384 for the CNSA 2.0 variant, SHA-256
  for every other KEX algorithm. HKDF output + info-string context
  digests + transcript-sig wrap hashes all follow the hash selector,
  so the CNSA 2.0 derivation path has zero SHA-256 anywhere.
- KEX_ALGORITHMS_REQUIRING_MLKEM subset for config validation.

Runtime availability probes:
- mlkem1024_available(), mldsa_available(level) mirror the existing
  mlkem768_available() pattern (try to actually generate a keypair,
  return bool). Config load rejects ML-DSA key_types and MLKEM1024
  when the underlying OpenSSL can't materialize them.

New operator-facing constants:
- CNSA2_ENCRYPTION_ALGORITHMS, CNSA2_SIGNING_ALGORITHMS,
  CNSA2_KEY_TYPES tuples name the compliant primitive set.

Tests: mldsa roundtrip at all three levels, cross-family rejection,
MLKEM1024 roundtrip, CNSA 2.0 full-stack handshake (ML-DSA-87
identity + MLKEM1024-HKDF-SHA384 KEX + AES-GCM wrap), catalog
coherence check. 116 pass + 1 skip locally.

Refs:
- NSA PQC transition press release (Dec 2026)
- NIST FIPS 203 (ML-KEM), FIPS 204 (ML-DSA), FIPS 186-5 (EdDSA)
CI Photon FIPS unit run (saltstack#71035, run 47617672322) failed on the
single-sweep test_config_load_rejects_kex_when_x25519_unavailable
because it iterates all KEX_ALGORITHMS and asserts "X25519" appears in
the raised SaltConfigurationError. The validator correctly surfaces
"ML-KEM-768 requires ML-KEM-768" (not "X25519") when the configured
algorithm is pure-MLKEM and ML-KEM isn't available -- the single-regex
assertion can't cover both cases.

Split into two tests, each gated on the relevant primitive's runtime
availability:

- test_config_load_rejects_x25519_kex_when_x25519_unavailable iterates
  only KEX_ALGORITHMS_REQUIRING_X25519 and expects "X25519" in the
  error. Same skip condition as before (x25519_available=False).
- test_config_load_rejects_mlkem_kex_when_mlkem_unavailable iterates
  the pure-MLKEM variants, expects "ML-KEM" in the error. Skips when
  both ML-KEM levels are available (no rejection path to test).

Observed side effect from the CI logs: the Photon 5 FIPS CI env does
not expose ML-KEM-768 either (relenv-bundled FIPS provider predates
the 3.5.4 FIPS 203 cert). The new split test will pass regardless;
if/when the container refreshes to 3.5.4+ FIPS, the rejection test
auto-skips because mlkem768_available() flips to True.

This branch was previously deployed

1 inactive deployment
ci — e1c79810 Deployed Dec 6, 2026 by dwoz via Build Onedir Packages / RPM (arm64) #29879
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant