Skip to content

Commit 2a0eac5

Browse files
committed
crypto: improve help
1 parent 7bf89e0 commit 2a0eac5

13 files changed

Lines changed: 390 additions & 184 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,11 @@ endif()
392392
option(LWS_WITH_MCUFONT_ENCODER "Build the ttf to mcufont encoder" OFF)
393393
option(LWS_WITH_WAKE_LOGGING "Log each wake reason" OFF)
394394
option(LWS_WITH_DHT "Include DHT frontend client APIs" OFF)
395-
option(LWS_WITH_DHT_BACKEND "Include full DHT backend node functionality" OFF)
395+
set(LWS_WITH_DHT_BACKEND_DEFAULT OFF)
396+
if (LWS_WITH_DHT)
397+
set(LWS_WITH_DHT_BACKEND_DEFAULT ON)
398+
endif()
399+
option(LWS_WITH_DHT_BACKEND "Include full DHT backend node functionality" ${LWS_WITH_DHT_BACKEND_DEFAULT})
396400
option(LWS_WITH_TRANSPORT_SEQUENCER "Include Transport Sequencer APIs" OFF)
397401
option(LWS_WITH_MNEMONIC "Include mnemonic key generation support" OFF)
398402
option(LWS_WITH_DTLS "Compile with support for Generic DTLS" OFF)

READMEs/README.dht.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Libwebsockets provides an implementation of a Kademlia-based Distributed Hash Ta
77
The DHT functionality is physically split into client and backend blocks to allow resource-constrained devices to participate as clients without maintaining full routing tables and storage on the device.
88

99
* `LWS_WITH_DHT`: Enables the DHT frontend and client API. This provides the core functionality to manage a DHT node ID (`dht-id.c`), serialize and parse base DHT protocol messages (`dht-bencode.c`), and manage networking and queries (`dht-tx.c`, `dht.c`).
10-
* `LWS_WITH_DHT_BACKEND`: Enables the full DHT backend. This includes managing buckets, maintaining the complex routing table, coordinating decentralized searches, maintaining in-memory storage, and automatically responding to incoming RPCs like `ping`, `find_node`, `get_peers`, and `announce_peer`. Enabling this automatically requires and implies `LWS_WITH_DHT`.
10+
* `LWS_WITH_DHT_BACKEND`: Enables the full DHT backend. This includes managing buckets, maintaining the complex routing table, coordinating decentralized searches, maintaining in-memory storage, and automatically responding to incoming RPCs like `ping`, `find_node`, `get_peers`, and `announce_peer`. This is automatically enabled by default when `LWS_WITH_DHT` is enabled, but can be forced off with `-DLWS_WITH_DHT_BACKEND=0`.
1111

1212
## Configuration Options (`lws_dht_info_t`)
1313

include/libwebsockets/lws-dht-dnssec.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,18 @@ struct lws_context;
2929

3030
struct lws_dht_dnssec_keygen_args {
3131
const char *domain;
32+
const char *type; /* e.g. "EC" or "RSA" */
3233
const char *curve;
33-
int is_ksk;
34+
int bits;
3435
};
3536

3637
struct lws_dht_dnssec_dsfromkey_args {
37-
const char *key_file;
38+
const char *domain;
3839
const char *hash; /* E.g., "SHA256" */
3940
};
4041

4142
struct lws_dht_dnssec_signzone_args {
4243
const char *domain;
43-
const char *input_filepath;
44-
const char *output_filepath;
45-
const char *jws_filepath;
46-
const char *zsk_jwk_filepath;
47-
const char *ksk_jwk_filepath;
4844
uint32_t sign_validity_duration;
4945
};
5046

minimal-examples-lowlevel/crypto/minimal-crypto-cose-key/main.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ enum {
2222
};
2323

2424
static const struct lws_switches switches[] = {
25-
[LWS_SW_BITS] = { "--bits", "Enable --bits feature" },
26-
[LWS_SW_CURVE] = { "--curve", "Enable --curve feature" },
27-
[LWS_SW_KID] = { "--kid", "Enable --kid feature" },
28-
[LWS_SW_KID_HEX] = { "--kid-hex", "Enable --kid-hex feature" },
29-
[LWS_SW_KTY] = { "--kty", "Enable --kty feature" },
30-
[LWS_SW_STDIN] = { "--stdin", "Enable --stdin feature" },
31-
[LWS_SW_STDOUT] = { "--stdout", "Enable --stdout feature" },
25+
[LWS_SW_BITS] = { "--bits", "Number of bits for the generated key (e.g. 2048)" },
26+
[LWS_SW_CURVE] = { "--curve", "EC algorithm curve (e.g. P-256)" },
27+
[LWS_SW_KID] = { "--kid", "Apply Key ID text format string" },
28+
[LWS_SW_KID_HEX] = { "--kid-hex", "Apply Key ID in hex format" },
29+
[LWS_SW_KTY] = { "--kty", "Key type (OKP, EC2, RSA, SYMMETRIC)" },
30+
[LWS_SW_STDIN] = { "--stdin", "Take input from standard input" },
31+
[LWS_SW_STDOUT] = { "--stdout", "Output to standard output" },
3232
[LWS_SW_D] = { "-d", "Debug logs (e.g. -d 15)" },
33-
[LWS_SW_HELP] = { "--help", "Show this help information" },
33+
[LWS_SW_HELP] = { "--help", "Show this help information (-h, --help)" },
3434
};
3535

3636
#include <sys/select.h>
@@ -147,7 +147,7 @@ int main(int argc, const char **argv)
147147
lws_lec_pctx_t lec;
148148
(void)switches;
149149

150-
if ((argc == 1) || lws_cmdline_option(argc, argv, switches[LWS_SW_HELP].sw)) {
150+
if ((argc == 1) || lws_cmdline_option(argc, argv, "-h") || lws_cmdline_option(argc, argv, switches[LWS_SW_HELP].sw)) {
151151
lws_switches_print_help(argv[0], switches, LWS_ARRAY_SIZE(switches));
152152
return 0;
153153
}

minimal-examples-lowlevel/crypto/minimal-crypto-cose-sign/main.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ enum {
2727
};
2828

2929
static const struct lws_switches switches[] = {
30-
[LWS_SW_ALG] = { "--alg", "Enable --alg feature" },
31-
[LWS_SW_COSE_MAC] = { "--cose-mac", "Enable --cose-mac feature" },
32-
[LWS_SW_COSE_MAC0] = { "--cose-mac0", "Enable --cose-mac0 feature" },
33-
[LWS_SW_COSE_SIGN] = { "--cose-sign", "Enable --cose-sign feature" },
34-
[LWS_SW_COSE_SIGN1] = { "--cose-sign1", "Enable --cose-sign1 feature" },
35-
[LWS_SW_EXTRA] = { "--extra", "Enable --extra feature" },
36-
[LWS_SW_KID] = { "--kid", "Enable --kid feature" },
37-
[LWS_SW_KID_HEX] = { "--kid-hex", "Enable --kid-hex feature" },
38-
[LWS_SW_STDIN] = { "--stdin", "Enable --stdin feature" },
39-
[LWS_SW_STDOUT] = { "--stdout", "Enable --stdout feature" },
30+
[LWS_SW_ALG] = { "--alg", "COSE alg to use for signing (e.g. ES256)" },
31+
[LWS_SW_COSE_MAC] = { "--cose-mac", "Emit a COSE_Mac message" },
32+
[LWS_SW_COSE_MAC0] = { "--cose-mac0", "Emit a COSE_Mac0 message" },
33+
[LWS_SW_COSE_SIGN] = { "--cose-sign", "Emit a COSE_Sign message (multi-signature)" },
34+
[LWS_SW_COSE_SIGN1] = { "--cose-sign1", "Emit a COSE_Sign1 message (single signature)" },
35+
[LWS_SW_EXTRA] = { "--extra", "Extra application data appended to signature (hex)" },
36+
[LWS_SW_KID] = { "--kid", "String specifying the kid to filter keys from keyset" },
37+
[LWS_SW_KID_HEX] = { "--kid-hex", "Hex string specifying the kid to filter keys from keyset" },
38+
[LWS_SW_STDIN] = { "--stdin", "Path to file to use as stdin (if not piping)" },
39+
[LWS_SW_STDOUT] = { "--stdout", "Path to file to write to stdout (if not piping)" },
4040
[LWS_SW_D] = { "-d", "Debug logs (e.g. -d 15)" },
41-
[LWS_SW_K] = { "-k", "Key or cert path" },
42-
[LWS_SW_S] = { "-s", "Use TLS / https" },
43-
[LWS_SW_HELP] = { "--help", "Show this help information" },
41+
[LWS_SW_K] = { "-k", "Path to keyset file to use" },
42+
[LWS_SW_S] = { "-s", "Sign instead of verify" },
43+
[LWS_SW_HELP] = { "--help", "Show this help information (-h, --help)" },
4444
};
4545

4646
#include <sys/types.h>
@@ -146,7 +146,7 @@ int main(int argc, const char **argv)
146146
const char *p;
147147
(void)switches;
148148

149-
if ((argc == 1) || lws_cmdline_option(argc, argv, switches[LWS_SW_HELP].sw)) {
149+
if ((argc == 1) || lws_cmdline_option(argc, argv, "-h") || lws_cmdline_option(argc, argv, switches[LWS_SW_HELP].sw)) {
150150
lws_switches_print_help(argv[0], switches, LWS_ARRAY_SIZE(switches));
151151
return 0;
152152
}

minimal-examples-lowlevel/crypto/minimal-crypto-dnssec/main.c

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,24 @@
1616

1717
enum {
1818
LWS_SW_CURVE,
19+
LWS_SW_TYPE,
20+
LWS_SW_BITS,
1921
LWS_SW_DURATION,
2022
LWS_SW_HASH,
21-
LWS_SW_KSK,
22-
LWS_SW_ZSK,
2323
LWS_SW_D,
24+
LWS_SW_P,
2425
LWS_SW_HELP,
2526
};
2627

2728
static const struct lws_switches switches[] = {
28-
[LWS_SW_CURVE] = { "--curve", "Enable --curve feature" },
29-
[LWS_SW_DURATION] = { "--duration", "Enable --duration feature" },
30-
[LWS_SW_HASH] = { "--hash", "Enable --hash feature" },
31-
[LWS_SW_KSK] = { "--ksk", "Enable --ksk feature" },
32-
[LWS_SW_ZSK] = { "--zsk", "Enable --zsk feature" },
29+
[LWS_SW_CURVE] = { "--curve", "Set crypto curve for EC keygen (e.g. P-256)" },
30+
[LWS_SW_TYPE] = { "--type", "Set key type (EC or RSA, default EC)" },
31+
[LWS_SW_BITS] = { "--bits", "Set key size for RSA keygen (e.g. 2048)" },
32+
[LWS_SW_DURATION] = { "--duration", "Set signature validity duration in hours" },
33+
[LWS_SW_HASH] = { "--hash", "Set hash type for DS record (e.g. SHA256)" },
3334
[LWS_SW_D] = { "-d", "Debug logs (e.g. -d 15)" },
34-
[LWS_SW_HELP] = { "--help", "Show this help information" },
35+
[LWS_SW_P] = { "-p", "Extra plugin dir" },
36+
[LWS_SW_HELP] = { "--help", "Show this help information (-h, --help)" },
3537
};
3638

3739
int main(int argc, const char **argv)
@@ -44,37 +46,60 @@ int main(int argc, const char **argv)
4446
const struct lws_dht_dnssec_ops *ops;
4547
struct lws_vhost *vh;
4648

47-
if ((argc == 1) || lws_cmdline_option(argc, argv, switches[LWS_SW_HELP].sw)) {
48-
lws_switches_print_help(argv[0], switches, LWS_ARRAY_SIZE(switches));
49-
return 0;
50-
}
51-
5249
if ((p = lws_cmdline_option(argc, argv, switches[LWS_SW_D].sw)))
5350
logs = atoi(p);
5451

5552
lws_set_log_level(logs, NULL);
53+
54+
if ((argc == 1) || lws_cmdline_option(argc, argv, "-h") || lws_cmdline_option(argc, argv, switches[LWS_SW_HELP].sw)) {
55+
lwsl_user("Usage: %s <keygen|dsfromkey|signzone> [args...]\n\n", argv[0]);
56+
lwsl_user(" keygen [--type <RSA|EC>] [--bits <size>] [--curve <curve>] <domain>\n");
57+
lwsl_user(" Outputs: <domain>.[ksk|zsk].key & <domain>.[ksk|zsk].private.jwk\n");
58+
lwsl_user(" dsfromkey [--hash <hash>] <domain>\n");
59+
lwsl_user(" Inputs : <domain>.ksk.key Outputs: Base64 DS Record to stdout\n");
60+
lwsl_user(" signzone [--duration <hours>] <domain>\n");
61+
lwsl_user(" Inputs : <domain>.zone, <domain>.ksk.private.jwk, <domain>.zsk.private.jwk\n");
62+
lwsl_user(" Outputs: <domain>.zone.signed and <domain>.zone.signed.jws\n\n");
63+
lws_switches_print_help(argv[0], switches, LWS_ARRAY_SIZE(switches));
64+
return 0;
65+
}
66+
5667
lwsl_user("LWS DNSSEC Crypto Utility (DHT Plugin Wrapper)\n");
5768

5869
if (argc < 2) {
5970
lwsl_err("Usage: lws-crypto-dnssec <keygen|dsfromkey|signzone> [args...]\n");
6071
return 1;
6172
}
6273

74+
#if 0
6375
static const char * const pdirs[] = {
6476
"./lib",
6577
"../lib",
78+
"./plugins",
79+
"../plugins",
6680
"./build/lib",
6781
"../build/lib",
6882
"../../lib",
6983
NULL
7084
};
85+
static const char * dynamic_pdirs[3];
86+
#endif
7187

7288
memset(&info, 0, sizeof info);
7389
#if defined(LWS_WITH_NETWORK)
7490
info.port = CONTEXT_PORT_NO_LISTEN;
7591
#endif
7692
info.options = 0;
77-
info.plugin_dirs = pdirs;
93+
94+
#if 0
95+
if ((p = lws_cmdline_option(argc, argv, switches[LWS_SW_P].sw))) {
96+
dynamic_pdirs[0] = p;
97+
dynamic_pdirs[1] = NULL;
98+
info.plugin_dirs = dynamic_pdirs;
99+
} else {
100+
info.plugin_dirs = pdirs;
101+
}
102+
#endif
78103

79104
context = lws_create_context(&info);
80105
if (!context) {
@@ -104,24 +129,37 @@ int main(int argc, const char **argv)
104129
}
105130

106131
const char *mode = argv[1];
132+
int n = argc - 1;
133+
134+
/* move back 1 arg each time the candidate begins with '-' */
135+
while (n > 1 && argv[n][0] == '-')
136+
n--;
137+
138+
if (n < 2) {
139+
lwsl_err("Missing domain argument\n");
140+
lws_context_destroy(context);
141+
return 1;
142+
}
107143

108144
if (!strcmp(mode, "keygen")) {
109145
struct lws_dht_dnssec_keygen_args kg_args;
110146
memset(&kg_args, 0, sizeof(kg_args));
111147

112-
if (lws_cmdline_option(argc, argv, switches[LWS_SW_KSK].sw))
113-
kg_args.is_ksk = 1;
114148
if ((p = lws_cmdline_option(argc, argv, switches[LWS_SW_CURVE].sw)))
115149
kg_args.curve = p;
150+
if ((p = lws_cmdline_option(argc, argv, switches[LWS_SW_TYPE].sw)))
151+
kg_args.type = p;
152+
if ((p = lws_cmdline_option(argc, argv, switches[LWS_SW_BITS].sw)))
153+
kg_args.bits = atoi(p);
116154

117-
kg_args.domain = argv[argc - 1];
155+
kg_args.domain = argv[n];
118156

119157
if (ops->keygen) result = ops->keygen(context, &kg_args);
120158
} else if (!strcmp(mode, "dsfromkey")) {
121159
struct lws_dht_dnssec_dsfromkey_args ds_args;
122160
memset(&ds_args, 0, sizeof(ds_args));
123161

124-
ds_args.key_file = argv[argc - 1];
162+
ds_args.domain = argv[n];
125163
if ((p = lws_cmdline_option(argc, argv, switches[LWS_SW_HASH].sw)))
126164
ds_args.hash = p;
127165

@@ -130,18 +168,10 @@ int main(int argc, const char **argv)
130168
struct lws_dht_dnssec_signzone_args sz_args;
131169
memset(&sz_args, 0, sizeof(sz_args));
132170

133-
if ((p = lws_cmdline_option(argc, argv, switches[LWS_SW_ZSK].sw)))
134-
sz_args.zsk_jwk_filepath = p;
135-
if ((p = lws_cmdline_option(argc, argv, switches[LWS_SW_KSK].sw)))
136-
sz_args.ksk_jwk_filepath = p;
137171
if ((p = lws_cmdline_option(argc, argv, switches[LWS_SW_DURATION].sw)))
138172
sz_args.sign_validity_duration = (uint32_t)atoi(p);
139173

140-
if (argc >= 4 && argv[argc - 3][0] != '-' && argv[argc - 2][0] != '-' && argv[argc - 1][0] != '-') {
141-
sz_args.input_filepath = argv[argc - 3];
142-
sz_args.output_filepath = argv[argc - 2];
143-
sz_args.jws_filepath = argv[argc - 1];
144-
}
174+
sz_args.domain = argv[n];
145175

146176
if (ops->signzone) result = ops->signzone(context, &sz_args);
147177
} else {

minimal-examples-lowlevel/crypto/minimal-crypto-jwe/main.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ enum {
1919
};
2020

2121
static const struct lws_switches switches[] = {
22-
[LWS_SW_C] = { "-c", "Client connections" },
22+
[LWS_SW_C] = { "-c", "Output in C array format" },
2323
[LWS_SW_D] = { "-d", "Debug logs (e.g. -d 15)" },
24-
[LWS_SW_E] = { "-e", "Enable -e feature" },
25-
[LWS_SW_F] = { "-f", "Enable -f feature" },
26-
[LWS_SW_K] = { "-k", "Key or cert path" },
27-
[LWS_SW_HELP] = { "--help", "Show this help information" },
24+
[LWS_SW_E] = { "-e", "Encrypt using <alg> <enc> format (e.g. 'RSA1_5 A128CBC-HS256')" },
25+
[LWS_SW_F] = { "-f", "Output in flattened representation" },
26+
[LWS_SW_K] = { "-k", "Path to the JWK key file" },
27+
[LWS_SW_HELP] = { "--help", "Show this help information (-h, --help)" },
2828
};
2929

3030
#include <sys/types.h>
@@ -111,7 +111,7 @@ int main(int argc, const char **argv)
111111
const char *p;
112112
(void)switches;
113113

114-
if ((argc == 1) || lws_cmdline_option(argc, argv, switches[LWS_SW_HELP].sw)) {
114+
if ((argc == 1) || lws_cmdline_option(argc, argv, "-h") || lws_cmdline_option(argc, argv, switches[LWS_SW_HELP].sw)) {
115115
lws_switches_print_help(argv[0], switches, LWS_ARRAY_SIZE(switches));
116116
return 0;
117117
}

minimal-examples-lowlevel/crypto/minimal-crypto-jwk/main.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ enum {
2525
};
2626

2727
static const struct lws_switches switches[] = {
28-
[LWS_SW_ALG] = { "--alg", "Enable --alg feature" },
29-
[LWS_SW_CURVE] = { "--curve", "Enable --curve feature" },
30-
[LWS_SW_KEY_OPS] = { "--key-ops", "Enable --key-ops feature" },
31-
[LWS_SW_KID] = { "--kid", "Enable --kid feature" },
32-
[LWS_SW_PUBLIC] = { "--public", "Enable --public feature" },
33-
[LWS_SW_USE] = { "--use", "Enable --use feature" },
34-
[LWS_SW_B] = { "-b", "Enable -b feature" },
35-
[LWS_SW_C] = { "-c", "Client connections" },
28+
[LWS_SW_ALG] = { "--alg", "Set the 'alg' JWS algorithm (e.g. RS256)" },
29+
[LWS_SW_CURVE] = { "--curve", "Set the EC curve (e.g. P-256)" },
30+
[LWS_SW_KEY_OPS] = { "--key-ops", "Set the 'key_ops' (e.g. sign, verify)" },
31+
[LWS_SW_KID] = { "--kid", "Set the 'kid' Key ID" },
32+
[LWS_SW_PUBLIC] = { "--public", "Output public key only to specified file" },
33+
[LWS_SW_USE] = { "--use", "Set the 'use' intended usage (e.g. sig)" },
34+
[LWS_SW_B] = { "-b", "Number of bits to generate (e.g. 2048, 4096)" },
35+
[LWS_SW_C] = { "-c", "Format output as C array for header files" },
3636
[LWS_SW_D] = { "-d", "Debug logs (e.g. -d 15)" },
37-
[LWS_SW_T] = { "-t", "Test flag" },
38-
[LWS_SW_V] = { "-v", "Set retry and idle policy" },
39-
[LWS_SW_HELP] = { "--help", "Show this help information" },
37+
[LWS_SW_T] = { "-t", "Key type to generate (RSA, EC, OCT)" },
38+
[LWS_SW_V] = { "-v", "Alias for --curve" },
39+
[LWS_SW_HELP] = { "--help", "Show this help information (-h, --help)" },
4040
};
4141

4242
#include <sys/types.h>
@@ -109,7 +109,7 @@ int main(int argc, const char **argv)
109109
int vl = sizeof(key);
110110
(void)switches;
111111

112-
if ((argc == 1) || lws_cmdline_option(argc, argv, switches[LWS_SW_HELP].sw)) {
112+
if ((argc == 1) || lws_cmdline_option(argc, argv, "-h") || lws_cmdline_option(argc, argv, switches[LWS_SW_HELP].sw)) {
113113
lws_switches_print_help(argv[0], switches, LWS_ARRAY_SIZE(switches));
114114
return 0;
115115
}

minimal-examples-lowlevel/crypto/minimal-crypto-jws/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ enum {
1919

2020
static const struct lws_switches switches[] = {
2121
[LWS_SW_D] = { "-d", "Debug logs (e.g. -d 15)" },
22-
[LWS_SW_F] = { "-f", "Enable -f feature" },
23-
[LWS_SW_K] = { "-k", "Key or cert path" },
24-
[LWS_SW_S] = { "-s", "Use TLS / https" },
25-
[LWS_SW_HELP] = { "--help", "Show this help information" },
22+
[LWS_SW_F] = { "-f", "Output JWS in flattened format" },
23+
[LWS_SW_K] = { "-k", "Path to the JWK key file" },
24+
[LWS_SW_S] = { "-s", "Sign plaintext from stdin using provided algorithm (e.g. RS256)" },
25+
[LWS_SW_HELP] = { "--help", "Show this help information (-h, --help)" },
2626
};
2727

2828
#include <sys/types.h>
@@ -46,7 +46,7 @@ int main(int argc, const char **argv)
4646
const char *p;
4747
(void)switches;
4848

49-
if ((argc == 1) || lws_cmdline_option(argc, argv, switches[LWS_SW_HELP].sw)) {
49+
if ((argc == 1) || lws_cmdline_option(argc, argv, "-h") || lws_cmdline_option(argc, argv, switches[LWS_SW_HELP].sw)) {
5050
lws_switches_print_help(argv[0], switches, LWS_ARRAY_SIZE(switches));
5151
return 0;
5252
}

0 commit comments

Comments
 (0)