/** * Copyright (c) 2019 Paul-Louis Ageneau * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #ifndef RTC_IMPL_CERTIFICATE_H #define RTC_IMPL_CERTIFICATE_H #include "description.hpp" // for CertificateFingerprint #include "common.hpp" #include "configuration.hpp" // for CertificateType #include "init.hpp" #include "tls.hpp" #include #include namespace rtc::impl { class Certificate { public: static Certificate FromString(string crt_pem, string key_pem); static Certificate FromFile(const string &crt_pem_file, const string &key_pem_file, const string &pass = ""); static Certificate Generate(CertificateType type, const string &commonName); #if USE_GNUTLS Certificate(gnutls_x509_crt_t crt, gnutls_x509_privkey_t privkey); gnutls_certificate_credentials_t credentials() const; #elif USE_MBEDTLS Certificate(shared_ptr crt, shared_ptr pk); std::tuple, shared_ptr> credentials() const; #else // OPENSSL Certificate(shared_ptr x509, shared_ptr pkey, std::vector> chain = {}); std::tuple credentials() const; std::vector chain() const; #endif CertificateFingerprint fingerprint() const; private: const init_token mInitToken = Init::Instance().token(); #if USE_GNUTLS Certificate(shared_ptr creds); const shared_ptr mCredentials; #elif USE_MBEDTLS const shared_ptr mCrt; const shared_ptr mPk; #else const shared_ptr mX509; const shared_ptr mPKey; const std::vector> mChain; #endif const string mFingerprint; }; #if USE_GNUTLS string make_fingerprint(gnutls_certificate_credentials_t credentials, CertificateFingerprint::Algorithm fingerprintAlgorithm); string make_fingerprint(gnutls_x509_crt_t crt, CertificateFingerprint::Algorithm fingerprintAlgorithm); #elif USE_MBEDTLS string make_fingerprint(mbedtls_x509_crt *crt, CertificateFingerprint::Algorithm fingerprintAlgorithm); #else string make_fingerprint(X509 *x509, CertificateFingerprint::Algorithm fingerprintAlgorithm); #endif using certificate_ptr = shared_ptr; using future_certificate_ptr = std::shared_future; future_certificate_ptr make_certificate(CertificateType type = CertificateType::Default); } // namespace rtc::impl #endif