r/cpp_questions • • 2d ago

OPEN Debugging certificate trust mismatches between Windows and OpenSSL in C++ apps

I maintain a C++ app on Windows that does TLS with OpenSSL, and I keep running into the same headache: the same server cert gets accepted by Windows (CryptoAPI/SChannel) but rejected by OpenSSL, or the other way around. Sometimes CryptoAPI builds a valid chain, sometimes OpenSSL can't find a trust anchor even though the cert is clearly in the Windows store. The result flips depending on the store, the CA bundle, and verification flags

For those who've dealt with this from C++

  • How do you actually investigate the difference? Do you dump chains via CryptoAPI, run openssl s_client/verify, write throwaway C++ that calls both APIs and compares, or some mix?
  • Is it usually quick to pin down the exact cause, or does it turn into hours of manual poking?
  • Has anything existing actually made this straightforward for you, or is it still custom glue code?

I'm especially interested in how people maintaining C++ Windows apps handle this in practice what your debugging flow looks like when Windows and OpenSSL disagree on the same cert

2 Upvotes

5 comments sorted by

1

u/hadrabap 1d ago

I deal a lot with TLS. Not directly with the codebase that uses OpenSSL, we do Java servers and clients. I deal with native languages at home. I use openssl s_client and curl debugging output. Good friend is openssl x509 -noout -text as well. By that you can see in the chains.

The worst part are browsers. They're not publishing much information. Best way is to go through Browser/CA specs and model the situations with custom CA (ROOT, intermediates, CRL server, OCSP responder if you need that...).

Sometimes, it is good to capture the traffic and visualize it in WireShark. But that's pretty rare, fortunately.

1

u/Stunning_Gas_3862 1d ago

That's a good point about certificate chains and testing with custom CAs not something people talk about enough

One thing I keep wondering about though: with TLS in native Windows apps, is certificate verification and trust-store handling actually straightforward for you, or does it get messy once you're juggling Windows cert stores, OpenSSL trust config, and the differences in how chains get built?

I'm just trying to get a clearer picture of where developers actually burn time when they're debugging or implementing TLS, especially in native apps

1

u/rbmm 1d ago

If you mean exactly tls handshake, windows code usually use InitializeSecurityContextW calls, which internally do cerificate validation, if ISC_REQ_MANUAL_CRED_VALIDATION not set. If you try validate separate certificate via  CertGetCertificateChain + CertVerifyCertificateChainPolicy this is already another story. And CertGetCertificateChain  auto download certificates from szOID_AUTHORITY_INFO_ACCESS extension in certificat ( if szOID_PKIX_CA_ISSUERS exist in this extension), while openssl not do this ( not issue network requests). In case TLS handshake this not problem, because server itself send not only end certificate, but all intermediate too, but in case separate certificate, need download intermediate certs from server. In any case - are you use and can show your winapi code and openssl code, for context and compare ?

1

u/Wild_Meeting1428 1d ago

Could be very simple if you are lucky: as I know, openssl has its own trust store and does not use the windows store by default. So make sure to install every chain in both stores or find out how openssl can access the os store.

1

u/Discordbothost 1d ago

Before comparing trust stores, check that both clients get the same leaf cert. Run s_client with -servername set to the exact hostname your app uses and compare the leaf fingerprint. A different leaf points you toward SNI or the network path first.