tools: update arguments
Modify the tools to take the certificate and private key directly as arguments, rather than the path to the directory that contains them.
Change-Id: I18010c27379d8e985b596bed0159155343265112
diff --git a/tools/dvpn/dvpn.cpp b/tools/dvpn/dvpn.cpp
index b7a0d03..47cd95c 100644
--- a/tools/dvpn/dvpn.cpp
+++ b/tools/dvpn/dvpn.cpp
@@ -156,8 +156,7 @@
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 @@
: 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 @@
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::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 @@
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 @@
// 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 6331907..e17775a 100644
--- a/tools/dvpn/dvpn.h
+++ b/tools/dvpn/dvpn.h
@@ -48,8 +48,7 @@
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 @@
{
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 @@
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 7e14842..5a3b155 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 8cbeebc..153a607 100644
--- a/tools/dvpn/main.cpp
+++ b/tools/dvpn/main.cpp
@@ -37,7 +37,7 @@
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 @@
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 @@
{"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 @@
{
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 @@
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 @@
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 @@
}
}
// 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 @@
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 @@
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 @@
" -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 @@
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 @@
params.anonymous_cnx);
} else {
dvpn = std::make_unique<dhtnet::DvpnClient>(params.peer_id,
- params.path,
identity,
params.bootstrap,
params.turn_host,