Some of the commits, especially engine have not strictly used uncrustify
clean code. Rerun uncrustify to make them compliant again.
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20200626125332.15385-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg20142.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
| ... | ... |
@@ -1083,7 +1083,8 @@ ui_reader(UI *ui, UI_STRING *uis) |
| 1083 | 1083 |
{
|
| 1084 | 1084 |
SSL_CTX *ctx = UI_get0_user_data(ui); |
| 1085 | 1085 |
|
| 1086 |
- if (UI_get_string_type(uis) == UIT_PROMPT) {
|
|
| 1086 |
+ if (UI_get_string_type(uis) == UIT_PROMPT) |
|
| 1087 |
+ {
|
|
| 1087 | 1088 |
pem_password_cb *cb = SSL_CTX_get_default_passwd_cb(ctx); |
| 1088 | 1089 |
void *d = SSL_CTX_get_default_passwd_cb_userdata(ctx); |
| 1089 | 1090 |
char password[64]; |
| ... | ... |
@@ -1105,14 +1106,17 @@ engine_load_key(const char *file, SSL_CTX *ctx) |
| 1105 | 1105 |
EVP_PKEY *pkey; |
| 1106 | 1106 |
|
| 1107 | 1107 |
if (!engine_persist) |
| 1108 |
+ {
|
|
| 1108 | 1109 |
return NULL; |
| 1110 |
+ } |
|
| 1109 | 1111 |
|
| 1110 | 1112 |
/* this will print out the error from BIO_read */ |
| 1111 | 1113 |
crypto_msg(M_INFO, "PEM_read_bio failed, now trying engine method to load private key"); |
| 1112 | 1114 |
|
| 1113 | 1115 |
ui = UI_create_method("openvpn");
|
| 1114 |
- if (!ui) {
|
|
| 1115 |
- crypto_msg(M_FATAL, "Engine UI creation failed"); |
|
| 1116 |
+ if (!ui) |
|
| 1117 |
+ {
|
|
| 1118 |
+ crypto_msg(M_FATAL, "Engine UI creation failed"); |
|
| 1116 | 1119 |
return NULL; |
| 1117 | 1120 |
} |
| 1118 | 1121 |
|
| ... | ... |
@@ -1122,13 +1126,15 @@ engine_load_key(const char *file, SSL_CTX *ctx) |
| 1122 | 1122 |
pkey = ENGINE_load_private_key(engine_persist, file, ui, ctx); |
| 1123 | 1123 |
ENGINE_finish(engine_persist); |
| 1124 | 1124 |
if (!pkey) |
| 1125 |
- crypto_msg(M_FATAL, "Engine could not load key file"); |
|
| 1125 |
+ {
|
|
| 1126 |
+ crypto_msg(M_FATAL, "Engine could not load key file"); |
|
| 1127 |
+ } |
|
| 1126 | 1128 |
|
| 1127 | 1129 |
UI_destroy_method(ui); |
| 1128 | 1130 |
return pkey; |
| 1129 |
-#else |
|
| 1131 |
+#else /* if HAVE_OPENSSL_ENGINE */ |
|
| 1130 | 1132 |
return NULL; |
| 1131 |
-#endif |
|
| 1133 |
+#endif /* if HAVE_OPENSSL_ENGINE */ |
|
| 1132 | 1134 |
} |
| 1133 | 1135 |
|
| 1134 | 1136 |
#endif /* ENABLE_CRYPTO_OPENSSL */ |
| ... | ... |
@@ -110,11 +110,11 @@ cipher_kt_var_key_size(const cipher_kt_t *cipher) |
| 110 | 110 |
/** |
| 111 | 111 |
* Load a key file from an engine |
| 112 | 112 |
* |
| 113 |
- * @param file The engine file to load |
|
| 114 |
- * @param ui The UI method for the password prompt |
|
| 115 |
- * @param data The data to pass to the UI method |
|
| 113 |
+ * @param file The engine file to load |
|
| 114 |
+ * @param ui The UI method for the password prompt |
|
| 115 |
+ * @param data The data to pass to the UI method |
|
| 116 | 116 |
* |
| 117 |
- * @return The private key if successful or NULL if not |
|
| 117 |
+ * @return The private key if successful or NULL if not |
|
| 118 | 118 |
*/ |
| 119 | 119 |
EVP_PKEY * |
| 120 | 120 |
engine_load_key(const char *file, SSL_CTX *ctx); |
| ... | ... |
@@ -439,7 +439,7 @@ void management_notify_client_cr_response(unsigned mda_key_id, |
| 439 | 439 |
const struct env_set *es, |
| 440 | 440 |
const char *response); |
| 441 | 441 |
|
| 442 |
-#endif |
|
| 442 |
+#endif /* ifdef MANAGEMENT_DEF_AUTH */ |
|
| 443 | 443 |
|
| 444 | 444 |
char *management_query_pk_sig(struct management *man, const char *b64_data, |
| 445 | 445 |
const char *algorithm); |
| ... | ... |
@@ -3320,8 +3320,8 @@ management_kill_by_cid(void *arg, const unsigned long cid, const char *kill_msg) |
| 3320 | 3320 |
|
| 3321 | 3321 |
static bool |
| 3322 | 3322 |
management_client_pending_auth(void *arg, |
| 3323 |
- const unsigned long cid, |
|
| 3324 |
- const char *extra) |
|
| 3323 |
+ const unsigned long cid, |
|
| 3324 |
+ const char *extra) |
|
| 3325 | 3325 |
{
|
| 3326 | 3326 |
struct multi_context *m = (struct multi_context *) arg; |
| 3327 | 3327 |
struct multi_instance *mi = lookup_by_cid(m, cid); |
| ... | ... |
@@ -130,8 +130,8 @@ time_string(time_t t, int usec, bool show_usec, struct gc_arena *gc) |
| 130 | 130 |
struct tm *tm = localtime(&t); |
| 131 | 131 |
|
| 132 | 132 |
buf_printf(&out, "%04d-%02d-%02d %02d:%02d:%02d", |
| 133 |
- tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, |
|
| 134 |
- tm->tm_hour, tm->tm_min, tm->tm_sec); |
|
| 133 |
+ tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, |
|
| 134 |
+ tm->tm_hour, tm->tm_min, tm->tm_sec); |
|
| 135 | 135 |
|
| 136 | 136 |
if (show_usec && tv.tv_usec) |
| 137 | 137 |
{
|
| ... | ... |
@@ -310,20 +310,20 @@ ifconfig_pool_acquire(struct ifconfig_pool *pool, in_addr_t *local, in_addr_t *r |
| 310 | 310 |
switch (pool->ipv4.type) |
| 311 | 311 |
{
|
| 312 | 312 |
case IFCONFIG_POOL_30NET: |
| 313 |
- {
|
|
| 314 |
- in_addr_t b = pool->ipv4.base + (i << 2); |
|
| 315 |
- *local = b + 1; |
|
| 316 |
- *remote = b + 2; |
|
| 317 |
- break; |
|
| 318 |
- } |
|
| 313 |
+ {
|
|
| 314 |
+ in_addr_t b = pool->ipv4.base + (i << 2); |
|
| 315 |
+ *local = b + 1; |
|
| 316 |
+ *remote = b + 2; |
|
| 317 |
+ break; |
|
| 318 |
+ } |
|
| 319 | 319 |
|
| 320 | 320 |
case IFCONFIG_POOL_INDIV: |
| 321 |
- {
|
|
| 322 |
- in_addr_t b = pool->ipv4.base + i; |
|
| 323 |
- *local = 0; |
|
| 324 |
- *remote = b; |
|
| 325 |
- break; |
|
| 326 |
- } |
|
| 321 |
+ {
|
|
| 322 |
+ in_addr_t b = pool->ipv4.base + i; |
|
| 323 |
+ *local = 0; |
|
| 324 |
+ *remote = b; |
|
| 325 |
+ break; |
|
| 326 |
+ } |
|
| 327 | 327 |
|
| 328 | 328 |
default: |
| 329 | 329 |
ASSERT(0); |
| ... | ... |
@@ -683,7 +683,9 @@ ifconfig_pool_read(struct ifconfig_pool_persist *persist, struct ifconfig_pool * |
| 683 | 683 |
* was not valid |
| 684 | 684 |
*/ |
| 685 | 685 |
if (h < 0) |
| 686 |
+ {
|
|
| 686 | 687 |
h = h6; |
| 688 |
+ } |
|
| 687 | 689 |
} |
| 688 | 690 |
} |
| 689 | 691 |
|
| ... | ... |
@@ -288,7 +288,7 @@ send_auth_failed(struct context *c, const char *client_reason) |
| 288 | 288 |
} |
| 289 | 289 |
|
| 290 | 290 |
bool |
| 291 |
-send_auth_pending_messages(struct context *c, const char* extra) |
|
| 291 |
+send_auth_pending_messages(struct context *c, const char *extra) |
|
| 292 | 292 |
{
|
| 293 | 293 |
send_control_channel_string(c, "AUTH_PENDING", D_PUSH); |
| 294 | 294 |
|
| ... | ... |
@@ -1930,7 +1930,8 @@ tls_session_generate_data_channel_keys(struct tls_session *session) |
| 1930 | 1930 |
const struct session_id *server_sid = !session->opt->server ? |
| 1931 | 1931 |
&ks->session_id_remote : &session->session_id; |
| 1932 | 1932 |
|
| 1933 |
- if (!ks->authenticated) {
|
|
| 1933 |
+ if (!ks->authenticated) |
|
| 1934 |
+ {
|
|
| 1934 | 1935 |
msg(D_TLS_ERRORS, "TLS Error: key_state not authenticated"); |
| 1935 | 1936 |
goto cleanup; |
| 1936 | 1937 |
} |
| ... | ... |
@@ -8,93 +8,108 @@ static char *engine_name = "Engine for testing openvpn engine key support"; |
| 8 | 8 |
|
| 9 | 9 |
static int is_initialized = 0; |
| 10 | 10 |
|
| 11 |
-static int engine_init(ENGINE *e) |
|
| 11 |
+static int |
|
| 12 |
+engine_init(ENGINE *e) |
|
| 12 | 13 |
{
|
| 13 |
- is_initialized = 1; |
|
| 14 |
- fprintf(stderr, "ENGINE: engine_init called\n"); |
|
| 15 |
- return 1; |
|
| 14 |
+ is_initialized = 1; |
|
| 15 |
+ fprintf(stderr, "ENGINE: engine_init called\n"); |
|
| 16 |
+ return 1; |
|
| 16 | 17 |
} |
| 17 | 18 |
|
| 18 |
-static int engine_finish(ENGINE *e) |
|
| 19 |
+static int |
|
| 20 |
+engine_finish(ENGINE *e) |
|
| 19 | 21 |
{
|
| 20 |
- fprintf(stderr, "ENGINE: engine_finsh called\n"); |
|
| 21 |
- is_initialized = 0; |
|
| 22 |
- return 1; |
|
| 22 |
+ fprintf(stderr, "ENGINE: engine_finsh called\n"); |
|
| 23 |
+ is_initialized = 0; |
|
| 24 |
+ return 1; |
|
| 23 | 25 |
} |
| 24 | 26 |
|
| 25 |
-static EVP_PKEY *engine_load_key(ENGINE *e, const char *key_id, |
|
| 26 |
- UI_METHOD *ui_method, void *cb_data) |
|
| 27 |
+static EVP_PKEY * |
|
| 28 |
+engine_load_key(ENGINE *e, const char *key_id, |
|
| 29 |
+ UI_METHOD *ui_method, void *cb_data) |
|
| 27 | 30 |
{
|
| 28 |
- BIO *b; |
|
| 29 |
- EVP_PKEY *pkey; |
|
| 30 |
- PKCS8_PRIV_KEY_INFO *p8inf; |
|
| 31 |
- UI *ui; |
|
| 32 |
- char auth[256]; |
|
| 33 |
- |
|
| 34 |
- fprintf(stderr, "ENGINE: engine_load_key called\n"); |
|
| 35 |
- |
|
| 36 |
- if (!is_initialized) {
|
|
| 37 |
- fprintf(stderr, "Load Key called without correct initialization\n"); |
|
| 38 |
- return NULL; |
|
| 39 |
- } |
|
| 40 |
- b = BIO_new_file(key_id, "r"); |
|
| 41 |
- if (!b) {
|
|
| 42 |
- fprintf(stderr, "File %s does not exist or cannot be read\n", key_id); |
|
| 43 |
- return 0; |
|
| 44 |
- } |
|
| 45 |
- /* Basically read an EVP_PKEY private key file with different |
|
| 46 |
- * PEM guards --- we are a test engine */ |
|
| 47 |
- p8inf = PEM_ASN1_read_bio((d2i_of_void *)d2i_PKCS8_PRIV_KEY_INFO, |
|
| 48 |
- "TEST ENGINE KEY", b, |
|
| 49 |
- NULL, NULL, NULL); |
|
| 50 |
- BIO_free(b); |
|
| 51 |
- if (!p8inf) {
|
|
| 52 |
- fprintf(stderr, "Failed to read engine private key\n"); |
|
| 53 |
- return NULL; |
|
| 54 |
- } |
|
| 55 |
- pkey = EVP_PKCS82PKEY(p8inf); |
|
| 56 |
- |
|
| 57 |
- /* now we have a private key, pretend it had a password |
|
| 58 |
- * this verifies the password makes it through openvpn OK */ |
|
| 59 |
- ui = UI_new(); |
|
| 60 |
- |
|
| 61 |
- if (ui_method) |
|
| 62 |
- UI_set_method(ui, ui_method); |
|
| 63 |
- |
|
| 64 |
- UI_add_user_data(ui, cb_data); |
|
| 65 |
- |
|
| 66 |
- if (UI_add_input_string(ui, "enter test engine key", |
|
| 67 |
- UI_INPUT_FLAG_DEFAULT_PWD, |
|
| 68 |
- auth, 0, sizeof(auth)) == 0) {
|
|
| 69 |
- fprintf(stderr, "UI_add_input_string failed\n"); |
|
| 70 |
- goto out; |
|
| 71 |
- } |
|
| 72 |
- |
|
| 73 |
- if (UI_process(ui)) {
|
|
| 74 |
- fprintf(stderr, "UI_process failed\n"); |
|
| 75 |
- goto out; |
|
| 76 |
- } |
|
| 77 |
- |
|
| 78 |
- fprintf(stderr, "ENGINE: engine_load_key got password %s\n", auth); |
|
| 79 |
- |
|
| 80 |
- out: |
|
| 81 |
- UI_free(ui); |
|
| 82 |
- |
|
| 83 |
- return pkey; |
|
| 31 |
+ BIO *b; |
|
| 32 |
+ EVP_PKEY *pkey; |
|
| 33 |
+ PKCS8_PRIV_KEY_INFO *p8inf; |
|
| 34 |
+ UI *ui; |
|
| 35 |
+ char auth[256]; |
|
| 36 |
+ |
|
| 37 |
+ fprintf(stderr, "ENGINE: engine_load_key called\n"); |
|
| 38 |
+ |
|
| 39 |
+ if (!is_initialized) |
|
| 40 |
+ {
|
|
| 41 |
+ fprintf(stderr, "Load Key called without correct initialization\n"); |
|
| 42 |
+ return NULL; |
|
| 43 |
+ } |
|
| 44 |
+ b = BIO_new_file(key_id, "r"); |
|
| 45 |
+ if (!b) |
|
| 46 |
+ {
|
|
| 47 |
+ fprintf(stderr, "File %s does not exist or cannot be read\n", key_id); |
|
| 48 |
+ return 0; |
|
| 49 |
+ } |
|
| 50 |
+ /* Basically read an EVP_PKEY private key file with different |
|
| 51 |
+ * PEM guards --- we are a test engine */ |
|
| 52 |
+ p8inf = PEM_ASN1_read_bio((d2i_of_void *)d2i_PKCS8_PRIV_KEY_INFO, |
|
| 53 |
+ "TEST ENGINE KEY", b, |
|
| 54 |
+ NULL, NULL, NULL); |
|
| 55 |
+ BIO_free(b); |
|
| 56 |
+ if (!p8inf) |
|
| 57 |
+ {
|
|
| 58 |
+ fprintf(stderr, "Failed to read engine private key\n"); |
|
| 59 |
+ return NULL; |
|
| 60 |
+ } |
|
| 61 |
+ pkey = EVP_PKCS82PKEY(p8inf); |
|
| 62 |
+ |
|
| 63 |
+ /* now we have a private key, pretend it had a password |
|
| 64 |
+ * this verifies the password makes it through openvpn OK */ |
|
| 65 |
+ ui = UI_new(); |
|
| 66 |
+ |
|
| 67 |
+ if (ui_method) |
|
| 68 |
+ {
|
|
| 69 |
+ UI_set_method(ui, ui_method); |
|
| 70 |
+ } |
|
| 71 |
+ |
|
| 72 |
+ UI_add_user_data(ui, cb_data); |
|
| 73 |
+ |
|
| 74 |
+ if (UI_add_input_string(ui, "enter test engine key", |
|
| 75 |
+ UI_INPUT_FLAG_DEFAULT_PWD, |
|
| 76 |
+ auth, 0, sizeof(auth)) == 0) |
|
| 77 |
+ {
|
|
| 78 |
+ fprintf(stderr, "UI_add_input_string failed\n"); |
|
| 79 |
+ goto out; |
|
| 80 |
+ } |
|
| 81 |
+ |
|
| 82 |
+ if (UI_process(ui)) |
|
| 83 |
+ {
|
|
| 84 |
+ fprintf(stderr, "UI_process failed\n"); |
|
| 85 |
+ goto out; |
|
| 86 |
+ } |
|
| 87 |
+ |
|
| 88 |
+ fprintf(stderr, "ENGINE: engine_load_key got password %s\n", auth); |
|
| 89 |
+ |
|
| 90 |
+out: |
|
| 91 |
+ UI_free(ui); |
|
| 92 |
+ |
|
| 93 |
+ return pkey; |
|
| 84 | 94 |
} |
| 85 | 95 |
|
| 86 | 96 |
|
| 87 |
-static int engine_bind_fn(ENGINE *e, const char *id) |
|
| 97 |
+static int |
|
| 98 |
+engine_bind_fn(ENGINE *e, const char *id) |
|
| 88 | 99 |
{
|
| 89 |
- if (id && strcmp(id, engine_id) != 0) |
|
| 90 |
- return 0; |
|
| 91 |
- if (!ENGINE_set_id(e, engine_id) || |
|
| 92 |
- !ENGINE_set_name(e, engine_name) || |
|
| 93 |
- !ENGINE_set_init_function(e, engine_init) || |
|
| 94 |
- !ENGINE_set_finish_function(e, engine_finish) || |
|
| 95 |
- !ENGINE_set_load_privkey_function(e, engine_load_key)) |
|
| 96 |
- return 0; |
|
| 97 |
- return 1; |
|
| 100 |
+ if (id && strcmp(id, engine_id) != 0) |
|
| 101 |
+ {
|
|
| 102 |
+ return 0; |
|
| 103 |
+ } |
|
| 104 |
+ if (!ENGINE_set_id(e, engine_id) |
|
| 105 |
+ || !ENGINE_set_name(e, engine_name) |
|
| 106 |
+ || !ENGINE_set_init_function(e, engine_init) |
|
| 107 |
+ || !ENGINE_set_finish_function(e, engine_finish) |
|
| 108 |
+ || !ENGINE_set_load_privkey_function(e, engine_load_key)) |
|
| 109 |
+ {
|
|
| 110 |
+ return 0; |
|
| 111 |
+ } |
|
| 112 |
+ return 1; |
|
| 98 | 113 |
} |
| 99 | 114 |
|
| 100 | 115 |
IMPLEMENT_DYNAMIC_CHECK_FN() |