Skip to content
Snippets Groups Projects
Commit 12a52c78 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

x509: make PrivateKey::getPublicKey() thread-safe

parent df2a7759
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,7 @@ extern "C" {
#include <vector>
#include <memory>
#include <atomic>
#include <mutex>
#ifdef _WIN32
#include <iso646.h>
......@@ -207,6 +208,7 @@ private:
PrivateKey& operator=(const PrivateKey&) = delete;
Blob decryptBloc(const uint8_t* src, size_t src_size) const;
mutable std::mutex publicKeyMutex_ {};
mutable std::shared_ptr<PublicKey> publicKey_ {};
};
......
......@@ -361,6 +361,7 @@ PrivateKey::getPublicKey() const
const std::shared_ptr<PublicKey>&
PrivateKey::getSharedPublicKey() const
{
std::lock_guard<std::mutex> lock(publicKeyMutex_);
if (not publicKey_) {
auto pk = std::make_shared<PublicKey>();
if (auto err = gnutls_pubkey_import_privkey(pk->pk, key, GNUTLS_KEY_KEY_CERT_SIGN | GNUTLS_KEY_CRL_SIGN, 0))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment