cass_ssl_set_cert drops intermediate certificates from a PEM chain (inverted condition in SSL_CTX_use_certificate_chain_bio)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust
- Domain
- cryptography, security
Research direction
Start in scylla-rust-wrapper/src/ssl.rs at the chain-loading helper used by cass_ssl_set_cert_n (around lines 353-378), then compare it with src/ssl/ssl_openssl_impl.cpp lines 188-240. Reproduce with the leaf+intermediate PEM test from the issue before editing. Done means the loop runs only after the leaf installs, the previous chain is cleared, PEM_R_NO_START_LINE is treated as end-of-input, CASS_OK is returned, and a unit test reports one extra chain cert.
Written by the indexing model from the issue text.
Description
What goes wrong
cass_ssl_set_cert() / cass_ssl_set_cert_n() never install intermediate certificates from a PEM bundle. SSL_CTX_use_certificate_chain_bio (a port of the C++ driver's helper) reads the leaf, calls SSL_CTX_use_certificate, and then only enters the "add following PEM certs as chain certs" loop when ret != 1, i.e. when installing the leaf failed:
So on the normal path (leaf installed, ret == 1) every intermediate in the bundle is silently dropped and CASS_OK is returned. On the failure path the loop needlessly mutates the context and always ends with ret = 0.
The original C++ driver runs the loop on success (if (ret)), and treats the end-of-input PEM_R_NO_START_LINE error as success:
Impact
A client configured for mutual TLS with a leaf + intermediate(s) bundle presents only the leaf during the handshake. Servers that trust only the root CA reject the client certificate, even though the application passed a correct chain and got CASS_OK. This is a regression compared to the C/C++ driver.
Reproduction
Temporary unit test in scylla-rust-wrapper/src/ssl.rs (root -> intermediate -> leaf generated with openssl, chain.pem = leaf.pem + int.pem):
let ssl = cass_ssl_new();
let rc = cass_ssl_set_cert_n(ssl.borrow(), CassStrLenDelimited::from_raw(CHAIN.as_ptr() as _), CassStrLen::from_raw(CHAIN.len() as _));
let ctx = ArcFFI::as_ref(ssl.borrow()).unwrap().ssl_context;
let mut sk: *mut openssl_sys::stack_st_X509 = std::ptr::null_mut();
openssl_sys::SSL_CTX_ctrl(ctx, 82 /* SSL_CTRL_GET_EXTRA_CHAIN_CERTS */, 0, &mut sk as *mut _ as *mut c_void);
let n = if sk.is_null() { 0 } else { openssl_sys::OPENSSL_sk_num(sk as *const _) };
Output on 7a86e01:
cass_ssl_set_cert_n rc=CassError_(0), extra chain certs = 0
Just flipping the condition to ret == 1 gives extra chain certs = 1 but then returns CASS_ERROR_SSL_INVALID_CERT, because reaching the end of the bundle (PEM_read_bio_X509 returning NULL) unconditionally sets ret = 0.
Fix direction
Run the chain loop only when SSL_CTX_use_certificate succeeded, clear any previous chain first (SSL_CTX_clear_chain_certs/extra certs), and when PEM_read_bio_X509 returns NULL check the last error: PEM_R_NO_START_LINE means "no more certificates" and should clear the error queue and keep ret = 1; any other error should fail. That mirrors OpenSSL's use_certificate_chain_file and the C++ driver. A unit test with a leaf + intermediate bundle asserting one extra chain cert and CASS_OK would cover it.
- Dominant language
- C++
- Stars
- 27
- Forks
- 18
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 5
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from scylladb/cpp-rs-driver
-
area/Driver_-_cpp-rs-driver bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
scylladb/cpp-rs-driver#546 ·
-
area/Driver_-_cpp-rs-driver bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
scylladb/cpp-rs-driver#545 ·
-
area/Driver_-_cpp-rs-driver bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
scylladb/cpp-rs-driver#544 ·
-
area/Driver_-_cpp-rs-driver bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
scylladb/cpp-rs-driver#543 ·
-
area/Driver_-_cpp-rs-driver bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
scylladb/cpp-rs-driver#541 ·
All issues in scylladb/cpp-rs-driver
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 95/100
Tracktion/tracktion_engine#505 ·
Maintainers usually reply within 1 day
-
Merge discards entry history (and the other side’s version) when “Max. history items” is unlimitedOpen
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
keepassxreboot/keepassxc#14157 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
tenstorrent/tt-metal#67322 ·
Maintainers usually reply within 1 day
-
`SIGFPE` reading `JSON` from a `Wide` part when `max_prefixes_deserialization_thread_pool_size` is 0Opencomp-json-datatype v25.8-affected v26.10-affected v26.11-affected v26.8-affected v26.9-affected
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ClickHouse/ClickHouse#134554 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
jesdga95/basalt#747 · 2 comments ·
Maintainers usually reply within 1 day