Skip to content

Conversation

@solarispika
Copy link
Contributor

Problem

set_ca_cert_path() and set_ca_cert_store() behave inconsistently regarding system certificate loading:

Method Skips system certs
set_ca_cert_path() Yes
set_ca_cert_store() No

Both APIs conceptually do the same thing: "use these CA certs for verification." However, when using set_ca_cert_store() for certificate pinning, system certs are still loaded in load_certs(), defeating the purpose of pinning.

Root Cause

In load_certs():

if (!ca_cert_file_path_.empty()) {
  // load from file - skips else branch
} else if (!ca_cert_dir_path_.empty()) {
  // load from dir - skips else branch
} else {
  // load system certs - ALWAYS runs when using set_ca_cert_store()
}

set_ca_cert_path() sets ca_cert_file_path_, taking the first branch and skipping system cert loading.

set_ca_cert_store() sets ca_cert_store_ (since #2217 fix), but load_certs() doesn't check it, so it falls through to the else branch where system certs are added to the user's custom store.

Fix

Check ca_cert_store_ in load_certs():

    } else if (!ca_cert_store_) {  // Was: } else {
      // load system certs
    }

This makes set_ca_cert_store() behave consistently with set_ca_cert_path().

Test

Added SSLClientTest.SetCaCertStoreSkipsSystemCerts_Online to verify system certs are not loaded when custom store is set.

Both APIs conceptually do the same thing: "use these CA certs for
verification." However, set_ca_cert_store() falls through to the else
branch in load_certs() where system certs are added to the user's
custom store, defeating the purpose of certificate pinning.

This change makes set_ca_cert_store() behave consistently with
set_ca_cert_path() by checking ca_cert_store_ before loading system
certificates.

Added test to verify system certs are not loaded when custom store is set.
@yhirose
Copy link
Owner

yhirose commented Jan 22, 2026

@solarispika thanks for finding the problem!

@yhirose yhirose merged commit c3fa061 into yhirose:master Jan 22, 2026
9 of 10 checks passed
@solarispika solarispika deleted the fix-set-ca-cert-store-skip-system-certs branch January 23, 2026 06:52
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.

2 participants