Electroneum
cryptonote::rpc_args Struct Reference

Processes command line arguments related to server-side RPC. More...

#include <rpc_args.h>

Collaboration diagram for cryptonote::rpc_args:

Classes

struct  descriptors
 

Static Public Member Functions

static const char * tr (const char *str)
 
static void init_options (boost::program_options::options_description &desc, const bool any_cert_option=false)
 
static boost::optional< rpc_argsprocess (const boost::program_options::variables_map &vm, const bool any_cert_option=false)
 
static boost::optional< epee::net_utils::ssl_options_tprocess_ssl (const boost::program_options::variables_map &vm, const bool any_cert_option=false)
 

Public Attributes

std::string bind_ip
 
std::vector< std::string > access_control_origins
 
boost::optional< tools::loginlogin
 
epee::net_utils::ssl_options_t ssl_options = epee::net_utils::ssl_support_t::e_ssl_support_enabled
 

Detailed Description

Processes command line arguments related to server-side RPC.

Definition at line 44 of file rpc_args.h.

Member Function Documentation

◆ init_options()

void cryptonote::rpc_args::init_options ( boost::program_options::options_description &  desc,
const bool  any_cert_option = false 
)
static

Definition at line 108 of file rpc_args.cpp.

109  {
110  const descriptors arg{};
111  command_line::add_arg(desc, arg.rpc_bind_ip);
112  command_line::add_arg(desc, arg.rpc_login);
113  command_line::add_arg(desc, arg.confirm_external_bind);
114  command_line::add_arg(desc, arg.rpc_access_control_origins);
115  command_line::add_arg(desc, arg.rpc_ssl);
116  command_line::add_arg(desc, arg.rpc_ssl_private_key);
117  command_line::add_arg(desc, arg.rpc_ssl_certificate);
118  command_line::add_arg(desc, arg.rpc_ssl_ca_certificates);
119  command_line::add_arg(desc, arg.rpc_ssl_allowed_fingerprints);
120  command_line::add_arg(desc, arg.rpc_ssl_allow_chained);
121  if (any_cert_option)
122  command_line::add_arg(desc, arg.rpc_ssl_allow_any_cert);
123  }
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
Definition: command_line.h:188
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process()

boost::optional< rpc_args > cryptonote::rpc_args::process ( const boost::program_options::variables_map &  vm,
const bool  any_cert_option = false 
)
static
Returns
Arguments specified by user, or boost::none if error

Definition at line 125 of file rpc_args.cpp.

126  {
127  const descriptors arg{};
128  rpc_args config{};
129 
130  config.bind_ip = command_line::get_arg(vm, arg.rpc_bind_ip);
131  if (!config.bind_ip.empty())
132  {
133  // always parse IP here for error consistency
134  boost::system::error_code ec{};
135  const auto parsed_ip = boost::asio::ip::address::from_string(config.bind_ip, ec);
136  if (ec)
137  {
138  LOG_ERROR(tr("Invalid IP address given for --") << arg.rpc_bind_ip.name);
139  return boost::none;
140  }
141 
142  if (!parsed_ip.is_loopback() && !command_line::get_arg(vm, arg.confirm_external_bind))
143  {
144  LOG_ERROR(
145  "--" << arg.rpc_bind_ip.name <<
146  tr(" permits inbound unencrypted external connections. Consider SSH tunnel or SSL proxy instead. Override with --") <<
147  arg.confirm_external_bind.name
148  );
149  return boost::none;
150  }
151  }
152 
153  const char *env_rpc_login = nullptr;
154  const bool has_rpc_arg = command_line::has_arg(vm, arg.rpc_login);
155  const bool use_rpc_env = !has_rpc_arg && (env_rpc_login = getenv("RPC_LOGIN")) != nullptr && strlen(env_rpc_login) > 0;
156  boost::optional<tools::login> login{};
157  if (has_rpc_arg || use_rpc_env)
158  {
159  config.login = tools::login::parse(
160  has_rpc_arg ? command_line::get_arg(vm, arg.rpc_login) : std::string(env_rpc_login), true, [](bool verify) {
161  return tools::password_container::prompt(verify, "RPC server password");
162  });
163 
164  if (!config.login)
165  return boost::none;
166 
167  if (config.login->username.empty())
168  {
169  LOG_ERROR(tr("Username specified with --") << arg.rpc_login.name << tr(" cannot be empty"));
170  return boost::none;
171  }
172  }
173 
174  auto access_control_origins_input = command_line::get_arg(vm, arg.rpc_access_control_origins);
175  if (!access_control_origins_input.empty())
176  {
177  if (!config.login)
178  {
179  LOG_ERROR(arg.rpc_access_control_origins.name << tr(" requires RPC server password --") << arg.rpc_login.name << tr(" cannot be empty"));
180  return boost::none;
181  }
182 
183  std::vector<std::string> access_control_origins;
184  boost::split(access_control_origins, access_control_origins_input, boost::is_any_of(","));
185  std::for_each(access_control_origins.begin(), access_control_origins.end(), std::bind(&boost::trim<std::string>, std::placeholders::_1, std::locale::classic()));
186  config.access_control_origins = std::move(access_control_origins);
187  }
188 
189  auto ssl_options = do_process_ssl(vm, arg, any_cert_option);
190  if (!ssl_options)
191  return boost::none;
192  config.ssl_options = std::move(*ssl_options);
193 
194  return {std::move(config)};
195  }
::std::string string
Definition: gtest-port.h:1097
std::vector< std::string > access_control_origins
Definition: rpc_args.h:80
static const char * tr(const char *str)
Definition: rpc_args.cpp:106
std::enable_if<!std::is_same< T, bool >::value, bool >::type has_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg)
Definition: command_line.h:258
epee::net_utils::ssl_options_t ssl_options
Definition: rpc_args.h:82
static boost::optional< login > parse(std::string &&userpass, bool verify, const std::function< boost::optional< password_container >(bool)> &prompt)
Definition: password.cpp:268
const T & move(const T &t)
Definition: gtest-port.h:1317
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
boost::optional< tools::login > login
Definition: rpc_args.h:81
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
Definition: command_line.h:271
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_ssl()

boost::optional< epee::net_utils::ssl_options_t > cryptonote::rpc_args::process_ssl ( const boost::program_options::variables_map &  vm,
const bool  any_cert_option = false 
)
static
Returns
SSL arguments specified by user, or boost::none if error

Definition at line 197 of file rpc_args.cpp.

198  {
199  const descriptors arg{};
200  return do_process_ssl(vm, arg, any_cert_option);
201  }
Here is the caller graph for this function:

◆ tr()

const char * cryptonote::rpc_args::tr ( const char *  str)
static

Definition at line 106 of file rpc_args.cpp.

106 { return i18n_translate(str, "cryptonote::rpc_args"); }
const char * i18n_translate(const char *s, const std::string &context)
Definition: i18n.cpp:323
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ access_control_origins

std::vector<std::string> cryptonote::rpc_args::access_control_origins

Definition at line 80 of file rpc_args.h.

◆ bind_ip

std::string cryptonote::rpc_args::bind_ip

Definition at line 79 of file rpc_args.h.

◆ login

boost::optional<tools::login> cryptonote::rpc_args::login

Definition at line 81 of file rpc_args.h.

◆ ssl_options

Definition at line 82 of file rpc_args.h.


The documentation for this struct was generated from the following files: