Skip to content

fix(ext/node): fix TLS client certificate authentication verification#33576

Open
bartlomieju wants to merge 1 commit intomainfrom
fix/tls-client-auth
Open

fix(ext/node): fix TLS client certificate authentication verification#33576
bartlomieju wants to merge 1 commit intomainfrom
fix/tls-client-auth

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

Fixes several issues in the node:tls client certificate authentication flow:

  • PEM header normalization: BEGIN TRUSTED CERTIFICATE and BEGIN X509 CERTIFICATE headers are now normalized to BEGIN CERTIFICATE before parsing (both client and server configs), matching OpenSSL behavior
  • X.509v1 chain verification: Instead of blindly accepting v1 certs (which bypassed all chain verification), we now do structural chain checking via issuer/subject DER matching -- valid chains pass, broken chains produce the correct Node/OpenSSL error codes
  • Client cert rejection flow: NodeClientCertVerifier::verify_client_cert now always succeeds the TLS handshake, storing errors for the JS layer (onServerSocketSecure) to handle rejection via this.destroy(), producing ECONNRESET on the client instead of a TLS fatal alert, matching Node.js behavior
  • TLS alert mapping: Added CertificateRequired alert mapping with version-aware logic (TLS 1.2 maps to SSLV3_ALERT_HANDSHAKE_FAILURE to match OpenSSL)
  • Error code accuracy: Fixed UNABLE_TO_GET_ISSUER_CERT_LOCALLY vs UNABLE_TO_VERIFY_LEAF_SIGNATURE distinction based on whether explicit CAs were provided

Test plan

  • ./x test-compat test-tls-client-auth.js passes (was failing)
  • ./x test-compat test-tls-client -- same pass/fail set as before (no regressions), plus test-tls-client-auth.js now passing
  • ./tools/lint.js passes
  • ./tools/format.js passes

Fixes several issues in the node:tls client certificate authentication
flow so that `test-tls-client-auth.js` passes:

- Normalize `BEGIN TRUSTED CERTIFICATE` and `BEGIN X509 CERTIFICATE`
  PEM headers to `BEGIN CERTIFICATE` before passing to rustls_pemfile,
  matching OpenSSL behavior.

- Replace blanket acceptance of X.509v1 certs (UnsupportedCertVersion)
  with structural chain verification via issuer/subject DER matching,
  so v1 certs with valid chains succeed while broken chains produce
  the correct Node/OpenSSL error codes.

- Make NodeClientCertVerifier store errors and always succeed the TLS
  handshake, letting the JS layer (onServerSocketSecure) handle client
  cert rejection. This produces ECONNRESET on the client instead of a
  TLS fatal alert, matching Node.js behavior.

- Add CertificateRequired alert mapping with TLS-version awareness
  (TLS 1.2 maps to SSLV3_ALERT_HANDSHAKE_FAILURE to match OpenSSL).

- Fix UNABLE_TO_GET_ISSUER_CERT_LOCALLY vs UNABLE_TO_VERIFY_LEAF_SIGNATURE
  distinction based on whether explicit CAs were provided.
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