diff --git a/system/security/cryptohelper/cryptocommon.hpp b/system/security/cryptohelper/cryptocommon.hpp index 0261dfe201d..27784ff4d5d 100644 --- a/system/security/cryptohelper/cryptocommon.hpp +++ b/system/security/cryptohelper/cryptocommon.hpp @@ -46,14 +46,20 @@ inline void voidSSLCTXfree(SSL_CTX *ctx) if (ctx) SSL_CTX_free(ctx); } +inline void voidX509StoreFree(X509_STORE *store) +{ + if (store) + X509_STORE_free(store); +} inline void voidX509StkPopFree(STACK_OF(X509_INFO) *infoStk) { if (infoStk) sk_X509_INFO_pop_free(infoStk, X509_INFO_free); } -typedef OwnedPtrCustomFree OwnedX509Stkptr; -typedef OwnedPtrCustomFree OwnedSSLCTXptr; +typedef OwnedPtrCustomFree OwnedX509Store; +typedef OwnedPtrCustomFree OwnedX509StkPtr; +typedef OwnedPtrCustomFree OwnedSSLCTX; typedef OwnedPtrCustomFree OwnedEVPBio; typedef OwnedPtrCustomFree OwnedEVPPkey; typedef OwnedPtrCustomFree OwnedEVPPkeyCtx; diff --git a/system/security/securesocket/securesocket.cpp b/system/security/securesocket/securesocket.cpp index 591cf3c409e..37285487129 100644 --- a/system/security/securesocket/securesocket.cpp +++ b/system/security/securesocket/securesocket.cpp @@ -1188,7 +1188,7 @@ static bool useCertificateChainPEMBuffer(SSL_CTX *ctx, const char *certBuf, int if (!cbio) return false; - OwnedX509Stkptr infoStk(PEM_X509_INFO_read_bio(cbio, NULL, NULL, NULL)); + OwnedX509StkPtr infoStk(PEM_X509_INFO_read_bio(cbio, NULL, NULL, NULL)); if (!infoStk) return false; @@ -1242,11 +1242,13 @@ static bool setVerifyCertsPEMBuffer(SSL_CTX *ctx, const char *caCertBuf, int caC if (!cbio) return false; - OwnedX509Stkptr infoStk(PEM_X509_INFO_read_bio(cbio, NULL, NULL, NULL)); - if (!infoStk) + OwnedX509Store store(X509_STORE_new()); + if (!store) return false; - X509_STORE *store = SSL_CTX_get_cert_store(ctx); + OwnedX509StkPtr infoStk(PEM_X509_INFO_read_bio(cbio, NULL, NULL, NULL)); + if (!infoStk) + return false; X509_INFO *infoVal; for (int i = 0; i < sk_X509_INFO_num(infoStk); i++) @@ -1261,13 +1263,15 @@ static bool setVerifyCertsPEMBuffer(SSL_CTX *ctx, const char *caCertBuf, int caC } } + SSL_CTX_set_cert_store(ctx, store.getClear()); + return true; } class CSecureSocketContext : public CInterfaceOf { private: - OwnedSSLCTXptr m_ctx; + OwnedSSLCTX m_ctx; #if (OPENSSL_VERSION_NUMBER > 0x00909000L) const SSL_METHOD* m_meth = nullptr; #else