Skip to content

keys: generate only P256 keys under FIPS 140-only mode#42

Merged
JackDoan merged 2 commits into
mainfrom
fips140-p256-only-keys
Jul 3, 2026
Merged

keys: generate only P256 keys under FIPS 140-only mode#42
JackDoan merged 2 commits into
mainfrom
fips140-p256-only-keys

Conversation

@JackDoan

@JackDoan JackDoan commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Under GODEBUG=fips140=only, crypto/ecdh refuses to generate an X25519 key. As a result keys.New() failed outright, and even with that guarded, Client.Enroll() panicked dereferencing the nil Ed25519 host key. This made it impossible for a FIPS-enforcing build to enroll at all, even into a P256 network.

Generate the P256 keypair unconditionally, and only generate the X25519/Ed25519 keypair when crypto/fips140 is not enabled. Enroll() now includes the 25519 public keys only when they were generated.

Non-FIPS builds are unchanged: both key sets are generated and sent. FIPS builds send only P256, which the DN API accepts for P256 networks (FIPS networks are always P256). Verified end to end: a fips140=only dnclient now enrolls into a P256 network and completes a P256 Nebula handshake.

Under GODEBUG=fips140=only, crypto/ecdh refuses to generate an X25519
key. As a result keys.New() failed outright, and even with that guarded,
Client.Enroll() panicked dereferencing the nil Ed25519 host key. This
made it impossible for a FIPS-enforcing build to enroll at all, even into
a P256 network.

Generate the P256 keypair unconditionally, and only generate the
X25519/Ed25519 keypair when crypto/fips140 is not enabled. Enroll() now
includes the 25519 public keys only when they were generated.

Non-FIPS builds are unchanged: both key sets are generated and sent. FIPS
builds send only P256, which the DN API accepts for P256 networks (FIPS
networks are always P256). Verified end to end: a fips140=only dnclient
now enrolls into a P256 network and completes a P256 Nebula handshake.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sk4ZZA8bcjVi6FJ3k2opFB
@JackDoan JackDoan requested a review from nbrownus July 3, 2026 00:41
Add TestNewFIPSAware covering both modes: without FIPS both key sets are
generated, and under GODEBUG=fips140=only only P256 keys are produced and
New() does not error (the regression that previously broke enrollment for
FIPS builds). CI now runs the keys package a second time under
GOFIPS140=v1.0.0 GODEBUG=fips140=only to exercise the FIPS branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sk4ZZA8bcjVi6FJ3k2opFB
# In fips140=only mode crypto/ecdh rejects X25519, so this also guards
# against a regression that would break enrollment for FIPS builds.
- name: Run FIPS key-generation tests
run: GOFIPS140=v1.0.0 GODEBUG=fips140=only go test ./keys/...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it'd hurt to run the whole test suite under fips140.

@JackDoan JackDoan merged commit 797464c into main Jul 3, 2026
2 checks passed
@JackDoan JackDoan deleted the fips140-p256-only-keys branch July 3, 2026 01:23
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.

2 participants