diff --git a/tools/common.cpp b/tools/common.cpp index 76597a824d0655043b761eac81c9dd66ccb42130..aeb21ed83fec1d87d70f2387f2babed6bc4df796 100644 --- a/tools/common.cpp +++ b/tools/common.cpp @@ -30,8 +30,7 @@ namespace dhtnet { std::unique_ptr<ConnectionManager::Config> -connectionManagerConfig(const std::filesystem::path& path, - dht::crypto::Identity identity, +connectionManagerConfig(dht::crypto::Identity identity, const std::string& bootstrap, std::shared_ptr<Logger> logger, std::shared_ptr<tls::CertificateStore> certStore, @@ -42,8 +41,7 @@ connectionManagerConfig(const std::filesystem::path& path, const std::string& turn_pass, const std::string& turn_realm) { - std::filesystem::create_directories(path / "certstore"); - + std::filesystem::create_directories(PATH/"certstore"); // DHT node creation: To make a connection manager at first a DHT node should be created dht::DhtRunner::Config dhtConfig; dhtConfig.dht_config.id = identity; @@ -72,8 +70,8 @@ connectionManagerConfig(const std::filesystem::path& path, config->id = identity; config->ioContext = ioContext; config->certStore = certStore; + config->cachePath = PATH; config->factory = iceFactory; - config->cachePath = path; config->logger = logger; if (!turn_host.empty()){ config->turnEnabled = true; diff --git a/tools/common.h b/tools/common.h index 67672d08bf62036ee063a9768bec57957e273b2f..d08512d7f0aaf7d576a64270645a058c62c436d1 100644 --- a/tools/common.h +++ b/tools/common.h @@ -15,6 +15,7 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include <opendht/crypto.h> +#include <filesystem> #include "connectionmanager.h" #include "multiplexed_socket.h" #include "ice_transport_factory.h" @@ -24,9 +25,9 @@ namespace dhtnet { using Buffer = std::shared_ptr<std::vector<uint8_t>>; constexpr size_t BUFFER_SIZE = 64 * 1024; +const std::filesystem::path PATH = std::filesystem::path(getenv("HOME")) / ".dhtnet"; std::unique_ptr<ConnectionManager::Config> connectionManagerConfig( - const std::filesystem::path& path, dht::crypto::Identity identity, const std::string& bootstrap, std::shared_ptr<Logger> logger, diff --git a/tools/dnc/dnc.cpp b/tools/dnc/dnc.cpp index 88bf61d93ef7821273241edf1d8895e02d7e2b2c..6bde30e9c61103517ecb5967cd7c634e95d9ce2a 100644 --- a/tools/dnc/dnc.cpp +++ b/tools/dnc/dnc.cpp @@ -53,8 +53,7 @@ Dnc::parseName(const std::string_view name) } // Build a server -Dnc::Dnc(const std::filesystem::path& path, - dht::crypto::Identity identity, +Dnc::Dnc(dht::crypto::Identity identity, const std::string& bootstrap, const std::string& turn_host, const std::string& turn_user, @@ -64,7 +63,7 @@ Dnc::Dnc(const std::filesystem::path& path, : logger(dht::log::getStdLogger()) , ioContext(std::make_shared<asio::io_context>()), iceFactory(std::make_shared<IceTransportFactory>(logger)), - certStore(std::make_shared<tls::CertificateStore>(path / "certstore", logger)), + certStore(std::make_shared<tls::CertificateStore>(PATH/"certstore", logger)), trustStore(std::make_shared<tls::TrustStore>(*certStore)) { ioContextRunner = std::thread([context = ioContext, logger = logger] { @@ -80,8 +79,7 @@ Dnc::Dnc(const std::filesystem::path& path, auto ca = identity.second->issuer; trustStore->setCertificateStatus(ca->getId().toString(), tls::TrustStore::PermissionStatus::ALLOWED); - auto config = connectionManagerConfig(path, - identity, + auto config = connectionManagerConfig(identity, bootstrap, logger, certStore, @@ -171,8 +169,7 @@ Dnc::Dnc(const std::filesystem::path& path, }); } // Build a client -Dnc::Dnc(const std::filesystem::path& path, - dht::crypto::Identity identity, +Dnc::Dnc(dht::crypto::Identity identity, const std::string& bootstrap, dht::InfoHash peer_id, const std::string& remote_host, @@ -181,7 +178,7 @@ Dnc::Dnc(const std::filesystem::path& path, const std::string& turn_user, const std::string& turn_pass, const std::string& turn_realm) - : Dnc(path, identity, bootstrap,turn_host,turn_user,turn_pass, turn_realm, true) + : Dnc(identity, bootstrap,turn_host,turn_user,turn_pass, turn_realm, true) { std::condition_variable cv; auto name = fmt::format("nc://{:s}:{:d}", remote_host, remote_port); diff --git a/tools/dnc/dnc.h b/tools/dnc/dnc.h index 77cfe9feeccb92f47863b6507fb7c92869a19025..0f8e24eab217015002549db8eb8ca5d93cfc1d52 100644 --- a/tools/dnc/dnc.h +++ b/tools/dnc/dnc.h @@ -32,7 +32,7 @@ class Dnc { public: // Build a server - Dnc(const std::filesystem::path& path, + Dnc( dht::crypto::Identity identity, const std::string& bootstrap, const std::string& turn_host, @@ -41,7 +41,7 @@ public: const std::string& turn_realm, const bool anonymous); // Build a client - Dnc(const std::filesystem::path& path, + Dnc( dht::crypto::Identity identity, const std::string& bootstrap, dht::InfoHash peer_id, diff --git a/tools/dnc/dnc.yaml b/tools/dnc/dnc.yaml index a107615b3493e7e1cf9933db133cda6d5062bcf9..adf3be15b9b02e639492d343e0eb351c23d3e8ae 100644 --- a/tools/dnc/dnc.yaml +++ b/tools/dnc/dnc.yaml @@ -1,10 +1,10 @@ bootstrap: "bootstrap.jami.net" -id_path: HOME/.dhtnet # Change this to the path of the id directory turn_host: "turn.jami.net" turn_user: "ring" turn_pass: "ring" turn_realm: "ring" port: 22 ip: "127.0.0.1" -CA: HOME/.dhtnet # Change this to the path of the CA directory -anonymous: false \ No newline at end of file +# certificate: "to/your/certificate.crt" +# privateKey: "to/your/privatekey.pem" +anonymous: true \ No newline at end of file diff --git a/tools/dnc/main.cpp b/tools/dnc/main.cpp index 02debd54e6c12f01faaacb858bc8667e83b114dd..239307d4a155c65cf4f457fad3a9e0b31ed9f9a4 100644 --- a/tools/dnc/main.cpp +++ b/tools/dnc/main.cpp @@ -37,7 +37,8 @@ struct dhtnc_params bool help {false}; bool version {false}; bool listen {false}; - std::filesystem::path path {}; + std::filesystem::path privateKey {}; + std::filesystem::path cert {}; std::string bootstrap {}; std::string remote_host {}; in_port_t remote_port {}; @@ -46,25 +47,24 @@ struct dhtnc_params std::string turn_user {}; std::string turn_pass {}; std::string turn_realm {}; - std::string ca {}; - std::string dnc_configuration {}; + std::string configuration {}; bool anonymous_cnx {false}; }; static const constexpr struct option long_options[] = {{"help", no_argument, nullptr, 'h'}, {"version", no_argument, nullptr, 'v'}, - {"port", required_argument, nullptr, 'p'}, + {"port", required_argument, nullptr, 'P'}, {"ip", required_argument, nullptr, 'i'}, {"listen", no_argument, nullptr, 'l'}, {"bootstrap", required_argument, nullptr, 'b'}, - {"id_path", required_argument, nullptr, 'I'}, + {"privateKey", required_argument, nullptr, 'p'}, {"turn_host", required_argument, nullptr, 't'}, {"turn_user", required_argument, nullptr, 'u'}, {"turn_pass", required_argument, nullptr, 'w'}, {"turn_realm", required_argument, nullptr, 'r'}, - {"CA", required_argument, nullptr, 'C'}, - {"dnc_configuration", required_argument, nullptr, 'd'}, + {"cert", required_argument, nullptr, 'c'}, + {"configuration", required_argument, nullptr, 'd'}, {"anonymous_cnx", no_argument, nullptr, 'a'}, {nullptr, 0, nullptr, 0}}; @@ -73,7 +73,7 @@ parse_args(int argc, char** argv) { dhtnc_params params; int opt; - while ((opt = getopt_long(argc, argv, "ahvlw:r:u:t:I:b:p:i:C:d:", long_options, nullptr)) != -1) { + while ((opt = getopt_long(argc, argv, "ahvlw:r:u:t:P:b:p:i:c:d:", long_options, nullptr)) != -1) { switch (opt) { case 'h': params.help = true; @@ -81,7 +81,7 @@ parse_args(int argc, char** argv) case 'v': params.version = true; break; - case 'p': + case 'P': params.remote_port = std::stoi(optarg); break; case 'i': @@ -93,8 +93,8 @@ parse_args(int argc, char** argv) case 'b': params.bootstrap = optarg; break; - case 'I': - params.path = optarg; + case 'p': + params.privateKey = optarg; break; case 't': params.turn_host = optarg; @@ -108,11 +108,11 @@ parse_args(int argc, char** argv) case 'r': params.turn_realm = optarg; break; - case 'C': - params.ca = optarg; + case 'c': + params.cert = optarg; break; case 'd': - params.dnc_configuration = optarg; + params.configuration = optarg; break; case 'a': params.anonymous_cnx = true; @@ -135,9 +135,9 @@ parse_args(int argc, char** argv) } // extract values from dnc yaml file - if (!params.dnc_configuration.empty()) { - printf("read configuration file: %s\n", params.dnc_configuration.c_str()); - std::ifstream config_file(params.dnc_configuration); + if (!params.configuration.empty()) { + printf("read configuration file: %s\n", params.configuration.c_str()); + std::ifstream config_file(params.configuration); if (!config_file.is_open()) { std::cerr << "Error: Could not open configuration file.\n"; } else { @@ -145,8 +145,8 @@ parse_args(int argc, char** argv) if (config["bootstrap"] && params.bootstrap.empty()) { params.bootstrap = config["bootstrap"].as<std::string>(); } - if (config["id_path"] && params.path.empty()) { - params.path = config["id_path"].as<std::string>(); + if (config["privateKey"] && params.privateKey.empty()) { + params.privateKey = config["privateKey"].as<std::string>(); } if (config["turn_host"] && params.turn_host.empty()) { params.turn_host = config["turn_host"].as<std::string>(); @@ -160,11 +160,11 @@ parse_args(int argc, char** argv) if (config["turn_realm"] && params.turn_realm.empty()) { params.turn_realm = config["turn_realm"].as<std::string>(); } - if (config["CA"] && params.ca.empty()) { - params.ca = config["CA"].as<std::string>(); + if (config["certificate"] && params.cert.empty()) { + params.cert = config["certificate"].as<std::string>(); } if (config["ip"] && params.remote_host.empty()) { - params.dnc_configuration = config["ip"].as<std::string>(); + params.configuration = config["ip"].as<std::string>(); } if (config["port"] && params.remote_port == 0) { params.remote_port = config["port"].as<int>(); @@ -203,17 +203,17 @@ main(int argc, char** argv) "\nOptions:\n" " -h, --help Show this help message and exit.\n" " -v, --version Display the program version.\n" - " -p, --port Specify the port option with an argument.\n" + " -P, --port Specify the port option with an argument.\n" " -i, --ip Specify the ip option with an argument.\n" " -l, --listen Start the program in listen mode.\n" " -b, --bootstrap Specify the bootstrap option with an argument.\n" - " -I, --id_path Specify the id_path option with an argument.\n" " -t, --turn_host Specify the turn_host option with an argument.\n" " -u, --turn_user Specify the turn_user option with an argument.\n" " -w, --turn_pass Specify the turn_pass option with an argument.\n" " -r, --turn_realm Specify the turn_realm option with an argument.\n" - " -C, --CA Specify the CA option with an argument.\n" - " -d, --dnc_configuration Specify the dnc_configuration option with an argument.\n" + " -c, --certificate Specify the certificate option with an argument.\n" + " -d, --configuration Specify the configuration option with an argument.\n" + " -p, --privateKey Specify the privateKey option with an argument.\n" " -a, --anonymous_cnx Enable the anonymous mode.\n"); return EXIT_SUCCESS; } @@ -222,17 +222,16 @@ main(int argc, char** argv) fmt::print("dnc v1.0\n"); return EXIT_SUCCESS; } - auto identity = dhtnet::loadIdentity(params.path, params.ca); + auto identity = dhtnet::loadIdentity(params.privateKey, params.cert); + fmt::print("Loaded identity: {}\n", identity.second->getId()); fmt::print("dnc 1.0\n"); - fmt::print("Loaded identity: {} from {}\n", identity.second->getId(), params.path); std::unique_ptr<dhtnet::Dnc> dhtnc; if (params.listen) { // create dnc instance - dhtnc = std::make_unique<dhtnet::Dnc>(params.path, - identity, + dhtnc = std::make_unique<dhtnet::Dnc>(identity, params.bootstrap, params.turn_host, params.turn_user, @@ -240,8 +239,7 @@ main(int argc, char** argv) params.turn_realm, params.anonymous_cnx); } else { - dhtnc = std::make_unique<dhtnet::Dnc>(params.path, - identity, + dhtnc = std::make_unique<dhtnet::Dnc>(identity, params.bootstrap, params.peer_id, params.remote_host, diff --git a/tools/dsh/dsh.cpp b/tools/dsh/dsh.cpp index 4e7507d7e555b02deca73d7fe9a16be6761be73a..60637ff2c9fc70d6457d3022edc7108b2017ed9b 100644 --- a/tools/dsh/dsh.cpp +++ b/tools/dsh/dsh.cpp @@ -85,8 +85,7 @@ child_proc(const int in_pipe[2], exit(EXIT_FAILURE); } -dhtnet::Dsh::Dsh(const std::filesystem::path& path, - dht::crypto::Identity identity, +dhtnet::Dsh::Dsh(dht::crypto::Identity identity, const std::string& bootstrap, const std::string& turn_host, const std::string& turn_user, @@ -96,7 +95,7 @@ dhtnet::Dsh::Dsh(const std::filesystem::path& path, :logger(dht::log::getStdLogger()) , ioContext(std::make_shared<asio::io_context>()), iceFactory(std::make_shared<IceTransportFactory>(logger)), - certStore(std::make_shared<tls::CertificateStore>(path / "certstore", logger)), + certStore(std::make_shared<tls::CertificateStore>(PATH/"certstore", logger)), trustStore(std::make_shared<tls::TrustStore>(*certStore)) { ioContext = std::make_shared<asio::io_context>(); @@ -112,8 +111,7 @@ dhtnet::Dsh::Dsh(const std::filesystem::path& path, auto ca = identity.second->issuer; trustStore->setCertificateStatus(ca->getId().toString(), tls::TrustStore::PermissionStatus::ALLOWED); // Build a server - auto config = connectionManagerConfig(path, - identity, + auto config = connectionManagerConfig(identity, bootstrap, logger, certStore, @@ -220,8 +218,7 @@ dhtnet::Dsh::Dsh(const std::filesystem::path& path, }); } -dhtnet::Dsh::Dsh(const std::filesystem::path& path, - dht::crypto::Identity identity, +dhtnet::Dsh::Dsh(dht::crypto::Identity identity, const std::string& bootstrap, dht::InfoHash peer_id, const std::string& binary, @@ -229,7 +226,7 @@ dhtnet::Dsh::Dsh(const std::filesystem::path& path, const std::string& turn_user, const std::string& turn_pass, const std::string& turn_realm) - : Dsh(path, identity, bootstrap, turn_host, turn_user, turn_pass, turn_realm, false) + : Dsh(identity, bootstrap, turn_host, turn_user, turn_pass, turn_realm, false) { // Build a client std::condition_variable cv; diff --git a/tools/dsh/dsh.h b/tools/dsh/dsh.h index dd6a4ea616c9e43e019619ad4986f5d293dedab1..ec983a2f79acb41dcb461f7aa33bd563b1733d47 100644 --- a/tools/dsh/dsh.h +++ b/tools/dsh/dsh.h @@ -27,8 +27,7 @@ class Dsh { public: // Build a server - Dsh(const std::filesystem::path& path, - dht::crypto::Identity identity, + Dsh(dht::crypto::Identity identity, const std::string& bootstrap, const std::string& turn_host, const std::string& turn_user, @@ -36,8 +35,7 @@ public: const std::string& turn_realm, const bool anonymous); // Build a client - Dsh(const std::filesystem::path& path, - dht::crypto::Identity identity, + Dsh(dht::crypto::Identity identity, const std::string& bootstrap, dht::InfoHash peer_id, const std::string& binary, diff --git a/tools/dsh/dsh.yaml b/tools/dsh/dsh.yaml index a023aa3afde6270837bcf3f66976f210be92402e..1e236495406d95a4ecd1f5ea82e1ba630d85f2fc 100644 --- a/tools/dsh/dsh.yaml +++ b/tools/dsh/dsh.yaml @@ -1,9 +1,9 @@ bootstrap: "bootstrap.jami.net" -id_path: HOME/.dhtnet # Change this to the path of the id directory turn_host: "turn.jami.net" turn_user: "ring" turn_pass: "ring" turn_realm: "ring" binary: "bash" -CA: HOME/.dhtnet # Change this to the path of the CA directory +# certificate: "/path/to/ca" +# privateKey: "/path/to/privateKey" anonymous: false diff --git a/tools/dsh/main.cpp b/tools/dsh/main.cpp index 0e91e91f72c2de14343d17308c61449ee55764f7..3b2592d30ebdd8e389c70851ab71193b6701d644 100644 --- a/tools/dsh/main.cpp +++ b/tools/dsh/main.cpp @@ -38,16 +38,16 @@ struct dhtsh_params bool help {false}; bool version {false}; bool listen {false}; - std::filesystem::path path {}; + std::filesystem::path privateKey {}; std::string bootstrap {}; dht::InfoHash peer_id {}; std::string binary {}; - std::string ca {}; + std::filesystem::path cert {}; std::string turn_host {}; std::string turn_user {}; std::string turn_pass {}; std::string turn_realm {}; - std::string dsh_configuration {}; + std::string configuration {}; bool anonymous_cnx {false}; }; @@ -57,13 +57,13 @@ static const constexpr struct option long_options[] {"listen", no_argument, nullptr, 'l'}, {"bootstrap", required_argument, nullptr, 'b'}, {"binary", required_argument, nullptr, 's'}, - {"id_path", required_argument, nullptr, 'I'}, - {"CA", required_argument, nullptr, 'C'}, + {"privateKey", required_argument, nullptr, 'p'}, + {"certificate", required_argument, nullptr, 'c'}, {"turn_host", required_argument, nullptr, 't'}, {"turn_user", required_argument, nullptr, 'u'}, {"turn_pass", required_argument, nullptr, 'w'}, {"turn_realm", required_argument, nullptr, 'r'}, - {"dsh_configuration", required_argument, nullptr, 'd'}, + {"configuration", required_argument, nullptr, 'd'}, {"anonymous", no_argument, nullptr, 'a'}, {nullptr, 0, nullptr, 0}}; @@ -72,7 +72,7 @@ parse_args(int argc, char** argv) { dhtsh_params params; int opt; - while ((opt = getopt_long(argc, argv, "hvls:I:p:i:C:r:w:u:t:d:", long_options, nullptr)) != -1) { + while ((opt = getopt_long(argc, argv, "hvls:p:i:c:r:w:u:t:d:", long_options, nullptr)) != -1) { switch (opt) { case 'h': params.help = true; @@ -89,8 +89,8 @@ parse_args(int argc, char** argv) case 's': params.binary = optarg; break; - case 'I': - params.path = optarg; + case 'p': + params.privateKey = optarg; break; case 't': params.turn_host = optarg; @@ -104,11 +104,11 @@ parse_args(int argc, char** argv) case 'r': params.turn_realm = optarg; break; - case 'C': - params.ca = optarg; + case 'c': + params.cert = optarg; break; case 'd': - params.dsh_configuration = optarg; + params.configuration = optarg; break; case 'a': params.anonymous_cnx = true; @@ -131,9 +131,9 @@ parse_args(int argc, char** argv) } // extract values from dsh yaml file - if (!params.dsh_configuration.empty()) { - printf("read configuration file: %s\n", params.dsh_configuration.c_str()); - std::ifstream config_file(params.dsh_configuration); + if (!params.configuration.empty()) { + printf("read configuration file: %s\n", params.configuration.c_str()); + std::ifstream config_file(params.configuration); if (!config_file.is_open()) { std::cerr << "Error: Could not open configuration file.\n"; } else { @@ -141,8 +141,8 @@ parse_args(int argc, char** argv) if (config["bootstrap"] && params.bootstrap.empty()) { params.bootstrap = config["bootstrap"].as<std::string>(); } - if (config["id_path"] && params.path.empty()) { - params.path = config["id_path"].as<std::string>(); + if (config["privateKey"] && params.privateKey.empty()) { + params.privateKey = config["privateKey"].as<std::string>(); } if (config["turn_host"] && params.turn_host.empty()) { params.turn_host = config["turn_host"].as<std::string>(); @@ -156,8 +156,8 @@ parse_args(int argc, char** argv) if (config["turn_realm"] && params.turn_realm.empty()) { params.turn_realm = config["turn_realm"].as<std::string>(); } - if (config["CA"] && params.ca.empty()) { - params.ca = config["CA"].as<std::string>(); + if (config["certificate"] && params.cert.empty()) { + params.cert = config["certificate"].as<std::string>(); } if (config["binary"] && params.binary.empty()) { params.binary = config["binary"].as<std::string>(); @@ -203,8 +203,8 @@ main(int argc, char** argv) " -l, --listen Start the program in listen mode.\n" " -b, --bootstrap Specify the bootstrap option with an argument.\n" " -s, --binary Specify the binary option with an argument.\n" - " -I, --id_path Specify the id_path option with an argument.\n" - " -C, --CA Specify the CA option with an argument.\n" + " -I, --privateKey Specify the privateKey option with an argument.\n" + " -c, --c Specify the certificate option with an argument.\n" " -t, --turn_host Specify the turn_host option with an argument.\n" " -u, --turn_user Specify the turn_user option with an argument.\n" " -w, --turn_pass Specify the turn_pass option with an argument.\n" @@ -218,14 +218,13 @@ main(int argc, char** argv) fmt::print("dsh 1.0\n"); - auto identity = dhtnet::loadIdentity(params.path, params.ca); - fmt::print("Loaded identity: {} from {}\n", identity.second->getId(), params.path); + auto identity = dhtnet::loadIdentity(params.privateKey, params.cert); + fmt::print("Loaded identity: {} \n", identity.second->getId()); std::unique_ptr<dhtnet::Dsh> dhtsh; if (params.listen) { // create dsh instance - dhtsh = std::make_unique<dhtnet::Dsh>(params.path, - identity, + dhtsh = std::make_unique<dhtnet::Dsh>(identity, params.bootstrap, params.turn_host, params.turn_user, @@ -233,8 +232,7 @@ main(int argc, char** argv) params.turn_realm, params.anonymous_cnx); } else { - dhtsh = std::make_unique<dhtnet::Dsh>(params.path, - identity, + dhtsh = std::make_unique<dhtnet::Dsh>(identity, params.bootstrap, params.peer_id, params.binary, diff --git a/tools/dvpn/dvpn.cpp b/tools/dvpn/dvpn.cpp index b7a0d03e9771839f6e5e10b43bfc61cdefb7b707..47cd95c675879a96ea43923587e93061a2015c2f 100644 --- a/tools/dvpn/dvpn.cpp +++ b/tools/dvpn/dvpn.cpp @@ -156,8 +156,7 @@ open_tun(char* dev) return fd; } -dhtnet::Dvpn::Dvpn(const std::filesystem::path& path, - dht::crypto::Identity identity, +dhtnet::Dvpn::Dvpn(dht::crypto::Identity identity, const std::string& bootstrap, const std::string& turn_host, const std::string& turn_user, @@ -167,7 +166,7 @@ dhtnet::Dvpn::Dvpn(const std::filesystem::path& path, : logger(dht::log::getStdLogger()) , ioContext(std::make_shared<asio::io_context>()), iceFactory(std::make_shared<IceTransportFactory>(logger)), - certStore(std::make_shared<tls::CertificateStore>(path / "certstore", logger)), + certStore(std::make_shared<tls::CertificateStore>(PATH/"certstore", logger)), trustStore(std::make_shared<tls::TrustStore>(*certStore)) { ioContextRunner = std::thread([context = ioContext, logger = logger] { @@ -182,8 +181,7 @@ dhtnet::Dvpn::Dvpn(const std::filesystem::path& path, auto ca = identity.second->issuer; trustStore->setCertificateStatus(ca->getId().toString(), tls::TrustStore::PermissionStatus::ALLOWED); - auto config = connectionManagerConfig(path, - identity, + auto config = connectionManagerConfig(identity, bootstrap, logger, certStore, @@ -200,8 +198,7 @@ dhtnet::Dvpn::Dvpn(const std::filesystem::path& path, } -dhtnet::DvpnServer::DvpnServer(const std::filesystem::path& path, - dht::crypto::Identity identity, +dhtnet::DvpnServer::DvpnServer(dht::crypto::Identity identity, const std::string& bootstrap, const std::string& turn_host, const std::string& turn_user, @@ -209,7 +206,7 @@ dhtnet::DvpnServer::DvpnServer(const std::filesystem::path& path, const std::string& turn_realm, const std::string& configuration_file, bool anonymous) - : Dvpn(path, identity, bootstrap, turn_host, turn_user, turn_pass, turn_realm, configuration_file) + : Dvpn(identity, bootstrap, turn_host, turn_user, turn_pass, turn_realm, configuration_file) { std::mutex mtx; std::unique_lock<std::mutex> lk {mtx}; @@ -294,16 +291,14 @@ dhtnet::DvpnServer::DvpnServer(const std::filesystem::path& path, // Build a client dhtnet::DvpnClient::DvpnClient(dht::InfoHash peer_id, - const std::filesystem::path& path, dht::crypto::Identity identity, const std::string& bootstrap, - const std::string& turn_host, const std::string& turn_user, const std::string& turn_pass, const std::string& turn_realm, const std::string& configuration_file) - : Dvpn(path, identity, bootstrap, turn_host, turn_user, turn_pass, turn_realm, configuration_file) + : Dvpn(identity, bootstrap, turn_host, turn_user, turn_pass, turn_realm, configuration_file) { // connect to a peer connectionManager->connectDevice( diff --git a/tools/dvpn/dvpn.h b/tools/dvpn/dvpn.h index 6331907b86b34a2dd195cff9703f4316129f8e69..e17775aac043a57a4e63ea1e6aa584e743946db5 100644 --- a/tools/dvpn/dvpn.h +++ b/tools/dvpn/dvpn.h @@ -48,8 +48,7 @@ struct MetaData class Dvpn { public: - Dvpn(const std::filesystem::path& path, - dht::crypto::Identity identity, + Dvpn(dht::crypto::Identity identity, const std::string& bootstrap, const std::string& turn_host, const std::string& turn_user, @@ -73,8 +72,7 @@ class DvpnServer : public Dvpn { public: // Build a server - DvpnServer(const std::filesystem::path& path, - dht::crypto::Identity identity, + DvpnServer(dht::crypto::Identity identity, const std::string& bootstrap, const std::string& turn_host, const std::string& turn_user, @@ -89,7 +87,6 @@ class DvpnClient : public Dvpn public: // Build a client DvpnClient(dht::InfoHash peer_id, - const std::filesystem::path& path, dht::crypto::Identity identity, const std::string& bootstrap, const std::string& turn_host, diff --git a/tools/dvpn/dvpn.yaml b/tools/dvpn/dvpn.yaml index 7e14842752658645dbefe7b8e10551026bf1fc49..5a3b155f09c01febd6e7d6e950c7c2f094ce8036 100644 --- a/tools/dvpn/dvpn.yaml +++ b/tools/dvpn/dvpn.yaml @@ -1,9 +1,9 @@ bootstrap: "bootstrap.jami.net" -id_path: HOME/.dhtnet # Change this to the path of the id directory turn_host: "turn.jami.net" turn_user: "ring" turn_pass: "ring" turn_realm: "ring" -configuration_file: "HOME/dhtnet/tools/dvpn/dvpn.yaml" # Change this to the path of the dvpn.yaml file -CA: HOME/.dhtnet # Change this to the path of the CA directory +# configuration_file: "HOME/dhtnet/tools/dvpn/dvpn.yaml" # Change this to the path of the dvpn.yaml file +# certificate: /path/to/certificate +# privateKey: /path/to/privateKey anonymous: false \ No newline at end of file diff --git a/tools/dvpn/main.cpp b/tools/dvpn/main.cpp index 8cbeebc208b74d1e7cae2c4ec3e24375a7a1e970..153a607791aa7fcb9c04e238f544f72b47c90d5c 100644 --- a/tools/dvpn/main.cpp +++ b/tools/dvpn/main.cpp @@ -37,7 +37,7 @@ struct dhtvpn_params bool help {false}; bool version {false}; bool listen {false}; - std::filesystem::path path {}; + std::filesystem::path privateKey {}; std::string bootstrap {}; dht::InfoHash peer_id {}; std::string turn_host {}; @@ -45,8 +45,8 @@ struct dhtvpn_params std::string turn_pass {}; std::string turn_realm {}; std::string configuration_file {}; - std::string ca {}; - std::string dvpn_configuration_file {}; + std::filesystem::path cert {}; + std::string configuration {}; bool anonymous_cnx {false}; }; @@ -55,14 +55,14 @@ static const constexpr struct option long_options[] {"version", no_argument, nullptr, 'v'}, {"listen", no_argument, nullptr, 'l'}, {"bootstrap", required_argument, nullptr, 'b'}, - {"id_path", required_argument, nullptr, 'I'}, + {"privateKey", required_argument, nullptr, 'p'}, {"turn_host", required_argument, nullptr, 't'}, {"turn_user", required_argument, nullptr, 'u'}, {"turn_pass", required_argument, nullptr, 'w'}, {"turn_realm", required_argument, nullptr, 'r'}, - {"vpn_configuration_file", required_argument, nullptr, 'c'}, - {"CA", required_argument, nullptr, 'C'}, - {"dvpn_configuration_file", required_argument, nullptr, 'd'}, + {"vpn_configuration_file", required_argument, nullptr, 'C'}, + {"certificate", required_argument, nullptr, 'c'}, + {"configuration", required_argument, nullptr, 'd'}, {"anonymous", no_argument, nullptr, 'a'}, {nullptr, 0, nullptr, 0}}; @@ -71,7 +71,7 @@ parse_args(int argc, char** argv) { dhtvpn_params params; int opt; - while ((opt = getopt_long(argc, argv, "hvlw:r:u:t:I:b:c:C:d:", long_options, nullptr)) != -1) { + while ((opt = getopt_long(argc, argv, "hvlw:r:u:t:p:b:c:C:d:", long_options, nullptr)) != -1) { switch (opt) { case 'h': params.help = true; @@ -85,8 +85,8 @@ parse_args(int argc, char** argv) case 'b': params.bootstrap = optarg; break; - case 'I': - params.path = optarg; + case 'p': + params.privateKey = optarg; break; case 't': params.turn_host = optarg; @@ -100,14 +100,14 @@ parse_args(int argc, char** argv) case 'r': params.turn_realm = optarg; break; - case 'c': + case 'C': params.configuration_file = optarg; break; - case 'C': - params.ca = optarg; + case 'c': + params.cert = optarg; break; case 'd': - params.dvpn_configuration_file = optarg; + params.configuration = optarg; break; case 'a': params.anonymous_cnx = true; @@ -118,9 +118,9 @@ parse_args(int argc, char** argv) } } // extract values from dvpn yaml file - if (!params.dvpn_configuration_file.empty()) { - printf("read configuration file: %s\n", params.dvpn_configuration_file.c_str()); - std::ifstream config_file(params.dvpn_configuration_file); + if (!params.configuration.empty()) { + printf("read configuration file: %s\n", params.configuration.c_str()); + std::ifstream config_file(params.configuration); if (!config_file.is_open()) { std::cerr << "Error: Could not open configuration file.\n"; } else { @@ -128,8 +128,8 @@ parse_args(int argc, char** argv) if (config["bootstrap"] && params.bootstrap.empty()) { params.bootstrap = config["bootstrap"].as<std::string>(); } - if (config["id_path"] && params.path.empty()) { - params.path = config["id_path"].as<std::string>(); + if (config["privateKey"] && params.privateKey.empty()) { + params.privateKey = config["privateKey"].as<std::string>(); } if (config["turn_host"] && params.turn_host.empty()) { params.turn_host = config["turn_host"].as<std::string>(); @@ -143,8 +143,8 @@ parse_args(int argc, char** argv) if (config["turn_realm"] && params.turn_realm.empty()) { params.turn_realm = config["turn_realm"].as<std::string>(); } - if (config["CA"] && params.ca.empty()) { - params.ca = config["CA"].as<std::string>(); + if (config["certificate"] && params.cert.empty()) { + params.cert = config["certificate"].as<std::string>(); } if (config["configuration_file"] && params.configuration_file.empty()) { params.configuration_file = config["configuration_file"].as<std::string>(); @@ -197,14 +197,14 @@ main(int argc, char** argv) " -v, --version Display the program version.\n" " -l, --listen Start the program in listen mode.\n" " -b, --bootstrap Specify the bootstrap option with an argument.\n" - " -I, --id_path Specify the id_path option with an argument.\n" + " -p, --privateKey Specify the privateKey option with an argument.\n" " -t, --turn_host Specify the turn_host option with an argument.\n" " -u, --turn_user Specify the turn_user option with an argument.\n" " -w, --turn_pass Specify the turn_pass option with an argument.\n" " -r, --turn_realm Specify the turn_realm option with an argument.\n" - " -c, --vpn_configuration_file Specify the vpn_configuration_file path option with an argument.\n" - " -C, --CA Specify the CA path option with an argument.\n" - " -d, --dvpn_configuration_file Specify the dvpn_configuration_file path option with an argument.\n" + " -C, --vpn_configuration Specify the vpn_configuration path option with an argument.\n" + " -c, --certificate Specify the certificate path option with an argument.\n" + " -d, --configuration Specify the configuration path option with an argument.\n" " -a, --anonymous Specify the anonymous option with an argument.\n" "\n"); return EXIT_SUCCESS; @@ -216,14 +216,13 @@ main(int argc, char** argv) fmt::print("dvpn 1.0\n"); - auto identity = dhtnet::loadIdentity(params.path, params.ca); - fmt::print("Loaded identity: {} from {}\n", identity.second->getId(), params.path); + auto identity = dhtnet::loadIdentity(params.privateKey, params.cert); + fmt::print("Loaded identity: {}\n", identity.second->getId()); std::unique_ptr<dhtnet::Dvpn> dvpn; if (params.listen) { // create dvpn instance - dvpn = std::make_unique<dhtnet::DvpnServer>(params.path, - identity, + dvpn = std::make_unique<dhtnet::DvpnServer>(identity, params.bootstrap, params.turn_host, params.turn_user, @@ -233,7 +232,6 @@ main(int argc, char** argv) params.anonymous_cnx); } else { dvpn = std::make_unique<dhtnet::DvpnClient>(params.peer_id, - params.path, identity, params.bootstrap, params.turn_host,