1 diff --git a/CREDITS b/CREDITS
2 index de17d9e..38e2108 100644
7 - Contributed OpenWRT support - see the extras/openwrt/ directory.
8 + - Suggested the addition of the --key-gen option to fwknopd.
11 - Assisted with getting fwknop included in BackTrack Linux - the choice
12 diff --git a/ChangeLog b/ChangeLog
13 index 21a5093..4daf008 100644
17 +fwknop-2.6.7 (05//2015):
18 + - Added --key-gen to fwknopd. This feature was suggested by Jonathan
19 + Bennett, and will help with ease of use efforts. The first platform to
20 + take advantage of this will likely be OpenWRT thanks to Jonathan.
22 fwknop-2.6.6 (04/23/2015):
23 - [server] Add the ability for fwknopd to function as an generic SPA
24 gateway. This allows scenarios such as the fwknopd system providing DHCP
25 diff --git a/client/config_init.c b/client/config_init.c
26 index cdb233d..f0ae135 100644
27 --- a/client/config_init.c
28 +++ b/client/config_init.c
29 @@ -199,7 +199,7 @@ static int critical_var_array[] =
33 - * @brief Generate Rijndael + HMAC keys from /dev/random (base64 encoded) and exit.
34 + * @brief Generate Rijndael + HMAC keys from /dev/urandom (base64 encoded).
36 * @param options FKO command line option structure
38 diff --git a/client/fwknop_common.h b/client/fwknop_common.h
39 index aef20c4..c57db02 100644
40 --- a/client/fwknop_common.h
41 +++ b/client/fwknop_common.h
43 #define MAX_HOSTNAME_LEN 70
44 #define MAX_URL_HOST_LEN 256
45 #define MAX_URL_PATH_LEN 1024
46 -#define MAX_KEY_LEN 128
47 -#define MAX_B64_KEY_LEN 180
49 /* fwknop client configuration parameters and values
51 @@ -156,10 +154,10 @@ typedef struct fko_cli_options
52 unsigned char use_gpg;
53 unsigned char use_gpg_agent;
54 unsigned char gpg_no_signing_pw;
55 + unsigned char key_gen;
57 int time_offset_minus;
61 char use_rc_stanza[MAX_LINE_LEN];
62 unsigned char got_named_stanza;
63 diff --git a/common/common.h b/common/common.h
64 index b63e7c2..c7b2e57 100644
67 @@ -157,6 +157,9 @@ enum {
68 #define MAX_GPG_KEY_ID 128
69 #define MAX_USERNAME_LEN 30
71 +#define MAX_KEY_LEN 128
72 +#define MAX_B64_KEY_LEN 180
74 /* Command line argument / argv handling
76 #define MAX_CMDLINE_ARGS 30 /*!< should be way more than enough */
77 diff --git a/doc/fwknop.man.asciidoc b/doc/fwknop.man.asciidoc
78 index 070ac77..efa99a7 100644
79 --- a/doc/fwknop.man.asciidoc
80 +++ b/doc/fwknop.man.asciidoc
81 @@ -196,6 +196,11 @@ GENERAL OPTIONS
82 keys are generally more secure than passphrases that are typed in from the
85 +*--key-gen-file*='<file>'::
86 + Write generated keys to the specified file. Note that the file is
87 + overwritten if it already exists. If this option is not given, then
88 + *--key-gen* writes the keys to stdout.
90 *--key-len*='<length>'::
91 Specify the number of bytes for a generated Rijndael key. The maximum size
92 is currently 128 bytes.
93 diff --git a/server/cmd_opts.h b/server/cmd_opts.h
94 index bc1eee1..d7a645c 100644
95 --- a/server/cmd_opts.h
96 +++ b/server/cmd_opts.h
97 @@ -141,6 +141,10 @@ enum {
108 @@ -178,7 +182,12 @@ static struct option cmd_opts[] =
109 {"fault-injection-tag", 1, NULL, FAULT_INJECTION_TAG},
110 {"help", 0, NULL, 'h'},
111 {"interface", 1, NULL, 'i'},
112 - {"kill", 0, NULL, 'K'},
113 + {"key-gen", 0, NULL, 'k'},
114 + {"key-gen-file", 1, NULL, KEY_GEN_FILE },
115 + {"key-len", 1, NULL, KEY_LEN },
116 + {"hmac-key-len", 1, NULL, HMAC_KEY_LEN },
117 + {"hmac-digest-type", 1, NULL, HMAC_DIGEST_TYPE },
118 + {"kill", 0, NULL, 'K' },
119 {"fw-flush", 0, NULL, FW_FLUSH },
120 {"fw-list", 0, NULL, FW_LIST },
121 {"fw-list-all", 0, NULL, FW_LIST_ALL },
122 diff --git a/server/config_init.c b/server/config_init.c
123 index 0ddceee..2f1d293 100644
124 --- a/server/config_init.c
125 +++ b/server/config_init.c
126 @@ -201,6 +201,69 @@ validate_int_var_ranges(fko_srv_options_t *opts)
131 + * @brief Generate Rijndael + HMAC keys from /dev/urandom (base64 encoded).
133 + * @param options FKO command line option structure
136 +generate_keys(fko_srv_options_t *options)
138 + char key_base64[MAX_B64_KEY_LEN+1];
139 + char hmac_key_base64[MAX_B64_KEY_LEN+1];
141 + FILE *key_gen_file_ptr = NULL;
144 + /* Set defaults and validate for --key-gen mode
146 + if(options->key_len == 0)
147 + options->key_len = FKO_DEFAULT_KEY_LEN;
149 + if(options->hmac_key_len == 0)
150 + options->hmac_key_len = FKO_DEFAULT_HMAC_KEY_LEN;
152 + if(options->hmac_type == 0)
153 + options->hmac_type = FKO_DEFAULT_HMAC_MODE;
155 + /* Zero out the key buffers */
156 + memset(key_base64, 0x00, sizeof(key_base64));
157 + memset(hmac_key_base64, 0x00, sizeof(hmac_key_base64));
159 + /* Generate the key through libfko */
160 + res = fko_key_gen(key_base64, options->key_len,
161 + hmac_key_base64, options->hmac_key_len,
162 + options->hmac_type);
164 + if(res != FKO_SUCCESS)
166 + log_msg(LOG_ERR, "%s: fko_key_gen: Error %i - %s",
167 + MY_NAME, res, fko_errstr(res));
168 + clean_exit(options, NO_FW_CLEANUP, EXIT_FAILURE);
171 + if(options->key_gen_file[0] != '\0')
173 + if ((key_gen_file_ptr = fopen(options->key_gen_file, "w")) == NULL)
175 + log_msg(LOG_ERR, "Unable to create key gen file: %s: %s",
176 + options->key_gen_file, strerror(errno));
177 + clean_exit(options, NO_FW_CLEANUP, EXIT_FAILURE);
179 + fprintf(key_gen_file_ptr, "KEY_BASE64: %s\nHMAC_KEY_BASE64: %s\n",
180 + key_base64, hmac_key_base64);
181 + fclose(key_gen_file_ptr);
182 + fprintf(stdout, "[+] Wrote Rijndael and HMAC keys to: %s",
183 + options->key_gen_file);
187 + fprintf(stdout, "KEY_BASE64: %s\nHMAC_KEY_BASE64: %s\n",
188 + key_base64, hmac_key_base64);
190 + clean_exit(options, NO_FW_CLEANUP, EXIT_SUCCESS);
193 /* Parse the config file...
196 @@ -427,7 +490,7 @@ validate_options(fko_srv_options_t *opts)
197 if(opts->config[CONF_ENABLE_DIGEST_PERSISTENCE] == NULL)
198 set_config_entry(opts, CONF_ENABLE_DIGEST_PERSISTENCE,
199 DEF_ENABLE_DIGEST_PERSISTENCE);
202 /* Enable destination rule.
204 if(opts->config[CONF_ENABLE_DESTINATION_RULE] == NULL)
205 @@ -928,8 +991,9 @@ config_init(fko_srv_options_t *opts, int argc, char **argv)
207 /* First, scan the command-line args for -h/--help or an alternate
208 * configuration file. If we find an alternate config file, use it,
209 - * otherwise use the default. We also grab any override config files
211 + * otherwise use the default. We also grab any override config files
212 + * as well. In addition, we handle key generation here since this is
213 + * independent of configuration parsing.
215 while ((cmd_arg = getopt_long(argc, argv,
216 GETOPTS_OPTION_STRING, cmd_opts, &index)) != -1) {
217 @@ -952,6 +1016,45 @@ config_init(fko_srv_options_t *opts, int argc, char **argv)
218 if(got_override_config > 0)
226 + strlcpy(opts->key_gen_file, optarg, sizeof(opts->key_gen_file));
228 + case KEY_LEN: /* used in --key-gen mode only */
229 + opts->key_len = strtol_wrapper(optarg, 1,
230 + MAX_KEY_LEN, NO_EXIT_UPON_ERR, &is_err);
231 + if(is_err != FKO_SUCCESS)
234 + "Invalid key length '%s', must be in [%d-%d]",
235 + optarg, 1, MAX_KEY_LEN);
236 + clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
239 + case HMAC_DIGEST_TYPE: /* used in --key-gen mode only */
240 + if((opts->hmac_type = hmac_digest_strtoint(optarg)) < 0)
243 + "* Invalid hmac digest type: %s, use {md5,sha1,sha256,sha384,sha512}",
245 + clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
248 + case HMAC_KEY_LEN: /* used in --key-gen mode only */
249 + opts->hmac_key_len = strtol_wrapper(optarg, 1,
250 + MAX_KEY_LEN, NO_EXIT_UPON_ERR, &is_err);
251 + if(is_err != FKO_SUCCESS)
254 + "Invalid hmac key length '%s', must be in [%d-%d]",
255 + optarg, 1, MAX_KEY_LEN);
256 + clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
260 /* Look for override configuration file arg.
263 @@ -965,6 +1068,9 @@ config_init(fko_srv_options_t *opts, int argc, char **argv)
268 + generate_keys(opts);
270 /* If no alternate configuration file was specified, we use the
273 diff --git a/server/fwknopd_common.h b/server/fwknopd_common.h
274 index ecf2a81..8c33eaa 100644
275 --- a/server/fwknopd_common.h
276 +++ b/server/fwknopd_common.h
277 @@ -585,10 +585,14 @@ typedef struct fko_srv_options
278 unsigned char fw_list; /* List current firewall rules */
279 unsigned char fw_list_all; /* List all current firewall rules */
280 unsigned char fw_flush; /* Flush current firewall rules */
281 + unsigned char key_gen; /* Generate keys and exit */
282 + unsigned char exit_after_parse_config; /* Parse config and exit */
284 + /* Operational flags
286 unsigned char test; /* Test mode flag */
287 unsigned char afl_fuzzing; /* SPA pkts from stdin for AFL fuzzing */
288 unsigned char verbose; /* Verbose mode flag */
289 - unsigned char exit_after_parse_config; /* Parse config and exit */
290 unsigned char enable_udp_server; /* Enable UDP server mode */
292 unsigned char firewd_disable_check_support; /* Don't use firewall-cmd ... -C */
293 @@ -605,6 +609,13 @@ typedef struct fko_srv_options
297 + /* Values used in --key-gen mode only
299 + char key_gen_file[MAX_PATH_LEN];
305 struct digest_cache_list *digest_cache; /* In-memory digest cache list */
307 diff --git a/test/tests/basic_operations.pl b/test/tests/basic_operations.pl
308 index f4dde2e..76a509d 100644
309 --- a/test/tests/basic_operations.pl
310 +++ b/test/tests/basic_operations.pl
313 'cmdline' => "$default_client_args --key-gen -K " . 'A'x1030
316 + 'category' => 'basic operations',
317 + 'subcategory' => 'server',
318 + 'detail' => '--key-gen file path (-K) too long',
319 + 'function' => \&generic_exec,
320 + 'exec_err' => $YES,
321 + 'cmdline' => "$fwknopdCmd --key-gen --key-gen-file " . 'A'x1030
325 'category' => 'basic operations',
326 diff --git a/test/tests/rijndael.pl b/test/tests/rijndael.pl
327 index 26aab6a..34af65e 100644
328 --- a/test/tests/rijndael.pl
329 +++ b/test/tests/rijndael.pl
331 'key_file' => $cf{'rc_named_key'},
334 - ### --key-gen tests
336 - 'category' => 'Rijndael',
337 - 'subcategory' => 'client',
338 - 'detail' => '--key-gen',
339 - 'function' => \&generic_exec,
340 - 'cmdline' => "$fwknopCmd --key-gen",
341 - 'positive_output_matches' => [qr/^KEY_BASE64\:?\s\S{10}/,
342 - qw/HMAC_KEY_BASE64\:?\s\S{10}/],
345 - 'category' => 'Rijndael',
346 - 'subcategory' => 'client',
347 - 'detail' => "--key-gen $uniq_keys key uniqueness",
348 - 'function' => \&key_gen_uniqueness,
349 - 'cmdline' => "$fwknopCmd --key-gen", ### no valgrind string (too slow for 100 client exec's)
350 - 'disable_valgrind' => $YES,
353 - 'category' => 'Rijndael',
354 - 'subcategory' => 'client',
355 - 'detail' => '--key-gen to file',
356 - 'function' => \&generic_exec,
357 - 'cmdline' => "$fwknopCmd --key-gen --key-gen-file $key_gen_file",
358 - 'positive_output_matches' => [qr/Wrote.*\skeys/],
363 'category' => 'Rijndael',
364 diff --git a/test/tests/rijndael_hmac.pl b/test/tests/rijndael_hmac.pl
365 index fc1a8af..fd80f04 100644
366 --- a/test/tests/rijndael_hmac.pl
367 +++ b/test/tests/rijndael_hmac.pl
372 + ### --key-gen tests
374 + 'category' => 'Rijndael+HMAC',
375 + 'subcategory' => 'client',
376 + 'detail' => '--key-gen',
377 + 'function' => \&generic_exec,
378 + 'cmdline' => "$fwknopCmd --key-gen",
379 + 'positive_output_matches' => [qr/^KEY_BASE64\:?\s\S{10}/,
380 + qw/HMAC_KEY_BASE64\:?\s\S{10}/],
383 + 'category' => 'Rijndael+HMAC',
384 + 'subcategory' => 'server',
385 + 'detail' => '--key-gen',
386 + 'function' => \&generic_exec,
387 + 'cmdline' => "$fwknopdCmd --key-gen",
388 + 'positive_output_matches' => [qr/^KEY_BASE64\:?\s\S{10}/,
389 + qw/HMAC_KEY_BASE64\:?\s\S{10}/],
392 + 'category' => 'Rijndael+HMAC',
393 + 'subcategory' => 'client',
394 + 'detail' => "--key-gen $uniq_keys key uniqueness",
395 + 'function' => \&key_gen_uniqueness,
396 + 'cmdline' => "$fwknopCmd --key-gen", ### no valgrind string (too slow for 100 exec's)
397 + 'disable_valgrind' => $YES,
400 + 'category' => 'Rijndael+HMAC',
401 + 'subcategory' => 'server',
402 + 'detail' => "--key-gen $uniq_keys key uniqueness",
403 + 'function' => \&key_gen_uniqueness,
404 + 'cmdline' => "$fwknopdCmd --key-gen", ### no valgrind string (too slow for 100 exec's)
405 + 'disable_valgrind' => $YES,
408 + 'category' => 'Rijndael+HMAC',
409 + 'subcategory' => 'client',
410 + 'detail' => '--key-gen to file',
411 + 'function' => \&generic_exec,
412 + 'cmdline' => "$fwknopCmd --key-gen --key-gen-file $key_gen_file",
413 + 'positive_output_matches' => [qr/Wrote.*\skeys/],
416 + 'category' => 'Rijndael+HMAC',
417 + 'subcategory' => 'server',
418 + 'detail' => '--key-gen to file',
419 + 'function' => \&generic_exec,
420 + 'cmdline' => "$fwknopdCmd --key-gen --key-gen-file $key_gen_file",
421 + 'positive_output_matches' => [qr/Wrote.*\skeys/],
424 + ### complete cycle tests
426 'category' => 'Rijndael+HMAC',
427 'subcategory' => 'client+server',