Repository navigation
rustls: consume CURLOPT_SSLCERT_BLOB / CURLOPT_SSLKEY_BLOB - #23196
ns-ylambert wants to merge 4 commits into
Conversation
1d09aee to
03a4139
Compare
|
Analysis of PR #23196 at 03a41392: Test ../../tests/http/test_02_download.py::TestDownload::test_02_34_max_total_conns[False-0-h2] failed, but it has been 0.5% flaky lately, so it's probably NOT a fault of the PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them). Note that this CI job has had a number of other flaky tests recently (3, to be specific) so it may be that this failure is rather a systemic issue with this job and not with this specific PR. Generated by Testclutch |
8d78947 to
f407945
Compare
|
@vszakats Thanks for the review. I added a test to exercise the |
+1, and will prevent the next new vTLS backend from overlooking wiring up the same functionality. |
cpu
left a comment
There was a problem hiding this comment.
I took a closer look at this diff, mainly focused on the rustls-ffi API updates. Those look good to me, but I had some other general feedback to consider.
Firstly, I think there could be some docs updates to go with this? I think all of these would be candidates to be updated to add rustls to the TLS-Backend header data:
- docs/libcurl/opts/CURLOPT_SSLCERT_BLOB.md:13
- docs/libcurl/opts/CURLOPT_SSLKEY_BLOB.md:12
- docs/libcurl/opts/CURLOPT_PROXY_SSLCERT_BLOB.md:14
- docs/libcurl/opts/CURLOPT_PROXY_SSLKEY_BLOB.md:13
More generally, it feels like the behavior of Curl_setblobopt taking the option data, and then passing it to a backend that ignores it is a deeper anti-pattern that might be nice to fix irrespective of making rustls support the opt?
E.g. should this have a new capability bit that curl should be using with Curl_ssl_supports(...) to be able to understand that the backend actually supports the option? I did a quick scan and it seemed like the GnuTLS vTLS backend might be in the same state as rustls before this PR (though I'm also surprised the test isn't catching that if so).
77bd596 to
d1ff442
Compare
|
Summary of changes (head
Gate rationale:
Out of scope (follow-ups):
|
|
Most recent diff LGTM. Considering the other feedback as follow-ups seems OK. Thanks again for the patch. |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The test precheck cannot detect unsupported TLS backends, error codes are misclassified, and the updated documentation is internally inconsistent.
Review effort: Balanced
Findings: 3
Open (8)
Preserve CURLE_TOO_LARGE for oversized certificate blobs · New Preserve CURLE_TOO_LARGE for oversized private-key blobs · New Check TLS backend blob support before running the mTLS test · New Clarify Rustls PEM support versus P12 formats · New Document Rustls PEM requirements in option availability · New Add Rustls PEM requirements to the format documentation · New Document Rustls PEM private-key support · New Align TLS backend coverage with the test description · New
What changed in this PR
Adds Rustls support for in-memory client certificate and key blobs, including proxy TLS configuration.
Changes:
- Loads certificate/key blobs before file paths in Rustls.
- Adds an mTLS blob integration test.
- Documents Rustls support for four blob options.
| File | Description |
|---|---|
lib/vtls/rustls.c |
Consumes client certificate and key blobs. |
tests/libtest/lib2095.c |
Adds blob-based mTLS test logic. |
tests/libtest/Makefile.inc |
Registers the libtest source. |
tests/data/test2095 |
Defines the mTLS test case. |
tests/data/Makefile.am |
Registers test 2095. |
docs/libcurl/opts/CURLOPT_SSLKEY_BLOB.md |
Advertises Rustls support. |
docs/libcurl/opts/CURLOPT_SSLCERT_BLOB.md |
Advertises Rustls support. |
docs/libcurl/opts/CURLOPT_PROXY_SSLKEY_BLOB.md |
Advertises proxy-key blob support. |
docs/libcurl/opts/CURLOPT_PROXY_SSLCERT_BLOB.md |
Advertises proxy-certificate blob support. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…tls backend `curl/lib/vtls/rustls.c` reads only the file-path client-cert fields (`conn_config->clientcert`, `conn_config->key`) via `read_file_into()`. The blob fields populated by `CURLOPT_SSLCERT_BLOB` / `CURLOPT_SSLKEY_BLOB` are never consulted, so callers that hand the client identity as in-memory blobs have their cert and key silently dropped and the server sees an anonymous TLS connection. At both call sites in `init_config_builder_client_auth`: check the blob field first (`conn_config->cert_blob` / `conn_config->key_blob`), copy its bytes into the dyn buffer if set, fall back to `read_file_into()` otherwise. Also extend the outer entry gate at `cr_init_backend` so `init_config_builder_client_auth` is reached when only the blob fields are set (no file paths). Same shape `openssl.c` and `schannel.c` already have: see how each consults `ca_info_blob` / `cert_blob` / `key_blob` before falling back to file paths. No new option is introduced; existing `CURLOPT_SSLCERT_BLOB` / `CURLOPT_SSLKEY_BLOB` just start working on curl+rustls-ffi. Scope excluded: `openssl.c`'s "reuse cert source as key source when no separate key is set" convenience is not mirrored here. That fallback exists for legacy combined-PEM bundles and relies on the backend's PEM parser being tolerant of mismatched blocks; rustls-ffi is designed explicit-over-implicit and callers with a combined PEM should split cert and key upstream.
Exercises the in-memory client-auth path added to the rustls backend. Uses the https-mtls server and loads CA cert, client certificate, and private key from disk into memory, then passes them as blobs via CURLOPT_CAINFO_BLOB, CURLOPT_SSLCERT_BLOB, and CURLOPT_SSLKEY_BLOB. Skipped on Schannel (native blobs not applicable) and on builds where CURLOPT_SSLCERT_BLOB is absent.
`CURLOPT_SSLCERT_BLOB` / `CURLOPT_SSLKEY_BLOB` (and their `PROXY_` variants) are now consumed by the rustls backend.
`init_config_builder_client_auth` never reads `conn_config->cert_type` / `conn_config->key_type`, so `CURLOPT_SSLCERTTYPE` / `CURLOPT_SSLKEYTYPE` set to anything but the default "PEM" were silently ignored. A "DER" or "P12" blob failed with an opaque parse error out of `rustls_certified_key_build` with no hint the type option was dropped. Reject both options unless they are NULL or "PEM", matching the checks `schannel.c` and `openssl.c` already apply: rustls-ffi only accepts PEM-encoded material (`PrivateKeyDer::from_pem_slice` / `CertificateDer::pem_slice_iter`).
0f9ff35 to
544b73f
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The implementation, validation, documentation, and integration-test registration are consistent and complete.
0 open findings
8 resolved since last review
Check TLS backend blob support before running the mTLS test Preserve CURLE_TOO_LARGE for oversized private-key blobs Preserve CURLE_TOO_LARGE for oversized certificate blobs Align TLS backend coverage with the test description Document Rustls PEM private-key support Add Rustls PEM requirements to the format documentation Document Rustls PEM requirements in option availability Clarify Rustls PEM support versus P12 formats
🧠 Review effort: Balanced
| HTTPS with in-memory client auth using blob options | ||
| </name> | ||
| <command> | ||
| https://localhost:%HTTPS-MTLSPORT/%TESTNUMBER %CERTDIR/certs/test-ca.crt %CERTDIR/certs/test-client-cert.crt %CERTDIR/certs/test-client-cert.key |
There was a problem hiding this comment.
| https://localhost:%HTTPS-MTLSPORT/%TESTNUMBER %CERTDIR/certs/test-ca.crt %CERTDIR/certs/test-client-cert.crt %CERTDIR/certs/test-client-cert.key | |
| https://localhost:%HTTPS-MTLSPORT/%TESTNUMBER | |
| %CERTDIR/certs/test-ca.crt | |
| %CERTDIR/certs/test-client-cert.crt | |
| %CERTDIR/certs/test-client-cert.key |
perhaps folding the line like this makes it more readable
and avoids this long line?
PR LGTM with or without this change.
vszakats
left a comment
There was a problem hiding this comment.
With one (optional) style suggestion:
https://github.com/curl/curl/pull/23196/files#r4212402570


Problem
lib/vtls/rustls.creads only the file-path client-cert fields (conn_config->clientcert,conn_config->key) viaread_file_into(). The blob fields populated byCURLOPT_SSLCERT_BLOB/CURLOPT_SSLKEY_BLOB(and theirPROXY_variants) are never consulted. Callers that hand the client identity as in-memory blobs have their cert and key silently dropped, and the server sees an anonymous TLS connection instead of receiving aCertificateVerifymessage.CURLOPT_CAINFO_BLOBis already handled inrustls.c(seecr_set_ssl_x509_store).CURLOPT_SSLCERT_BLOB/CURLOPT_SSLKEY_BLOBare the missing counterparts.openssl.candschannel.cboth consultcert_blob/key_blobbefore falling back to file paths.Fix
At both call sites in
init_config_builder_client_auth:conn_config->cert_blob/conn_config->key_blob).curlx_dyn_addn().read_file_into()otherwise.Also extend the outer entry gate in
cr_init_backendfromto
so
init_config_builder_client_authis reached when only blobs are set (no file paths).The cert-without-key and key-without-cert validation is updated to check the presence of either form (path or blob) rather than file paths alone.
CURLOPT_SSLCERTTYPE/CURLOPT_SSLKEYTYPE(and theirPROXY_variants) are now validated: rustls-ffi only accepts PEM-encoded material, so any type other thanNULLor"PEM"is rejected with a clear error instead of being silently ignored and failing later insiderustls_certified_key_build()with an opaque parse error. Same shape the other backends already apply (schannel.crejects types other than"P12";openssl.cfails on unsupported file types).Out of scope
openssl.chas a convenience: when a cert source is set but no key source is given, it reuses the cert bytes/file as the key source. That fallback exists for legacy combined-PEM bundles and relies on the OpenSSL PEM parser tolerating mismatched blocks. It is not mirrored here: rustls-ffi is designed explicit-over-implicit, and callers with a combined PEM should split cert chain and key before calling curl.Also out of scope, tracked as follow-ups:
gtls.cdoes not consultcert_blob/key_blob); test2095 is gated with!GnuTLSuntil that is addressed.!mbedtlsuntil that fix lands.SSLSUPP_*bit exists for them), so a build whose backend ignores them accepts them silently. Adding aSSLSUPP_*gate insetopt.cis a cross-backend change and belongs in its own PR.Test
tests/libtest/lib2095.c+tests/data/test2095: loads the CA cert, client certificate, and private key from disk into memory and passes them viaCURLOPT_CAINFO_BLOB,CURLOPT_SSLCERT_BLOB, andCURLOPT_SSLKEY_BLOBto anhttps-mtlsserver. The test is skipped on Schannel builds and on any build whereCURLOPT_SSLCERT_BLOBis absent. It is also gated off for GnuTLS (blob options ignored) and mbedTLS (fixed in #23274) for now. Coverage specific to the rustls backend comes from theAM rustlsCI job.Verification
Verified with a server requiring client certificate authentication, passing the certificate chain and private key via
CURLOPT_SSLCERT_BLOB/CURLOPT_SSLKEY_BLOBwith curl built against rustls-ffi. Pre-patch: the blobs are silently ignored, no client certificate is presented, and the server rejects the connection. Post-patch: theCertificateVerifyhandshake message is sent and the connection succeeds.Also verified: a blob larger than the 100 KiB dyn-buffer limit fails with
CURLE_TOO_LARGE, andCURLOPT_SSLCERTTYPE "DER"fails with a clear error instead of an opaque parse failure.Related
CURLOPT_CAINFO_BLOBsupport to the rustls backend.CAINFO_BLOBhas since landed via a different path, confirming the blob-in-rustls pattern is accepted. This PR is the natural follow-up for the client cert/key side.!mbedtlsgate on test2095 is dropped.