From 15e7caa67917a77269a3590e66e14f91da84093d Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 14 Feb 2023 08:53:18 -0800 Subject: [PATCH] updated pk emplace loop to pre-parse key addr - error logging update to newer log::warning --- llarp/config/config.cpp | 4 +++- llarp/rpc/rpc_server.cpp | 22 ++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index 19526fde62..a1f84f8893 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -3,6 +3,7 @@ #include "ini.hpp" #include +#include #include #include #include @@ -1174,9 +1175,10 @@ namespace llarp key = "tcp://" + key; auto pubkeys = split(values, ",", true); + oxenmq::address key_addr{key}; for (auto& pk : pubkeys) - m_rpcEncryptedAddresses[oxenmq::address{key}].emplace(pk); + m_rpcEncryptedAddresses[key_addr].emplace(pk); }, Comment{ "Specify encrypted listener addresses and comma-delimited public keys to be accepted ", diff --git a/llarp/rpc/rpc_server.cpp b/llarp/rpc/rpc_server.cpp index b33c8448e8..d3a56d18d1 100644 --- a/llarp/rpc/rpc_server.cpp +++ b/llarp/rpc/rpc_server.cpp @@ -1,5 +1,7 @@ #include "rpc_server.hpp" #include "llarp/rpc/rpc_request_definitions.hpp" +#include "llarp/util/logging.hpp" +#include "oxen/log.hpp" #include "rpc_request.hpp" #include "llarp/service/address.hpp" #include @@ -106,18 +108,22 @@ namespace llarp::rpc for (const auto& addr : r.GetConfig()->api.m_rpcBindAddresses) { m_LMQ->listen_plain(addr.zmq_address()); - LogInfo("Bound RPC server to ", addr.full_address()); + log::info(logcat, "Bound RPC server to {}", addr.full_address()); } - for (const auto& [address, allowed_keys] : r->GetConfig()->api.m_rpcEncryptedAddresses) + for (const auto& [address, allowed_keys] : r.GetConfig()->api.m_rpcEncryptedAddresses) { - m_LMQ->listen_curve(address.zmq_address(), [allowed_keys = allowed_keys](auto pk, ...) { - if (std::find(allowed_keys.begin(), allowed_keys.end(), pk) != allowed_keys.end()) - return oxenmq::AuthLevel::admin; + m_LMQ->listen_curve( + address.zmq_address(), [allowed_keys = allowed_keys](auto addr, auto pk, ...) { + if (allowed_keys.count(std::string{pk})) + return oxenmq::AuthLevel::admin; - LogInfo("Curve pubkey not found in whitelist"); - return oxenmq::AuthLevel::denied; - }); + log::warning( + logcat, + "Curve pubkey not in whitelist, denying incoming RPC connection from {}", + addr); + return oxenmq::AuthLevel::denied; + }); } AddCategories();