Skip to content

Commit

Permalink
updated pk emplace loop to pre-parse key addr
Browse files Browse the repository at this point in the history
- error logging update to newer log::warning
  • Loading branch information
dr7ana committed Feb 14, 2023
1 parent c9c37c8 commit 29180a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 3 additions & 1 deletion llarp/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ini.hpp"

#include <oxenmq/address.h>
#include <oxenmq/oxenmq.h>
#include <llarp/constants/files.hpp>
#include <llarp/constants/platform.hpp>
#include <llarp/constants/version.hpp>
Expand Down Expand Up @@ -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 ",
Expand Down
22 changes: 14 additions & 8 deletions llarp/rpc/rpc_server.cpp
Original file line number Diff line number Diff line change
@@ -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 <cmath>
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 29180a3

Please sign in to comment.