Skip to content

crypto: assert the negotiated curve in PQ handshake tests, cover PostQuantumStrict - #1811

Open
reservoir-cmyk wants to merge 1 commit into
cloudflare:masterfrom
reservoir-cmyk:test/negotiated-curve-assertions
Open

reservoir-cmyk wants to merge 1 commit into
cloudflare:masterfrom
reservoir-cmyk:test/negotiated-curve-assertions

Conversation

@reservoir-cmyk

Copy link
Copy Markdown

Companion to #1810.

TestSupportedCurvesNegotiation asserts only the SupportedCurves list the client advertises in its ClientHello; it never asserts which curve the handshake negotiated, and it skips PostQuantumStrict because httptest servers were assumed not to terminate X25519MLKEM768. That assumption predates the standard library's ML-KEM support: crypto/tls implements X25519MLKEM768 on both sides since Go 1.24, httptest's TLS stack is crypto/tls, and this module pins Go 1.27.4.

This PR adds crypto/curves_negotiation_test.go with three tests that pin the negotiated result via the client-side ConnectionState.CurveID:

  • TestNegotiatedCurveIsMLKEM768 — Prefer and Strict both negotiate X25519MLKEM768 against a stock httptest server,
  • TestStrictHasNoClassicalFallback — a Strict client refuses a classical-only server,
  • TestPreferFallsBackToClassical — a Prefer client still negotiates CurveP256 with that server.

All three pass locally against the current tree with a stock go1.27.4 toolchain (go vet ./crypto/ clean). The new file is standalone so the existing test file is untouched; happy to fold these into curves_test.go instead if that fits the codebase better.

One environment note, also raised in #1810: under the same stock toolchain, the existing test's Linux-branch assertion that P256Kyber768Draft00 is advertised does not hold, because the standard library does not implement 0xfe32. That failure reproduces on a pristine checkout (it is not caused by this PR) and may pass under Cloudflare's internal toolchain.

— Tomoki Murota, CISSP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant