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