Skip to content

Reject identity and small order peer ephemeral public keys - #503

Open
akasakariko wants to merge 1 commit into
cloudflare:masterfrom
akasakariko:fix/reject-non-contributory-ephemeral-keys
Open

akasakariko wants to merge 1 commit into
cloudflare:masterfrom
akasakariko:fix/reject-non-contributory-ephemeral-keys

Conversation

@akasakariko

Copy link
Copy Markdown

Fixes #502

Problem

The peer ephemeral public key received during the handshake is used in a Diffie-Hellman exchange without any check on the result

X25519 against the identity point or a small order point produces an all-zero shared secret, which was mixed into the key schedule instead of aborting the handshake, contrary to section 6 of RFC 7748

Fix

Add a check that rejects non contributory Diffie-Hellman results and return a new WireGuardError::InvalidPublicKey variant

The check is applied to every exchange that involves a peer supplied ephemeral public key

  • parse_handshake_anon
  • receive_handshake_initialization
  • both exchanges in receive_handshake_response

Peer static public keys that come from the local configuration are left unchanged

Tests

New unit tests in the handshake module cover the identity point and the small order point encodings in both handshake directions

The tests assert that the handshake fails with InvalidPublicKey, and they fail on the parent commit because the handshake is accepted there

Verification

  • cargo test -p boringtun: 13 passed
  • cargo test -p boringtun --features mock-instant: 14 passed
  • cargo test -p boringtun --doc: no doctests
  • cargo fmt --all --check
  • cargo clippy -p boringtun --all-targets, with and without mock-instant: no new warnings

The root integration tests were not run locally because they need a tun device and root privileges

X25519 against the identity point or a small order point yields an
all-zero shared secret, which was fed into the key schedule without any
check, as reported in issue cloudflare#502

Reject every non contributory Diffie-Hellman result that involves a peer
supplied ephemeral public key, as required by section 6 of RFC 7748, and
return a new InvalidPublicKey error instead of continuing the handshake

The check covers the anonymous handshake parsing, the handshake
initiation handling and both Diffie-Hellman computations of the handshake
response handling, and the regression tests cover the identity point and
the small order points in both handshake directions
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.

Identity and small-order points accepted as peer ephemeral keys

1 participant