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/dsh/dsh.cpp b/tools/dsh/dsh.cpp
index 4e7507d..60637ff 100644
--- a/tools/dsh/dsh.cpp
+++ b/tools/dsh/dsh.cpp
@@ -85,8 +85,7 @@
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 @@
: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 @@
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,
- 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 @@
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 dd6a4ea..ec983a2 100644
--- a/tools/dsh/dsh.h
+++ b/tools/dsh/dsh.h
@@ -27,8 +27,7 @@
{
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 @@
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 a023aa3..1e23649 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 0e91e91..3b2592d 100644
--- a/tools/dsh/main.cpp
+++ b/tools/dsh/main.cpp
@@ -38,16 +38,16 @@
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 @@
{"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 @@
{
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 @@
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 @@
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 @@
}
// 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 @@
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 @@
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 @@
" -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 @@
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 @@
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,