diff options
-rw-r--r-- | Swiften/TLS/OpenSSL/OpenSSLContext.cpp | 15 | ||||
-rw-r--r-- | Swiften/TLS/TLSOptions.h | 6 |
2 files changed, 21 insertions, 0 deletions
diff --git a/Swiften/TLS/OpenSSL/OpenSSLContext.cpp b/Swiften/TLS/OpenSSL/OpenSSLContext.cpp index d9560de..6dd75d6 100644 --- a/Swiften/TLS/OpenSSL/OpenSSLContext.cpp +++ b/Swiften/TLS/OpenSSL/OpenSSLContext.cpp @@ -398,2 +398,17 @@ bool OpenSSLContext::configure(const TLSOptions &options) + if (options.trustAnchors) { + // Add any additional Trust Anchors which are present in the TLSOptions + X509_STORE* store = SSL_CTX_get_cert_store(context_.get()); + + if (store) { + for (auto& certificate : *options.trustAnchors) { + auto openSSLCert = dynamic_cast<OpenSSLCertificate*>(certificate.get()); + if (openSSLCert && openSSLCert->getInternalX509()) { + X509_STORE_add_cert(store, openSSLCert->getInternalX509().get()); + // Don't need to increment reference count as X509_STORE_add_cert does thiS + } + } + } + } + return true; diff --git a/Swiften/TLS/TLSOptions.h b/Swiften/TLS/TLSOptions.h index 56648a3..4109096 100644 --- a/Swiften/TLS/TLSOptions.h +++ b/Swiften/TLS/TLSOptions.h @@ -10,2 +10,3 @@ namespace Swift { class TLSContext; + class Certificate; @@ -64,2 +65,7 @@ namespace Swift { boost::optional<std::function<int(const TLSContext *)>> verifyCertificateCallback; + + /** + * Allows specification of application-specific Trust Anchors + */ + boost::optional<std::vector<std::shared_ptr<Certificate>>> trustAnchors; }; |