From 78ac891f7b80c3cd8ab02424a00208e014fe77b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Wed, 3 Jan 2024 10:58:18 +0100 Subject: [PATCH] B #6445: Make RSA (de)encryption thread safe (#2882) Co-authored-by: Ruben S. Montero (cherry picked from commit 5966e8d60def2d8a20f6e0ad5669f78800115104) --- src/common/SSLUtil.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/common/SSLUtil.cc b/src/common/SSLUtil.cc index dc5938c9f6..cf52ef56b2 100644 --- a/src/common/SSLUtil.cc +++ b/src/common/SSLUtil.cc @@ -255,6 +255,9 @@ namespace ssl_util int rsa_public_encrypt(const std::string& in, std::string& out) { static RSA * rsa = nullptr; + static std::mutex m; + + std::lock_guard lock(m); if ( rsa == nullptr) //initialize RSA structure { @@ -297,6 +300,9 @@ namespace ssl_util int rsa_private_decrypt(const std::string& in, std::string& out) { static RSA * rsa = nullptr; + static std::mutex m; + + std::lock_guard lock(m); if ( rsa == nullptr) //initialize RSA structure {