Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions iocore/net/P_SSLSecret.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
limitations under the License.
*/

#include <string>
#include <string_view>
#include <mutex>
#include <unordered_map>

class SSLSecret
{
public:
Expand All @@ -33,4 +38,5 @@ class SSLSecret
bool loadFile(const std::string &name, std::string &data_item);

std::unordered_map<std::string, std::string> secret_map;
mutable std::recursive_mutex secret_map_mutex;
};
3 changes: 3 additions & 0 deletions iocore/net/SSLSecret.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ SSLSecret::loadFile(const std::string &name, std::string &data_item)
bool
SSLSecret::setSecret(const std::string &name, const char *data, int data_len)
{
std::scoped_lock lock(secret_map_mutex);
auto iter = secret_map.find(name);
if (iter == secret_map.end()) {
secret_map[name] = "";
Expand All @@ -88,6 +89,7 @@ SSLSecret::setSecret(const std::string &name, const char *data, int data_len)
const std::string *
SSLSecret::getSecretItem(const std::string &name) const
{
std::scoped_lock lock(secret_map_mutex);
auto iter = secret_map.find(name);
if (iter == secret_map.end()) {
return nullptr;
Expand All @@ -111,6 +113,7 @@ SSLSecret::getSecret(const std::string &name, std::string_view &data) const
bool
SSLSecret::getOrLoadSecret(const std::string &name1, const std::string &name2, std::string_view &data1, std::string_view &data2)
{
std::scoped_lock lock(secret_map_mutex);
bool found_secret1 = this->getSecret(name1, data1);
bool found_secret2 = name2.empty() || this->getSecret(name2, data2);

Expand Down