Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file test_server_thread.c |
| 3 | * \author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * \brief libnetconf2 tests - thread-safety of all server functions |
| 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
Michal Vasko | ad1cc6a | 2016-02-26 15:06:06 +0100 | [diff] [blame] | 11 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 12 | * https://opensource.org/licenses/BSD-3-Clause |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <pthread.h> |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 16 | #include <unistd.h> |
| 17 | #include <stdlib.h> |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 18 | #include <stdio.h> |
Michal Vasko | a28be9a | 2016-03-01 15:20:47 +0100 | [diff] [blame] | 19 | #include <string.h> |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 20 | #include <sys/types.h> |
| 21 | #include <sys/wait.h> |
| 22 | |
| 23 | #include <libyang/libyang.h> |
| 24 | |
| 25 | #include <session_client.h> |
| 26 | #include <session_server.h> |
| 27 | #include <log.h> |
| 28 | #include "config.h" |
| 29 | |
| 30 | /* millisec */ |
Michal Vasko | 15592cc | 2016-02-09 09:52:43 +0100 | [diff] [blame] | 31 | #define NC_ACCEPT_TIMEOUT 5000 |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 32 | /* millisec */ |
Michal Vasko | 15592cc | 2016-02-09 09:52:43 +0100 | [diff] [blame] | 33 | #define NC_PS_POLL_TIMEOUT 5000 |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 34 | /* sec */ |
Michal Vasko | 15592cc | 2016-02-09 09:52:43 +0100 | [diff] [blame] | 35 | #define CLIENT_SSH_AUTH_TIMEOUT 10 |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 36 | |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 37 | #define nc_assert(cond) if (!(cond)) { fprintf(stderr, "assert failed (%s:%d)\n", __FILE__, __LINE__); exit(1); } |
| 38 | |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 39 | pthread_barrier_t barrier; |
| 40 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 41 | #if defined(NC_ENABLED_SSH) || defined(NC_ENABLED_TLS) |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 42 | |
| 43 | static void * |
| 44 | server_thread(void *arg) |
| 45 | { |
| 46 | (void)arg; |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 47 | NC_MSG_TYPE msgtype; |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 48 | int ret; |
| 49 | struct nc_pollsession *ps; |
| 50 | struct nc_session *session; |
| 51 | |
| 52 | ps = nc_ps_new(); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 53 | nc_assert(ps); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 54 | |
| 55 | pthread_barrier_wait(&barrier); |
| 56 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 57 | #if defined(NC_ENABLED_SSH) && defined(NC_ENABLED_TLS) |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 58 | msgtype = nc_accept(NC_ACCEPT_TIMEOUT, &session); |
| 59 | nc_assert(msgtype == NC_MSG_HELLO); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 60 | |
| 61 | nc_ps_add_session(ps, session); |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 62 | ret = nc_ps_poll(ps, NC_PS_POLL_TIMEOUT, NULL); |
| 63 | nc_assert(ret & NC_PSPOLL_RPC); |
Michal Vasko | e1a64ec | 2016-03-01 12:21:58 +0100 | [diff] [blame] | 64 | nc_ps_clear(ps, 0, NULL); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 65 | #endif |
| 66 | |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 67 | msgtype = nc_accept(NC_ACCEPT_TIMEOUT, &session); |
| 68 | nc_assert(msgtype == NC_MSG_HELLO); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 69 | |
| 70 | nc_ps_add_session(ps, session); |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 71 | ret = nc_ps_poll(ps, NC_PS_POLL_TIMEOUT, NULL); |
| 72 | nc_assert(ret & NC_PSPOLL_RPC); |
Michal Vasko | e1a64ec | 2016-03-01 12:21:58 +0100 | [diff] [blame] | 73 | nc_ps_clear(ps, 0, NULL); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 74 | |
| 75 | nc_ps_free(ps); |
| 76 | |
| 77 | nc_thread_destroy(); |
| 78 | return NULL; |
| 79 | } |
| 80 | |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 81 | static void * |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 82 | add_endpt_thread(void *arg) |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 83 | { |
| 84 | (void)arg; |
| 85 | int ret; |
| 86 | |
| 87 | pthread_barrier_wait(&barrier); |
| 88 | |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 89 | ret = nc_server_add_endpt("tertiary"); |
| 90 | nc_assert(!ret); |
| 91 | |
| 92 | return NULL; |
| 93 | } |
| 94 | |
| 95 | static void * |
| 96 | del_endpt_thread(void *arg) |
| 97 | { |
| 98 | (void)arg; |
| 99 | int ret; |
| 100 | |
| 101 | pthread_barrier_wait(&barrier); |
| 102 | |
| 103 | ret = nc_server_del_endpt("secondary"); |
| 104 | nc_assert(!ret); |
| 105 | |
| 106 | return NULL; |
| 107 | } |
| 108 | |
| 109 | #endif /* NC_ENABLED_SSH || NC_ENABLED_TLS */ |
| 110 | |
| 111 | #ifdef NC_ENABLED_SSH |
| 112 | |
| 113 | static void * |
| 114 | ssh_endpt_set_address_thread(void *arg) |
| 115 | { |
| 116 | (void)arg; |
| 117 | int ret; |
| 118 | |
| 119 | pthread_barrier_wait(&barrier); |
| 120 | |
| 121 | ret = nc_server_ssh_endpt_set_address("quaternary", "0.0.0.0"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 122 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 123 | |
| 124 | return NULL; |
| 125 | } |
| 126 | |
| 127 | static void * |
| 128 | ssh_endpt_set_port_thread(void *arg) |
| 129 | { |
| 130 | (void)arg; |
| 131 | int ret; |
| 132 | |
| 133 | pthread_barrier_wait(&barrier); |
| 134 | |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 135 | ret = nc_server_ssh_endpt_set_port("quaternary", 6003); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 136 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 137 | |
| 138 | return NULL; |
| 139 | } |
| 140 | |
| 141 | static void * |
| 142 | ssh_endpt_set_hostkey_thread(void *arg) |
| 143 | { |
| 144 | (void)arg; |
| 145 | int ret; |
| 146 | |
| 147 | pthread_barrier_wait(&barrier); |
| 148 | |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 149 | ret = nc_server_ssh_endpt_add_hostkey("main", TESTS_DIR"/data/key_dsa"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 150 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 151 | |
| 152 | return NULL; |
| 153 | } |
| 154 | |
| 155 | static void * |
| 156 | ssh_endpt_set_banner_thread(void *arg) |
| 157 | { |
| 158 | (void)arg; |
| 159 | int ret; |
| 160 | |
| 161 | pthread_barrier_wait(&barrier); |
| 162 | |
| 163 | ret = nc_server_ssh_endpt_set_banner("main", "Howdy, partner!"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 164 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 165 | |
| 166 | return NULL; |
| 167 | } |
| 168 | |
| 169 | static void * |
| 170 | ssh_endpt_set_auth_methods_thread(void *arg) |
| 171 | { |
| 172 | (void)arg; |
| 173 | int ret; |
| 174 | |
| 175 | pthread_barrier_wait(&barrier); |
| 176 | |
| 177 | ret = nc_server_ssh_endpt_set_auth_methods("main", NC_SSH_AUTH_PUBLICKEY | NC_SSH_AUTH_PASSWORD | NC_SSH_AUTH_INTERACTIVE); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 178 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 179 | |
| 180 | return NULL; |
| 181 | } |
| 182 | |
| 183 | static void * |
| 184 | ssh_endpt_set_auth_attempts_thread(void *arg) |
| 185 | { |
| 186 | (void)arg; |
| 187 | int ret; |
| 188 | |
| 189 | pthread_barrier_wait(&barrier); |
| 190 | |
| 191 | ret = nc_server_ssh_endpt_set_auth_attempts("main", 2); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 192 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 193 | |
| 194 | return NULL; |
| 195 | } |
| 196 | |
| 197 | static void * |
| 198 | ssh_endpt_set_auth_timeout_thread(void *arg) |
| 199 | { |
| 200 | (void)arg; |
| 201 | int ret; |
| 202 | |
| 203 | pthread_barrier_wait(&barrier); |
| 204 | |
| 205 | ret = nc_server_ssh_endpt_set_auth_timeout("main", 5); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 206 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 207 | |
| 208 | return NULL; |
| 209 | } |
| 210 | |
| 211 | static void * |
| 212 | ssh_endpt_add_authkey_thread(void *arg) |
| 213 | { |
| 214 | (void)arg; |
| 215 | int ret; |
| 216 | |
| 217 | pthread_barrier_wait(&barrier); |
| 218 | |
Michal Vasko | b477b22 | 2016-02-09 14:30:15 +0100 | [diff] [blame] | 219 | ret = nc_server_ssh_endpt_add_authkey("main", TESTS_DIR"/data/key_rsa.pub", "test3"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 220 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 221 | |
| 222 | return NULL; |
| 223 | } |
| 224 | |
| 225 | static void * |
| 226 | ssh_endpt_del_authkey_thread(void *arg) |
| 227 | { |
| 228 | (void)arg; |
| 229 | int ret; |
| 230 | |
| 231 | pthread_barrier_wait(&barrier); |
| 232 | |
Michal Vasko | b477b22 | 2016-02-09 14:30:15 +0100 | [diff] [blame] | 233 | ret = nc_server_ssh_endpt_del_authkey("main", TESTS_DIR"/data/key_ecdsa.pub", "test2"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 234 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 235 | |
| 236 | return NULL; |
| 237 | } |
| 238 | |
Michal Vasko | 693eb11 | 2016-02-18 13:28:49 +0100 | [diff] [blame] | 239 | static int |
| 240 | ssh_hostkey_check_clb(const char *hostname, ssh_session session) |
| 241 | { |
| 242 | (void)hostname; |
| 243 | (void)session; |
| 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 248 | static void * |
| 249 | ssh_client_thread(void *arg) |
| 250 | { |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 251 | int ret, read_pipe = *(int *)arg; |
| 252 | char buf[9]; |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 253 | struct nc_session *session; |
| 254 | |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 255 | ret = read(read_pipe, buf, 9); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 256 | nc_assert(ret == 9); |
| 257 | nc_assert(!strncmp(buf, "ssh_ready", 9)); |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 258 | |
Michal Vasko | 693eb11 | 2016-02-18 13:28:49 +0100 | [diff] [blame] | 259 | /* skip the knownhost check */ |
| 260 | nc_client_ssh_set_auth_hostkey_check_clb(ssh_hostkey_check_clb); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 261 | |
Michal Vasko | 693eb11 | 2016-02-18 13:28:49 +0100 | [diff] [blame] | 262 | ret = nc_client_ssh_set_username("test"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 263 | nc_assert(!ret); |
Michal Vasko | 693eb11 | 2016-02-18 13:28:49 +0100 | [diff] [blame] | 264 | |
| 265 | ret = nc_client_ssh_add_keypair(TESTS_DIR"/data/key_dsa.pub", TESTS_DIR"/data/key_dsa"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 266 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 267 | |
| 268 | nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PUBLICKEY, 1); |
| 269 | nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PASSWORD, -1); |
| 270 | nc_client_ssh_set_auth_pref(NC_SSH_AUTH_INTERACTIVE, -1); |
| 271 | |
Michal Vasko | 693eb11 | 2016-02-18 13:28:49 +0100 | [diff] [blame] | 272 | session = nc_connect_ssh("127.0.0.1", 6001, NULL); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 273 | nc_assert(session); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 274 | |
Michal Vasko | e1a64ec | 2016-03-01 12:21:58 +0100 | [diff] [blame] | 275 | nc_session_free(session, NULL); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 276 | |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 277 | fprintf(stdout, "SSH client finished.\n"); |
| 278 | |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 279 | nc_thread_destroy(); |
| 280 | return NULL; |
| 281 | } |
| 282 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 283 | #endif /* NC_ENABLED_SSH */ |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 284 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 285 | #ifdef NC_ENABLED_TLS |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 286 | |
| 287 | static void * |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 288 | tls_endpt_set_address_thread(void *arg) |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 289 | { |
| 290 | (void)arg; |
| 291 | int ret; |
| 292 | |
| 293 | pthread_barrier_wait(&barrier); |
| 294 | |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 295 | ret = nc_server_tls_endpt_set_address("quaternary", "0.0.0.0"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 296 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 297 | |
| 298 | return NULL; |
| 299 | } |
| 300 | |
| 301 | static void * |
| 302 | tls_endpt_set_port_thread(void *arg) |
| 303 | { |
| 304 | (void)arg; |
| 305 | int ret; |
| 306 | |
| 307 | pthread_barrier_wait(&barrier); |
| 308 | |
| 309 | ret = nc_server_tls_endpt_set_port("quaternary", 6505); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 310 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 311 | |
| 312 | return NULL; |
| 313 | } |
| 314 | |
| 315 | static void * |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 316 | tls_endpt_set_cert_thread(void *arg) |
| 317 | { |
| 318 | (void)arg; |
| 319 | int ret; |
| 320 | |
| 321 | pthread_barrier_wait(&barrier); |
| 322 | |
| 323 | ret = nc_server_tls_endpt_set_cert("quaternary", "MIIEKjCCAxICCQDqSTPpuoUZkzANBgkqhkiG9w0BAQUFADBYMQswCQYDVQQGEwJB\n" |
| 324 | "VTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0\n" |
| 325 | "cyBQdHkgTHRkMREwDwYDVQQDDAhzZXJ2ZXJjYTAeFw0xNjAyMDgxMTE0MzdaFw0y\n" |
| 326 | "NjAyMDUxMTE0MzdaMFYxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRl\n" |
| 327 | "MSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxDzANBgNVBAMMBnNl\n" |
| 328 | "cnZlcjCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAOqI7Y3w5r8kD9WZ\n" |
| 329 | "CMAaa/e3ig7nm76aIJUR0Xb1bk6X/4FNVQKwEJsBodOYupZvE5FZdZ6DJSMSyQ3F\n" |
| 330 | "rJWnlZ+isr7F9B4bELV8Kj6sJGuVAr+mpcH/4rwL3DaXF9Y9Lf7iBgiOHUoip80A\n" |
| 331 | "sn9BU4q80JI6w2VHd5ng4TUE67gmpRleIHzViKt3taBrsAJ9bS5bvaE6xOB8zKYG\n" |
| 332 | "zRFOsDZrEqqcBsVIWC6EmjO29HS5qj/mXM0ktFGnNDxTZHoRkNgmCE/NH+fNKOFx\n" |
| 333 | "raCwlFBpKemAky+GdgngRGiQAVowyAx/nSmCFAalKc+E4ddoFwD/oft6iOvvXqaX\n" |
| 334 | "h6368wEQ7Hy48FDcUCbHtUEgK4wMrX9BSrRh6zkXO1tE4ghb0dM2qFDS0ypO3p04\n" |
| 335 | "kUPa31mTgLuOH1LzwmlwxOs113mlYKCgqOFR5YaN+nq1HI5RATPo5NvCMpG2RrQW\n" |
| 336 | "+ooCr2GtbT0oHmJv8yaBVY0HJ69eLnIv37dfjWvoTiBKBBIisXAD5Nm9rwSjZUSF\n" |
| 337 | "u1iyd7u2YrkBCUzZuvt3BOPpX8GgQgagU6BPnac76FF6DMhRUXlBXdTuWsbuH14L\n" |
| 338 | "dNIzGjkMZhNL/Tpkf6S/z1iH5VReGc+clTjWGg1XO5fr3mNKBGa7hDydIZRIMbgs\n" |
| 339 | "y63DIY7n5dqhNkO30CGmr/9TagVZAgMBAAEwDQYJKoZIhvcNAQEFBQADggEBAEVr\n" |
| 340 | "4skCpwuMuR+3WCmH6S17sYzWMYogJCGQdbZtFqmf4W3EDlNClk4HszAeUdmROMj6\n" |
| 341 | "MdqNDUnDM/GPxHB4Aje1DZOH1h68CCAl9W32LFRDC0KaUOquuYIG4rnZADJl6P4T\n" |
| 342 | "WVlaXfuE2bQjE7iYPhWGNWJtkb7JNIHmB8EAIa4tt3+XJs+vZiSpVDpiP2ucgrCn\n" |
| 343 | "BltsK0iOMPDLVlXdk1hpU5HvlMXdBHQebfTiCFDQSX7ViKc4wSJUHDt4CyoCzchY\n" |
| 344 | "mbQIcTc7uNDE5chQWV8Z3Vxkp4yuqZM3HdLskoo4IgFDOoj8eCAi+58+YRuKpaEQ\n" |
| 345 | "fWt+A9rvlaOApWryMW4="); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 346 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 347 | |
| 348 | nc_thread_destroy(); |
| 349 | return NULL; |
| 350 | } |
| 351 | |
| 352 | static void * |
| 353 | tls_endpt_set_key_thread(void *arg) |
| 354 | { |
| 355 | (void)arg; |
| 356 | int ret; |
| 357 | |
| 358 | pthread_barrier_wait(&barrier); |
| 359 | |
| 360 | ret = nc_server_tls_endpt_set_key("quaternary", "MIIJKAIBAAKCAgEA6ojtjfDmvyQP1ZkIwBpr97eKDuebvpoglRHRdvVuTpf/gU1V\n" |
| 361 | "ArAQmwGh05i6lm8TkVl1noMlIxLJDcWslaeVn6KyvsX0HhsQtXwqPqwka5UCv6al\n" |
| 362 | "wf/ivAvcNpcX1j0t/uIGCI4dSiKnzQCyf0FTirzQkjrDZUd3meDhNQTruCalGV4g\n" |
| 363 | "fNWIq3e1oGuwAn1tLlu9oTrE4HzMpgbNEU6wNmsSqpwGxUhYLoSaM7b0dLmqP+Zc\n" |
| 364 | "zSS0Uac0PFNkehGQ2CYIT80f580o4XGtoLCUUGkp6YCTL4Z2CeBEaJABWjDIDH+d\n" |
| 365 | "KYIUBqUpz4Th12gXAP+h+3qI6+9eppeHrfrzARDsfLjwUNxQJse1QSArjAytf0FK\n" |
| 366 | "tGHrORc7W0TiCFvR0zaoUNLTKk7enTiRQ9rfWZOAu44fUvPCaXDE6zXXeaVgoKCo\n" |
| 367 | "4VHlho36erUcjlEBM+jk28IykbZGtBb6igKvYa1tPSgeYm/zJoFVjQcnr14uci/f\n" |
| 368 | "t1+Na+hOIEoEEiKxcAPk2b2vBKNlRIW7WLJ3u7ZiuQEJTNm6+3cE4+lfwaBCBqBT\n" |
| 369 | "oE+dpzvoUXoMyFFReUFd1O5axu4fXgt00jMaOQxmE0v9OmR/pL/PWIflVF4Zz5yV\n" |
| 370 | "ONYaDVc7l+veY0oEZruEPJ0hlEgxuCzLrcMhjufl2qE2Q7fQIaav/1NqBVkCAwEA\n" |
| 371 | "AQKCAgAeRZw75Oszoqj0jfMmMILdD3Cfad+dY3FvLESYESeyt0XAX8XoOed6ymQj\n" |
| 372 | "1qPGxQGGkkBvPEgv1b3jrC8Rhfb3Ct39Z7mRpTar5iHhwwBUboBTUmQ0vR173iAH\n" |
| 373 | "X8sw2Oa17mCO/CDlr8Fu4Xcom7r3vlVBepo72VSjpPYMjN0MANjwhEi3NCyWzTXB\n" |
| 374 | "RgUK3TuZbzfzto0w2Irlpx0S7dAqxfk70jXBgwv2vSDWKfg1lL1X0BkMVX98xpMk\n" |
| 375 | "cjMW2muSqp4KBtTma4GqT6z0f7Y1Bs3lGLZmvPlBXxQVVvkFtiQsENCtSd/h17Gk\n" |
| 376 | "2mb4EbReaaBzwCYqJdRWtlpJ54kzy8U00co+Yn//ZS7sbbIDkqHPnXkpdIr+0rED\n" |
| 377 | "MlOw2Y3vRZCxqZFqfWCW0uzhwKqk2VoYqtDL+ORKG/aG/KTBQ4Y71Uh+7aabPwj5\n" |
| 378 | "R+NaVMjbqmrVeH70eKjoNVgcNYY1C9rGVF1d+LQEm7UsqS0DPp4wN9QKLAqIfuar\n" |
| 379 | "AhQBhZy1R7Sj1r5macD9DsGxsurM4mHZV0LNmYLZiFHjTUb6iRSPD5RBFW80vcNt\n" |
| 380 | "xZ0cxmkLtxrj/DVyExV11Cl0SbZLLa9mScYvxdl/qZutXt3PQyab0NiYxGzCD2Rn\n" |
| 381 | "LkCyxkh1vuHHjhvIWYfbd2VgZB/qGr+o9T07FGfMCu23//fugQKCAQEA9UH38glH\n" |
| 382 | "/rAjZ431sv6ryUEFY8I2FyLTijtvoj9CNGcQn8vJQAHvUPfMdyqDoum6wgcTmG+U\n" |
| 383 | "XA6mZzpGQCiY8JW5CoItgXRoYgNzpvVVe2aLf51QGtNLLEFpNDMpCtI+I+COpAmG\n" |
| 384 | "vWAukku0pZfRjm9eb1ydvTpHlFC9+VhVUsLzw3VtSC5PVW6r65mZcYcB6SFVPap+\n" |
| 385 | "31ENP/9jOMFoymh57lSMZJMxTEA5b0l2miFb9Rp906Zqiud5zv2jIqF6gL70giW3\n" |
| 386 | "ovVxR7LGKKTKIa9pxawHwB6Ithygs7YoJkjF2dm8pZTMZKsQN92K70XGj07SmYRL\n" |
| 387 | "ZpkVD7i+cqbbKQKCAQEA9M6580Rcw6W0twfcy0/iB4U5ZS52EcCjW8vHlL+MpUo7\n" |
| 388 | "YvXadSgV1ZaM28zW/ZGk3wE0zy1YT5s30SQkm0NiWN3t/J0l19ccAOxlPWfjhF7v\n" |
| 389 | "IQZr7XMo5HeaK0Ak5+68J6bx6KgcXmlJOup7INaE8DyGXB6vd4K6957IXyqs3/bf\n" |
| 390 | "JAUmz49hnveCfLFdTVVT/Uq4IoPKfQSbSZc0BvPBsnBCF164l4jllGBaWS302dhg\n" |
| 391 | "W4cgxzG0SZGgNwow4AhB+ygiiS8yvOa7UcHfUObVrzWeeq9mYSQ1PkvUTjkWR2/Y\n" |
| 392 | "8xy7WP0TRBdJOVSs90H51lerEDGNQWvQvI97S9ZOsQKCAQB59u9lpuXtqwxAQCFy\n" |
| 393 | "fSFSuQoEHR2nDcOjF4GhbtHum15yCPaw5QVs/33nuPWze4ZLXReKk9p0mTh5V0p+\n" |
| 394 | "N3IvGlXl+uzEVu5d55eI7LIw5sLymHmwjWjxvimiMtrzLbCHSPHGc5JU9NLUH9/b\n" |
| 395 | "BY/JxGpy+NzcsHHOOQTwTdRIjviIOAo7fgQn2RyX0k+zXE8/7zqjqvji9zyemdNu\n" |
| 396 | "8we4uJICSntyvJwkbj/hrufTKEnBrwXpzfVn1EsH+6w32ZPBGLUhT75txJ8r56SR\n" |
| 397 | "q7l1XPU9vxovmT+lSMFF/Y0j1MbHWnds5H1shoFPNtYTvWBL/gfPHjIc+H23zsiu\n" |
| 398 | "3XlZAoIBAC2xB/Pnpoi9vOUMiqFH36AXtYa1DURy+AqCFlYlClMvb7YgvQ1w1eJv\n" |
| 399 | "nwrHSLk7HdKhnwGsLPduuRRH8q0n/osnoOutSQroE0n41UyIv2ZNccRwNmSzQcai\n" |
| 400 | "rBu2dSz02hlsh2otNl5IuGpOqXyPjXBpW4qGD6n2tH7THALnLC0BHtTSQVQsJsRM\n" |
| 401 | "3gX39LoiWvLDp2qJvplm6rTpi8Rgap6rZSqHe1yNKIxxD2vlr/WY9SMgLXYASO4S\n" |
| 402 | "SBz9wfGOmQIPk6KXNJkdV4kC7nNjIi75iwLLCgjHgUiHTrDq5sWekpeNnUoWsinb\n" |
| 403 | "Tsdsjnv3zHG9GyiClyLGxMbs4M5eyYECggEBAKuC8ZMpdIrjk6tERYB6g0LnQ7mW\n" |
| 404 | "8XYbDFAmLYMLs9yfG2jcjVbsW9Kugsr+3poUUv/q+hNO3jfY4HazhZDa0MalgNPo\n" |
| 405 | "Swr/VNRnkck40x2ovFb989J7yl++zTrnIrax9XRH1V0cNu+Kj7OMwZ2RRfbNv5JB\n" |
| 406 | "dOZPvkfqyIKFmbQgYbtD66rHuzNOfJpzqr/WVLO57/zzW8245NKG2B6B0oXkei/K\n" |
| 407 | "qDY0DAbHR3i3EOj1NPtVI1FC/xX8R9BREaid458bqoHJKuInrGcBjaUI9Cvymv8T\n" |
| 408 | "bstUgD6NPbJR4Sm6vrLeUqzjWZP3t1+Z6DjXmnpR2vvhMU/FWb//21p/88o=", 1); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 409 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 410 | |
| 411 | nc_thread_destroy(); |
| 412 | return NULL; |
| 413 | } |
| 414 | |
| 415 | static void * |
| 416 | tls_endpt_add_trusted_cert_thread(void *arg) |
| 417 | { |
| 418 | (void)arg; |
| 419 | int ret; |
| 420 | |
| 421 | pthread_barrier_wait(&barrier); |
| 422 | |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 423 | ret = nc_server_tls_endpt_add_trusted_cert("quaternary", "cert1", "MIIDgzCCAmugAwIBAgIJAL+y0WMRGax0MA0GCSqGSIb3DQEBBQUAMFgxCzAJBgNV\n" |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 424 | "BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX\n" |
| 425 | "aWRnaXRzIFB0eSBMdGQxETAPBgNVBAMMCGNsaWVudGNhMB4XDTE2MDExMTEyMTAx\n" |
| 426 | "OVoXDTE4MTAzMTEyMTAxOVowWDELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUt\n" |
| 427 | "U3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDERMA8GA1UE\n" |
| 428 | "AwwIY2xpZW50Y2EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCw7Eyq\n" |
| 429 | "5T5tX6tAv5DHHfWNuaD/a3gVIBlGRWMAXkFWWJEa3o6leIjKxoDnL6tcBWNVJ+Gw\n" |
| 430 | "32MHerpHY6o5czsEHQ2XsOgodyFqe5cvx0kjQbjYQqnIMrslcdvSYuNe/ItqFP/w\n" |
| 431 | "uxb6kQbCYnCQKd/qhdhfoXjIHcnXpZzMCPKQ/uqls7LANJymtQkAuzydlf3+UqoG\n" |
| 432 | "4oo04GXK1Dc0A12cgCXxf+kWx7x34ctx2VEvDsJzw6LiZm8czOWjMFcuqqm/+kla\n" |
| 433 | "N3+6O7Z1kZlft/KNSrOYtc45xKNoSVrdVwFLkxipVDfOql6/DmWfE8iVmlX3QflO\n" |
| 434 | "u3+fzZZQpR5jYzUNAgMBAAGjUDBOMB0GA1UdDgQWBBTjBbQJ6p/mjnjBWXLgXXXW\n" |
| 435 | "a3ieoTAfBgNVHSMEGDAWgBTjBbQJ6p/mjnjBWXLgXXXWa3ieoTAMBgNVHRMEBTAD\n" |
| 436 | "AQH/MA0GCSqGSIb3DQEBBQUAA4IBAQAZr9b0YTaDV5XZr/QQPP1pvHkN3Ezbm9F4\n" |
| 437 | "MiYe4e0QnM9JtjNLDKq1dDnqVDQ/BYdupWWh0398tObFACssWkm4aubPG7LVh5Ck\n" |
| 438 | "O8I8i/GHiXYLmYT22hslWe5dFvidUICkTXoj1h5X2vwfBrNTI1+gnVXXw842xCvU\n" |
| 439 | "sgq28vGMSXLSYKBNaP/llXNmqW35oLs6CwVuiCL7Go0IDIOmiXN2bssb87hZSw3B\n" |
| 440 | "6iwU78wYshJUGZjLaK9PuMvFYJLFWSAePA2Yb+aEv80wMbX1oANSryU7Uf5BJk8V\n" |
| 441 | "kO3mlRDh2b1/5Gb5xA2vU2z3ReHdPNy6qSx0Mk4XJvQw9FsVHZ13"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 442 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 443 | |
| 444 | nc_thread_destroy(); |
| 445 | return NULL; |
| 446 | } |
| 447 | |
| 448 | static void * |
| 449 | tls_endpt_set_trusted_ca_paths_thread(void *arg) |
| 450 | { |
| 451 | (void)arg; |
| 452 | int ret; |
| 453 | |
| 454 | pthread_barrier_wait(&barrier); |
| 455 | |
Michal Vasko | b477b22 | 2016-02-09 14:30:15 +0100 | [diff] [blame] | 456 | ret = nc_server_tls_endpt_set_trusted_ca_paths("quaternary", TESTS_DIR"/data/serverca.pem", "data"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 457 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 458 | |
| 459 | nc_thread_destroy(); |
| 460 | return NULL; |
| 461 | } |
| 462 | |
| 463 | static void * |
| 464 | tls_endpt_clear_certs_thread(void *arg) |
| 465 | { |
| 466 | (void)arg; |
| 467 | |
| 468 | pthread_barrier_wait(&barrier); |
| 469 | |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 470 | nc_server_tls_endpt_del_trusted_cert("quaternary", "cert1"); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 471 | |
| 472 | return NULL; |
| 473 | } |
| 474 | |
| 475 | static void * |
| 476 | tls_endpt_set_crl_paths_thread(void *arg) |
| 477 | { |
| 478 | (void)arg; |
| 479 | int ret; |
| 480 | |
| 481 | pthread_barrier_wait(&barrier); |
| 482 | |
| 483 | ret = nc_server_tls_endpt_set_crl_paths("quaternary", NULL, "data"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 484 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 485 | |
| 486 | nc_thread_destroy(); |
| 487 | return NULL; |
| 488 | } |
| 489 | |
| 490 | static void * |
| 491 | tls_endpt_clear_crls_thread(void *arg) |
| 492 | { |
| 493 | (void)arg; |
| 494 | |
| 495 | pthread_barrier_wait(&barrier); |
| 496 | |
| 497 | nc_server_tls_endpt_clear_crls("quaternary"); |
| 498 | |
| 499 | return NULL; |
| 500 | } |
| 501 | |
| 502 | static void * |
| 503 | tls_endpt_add_ctn_thread(void *arg) |
| 504 | { |
| 505 | (void)arg; |
| 506 | int ret; |
| 507 | |
| 508 | pthread_barrier_wait(&barrier); |
| 509 | |
| 510 | ret = nc_server_tls_endpt_add_ctn("main", 0, "02:F0:F1:F2:F3:F4:F5:F6:F7:F8:F9:10:11:12:EE:FF:A0:A1:A2:A3", |
| 511 | NC_TLS_CTN_SAN_IP_ADDRESS, NULL); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 512 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 513 | |
| 514 | return NULL; |
| 515 | } |
| 516 | |
| 517 | static void * |
| 518 | tls_endpt_del_ctn_thread(void *arg) |
| 519 | { |
| 520 | (void)arg; |
| 521 | int ret; |
| 522 | |
| 523 | pthread_barrier_wait(&barrier); |
| 524 | |
| 525 | ret = nc_server_tls_endpt_del_ctn("main", -1, NULL, NC_TLS_CTN_SAN_ANY, NULL); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 526 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 527 | |
| 528 | return NULL; |
| 529 | } |
| 530 | |
| 531 | static void * |
| 532 | tls_client_thread(void *arg) |
| 533 | { |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 534 | int ret, read_pipe = *(int *)arg; |
| 535 | char buf[9]; |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 536 | struct nc_session *session; |
| 537 | |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 538 | ret = read(read_pipe, buf, 9); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 539 | nc_assert(ret == 9); |
| 540 | nc_assert(!strncmp(buf, "tls_ready", 9)); |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 541 | |
Michal Vasko | b477b22 | 2016-02-09 14:30:15 +0100 | [diff] [blame] | 542 | ret = nc_client_tls_set_cert_key_paths(TESTS_DIR"/data/client.crt", TESTS_DIR"/data/client.key"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 543 | nc_assert(!ret); |
Michal Vasko | bc2ae55 | 2016-02-09 14:38:47 +0100 | [diff] [blame] | 544 | ret = nc_client_tls_set_trusted_ca_paths(NULL, TESTS_DIR"/data"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 545 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 546 | |
| 547 | session = nc_connect_tls("127.0.0.1", 6501, NULL); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 548 | nc_assert(session); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 549 | |
Michal Vasko | e1a64ec | 2016-03-01 12:21:58 +0100 | [diff] [blame] | 550 | nc_session_free(session, NULL); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 551 | |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 552 | fprintf(stdout, "TLS client finished.\n"); |
| 553 | |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 554 | nc_thread_destroy(); |
| 555 | return NULL; |
| 556 | } |
| 557 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 558 | #endif /* NC_ENABLED_TLS */ |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 559 | |
| 560 | static void *(*thread_funcs[])(void *) = { |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 561 | #if defined(NC_ENABLED_SSH) || defined(NC_ENABLED_TLS) |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 562 | server_thread, |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 563 | add_endpt_thread, |
| 564 | del_endpt_thread, |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 565 | #endif |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 566 | #ifdef NC_ENABLED_SSH |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 567 | ssh_endpt_set_address_thread, |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 568 | ssh_endpt_set_port_thread, |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 569 | ssh_endpt_set_hostkey_thread, |
| 570 | ssh_endpt_set_banner_thread, |
| 571 | ssh_endpt_set_auth_methods_thread, |
| 572 | ssh_endpt_set_auth_attempts_thread, |
| 573 | ssh_endpt_set_auth_timeout_thread, |
| 574 | ssh_endpt_add_authkey_thread, |
| 575 | ssh_endpt_del_authkey_thread, |
| 576 | #endif |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 577 | #ifdef NC_ENABLED_TLS |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 578 | tls_endpt_set_address_thread, |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 579 | tls_endpt_set_port_thread, |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 580 | tls_endpt_set_cert_thread, |
| 581 | tls_endpt_set_key_thread, |
| 582 | tls_endpt_add_trusted_cert_thread, |
| 583 | tls_endpt_set_trusted_ca_paths_thread, |
| 584 | tls_endpt_clear_certs_thread, |
| 585 | tls_endpt_set_crl_paths_thread, |
| 586 | tls_endpt_clear_crls_thread, |
| 587 | tls_endpt_add_ctn_thread, |
| 588 | tls_endpt_del_ctn_thread, |
| 589 | #endif |
| 590 | }; |
| 591 | |
| 592 | const int thread_count = sizeof thread_funcs / sizeof *thread_funcs; |
| 593 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 594 | #if defined(NC_ENABLED_SSH) && defined(NC_ENABLED_TLS) |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 595 | const int client_count = 2; |
| 596 | pid_t pids[2]; |
| 597 | int pipes[4]; |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 598 | #else |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 599 | const int client_count = 1; |
| 600 | pid_t pids[1]; |
| 601 | int pipes[2]; |
| 602 | #endif |
| 603 | |
| 604 | static void |
| 605 | client_fork(void) |
| 606 | { |
| 607 | int ret, clients = 0; |
| 608 | |
| 609 | #ifdef NC_ENABLED_SSH |
| 610 | pipe(pipes + clients * 2); |
| 611 | |
| 612 | if (!(pids[clients] = fork())) { |
| 613 | nc_client_init(); |
| 614 | |
Michal Vasko | 7f1c0ef | 2016-03-11 11:13:06 +0100 | [diff] [blame] | 615 | ret = nc_client_set_schema_searchpath(TESTS_DIR"/../schemas"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 616 | nc_assert(!ret); |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 617 | |
| 618 | /* close write */ |
| 619 | close(pipes[clients * 2 + 1]); |
| 620 | ssh_client_thread(&pipes[clients * 2]); |
| 621 | close(pipes[clients * 2]); |
| 622 | nc_client_destroy(); |
| 623 | exit(0); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 624 | } |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 625 | /* close read */ |
| 626 | close(pipes[clients * 2]); |
| 627 | |
| 628 | ++clients; |
| 629 | #endif |
| 630 | |
| 631 | #ifdef NC_ENABLED_TLS |
| 632 | pipe(pipes + clients * 2); |
| 633 | |
| 634 | if (!(pids[clients] = fork())) { |
| 635 | nc_client_init(); |
| 636 | |
Michal Vasko | 7f1c0ef | 2016-03-11 11:13:06 +0100 | [diff] [blame] | 637 | ret = nc_client_set_schema_searchpath(TESTS_DIR"/../schemas"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 638 | nc_assert(!ret); |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 639 | |
| 640 | /* close write */ |
| 641 | close(pipes[clients * 2 + 1]); |
| 642 | tls_client_thread(&pipes[clients * 2]); |
| 643 | close(pipes[clients * 2]); |
| 644 | nc_client_destroy(); |
| 645 | exit(0); |
| 646 | } |
| 647 | /* close read */ |
| 648 | close(pipes[clients * 2]); |
| 649 | |
| 650 | ++clients; |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 651 | #endif |
| 652 | } |
| 653 | |
| 654 | int |
| 655 | main(void) |
| 656 | { |
| 657 | struct ly_ctx *ctx; |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 658 | int ret, i, clients = 0; |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 659 | pthread_t tids[thread_count]; |
| 660 | |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 661 | nc_verbosity(NC_VERB_VERBOSE); |
| 662 | |
| 663 | client_fork(); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 664 | |
| 665 | ctx = ly_ctx_new(TESTS_DIR"/../schemas"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 666 | nc_assert(ctx); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 667 | ly_ctx_load_module(ctx, "ietf-netconf", NULL); |
| 668 | nc_server_init(ctx); |
| 669 | |
| 670 | pthread_barrier_init(&barrier, NULL, thread_count); |
| 671 | |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 672 | ret = nc_server_add_endpt("main"); |
| 673 | nc_assert(!ret); |
| 674 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 675 | #ifdef NC_ENABLED_SSH |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 676 | /* do first, so that client can connect on SSH */ |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 677 | ret = nc_server_ssh_endpt_set_address("main", "0.0.0.0"); |
| 678 | nc_assert(!ret); |
| 679 | ret = nc_server_ssh_endpt_set_port("main", 6001); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 680 | nc_assert(!ret); |
Michal Vasko | b477b22 | 2016-02-09 14:30:15 +0100 | [diff] [blame] | 681 | ret = nc_server_ssh_endpt_add_authkey("main", TESTS_DIR"/data/key_dsa.pub", "test"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 682 | nc_assert(!ret); |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 683 | ret = nc_server_ssh_endpt_add_hostkey("main", TESTS_DIR"/data/key_rsa"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 684 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 685 | |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 686 | /* client ready */ |
| 687 | ret = write(pipes[clients * 2 + 1], "ssh_ready", 9); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 688 | nc_assert(ret == 9); |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 689 | ++clients; |
| 690 | |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 691 | /* for ssh_endpt_del_authkey */ |
Michal Vasko | b477b22 | 2016-02-09 14:30:15 +0100 | [diff] [blame] | 692 | ret = nc_server_ssh_endpt_add_authkey("main", TESTS_DIR"/data/key_ecdsa.pub", "test2"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 693 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 694 | #endif |
| 695 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 696 | #ifdef NC_ENABLED_TLS |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 697 | /* do first, so that client can connect on TLS */ |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 698 | ret = nc_server_tls_endpt_set_address("main", "0.0.0.0"); |
| 699 | nc_assert(!ret); |
| 700 | ret = nc_server_tls_endpt_set_port("main", 6501); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 701 | nc_assert(!ret); |
Michal Vasko | b477b22 | 2016-02-09 14:30:15 +0100 | [diff] [blame] | 702 | ret = nc_server_tls_endpt_set_cert_path("main", TESTS_DIR"/data/server.crt"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 703 | nc_assert(!ret); |
Michal Vasko | b477b22 | 2016-02-09 14:30:15 +0100 | [diff] [blame] | 704 | ret = nc_server_tls_endpt_set_key_path("main", TESTS_DIR"/data/server.key"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 705 | nc_assert(!ret); |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 706 | ret = nc_server_tls_endpt_add_trusted_cert_path("main", "client", TESTS_DIR"/data/client.crt"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 707 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 708 | ret = nc_server_tls_endpt_add_ctn("main", 0, "02:D3:03:0E:77:21:E2:14:1F:E5:75:48:98:6B:FD:8A:63:BB:DE:40:34", NC_TLS_CTN_SPECIFIED, "test"); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 709 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 710 | |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 711 | /* client ready */ |
| 712 | ret = write(pipes[clients * 2 + 1], "tls_ready", 9); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 713 | nc_assert(ret == 9); |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 714 | ++clients; |
| 715 | |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 716 | /* for tls_endpt_del_ctn */ |
| 717 | ret = nc_server_tls_endpt_add_ctn("main", 0, "02:00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:A0:A1:A2:A3", NC_TLS_CTN_SAN_ANY, NULL); |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 718 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 719 | #endif |
| 720 | |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 721 | /* for del_endpt */ |
| 722 | ret = nc_server_add_endpt("secondary"); |
| 723 | nc_assert(!ret); |
| 724 | |
| 725 | /* for endpt_set_address, endpt_set_port */ |
| 726 | ret = nc_server_add_endpt("quaternary"); |
| 727 | nc_assert(!ret); |
| 728 | |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 729 | /* threads'n'stuff */ |
| 730 | ret = 0; |
| 731 | for (i = 0; i < thread_count; ++i) { |
| 732 | ret += pthread_create(&tids[i], NULL, thread_funcs[i], NULL); |
| 733 | } |
Michal Vasko | 64b31a2 | 2016-03-03 11:00:00 +0100 | [diff] [blame] | 734 | nc_assert(!ret); |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 735 | |
| 736 | /* cleanup */ |
| 737 | for (i = 0; i < thread_count; ++i) { |
| 738 | pthread_join(tids[i], NULL); |
| 739 | } |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 740 | for (i = 0; i < client_count; ++i) { |
| 741 | waitpid(pids[i], NULL, 0); |
| 742 | close(pipes[i * 2 + 1]); |
| 743 | } |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 744 | |
| 745 | pthread_barrier_destroy(&barrier); |
| 746 | |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 747 | nc_server_destroy(); |
| 748 | ly_ctx_destroy(ctx, NULL); |
| 749 | |
Michal Vasko | 734360b | 2016-02-08 15:38:25 +0100 | [diff] [blame] | 750 | return 0; |
| 751 | } |