Skip to content

Commit

Permalink
pass CA certificates to SSLCtx when provided by pkcs12 (#1444)
Browse files Browse the repository at this point in the history
* pass CA certificates to SSLCtx when provided

* Apply suggestions from code review

* Update src/platform/tls_openssl.c

Co-authored-by: Nick Banks <nibanks@microsoft.com>
  • Loading branch information
wfurt and nibanks authored Apr 6, 2021
1 parent a97c81a commit 21c9ede
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/platform/tls_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1154,11 +1154,17 @@ CxPlatTlsSecConfigCreate(
goto Exit;
}

STACK_OF(X509) *Ca = NULL;
STACK_OF(X509) *CaCertificates = NULL;
Ret =
PKCS12_parse(Pkcs12, CredConfig->CertificatePkcs12->PrivateKeyPassword, &PrivateKey, &X509Cert, &Ca);
if (Ca) {
sk_X509_pop_free(Ca, X509_free); // no handling for custom certificate chains yet.
PKCS12_parse(Pkcs12, CredConfig->CertificatePkcs12->PrivateKeyPassword, &PrivateKey, &X509Cert, &CaCertificates);
if (CaCertificates) {
X509* CaCert;
while ((CaCert = sk_X509_pop(CaCertificates)) != NULL) {
//
// This transfers ownership to SSLCtx and CaCert does not need to be freed.
//
SSL_CTX_add_extra_chain_cert(SecurityConfig->SSLCtx, CaCert);
}
}
if (Pkcs12) {
PKCS12_free(Pkcs12);
Expand Down

0 comments on commit 21c9ede

Please sign in to comment.