This change is preperation for changing the way --genkey works.
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20190510121114.30468-2-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18445.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
... | ... |
@@ -1465,8 +1465,13 @@ write_key_file(const int nkeys, const char *filename) |
1465 | 1465 |
|
1466 | 1466 |
buf_printf(&out, "%s\n", static_key_foot); |
1467 | 1467 |
|
1468 |
+ /* write key file to stdout if no filename given */ |
|
1469 |
+ if (!filename || strcmp(filename, "")==0) |
|
1470 |
+ { |
|
1471 |
+ printf("%s\n", BPTR(&out)); |
|
1472 |
+ } |
|
1468 | 1473 |
/* write key file, now formatted in out, to file */ |
1469 |
- if (!buffer_write_file(filename, &out)) |
|
1474 |
+ else if (!buffer_write_file(filename, &out)) |
|
1470 | 1475 |
{ |
1471 | 1476 |
nbits = -1; |
1472 | 1477 |
} |
... | ... |
@@ -1870,7 +1875,11 @@ write_pem_key_file(const char *filename, const char *pem_name) |
1870 | 1870 |
goto cleanup; |
1871 | 1871 |
} |
1872 | 1872 |
|
1873 |
- if (!buffer_write_file(filename, &server_key_pem)) |
|
1873 |
+ if (!filename || strcmp(filename, "")==0) |
|
1874 |
+ { |
|
1875 |
+ printf("%s\n", BPTR(&server_key_pem)); |
|
1876 |
+ } |
|
1877 |
+ else if (!buffer_write_file(filename, &server_key_pem)) |
|
1874 | 1878 |
{ |
1875 | 1879 |
msg(M_ERR, "ERROR: could not write key file"); |
1876 | 1880 |
goto cleanup; |
... | ... |
@@ -697,7 +697,16 @@ tls_crypt_v2_write_client_key_file(const char *filename, |
697 | 697 |
goto cleanup; |
698 | 698 |
} |
699 | 699 |
|
700 |
- if (!buffer_write_file(filename, &client_key_pem)) |
|
700 |
+ const char *client_filename = filename; |
|
701 |
+ const char *client_inline = NULL; |
|
702 |
+ |
|
703 |
+ if (!filename || streq(filename, "")) |
|
704 |
+ { |
|
705 |
+ printf("%s\n", BPTR(&client_key_pem)); |
|
706 |
+ client_filename = INLINE_FILE_TAG; |
|
707 |
+ client_inline = (const char *)BPTR(&client_key_pem); |
|
708 |
+ } |
|
709 |
+ else if (!buffer_write_file(filename, &client_key_pem)) |
|
701 | 710 |
{ |
702 | 711 |
msg(M_FATAL, "ERROR: could not write client key file"); |
703 | 712 |
goto cleanup; |
... | ... |
@@ -708,7 +717,7 @@ tls_crypt_v2_write_client_key_file(const char *filename, |
708 | 708 |
struct buffer test_wrapped_client_key; |
709 | 709 |
msg(D_GENKEY, "Testing client-side key loading..."); |
710 | 710 |
tls_crypt_v2_init_client_key(&test_client_key, &test_wrapped_client_key, |
711 |
- filename, NULL); |
|
711 |
+ client_filename, client_inline); |
|
712 | 712 |
free_key_ctx_bi(&test_client_key); |
713 | 713 |
|
714 | 714 |
/* Sanity check: unwrap and load client key (as "server") */ |