mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-29 18:53:14 +00:00
device/trezor: env-configurable ports
This commit is contained in:
parent
c97a1f79d6
commit
41901b8deb
3 changed files with 54 additions and 22 deletions
|
@ -223,6 +223,11 @@ namespace trezor{
|
|||
msg = msg_wrap;
|
||||
}
|
||||
|
||||
static void assert_port_number(uint32_t port)
|
||||
{
|
||||
CHECK_AND_ASSERT_THROW_MES(port >= 1024 && port < 65535, "Invalid port number: " << port);
|
||||
}
|
||||
|
||||
Transport::Transport(): m_open_counter(0) {
|
||||
|
||||
}
|
||||
|
@ -263,6 +268,29 @@ namespace trezor{
|
|||
|
||||
const char * BridgeTransport::PATH_PREFIX = "bridge:";
|
||||
|
||||
BridgeTransport::BridgeTransport(
|
||||
boost::optional<std::string> device_path,
|
||||
boost::optional<std::string> bridge_host):
|
||||
m_device_path(device_path),
|
||||
m_bridge_host(bridge_host ? bridge_host.get() : DEFAULT_BRIDGE),
|
||||
m_response(boost::none),
|
||||
m_session(boost::none),
|
||||
m_device_info(boost::none)
|
||||
{
|
||||
const char *env_bridge_port = nullptr;
|
||||
if (!bridge_host && (env_bridge_port = getenv("TREZOR_BRIDGE_PORT")) != nullptr)
|
||||
{
|
||||
uint16_t bridge_port;
|
||||
CHECK_AND_ASSERT_THROW_MES(epee::string_tools::get_xtype_from_string(bridge_port, env_bridge_port), "Invalid bridge port: " << env_bridge_port);
|
||||
assert_port_number(bridge_port);
|
||||
|
||||
m_bridge_host = std::string("127.0.0.1:") + boost::lexical_cast<std::string>(env_bridge_port);
|
||||
MDEBUG("Bridge host: " << m_bridge_host);
|
||||
}
|
||||
|
||||
m_http_client.set_server(m_bridge_host, boost::none, epee::net_utils::ssl_support_t::e_ssl_support_disabled);
|
||||
}
|
||||
|
||||
std::string BridgeTransport::get_path() const {
|
||||
if (!m_device_path){
|
||||
return "";
|
||||
|
@ -401,28 +429,40 @@ namespace trezor{
|
|||
const char * UdpTransport::DEFAULT_HOST = "127.0.0.1";
|
||||
const int UdpTransport::DEFAULT_PORT = 21324;
|
||||
|
||||
static void parse_udp_path(std::string &host, int &port, std::string path)
|
||||
{
|
||||
if (boost::starts_with(path, UdpTransport::PATH_PREFIX))
|
||||
{
|
||||
path = path.substr(strlen(UdpTransport::PATH_PREFIX));
|
||||
}
|
||||
|
||||
auto delim = path.find(':');
|
||||
if (delim == std::string::npos) {
|
||||
host = path;
|
||||
} else {
|
||||
host = path.substr(0, delim);
|
||||
port = std::stoi(path.substr(delim + 1));
|
||||
}
|
||||
}
|
||||
|
||||
UdpTransport::UdpTransport(boost::optional<std::string> device_path,
|
||||
boost::optional<std::shared_ptr<Protocol>> proto) :
|
||||
m_io_service(), m_deadline(m_io_service)
|
||||
{
|
||||
m_device_host = DEFAULT_HOST;
|
||||
m_device_port = DEFAULT_PORT;
|
||||
const char *env_trezor_path = nullptr;
|
||||
|
||||
if (device_path) {
|
||||
const std::string device_str = device_path.get();
|
||||
auto delim = device_str.find(':');
|
||||
if (delim == std::string::npos) {
|
||||
m_device_host = device_str;
|
||||
} else {
|
||||
m_device_host = device_str.substr(0, delim);
|
||||
m_device_port = std::stoi(device_str.substr(delim + 1));
|
||||
}
|
||||
parse_udp_path(m_device_host, m_device_port, device_path.get());
|
||||
} else if ((env_trezor_path = getenv("TREZOR_PATH")) != nullptr && boost::starts_with(env_trezor_path, UdpTransport::PATH_PREFIX)){
|
||||
parse_udp_path(m_device_host, m_device_port, std::string(env_trezor_path));
|
||||
MDEBUG("Applied TREZOR_PATH: " << m_device_host << ":" << m_device_port);
|
||||
} else {
|
||||
m_device_host = DEFAULT_HOST;
|
||||
}
|
||||
|
||||
if (m_device_port <= 1024 || m_device_port > 65535){
|
||||
throw std::invalid_argument("Port number invalid");
|
||||
}
|
||||
|
||||
assert_port_number((uint32_t)m_device_port);
|
||||
if (m_device_host != "localhost" && m_device_host != DEFAULT_HOST){
|
||||
throw std::invalid_argument("Local endpoint allowed only");
|
||||
}
|
||||
|
|
|
@ -163,15 +163,7 @@ namespace trezor {
|
|||
public:
|
||||
BridgeTransport(
|
||||
boost::optional<std::string> device_path = boost::none,
|
||||
boost::optional<std::string> bridge_host = boost::none):
|
||||
m_device_path(device_path),
|
||||
m_bridge_host(bridge_host ? bridge_host.get() : DEFAULT_BRIDGE),
|
||||
m_response(boost::none),
|
||||
m_session(boost::none),
|
||||
m_device_info(boost::none)
|
||||
{
|
||||
m_http_client.set_server(m_bridge_host, boost::none, epee::net_utils::ssl_support_t::e_ssl_support_disabled);
|
||||
}
|
||||
boost::optional<std::string> bridge_host = boost::none);
|
||||
|
||||
virtual ~BridgeTransport() = default;
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ int main(int argc, char* argv[])
|
|||
// Bootstrapping common chain & accounts
|
||||
const uint8_t initial_hf = (uint8_t)get_env_long("TEST_MIN_HF", 11);
|
||||
const uint8_t max_hf = (uint8_t)get_env_long("TEST_MAX_HF", 11);
|
||||
MINFO("Test versions " << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL);
|
||||
MINFO("Test versions " << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")");
|
||||
MINFO("Testing hardforks [" << (int)initial_hf << ", " << (int)max_hf << "]");
|
||||
|
||||
cryptonote::core core_obj(nullptr);
|
||||
|
|
Loading…
Reference in a new issue