From 925e8316c782485601417a273239b5f3d969cd30 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 12 Jul 2019 20:58:17 -0400 Subject: [PATCH] read i2cp.leaseSetAuthType, i2cp.leaseSetClient.dh.nnn and i2cp.leaseSetClient.psk.nnn from tunnel config --- libi2pd/Destination.h | 5 ++++- libi2pd_client/ClientContext.cpp | 19 +++++++++++++++++++ libi2pd_client/ClientContext.h | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/libi2pd/Destination.h b/libi2pd/Destination.h index 35a9dbae..25f2f1c1 100644 --- a/libi2pd/Destination.h +++ b/libi2pd/Destination.h @@ -56,7 +56,10 @@ namespace client const int DEFAULT_LEASESET_TYPE = 1; const char I2CP_PARAM_LEASESET_ENCRYPTION_TYPE[] = "i2cp.leaseSetEncType"; const char I2CP_PARAM_LEASESET_PRIV_KEY[] = "i2cp.leaseSetPrivKey"; // PSK decryption key, base64 - + const char I2CP_PARAM_LEASESET_AUTH_TYPE[] = "i2cp.leaseSetAuthType"; + const char I2CP_PARAM_LEASESET_CLIENT_DH[] = "i2cp.leaseSetClient.dh"; // group of i2cp.leaseSetClient.dh.nnn + const char I2CP_PARAM_LEASESET_CLIENT_PSK[] = "i2cp.leaseSetClient.psk"; // group of i2cp.leaseSetClient.psk.nnn + // latency const char I2CP_PARAM_MIN_TUNNEL_LATENCY[] = "latency.min"; const int DEFAULT_MIN_TUNNEL_LATENCY = 0; diff --git a/libi2pd_client/ClientContext.cpp b/libi2pd_client/ClientContext.cpp index c286007c..e10c1e07 100644 --- a/libi2pd_client/ClientContext.cpp +++ b/libi2pd_client/ClientContext.cpp @@ -381,6 +381,16 @@ namespace client return section.second.get (boost::property_tree::ptree::path_type (name, '/'), value); } + template + void ClientContext::ReadI2CPOptionsGroup (const Section& section, const std::string& group, std::map& options) const + { + for (auto it: section.second) + { + if (it.first.length () >= group.length () && !it.first.compare (0, group.length (), group)) + options[it.first] = it.second.get_value (""); + } + } + template void ClientContext::ReadI2CPOptions (const Section& section, std::map& options) const { @@ -397,6 +407,15 @@ namespace client if (encType.length () > 0) options[I2CP_PARAM_LEASESET_ENCRYPTION_TYPE] = encType; std::string privKey = GetI2CPStringOption(section, I2CP_PARAM_LEASESET_PRIV_KEY, ""); if (privKey.length () > 0) options[I2CP_PARAM_LEASESET_PRIV_KEY] = privKey; + auto authType = GetI2CPOption(section, I2CP_PARAM_LEASESET_AUTH_TYPE, 0); + if (authType != "0") // auth is set + { + options[I2CP_PARAM_LEASESET_TYPE] = authType; + if (authType == "1") // DH + ReadI2CPOptionsGroup (section, I2CP_PARAM_LEASESET_CLIENT_DH, options); + else if (authType == "2") // PSK + ReadI2CPOptionsGroup (section, I2CP_PARAM_LEASESET_CLIENT_PSK, options); + } } void ClientContext::ReadI2CPOptionsFromConfig (const std::string& prefix, std::map& options) const diff --git a/libi2pd_client/ClientContext.h b/libi2pd_client/ClientContext.h index 71e052c3..94aa8594 100644 --- a/libi2pd_client/ClientContext.h +++ b/libi2pd_client/ClientContext.h @@ -95,6 +95,8 @@ namespace client template std::string GetI2CPStringOption (const Section& section, const std::string& name, const std::string& value) const; // GetI2CPOption with string default value template + void ReadI2CPOptionsGroup (const Section& section, const std::string& group, std::map& options) const; + template void ReadI2CPOptions (const Section& section, std::map& options) const; // for tunnels void ReadI2CPOptionsFromConfig (const std::string& prefix, std::map& options) const; // for HTTP and SOCKS proxy