mirror of
https://github.com/monero-project/monero.git
synced 2025-07-22 22:10:45 -04:00
Add server auth to monerod, and client auth to wallet-cli and wallet-rpc
This commit is contained in:
parent
e56bf442c3
commit
ce7fcbb4ae
38 changed files with 495 additions and 189 deletions
|
@ -37,11 +37,11 @@ namespace daemonize {
|
|||
t_command_parser_executor::t_command_parser_executor(
|
||||
uint32_t ip
|
||||
, uint16_t port
|
||||
, const std::string &user_agent
|
||||
, const boost::optional<tools::login>& login
|
||||
, bool is_rpc
|
||||
, cryptonote::core_rpc_server* rpc_server
|
||||
)
|
||||
: m_executor(ip, port, user_agent, is_rpc, rpc_server)
|
||||
: m_executor(ip, port, login, is_rpc, rpc_server)
|
||||
{}
|
||||
|
||||
bool t_command_parser_executor::print_peer_list(const std::vector<std::string>& args)
|
||||
|
|
|
@ -36,7 +36,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <boost/optional/optional_fwd.hpp>
|
||||
|
||||
#include "daemon/rpc_command_executor.h"
|
||||
#include "common/common_fwd.h"
|
||||
#include "rpc/core_rpc_server.h"
|
||||
|
||||
namespace daemonize {
|
||||
|
@ -49,7 +52,7 @@ public:
|
|||
t_command_parser_executor(
|
||||
uint32_t ip
|
||||
, uint16_t port
|
||||
, const std::string &user_agent
|
||||
, const boost::optional<tools::login>& login
|
||||
, bool is_rpc
|
||||
, cryptonote::core_rpc_server* rpc_server = NULL
|
||||
);
|
||||
|
|
|
@ -40,11 +40,11 @@ namespace p = std::placeholders;
|
|||
t_command_server::t_command_server(
|
||||
uint32_t ip
|
||||
, uint16_t port
|
||||
, const std::string &user_agent
|
||||
, const boost::optional<tools::login>& login
|
||||
, bool is_rpc
|
||||
, cryptonote::core_rpc_server* rpc_server
|
||||
)
|
||||
: m_parser(ip, port, user_agent, is_rpc, rpc_server)
|
||||
: m_parser(ip, port, login, is_rpc, rpc_server)
|
||||
, m_command_lookup()
|
||||
, m_is_rpc(is_rpc)
|
||||
{
|
||||
|
|
|
@ -39,6 +39,8 @@ Passing RPC commands:
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <boost/optional/optional_fwd.hpp>
|
||||
#include "common/common_fwd.h"
|
||||
#include "console_handler.h"
|
||||
#include "daemon/command_parser_executor.h"
|
||||
|
||||
|
@ -54,7 +56,7 @@ public:
|
|||
t_command_server(
|
||||
uint32_t ip
|
||||
, uint16_t port
|
||||
, const std::string &user_agent
|
||||
, const boost::optional<tools::login>& login
|
||||
, bool is_rpc = true
|
||||
, cryptonote::core_rpc_server* rpc_server = NULL
|
||||
);
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "misc_log_ex.h"
|
||||
#include "daemon/daemon.h"
|
||||
|
||||
#include "common/password.h"
|
||||
#include "common/util.h"
|
||||
#include "daemon/core.h"
|
||||
#include "daemon/p2p.h"
|
||||
|
@ -127,7 +128,8 @@ bool t_daemon::run(bool interactive)
|
|||
|
||||
if (interactive)
|
||||
{
|
||||
rpc_commands = new daemonize::t_command_server(0, 0, "", false, mp_internals->rpc.get_server());
|
||||
// The first three variables are not used when the fourth is false
|
||||
rpc_commands = new daemonize::t_command_server(0, 0, boost::none, false, mp_internals->rpc.get_server());
|
||||
rpc_commands->start_handling(std::bind(&daemonize::t_daemon::stop_p2p, this));
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include "common/command_line.h"
|
||||
#include "common/scoped_message_writer.h"
|
||||
#include "common/password.h"
|
||||
#include "common/util.h"
|
||||
#include "cryptonote_core/cryptonote_core.h"
|
||||
#include "cryptonote_core/miner.h"
|
||||
|
@ -40,6 +41,7 @@
|
|||
#include "misc_log_ex.h"
|
||||
#include "p2p/net_node.h"
|
||||
#include "rpc/core_rpc_server.h"
|
||||
#include "rpc/rpc_args.h"
|
||||
#include "daemon/command_line_args.h"
|
||||
#include "blockchain_db/db_types.h"
|
||||
|
||||
|
@ -220,13 +222,13 @@ int main(int argc, char const * argv[])
|
|||
|
||||
if (command.size())
|
||||
{
|
||||
auto rpc_ip_str = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_rpc_bind_ip);
|
||||
const cryptonote::rpc_args::descriptors arg{};
|
||||
auto rpc_ip_str = command_line::get_arg(vm, arg.rpc_bind_ip);
|
||||
auto rpc_port_str = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_rpc_bind_port);
|
||||
if (testnet_mode)
|
||||
{
|
||||
rpc_port_str = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_testnet_rpc_bind_port);
|
||||
}
|
||||
auto user_agent = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_user_agent);
|
||||
|
||||
uint32_t rpc_ip;
|
||||
uint16_t rpc_port;
|
||||
|
@ -241,7 +243,20 @@ int main(int argc, char const * argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
daemonize::t_command_server rpc_commands{rpc_ip, rpc_port, user_agent};
|
||||
boost::optional<tools::login> login{};
|
||||
if (command_line::has_arg(vm, arg.rpc_login))
|
||||
{
|
||||
login = tools::login::parse(
|
||||
command_line::get_arg(vm, arg.rpc_login), false, "Daemon client password"
|
||||
);
|
||||
if (!login)
|
||||
{
|
||||
std::cerr << "Failed to obtain password" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
daemonize::t_command_server rpc_commands{rpc_ip, rpc_port, std::move(login)};
|
||||
if (rpc_commands.process_command_vec(command))
|
||||
{
|
||||
return 0;
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||
|
||||
#include "string_tools.h"
|
||||
#include "common/password.h"
|
||||
#include "common/scoped_message_writer.h"
|
||||
#include "daemon/rpc_command_executor.h"
|
||||
#include "rpc/core_rpc_server_commands_defs.h"
|
||||
|
@ -95,7 +96,7 @@ namespace {
|
|||
t_rpc_command_executor::t_rpc_command_executor(
|
||||
uint32_t ip
|
||||
, uint16_t port
|
||||
, const std::string &user_agent
|
||||
, const boost::optional<tools::login>& login
|
||||
, bool is_rpc
|
||||
, cryptonote::core_rpc_server* rpc_server
|
||||
)
|
||||
|
@ -103,7 +104,10 @@ t_rpc_command_executor::t_rpc_command_executor(
|
|||
{
|
||||
if (is_rpc)
|
||||
{
|
||||
m_rpc_client = new tools::t_rpc_client(ip, port);
|
||||
boost::optional<epee::net_utils::http::login> http_login{};
|
||||
if (login)
|
||||
http_login.emplace(login->username, login->password.password());
|
||||
m_rpc_client = new tools::t_rpc_client(ip, port, std::move(http_login));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -38,6 +38,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <boost/optional/optional_fwd.hpp>
|
||||
|
||||
#include "common/common_fwd.h"
|
||||
#include "common/rpc_client.h"
|
||||
#include "misc_log_ex.h"
|
||||
#include "cryptonote_core/cryptonote_core.h"
|
||||
|
@ -60,7 +63,7 @@ public:
|
|||
t_rpc_command_executor(
|
||||
uint32_t ip
|
||||
, uint16_t port
|
||||
, const std::string &user_agent
|
||||
, const boost::optional<tools::login>& user
|
||||
, bool is_rpc = true
|
||||
, cryptonote::core_rpc_server* rpc_server = NULL
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue