Skip to content

Commit d887d3b

Browse files
committed
crtmgr: clean code and switch -g option to -a
-g option is incoherent with --identifier option it represent. Changed to -a as plenty of unix tools use it when displaying all information. Also removed double space and indented a block of code for linting. Change-Id: I1de7355da1f47b5ea1200d3dd4fe3373091e7403
1 parent 9737f53 commit d887d3b

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

extras/packaging/gnu-linux/debian/postinst

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ create_server_keys() {
88
if [ ! -f /etc/dhtnet/id/id-server.crt ] && [ ! -f /etc/dhtnet/id/id-server.pem ]; then
99
echo "Generating server keys..."
1010
dhtnet-crtmgr --setup -o /etc/dhtnet/
11-
dhtnet-crtmgr -g -c /etc/dhtnet/id/id-server.crt -p /etc/dhtnet/id/id-server.pem
11+
dhtnet-crtmgr -a -c /etc/dhtnet/id/id-server.crt -p /etc/dhtnet/id/id-server.pem
1212
disable_dnc_service
1313
fi
1414
}

tools/dhtnet_crtmgr/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The DHTNet Certificate Manager is a command-line tool designed to manage certifi
1818
- `-p, --privatekey`: Provide the path to the private key as an argument.
1919
- `-c, --certificate`: Provide the path to the certificate as an argument.
2020
- `-o, --output`: Provide the path where the generated certificate should be saved as an argument.
21-
- `-g, --identifier`: Display the user identifier.
21+
- `-a, --identifier`: Display the user identifier.
2222
- `-n, --name`: Provide the name of the certificate to be generated.
2323
- `-s, --setup`: Create an CA and an certificate.
2424
- `-i, --interactive`: Create certificate using interactive mode.
@@ -38,7 +38,7 @@ dhtnet-crtmgr -o <output> -c <signer_certificate_path> -p <signer_private_key_pa
3838

3939
To display the identifier:
4040
```bash
41-
dhtnet-crtmgr -g <output> -c <certificate_path> -p <private_key_path>
41+
dhtnet-crtmgr -a -c <certificate_path> -p <private_key_path>
4242
```
4343

4444
To generate a CA and an certificate:

tools/dhtnet_crtmgr/main.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static const constexpr struct option long_options[]
4747
{"id", required_argument, nullptr, 'o'},
4848
{"privatekey", required_argument, nullptr, 'p'},
4949
{"name", required_argument, nullptr, 'n'},
50-
{"pkid", no_argument, nullptr, 'g'},
50+
{"pkid", no_argument, nullptr, 'a'},
5151
{"setup", no_argument, nullptr, 's'},
5252
{"interactive", no_argument, nullptr, 'i'},
5353
{nullptr, 0, nullptr, 0}};
@@ -57,7 +57,7 @@ parse_args(int argc, char** argv)
5757
{
5858
dhtnet_crtmgr_params params;
5959
int opt;
60-
while ((opt = getopt_long(argc, argv, "hgsvi:c:o:p:n:", long_options, nullptr)) != -1) {
60+
while ((opt = getopt_long(argc, argv, "hasvi:c:o:p:n:", long_options, nullptr)) != -1) {
6161
switch (opt) {
6262
case 'h':
6363
params.help = true;
@@ -74,7 +74,7 @@ parse_args(int argc, char** argv)
7474
case 'p':
7575
params.privatekey = optarg;
7676
break;
77-
case 'g':
77+
case 'a':
7878
params.pkid = true;
7979
break;
8080
case 'n':
@@ -197,15 +197,15 @@ main(int argc, char** argv)
197197
if (params.help) {
198198
fmt::print("Usage: dhtnet-crtmgr [options]\n"
199199
"\nOptions:\n"
200-
" -h, --help Display this help message and then exit.\n"
201-
" -v, --version Show the version of the program.\n"
202-
" -p, --privatekey Provide the path to the private key as an argument.\n"
203-
" -c, --certificate Provide the path to the certificate as an argument.\n"
204-
" -o, --output Provide the path where the generated certificate should be saved as an argument.\n"
205-
" -g, --identifier Display the user identifier.\n"
206-
" -n, --name Provide the name of the certificate to be generated.\n"
207-
" -s, --setup Create an CA and a certificate.\n"
208-
" -i, --interactive Interactively create and setup identities.\n");
200+
" -h, --help Display this help message and then exit.\n"
201+
" -v, --version Show the version of the program.\n"
202+
" -p, --privatekey [PATH] Provide the path to the private key as an argument.\n"
203+
" -c, --certificate [PATH] Provide the path to the certificate as an argument.\n"
204+
" -o, --output [FOLDER] Provide the path where the generated certificate should be saved as an argument.\n"
205+
" -a, --identifier Display the user identifier.\n"
206+
" -n, --name [NAME] Provide the name of the certificate to be generated.\n"
207+
" -s, --setup Create an CA and a certificate.\n"
208+
" -i, --interactive Interactively create and setup identities.\n");
209209
return EXIT_SUCCESS;
210210
}
211211

@@ -216,7 +216,7 @@ main(int argc, char** argv)
216216
// check if the public key id is requested
217217
if (params.pkid) {
218218
if (params.ca.empty() || params.privatekey.empty()) {
219-
fmt::print(stderr, "Error: The path to the private key and the certificate is not provided.\n Please specify the path for the private key and the certificate using the -p and -c options.\n");
219+
fmt::print(stderr, "Error: The path to the private key and the certificate is not provided.\n Please specify the path for the private key and the certificate using the -p and -c options.\n");
220220
exit(EXIT_FAILURE);
221221
}
222222
auto identity = dhtnet::loadIdentity(params.privatekey, params.ca);
@@ -362,8 +362,8 @@ main(int argc, char** argv)
362362
auto ca = dhtnet::generateIdentity(params.id, "ca");
363363
fmt::print("Generated certificate in {}: {} {}\n", params.id, "ca", ca.second->getId());
364364
}else{
365-
auto ca = dhtnet::generateIdentity(params.id, params.name);
366-
fmt::print("Generated certificate in {}: {} {}\n", params.id, params.name, ca.second->getId());
365+
auto ca = dhtnet::generateIdentity(params.id, params.name);
366+
fmt::print("Generated certificate in {}: {} {}\n", params.id, params.name, ca.second->getId());
367367
}
368368
}else{
369369
auto ca = dhtnet::loadIdentity(params.privatekey, params.ca);

tools/dnc/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ systemctl start dnc.service
5757
```
5858
Obtain the user identifier with the following command:
5959
```shell
60-
dhtnet-crtmgr -g -p <privateKey_path> -c <cert_path>
60+
dhtnet-crtmgr -a -p <privateKey_path> -c <cert_path>
6161
```
6262
For the server, use:
6363
```shell
64-
dhtnet-crtmgr -g -c /usr/local/etc/dhtnet/id/id-server.crt -p /usr/local/etc/dhtnet/id/id-server.pem
64+
dhtnet-crtmgr -a -c /usr/local/etc/dhtnet/id/id-server.crt -p /usr/local/etc/dhtnet/id/id-server.pem
6565
```
6666

6767
#### Client Connection

0 commit comments

Comments
 (0)