Skip to content

Fix extract_keys suite variants and the TLS 1.2 IV assembly - #323

Open
42Pupusas wants to merge 2 commits into
RustCrypto:masterfrom
42Pupusas:fix-extract-keys-panic-and-suite-variants
Open

42Pupusas wants to merge 2 commits into
RustCrypto:masterfrom
42Pupusas:fix-extract-keys-panic-and-suite-variants

Conversation

@42Pupusas

Copy link
Copy Markdown

Two defects make ConnectionTrafficSecrets unusable for every AES-GCM cipher suite except TLS 1.3 AES-256-GCM:

  • Tls13AeadAlgorithm::extract_keys returned Aes256Gcm for both macro instantiations, reporting a 32-byte key for the AES-128 suite. A 16-byte key is not valid AES-256 key material, so consumers such as kTLS SET_TLS_RX reject a TLS 1.3 AES-128 handoff.
  • Tls12AeadAlgorithm::extract_keys returned Aes128Gcm for both macro instantiations and converted the fixed_iv slice with try_into().unwrap() as though it were the full 12-byte IV. rustls passes the 4-byte fixed IV and the 8-byte explicit nonce separately (see KeyBlockShape), so every TLS 1.2 AES-GCM extract panicked with TryFromSliceError. The IV is now assembled as fixed_iv || explicit, the same construction the TLS 1.2 encrypter already uses, and a wrong-length input returns UnsupportedOperationError instead of panicking.

Regression tests cover the TLS 1.3 secret shape, the TLS 1.2 IV assembly, and malformed key-block slices.

Two defects make ConnectionTrafficSecrets unusable for every AES-GCM
cipher suite except TLS 1.3 AES-256-GCM:

- Tls13AeadAlgorithm::extract_keys returned Aes256Gcm for both macro
  instantiations, reporting a 32-byte key for the AES-128 suite. A
  16-byte key is not valid AES-256 key material, so consumers such as
  kTLS SET_TLS_RX reject a TLS 1.3 AES-128 handoff.
- Tls12AeadAlgorithm::extract_keys returned Aes128Gcm for both macro
  instantiations and converted the fixed_iv slice with
  try_into().unwrap() as though it were the full 12-byte IV. rustls
  passes the 4-byte fixed IV and the 8-byte explicit nonce separately
  (see KeyBlockShape), so every TLS 1.2 AES-GCM extract panicked with
  TryFromSliceError. The IV is now assembled as fixed_iv || explicit,
  the same construction the TLS 1.2 encrypter already uses, and a
  wrong-length input returns UnsupportedOperationError instead of
  panicking.

Regression tests cover the TLS 1.3 secret shape, the TLS 1.2 IV
assembly, and malformed key-block slices. Suite confidentiality
limits are unchanged and handled separately.
The new test module was hand-formatted and disagrees with rustfmt's
default settings in three places (import grouping and two wrapped
calls). cargo fmt --all -- --check is clean now.
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