blob: 8163cddbb4d056bc41dcfe4468c3eeb2393b0be9 [file] [log] [blame]
Michal Vasko734360b2016-02-08 15:38:25 +01001/**
2 * \file test_server_thread.c
3 * \author Michal Vasko <mvasko@cesnet.cz>
4 * \brief libnetconf2 tests - thread-safety of all server functions
5 *
Michal Vasko4c1fb492017-01-30 14:31:07 +01006 * Copyright (c) 2017 CESNET, z.s.p.o.
Michal Vasko734360b2016-02-08 15:38:25 +01007 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +01008 * 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 Vaskoad1cc6a2016-02-26 15:06:06 +010011 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +010012 * https://opensource.org/licenses/BSD-3-Clause
Michal Vasko734360b2016-02-08 15:38:25 +010013 */
14
15#include <pthread.h>
Michal Vasko734360b2016-02-08 15:38:25 +010016#include <unistd.h>
17#include <stdlib.h>
Michal Vasko64b31a22016-03-03 11:00:00 +010018#include <stdio.h>
Michal Vaskoa28be9a2016-03-01 15:20:47 +010019#include <string.h>
Michal Vasko734360b2016-02-08 15:38:25 +010020#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>
Jan Kundrátcf15d6c2017-10-26 18:07:56 +020028#include "tests/config.h"
Michal Vasko734360b2016-02-08 15:38:25 +010029
30/* millisec */
Michal Vasko15592cc2016-02-09 09:52:43 +010031#define NC_ACCEPT_TIMEOUT 5000
Michal Vasko734360b2016-02-08 15:38:25 +010032/* millisec */
Michal Vasko15592cc2016-02-09 09:52:43 +010033#define NC_PS_POLL_TIMEOUT 5000
Michal Vasko734360b2016-02-08 15:38:25 +010034/* sec */
Michal Vasko15592cc2016-02-09 09:52:43 +010035#define CLIENT_SSH_AUTH_TIMEOUT 10
Michal Vasko734360b2016-02-08 15:38:25 +010036
Michal Vasko64b31a22016-03-03 11:00:00 +010037#define nc_assert(cond) if (!(cond)) { fprintf(stderr, "assert failed (%s:%d)\n", __FILE__, __LINE__); exit(1); }
38
Michal Vasko734360b2016-02-08 15:38:25 +010039pthread_barrier_t barrier;
40
Radek Krejci53691be2016-02-22 13:58:37 +010041#if defined(NC_ENABLED_SSH) || defined(NC_ENABLED_TLS)
Michal Vasko734360b2016-02-08 15:38:25 +010042
43static void *
44server_thread(void *arg)
45{
46 (void)arg;
Michal Vasko71090fc2016-05-24 16:37:28 +020047 NC_MSG_TYPE msgtype;
Michal Vasko734360b2016-02-08 15:38:25 +010048 int ret;
49 struct nc_pollsession *ps;
50 struct nc_session *session;
51
52 ps = nc_ps_new();
Michal Vasko64b31a22016-03-03 11:00:00 +010053 nc_assert(ps);
Michal Vasko734360b2016-02-08 15:38:25 +010054
55 pthread_barrier_wait(&barrier);
56
Radek Krejci53691be2016-02-22 13:58:37 +010057#if defined(NC_ENABLED_SSH) && defined(NC_ENABLED_TLS)
Michal Vasko71090fc2016-05-24 16:37:28 +020058 msgtype = nc_accept(NC_ACCEPT_TIMEOUT, &session);
59 nc_assert(msgtype == NC_MSG_HELLO);
Michal Vasko734360b2016-02-08 15:38:25 +010060
61 nc_ps_add_session(ps, session);
Michal Vasko71090fc2016-05-24 16:37:28 +020062 ret = nc_ps_poll(ps, NC_PS_POLL_TIMEOUT, NULL);
63 nc_assert(ret & NC_PSPOLL_RPC);
Michal Vaskoe1a64ec2016-03-01 12:21:58 +010064 nc_ps_clear(ps, 0, NULL);
Michal Vasko734360b2016-02-08 15:38:25 +010065#endif
66
Michal Vasko71090fc2016-05-24 16:37:28 +020067 msgtype = nc_accept(NC_ACCEPT_TIMEOUT, &session);
68 nc_assert(msgtype == NC_MSG_HELLO);
Michal Vasko734360b2016-02-08 15:38:25 +010069
70 nc_ps_add_session(ps, session);
Michal Vasko71090fc2016-05-24 16:37:28 +020071 ret = nc_ps_poll(ps, NC_PS_POLL_TIMEOUT, NULL);
72 nc_assert(ret & NC_PSPOLL_RPC);
Michal Vaskoe1a64ec2016-03-01 12:21:58 +010073 nc_ps_clear(ps, 0, NULL);
Michal Vasko734360b2016-02-08 15:38:25 +010074
75 nc_ps_free(ps);
76
77 nc_thread_destroy();
78 return NULL;
79}
80
Michal Vasko338f8472016-10-13 15:01:27 +020081#endif /* NC_ENABLED_SSH || NC_ENABLED_TLS */
82
83#ifdef NC_ENABLED_SSH
84
Michal Vasko4c1fb492017-01-30 14:31:07 +010085static int
86clb_hostkeys(const char *name, void *UNUSED(user_data), char **privkey_path, char **UNUSED(privkey_data),
87 int *UNUSED(privkey_data_rsa))
88{
89 if (!strcmp(name, "key_rsa")) {
90 *privkey_path = strdup(TESTS_DIR"/data/key_rsa");
91 return 0;
92 } else if (!strcmp(name, "key_dsa")) {
93 *privkey_path = strdup(TESTS_DIR"/data/key_dsa");
94 return 0;
95 }
96
97 return 1;
98}
99
Michal Vasko734360b2016-02-08 15:38:25 +0100100static void *
Michal Vaskoe2713da2016-08-22 16:06:40 +0200101add_endpt_thread(void *arg)
Michal Vasko734360b2016-02-08 15:38:25 +0100102{
103 (void)arg;
104 int ret;
105
106 pthread_barrier_wait(&barrier);
Michal Vasko338f8472016-10-13 15:01:27 +0200107 ret = nc_server_add_endpt("tertiary", NC_TI_LIBSSH);
Michal Vaskoe2713da2016-08-22 16:06:40 +0200108 nc_assert(!ret);
109
110 return NULL;
111}
112
113static void *
114del_endpt_thread(void *arg)
115{
116 (void)arg;
117 int ret;
118
119 pthread_barrier_wait(&barrier);
120
Michal Vasko59050372016-11-22 14:33:55 +0100121 ret = nc_server_del_endpt("secondary", 0);
Michal Vaskoe2713da2016-08-22 16:06:40 +0200122 nc_assert(!ret);
123
124 return NULL;
125}
126
Michal Vasko734360b2016-02-08 15:38:25 +0100127static void *
128ssh_endpt_set_hostkey_thread(void *arg)
129{
130 (void)arg;
131 int ret;
132
133 pthread_barrier_wait(&barrier);
134
Michal Vasko7d255882017-02-09 13:35:08 +0100135 ret = nc_server_ssh_endpt_add_hostkey("main_ssh", "key_dsa", -1);
Michal Vasko64b31a22016-03-03 11:00:00 +0100136 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100137
138 return NULL;
139}
140
141static void *
142ssh_endpt_set_banner_thread(void *arg)
143{
144 (void)arg;
145 int ret;
146
147 pthread_barrier_wait(&barrier);
148
Michal Vasko338f8472016-10-13 15:01:27 +0200149 ret = nc_server_ssh_endpt_set_banner("main_ssh", "Howdy, partner!");
Michal Vasko64b31a22016-03-03 11:00:00 +0100150 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100151
152 return NULL;
153}
154
155static void *
156ssh_endpt_set_auth_methods_thread(void *arg)
157{
158 (void)arg;
159 int ret;
160
161 pthread_barrier_wait(&barrier);
162
Michal Vasko338f8472016-10-13 15:01:27 +0200163 ret = nc_server_ssh_endpt_set_auth_methods("main_ssh", NC_SSH_AUTH_PUBLICKEY | NC_SSH_AUTH_PASSWORD | NC_SSH_AUTH_INTERACTIVE);
Michal Vasko64b31a22016-03-03 11:00:00 +0100164 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100165
166 return NULL;
167}
168
169static void *
170ssh_endpt_set_auth_attempts_thread(void *arg)
171{
172 (void)arg;
173 int ret;
174
175 pthread_barrier_wait(&barrier);
176
Michal Vasko338f8472016-10-13 15:01:27 +0200177 ret = nc_server_ssh_endpt_set_auth_attempts("main_ssh", 2);
Michal Vasko64b31a22016-03-03 11:00:00 +0100178 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100179
180 return NULL;
181}
182
183static void *
184ssh_endpt_set_auth_timeout_thread(void *arg)
185{
186 (void)arg;
187 int ret;
188
189 pthread_barrier_wait(&barrier);
190
Michal Vasko338f8472016-10-13 15:01:27 +0200191 ret = nc_server_ssh_endpt_set_auth_timeout("main_ssh", 5);
Michal Vasko64b31a22016-03-03 11:00:00 +0100192 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100193
194 return NULL;
195}
196
197static void *
198ssh_endpt_add_authkey_thread(void *arg)
199{
200 (void)arg;
201 int ret;
202
203 pthread_barrier_wait(&barrier);
204
Michal Vasko17dfda92016-12-01 14:06:16 +0100205 ret = nc_server_ssh_add_authkey_path(TESTS_DIR"/data/key_rsa.pub", "test3");
Michal Vasko64b31a22016-03-03 11:00:00 +0100206 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100207
208 return NULL;
209}
210
211static void *
212ssh_endpt_del_authkey_thread(void *arg)
213{
214 (void)arg;
215 int ret;
216
217 pthread_barrier_wait(&barrier);
218
Michal Vasko17dfda92016-12-01 14:06:16 +0100219 ret = nc_server_ssh_del_authkey(TESTS_DIR"/data/key_ecdsa.pub", NULL, 0, "test2");
Michal Vasko64b31a22016-03-03 11:00:00 +0100220 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100221
222 return NULL;
223}
224
Michal Vasko693eb112016-02-18 13:28:49 +0100225static int
Radek Krejci90a84a22017-05-25 13:53:00 +0200226ssh_hostkey_check_clb(const char *hostname, ssh_session session, void *priv)
Michal Vasko693eb112016-02-18 13:28:49 +0100227{
228 (void)hostname;
229 (void)session;
Radek Krejci90a84a22017-05-25 13:53:00 +0200230 (void)priv;
Michal Vasko693eb112016-02-18 13:28:49 +0100231
232 return 0;
233}
234
Michal Vasko734360b2016-02-08 15:38:25 +0100235static void *
236ssh_client_thread(void *arg)
237{
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100238 int ret, read_pipe = *(int *)arg;
239 char buf[9];
Michal Vasko734360b2016-02-08 15:38:25 +0100240 struct nc_session *session;
241
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100242 ret = read(read_pipe, buf, 9);
Michal Vasko64b31a22016-03-03 11:00:00 +0100243 nc_assert(ret == 9);
244 nc_assert(!strncmp(buf, "ssh_ready", 9));
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100245
Michal Vasko693eb112016-02-18 13:28:49 +0100246 /* skip the knownhost check */
Radek Krejci90a84a22017-05-25 13:53:00 +0200247 nc_client_ssh_set_auth_hostkey_check_clb(ssh_hostkey_check_clb, NULL);
Michal Vasko734360b2016-02-08 15:38:25 +0100248
Michal Vasko693eb112016-02-18 13:28:49 +0100249 ret = nc_client_ssh_set_username("test");
Michal Vasko64b31a22016-03-03 11:00:00 +0100250 nc_assert(!ret);
Michal Vasko693eb112016-02-18 13:28:49 +0100251
252 ret = nc_client_ssh_add_keypair(TESTS_DIR"/data/key_dsa.pub", TESTS_DIR"/data/key_dsa");
Michal Vasko64b31a22016-03-03 11:00:00 +0100253 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100254
255 nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PUBLICKEY, 1);
256 nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PASSWORD, -1);
257 nc_client_ssh_set_auth_pref(NC_SSH_AUTH_INTERACTIVE, -1);
258
Michal Vasko693eb112016-02-18 13:28:49 +0100259 session = nc_connect_ssh("127.0.0.1", 6001, NULL);
Michal Vasko64b31a22016-03-03 11:00:00 +0100260 nc_assert(session);
Michal Vasko734360b2016-02-08 15:38:25 +0100261
Michal Vaskoe1a64ec2016-03-01 12:21:58 +0100262 nc_session_free(session, NULL);
Michal Vasko734360b2016-02-08 15:38:25 +0100263
Michal Vaskoe2713da2016-08-22 16:06:40 +0200264 fprintf(stdout, "SSH client finished.\n");
265
Michal Vasko734360b2016-02-08 15:38:25 +0100266 nc_thread_destroy();
267 return NULL;
268}
269
Radek Krejci53691be2016-02-22 13:58:37 +0100270#endif /* NC_ENABLED_SSH */
Michal Vasko734360b2016-02-08 15:38:25 +0100271
Radek Krejci53691be2016-02-22 13:58:37 +0100272#ifdef NC_ENABLED_TLS
Michal Vasko734360b2016-02-08 15:38:25 +0100273
Michal Vasko4c1fb492017-01-30 14:31:07 +0100274static int
275clb_server_cert(const char *name, void *UNUSED(user_data), char **cert_path, char **cert_data, char **privkey_path,
276 char **privkey_data, int *privkey_data_rsa)
277{
278 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vxovmT+lSMFF/Y0j1MbHWnds5H1shoFPNtYTvWBL/gfPHjIc+H23zsiu\n"
340 "3XlZAoIBAC2xB/Pnpoi9vOUMiqFH36AXtYa1DURy+AqCFlYlClMvb7YgvQ1w1eJv\n"
341 "nwrHSLk7HdKhnwGsLPduuRRH8q0n/osnoOutSQroE0n41UyIv2ZNccRwNmSzQcai\n"
342 "rBu2dSz02hlsh2otNl5IuGpOqXyPjXBpW4qGD6n2tH7THALnLC0BHtTSQVQsJsRM\n"
343 "3gX39LoiWvLDp2qJvplm6rTpi8Rgap6rZSqHe1yNKIxxD2vlr/WY9SMgLXYASO4S\n"
344 "SBz9wfGOmQIPk6KXNJkdV4kC7nNjIi75iwLLCgjHgUiHTrDq5sWekpeNnUoWsinb\n"
345 "Tsdsjnv3zHG9GyiClyLGxMbs4M5eyYECggEBAKuC8ZMpdIrjk6tERYB6g0LnQ7mW\n"
346 "8XYbDFAmLYMLs9yfG2jcjVbsW9Kugsr+3poUUv/q+hNO3jfY4HazhZDa0MalgNPo\n"
347 "Swr/VNRnkck40x2ovFb989J7yl++zTrnIrax9XRH1V0cNu+Kj7OMwZ2RRfbNv5JB\n"
348 "dOZPvkfqyIKFmbQgYbtD66rHuzNOfJpzqr/WVLO57/zzW8245NKG2B6B0oXkei/K\n"
349 "qDY0DAbHR3i3EOj1NPtVI1FC/xX8R9BREaid458bqoHJKuInrGcBjaUI9Cvymv8T\n"
350 "bstUgD6NPbJR4Sm6vrLeUqzjWZP3t1+Z6DjXmnpR2vvhMU/FWb//21p/88o=");
351 *privkey_data_rsa = 1;
352 return 0;
353 } else if (!strcmp(name, "main_cert")) {
354 *cert_path = strdup(TESTS_DIR"/data/server.crt");
355 *privkey_path = strdup(TESTS_DIR"/data/server.key");
356 return 0;
357 }
358
359 return 1;
360}
361
362static int
363clb_trusted_cert_lists(const char *name, void *UNUSED(user_data), char ***cert_paths, int *cert_path_count,
364 char ***cert_data, int *cert_data_count)
365{
366 if (!strcmp(name, "trusted_cert_list1")) {
Michal Vaskoad0bcb52017-03-22 11:55:47 +0100367 *cert_data = malloc(sizeof **cert_data);
Michal Vasko4c1fb492017-01-30 14:31:07 +0100368 (*cert_data)[0] = strdup("MIIDgzCCAmugAwIBAgIJAL+y0WMRGax0MA0GCSqGSIb3DQEBBQUAMFgxCzAJBgNV\n"
369 "BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX\n"
370 "aWRnaXRzIFB0eSBMdGQxETAPBgNVBAMMCGNsaWVudGNhMB4XDTE2MDExMTEyMTAx\n"
371 "OVoXDTE4MTAzMTEyMTAxOVowWDELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUt\n"
372 "U3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDERMA8GA1UE\n"
373 "AwwIY2xpZW50Y2EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCw7Eyq\n"
374 "5T5tX6tAv5DHHfWNuaD/a3gVIBlGRWMAXkFWWJEa3o6leIjKxoDnL6tcBWNVJ+Gw\n"
375 "32MHerpHY6o5czsEHQ2XsOgodyFqe5cvx0kjQbjYQqnIMrslcdvSYuNe/ItqFP/w\n"
376 "uxb6kQbCYnCQKd/qhdhfoXjIHcnXpZzMCPKQ/uqls7LANJymtQkAuzydlf3+UqoG\n"
377 "4oo04GXK1Dc0A12cgCXxf+kWx7x34ctx2VEvDsJzw6LiZm8czOWjMFcuqqm/+kla\n"
378 "N3+6O7Z1kZlft/KNSrOYtc45xKNoSVrdVwFLkxipVDfOql6/DmWfE8iVmlX3QflO\n"
379 "u3+fzZZQpR5jYzUNAgMBAAGjUDBOMB0GA1UdDgQWBBTjBbQJ6p/mjnjBWXLgXXXW\n"
380 "a3ieoTAfBgNVHSMEGDAWgBTjBbQJ6p/mjnjBWXLgXXXWa3ieoTAMBgNVHRMEBTAD\n"
381 "AQH/MA0GCSqGSIb3DQEBBQUAA4IBAQAZr9b0YTaDV5XZr/QQPP1pvHkN3Ezbm9F4\n"
382 "MiYe4e0QnM9JtjNLDKq1dDnqVDQ/BYdupWWh0398tObFACssWkm4aubPG7LVh5Ck\n"
383 "O8I8i/GHiXYLmYT22hslWe5dFvidUICkTXoj1h5X2vwfBrNTI1+gnVXXw842xCvU\n"
384 "sgq28vGMSXLSYKBNaP/llXNmqW35oLs6CwVuiCL7Go0IDIOmiXN2bssb87hZSw3B\n"
385 "6iwU78wYshJUGZjLaK9PuMvFYJLFWSAePA2Yb+aEv80wMbX1oANSryU7Uf5BJk8V\n"
386 "kO3mlRDh2b1/5Gb5xA2vU2z3ReHdPNy6qSx0Mk4XJvQw9FsVHZ13");
387 *cert_data_count = 1;
388 return 0;
389 } else if (!strcmp(name, "client_cert_list")) {
Michal Vasko75ff74b2017-03-21 15:34:34 +0100390 *cert_paths = malloc(sizeof **cert_paths);
Michal Vasko4c1fb492017-01-30 14:31:07 +0100391 (*cert_paths)[0] = strdup(TESTS_DIR"/data/client.crt");
392 *cert_path_count = 1;
393 return 0;
394 }
395
396 return 1;
397}
398
Michal Vasko734360b2016-02-08 15:38:25 +0100399static void *
Michal Vasko338f8472016-10-13 15:01:27 +0200400endpt_set_address_thread(void *arg)
Michal Vasko734360b2016-02-08 15:38:25 +0100401{
402 (void)arg;
403 int ret;
404
405 pthread_barrier_wait(&barrier);
406
Michal Vasko338f8472016-10-13 15:01:27 +0200407 ret = nc_server_endpt_set_address("quaternary", "0.0.0.0");
Michal Vasko64b31a22016-03-03 11:00:00 +0100408 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100409
410 return NULL;
411}
412
413static void *
Michal Vasko338f8472016-10-13 15:01:27 +0200414endpt_set_port_thread(void *arg)
Michal Vasko734360b2016-02-08 15:38:25 +0100415{
416 (void)arg;
417 int ret;
418
419 pthread_barrier_wait(&barrier);
420
Michal Vasko338f8472016-10-13 15:01:27 +0200421 ret = nc_server_endpt_set_port("quaternary", 6003);
Michal Vasko64b31a22016-03-03 11:00:00 +0100422 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100423
424 return NULL;
425}
426
427static void *
Michal Vasko4c1fb492017-01-30 14:31:07 +0100428tls_endpt_set_server_cert_thread(void *arg)
Michal Vasko734360b2016-02-08 15:38:25 +0100429{
430 (void)arg;
431 int ret;
432
433 pthread_barrier_wait(&barrier);
434
Michal Vasko4c1fb492017-01-30 14:31:07 +0100435 ret = nc_server_tls_endpt_set_server_cert("quaternary", "server_cert1");
Michal Vasko64b31a22016-03-03 11:00:00 +0100436 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100437
438 nc_thread_destroy();
439 return NULL;
440}
441
442static void *
Michal Vasko4c1fb492017-01-30 14:31:07 +0100443tls_endpt_add_trusted_cert_list_thread(void *arg)
Michal Vasko734360b2016-02-08 15:38:25 +0100444{
445 (void)arg;
446 int ret;
447
448 pthread_barrier_wait(&barrier);
449
Michal Vasko4c1fb492017-01-30 14:31:07 +0100450 ret = nc_server_tls_endpt_add_trusted_cert_list("quaternary", "trusted_cert_list1");
Michal Vasko64b31a22016-03-03 11:00:00 +0100451 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100452
453 nc_thread_destroy();
454 return NULL;
455}
456
457static void *
458tls_endpt_set_trusted_ca_paths_thread(void *arg)
459{
460 (void)arg;
461 int ret;
462
463 pthread_barrier_wait(&barrier);
464
Michal Vaskob477b222016-02-09 14:30:15 +0100465 ret = nc_server_tls_endpt_set_trusted_ca_paths("quaternary", TESTS_DIR"/data/serverca.pem", "data");
Michal Vasko64b31a22016-03-03 11:00:00 +0100466 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100467
468 nc_thread_destroy();
469 return NULL;
470}
471
472static void *
Michal Vasko4c1fb492017-01-30 14:31:07 +0100473tls_endpt_del_trusted_cert_list_thread(void *arg)
Michal Vasko734360b2016-02-08 15:38:25 +0100474{
475 (void)arg;
476
477 pthread_barrier_wait(&barrier);
478
Michal Vasko4c1fb492017-01-30 14:31:07 +0100479 nc_server_tls_endpt_del_trusted_cert_list("quaternary", "trusted_cert_list1");
Michal Vasko734360b2016-02-08 15:38:25 +0100480
481 return NULL;
482}
483
484static void *
485tls_endpt_set_crl_paths_thread(void *arg)
486{
487 (void)arg;
488 int ret;
489
490 pthread_barrier_wait(&barrier);
491
492 ret = nc_server_tls_endpt_set_crl_paths("quaternary", NULL, "data");
Michal Vasko64b31a22016-03-03 11:00:00 +0100493 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100494
495 nc_thread_destroy();
496 return NULL;
497}
498
499static void *
500tls_endpt_clear_crls_thread(void *arg)
501{
502 (void)arg;
503
504 pthread_barrier_wait(&barrier);
505
506 nc_server_tls_endpt_clear_crls("quaternary");
507
508 return NULL;
509}
510
511static void *
512tls_endpt_add_ctn_thread(void *arg)
513{
514 (void)arg;
515 int ret;
516
517 pthread_barrier_wait(&barrier);
518
Michal Vasko3cf4aaa2017-02-01 15:03:36 +0100519 ret = nc_server_tls_endpt_add_ctn("main_tls", 2, "02:F0:F1:F2:F3:F4:F5:F6:F7:F8:F9:10:11:12:EE:FF:A0:A1:A2:A3",
Michal Vasko734360b2016-02-08 15:38:25 +0100520 NC_TLS_CTN_SAN_IP_ADDRESS, NULL);
Michal Vasko64b31a22016-03-03 11:00:00 +0100521 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100522
523 return NULL;
524}
525
526static void *
527tls_endpt_del_ctn_thread(void *arg)
528{
529 (void)arg;
530 int ret;
531
532 pthread_barrier_wait(&barrier);
533
Michal Vasko338f8472016-10-13 15:01:27 +0200534 ret = nc_server_tls_endpt_del_ctn("main_tls", -1, NULL, NC_TLS_CTN_SAN_ANY, NULL);
Michal Vasko64b31a22016-03-03 11:00:00 +0100535 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100536
537 return NULL;
538}
539
540static void *
541tls_client_thread(void *arg)
542{
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100543 int ret, read_pipe = *(int *)arg;
544 char buf[9];
Michal Vasko734360b2016-02-08 15:38:25 +0100545 struct nc_session *session;
546
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100547 ret = read(read_pipe, buf, 9);
Michal Vasko64b31a22016-03-03 11:00:00 +0100548 nc_assert(ret == 9);
549 nc_assert(!strncmp(buf, "tls_ready", 9));
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100550
Michal Vaskob477b222016-02-09 14:30:15 +0100551 ret = nc_client_tls_set_cert_key_paths(TESTS_DIR"/data/client.crt", TESTS_DIR"/data/client.key");
Michal Vasko64b31a22016-03-03 11:00:00 +0100552 nc_assert(!ret);
Michal Vaskobc2ae552016-02-09 14:38:47 +0100553 ret = nc_client_tls_set_trusted_ca_paths(NULL, TESTS_DIR"/data");
Michal Vasko64b31a22016-03-03 11:00:00 +0100554 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100555
556 session = nc_connect_tls("127.0.0.1", 6501, NULL);
Michal Vasko64b31a22016-03-03 11:00:00 +0100557 nc_assert(session);
Michal Vasko734360b2016-02-08 15:38:25 +0100558
Michal Vaskoe1a64ec2016-03-01 12:21:58 +0100559 nc_session_free(session, NULL);
Michal Vasko734360b2016-02-08 15:38:25 +0100560
Michal Vaskoe2713da2016-08-22 16:06:40 +0200561 fprintf(stdout, "TLS client finished.\n");
562
Michal Vasko734360b2016-02-08 15:38:25 +0100563 nc_thread_destroy();
564 return NULL;
565}
566
Radek Krejci53691be2016-02-22 13:58:37 +0100567#endif /* NC_ENABLED_TLS */
Michal Vasko734360b2016-02-08 15:38:25 +0100568
569static void *(*thread_funcs[])(void *) = {
Radek Krejci53691be2016-02-22 13:58:37 +0100570#if defined(NC_ENABLED_SSH) || defined(NC_ENABLED_TLS)
Michal Vasko734360b2016-02-08 15:38:25 +0100571 server_thread,
572#endif
Radek Krejci53691be2016-02-22 13:58:37 +0100573#ifdef NC_ENABLED_SSH
Michal Vasko8727e432016-10-13 15:44:10 +0200574 add_endpt_thread,
575 del_endpt_thread,
Michal Vasko734360b2016-02-08 15:38:25 +0100576 ssh_endpt_set_hostkey_thread,
577 ssh_endpt_set_banner_thread,
578 ssh_endpt_set_auth_methods_thread,
579 ssh_endpt_set_auth_attempts_thread,
580 ssh_endpt_set_auth_timeout_thread,
581 ssh_endpt_add_authkey_thread,
582 ssh_endpt_del_authkey_thread,
583#endif
Radek Krejci53691be2016-02-22 13:58:37 +0100584#ifdef NC_ENABLED_TLS
Michal Vasko8727e432016-10-13 15:44:10 +0200585 endpt_set_address_thread,
586 endpt_set_port_thread,
Michal Vasko4c1fb492017-01-30 14:31:07 +0100587 tls_endpt_set_server_cert_thread,
588 tls_endpt_add_trusted_cert_list_thread,
Michal Vasko734360b2016-02-08 15:38:25 +0100589 tls_endpt_set_trusted_ca_paths_thread,
Michal Vasko4c1fb492017-01-30 14:31:07 +0100590 tls_endpt_del_trusted_cert_list_thread,
Michal Vasko734360b2016-02-08 15:38:25 +0100591 tls_endpt_set_crl_paths_thread,
592 tls_endpt_clear_crls_thread,
593 tls_endpt_add_ctn_thread,
594 tls_endpt_del_ctn_thread,
595#endif
596};
597
598const int thread_count = sizeof thread_funcs / sizeof *thread_funcs;
599
Radek Krejci53691be2016-02-22 13:58:37 +0100600#if defined(NC_ENABLED_SSH) && defined(NC_ENABLED_TLS)
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100601const int client_count = 2;
602pid_t pids[2];
603int pipes[4];
Michal Vasko734360b2016-02-08 15:38:25 +0100604#else
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100605const int client_count = 1;
606pid_t pids[1];
607int pipes[2];
608#endif
609
610static void
611client_fork(void)
612{
613 int ret, clients = 0;
614
615#ifdef NC_ENABLED_SSH
616 pipe(pipes + clients * 2);
617
618 if (!(pids[clients] = fork())) {
619 nc_client_init();
620
Michal Vasko7f1c0ef2016-03-11 11:13:06 +0100621 ret = nc_client_set_schema_searchpath(TESTS_DIR"/../schemas");
Michal Vasko64b31a22016-03-03 11:00:00 +0100622 nc_assert(!ret);
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100623
624 /* close write */
625 close(pipes[clients * 2 + 1]);
626 ssh_client_thread(&pipes[clients * 2]);
627 close(pipes[clients * 2]);
628 nc_client_destroy();
629 exit(0);
Michal Vasko734360b2016-02-08 15:38:25 +0100630 }
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100631 /* close read */
632 close(pipes[clients * 2]);
633
634 ++clients;
635#endif
636
637#ifdef NC_ENABLED_TLS
638 pipe(pipes + clients * 2);
639
640 if (!(pids[clients] = fork())) {
641 nc_client_init();
642
Michal Vasko7f1c0ef2016-03-11 11:13:06 +0100643 ret = nc_client_set_schema_searchpath(TESTS_DIR"/../schemas");
Michal Vasko64b31a22016-03-03 11:00:00 +0100644 nc_assert(!ret);
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100645
646 /* close write */
647 close(pipes[clients * 2 + 1]);
648 tls_client_thread(&pipes[clients * 2]);
649 close(pipes[clients * 2]);
650 nc_client_destroy();
651 exit(0);
652 }
653 /* close read */
654 close(pipes[clients * 2]);
655
656 ++clients;
Michal Vasko734360b2016-02-08 15:38:25 +0100657#endif
658}
659
660int
661main(void)
662{
663 struct ly_ctx *ctx;
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100664 int ret, i, clients = 0;
Michal Vasko734360b2016-02-08 15:38:25 +0100665 pthread_t tids[thread_count];
666
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100667 nc_verbosity(NC_VERB_VERBOSE);
668
669 client_fork();
Michal Vasko734360b2016-02-08 15:38:25 +0100670
Radek Krejci3222b7d2017-09-21 16:04:30 +0200671 ctx = ly_ctx_new(TESTS_DIR"/../schemas", 0);
Michal Vasko64b31a22016-03-03 11:00:00 +0100672 nc_assert(ctx);
Michal Vasko734360b2016-02-08 15:38:25 +0100673 ly_ctx_load_module(ctx, "ietf-netconf", NULL);
674 nc_server_init(ctx);
675
676 pthread_barrier_init(&barrier, NULL, thread_count);
677
Radek Krejci53691be2016-02-22 13:58:37 +0100678#ifdef NC_ENABLED_SSH
Michal Vasko4c1fb492017-01-30 14:31:07 +0100679 /* set callback */
680 nc_server_ssh_set_hostkey_clb(clb_hostkeys, NULL, NULL);
681
Michal Vasko734360b2016-02-08 15:38:25 +0100682 /* do first, so that client can connect on SSH */
Michal Vasko338f8472016-10-13 15:01:27 +0200683 ret = nc_server_add_endpt("main_ssh", NC_TI_LIBSSH);
Michal Vaskoe2713da2016-08-22 16:06:40 +0200684 nc_assert(!ret);
Michal Vasko338f8472016-10-13 15:01:27 +0200685 ret = nc_server_endpt_set_address("main_ssh", "0.0.0.0");
Michal Vasko64b31a22016-03-03 11:00:00 +0100686 nc_assert(!ret);
Michal Vasko338f8472016-10-13 15:01:27 +0200687 ret = nc_server_endpt_set_port("main_ssh", 6001);
Michal Vasko64b31a22016-03-03 11:00:00 +0100688 nc_assert(!ret);
Michal Vasko17dfda92016-12-01 14:06:16 +0100689 ret = nc_server_ssh_add_authkey_path(TESTS_DIR"/data/key_dsa.pub", "test");
Michal Vasko338f8472016-10-13 15:01:27 +0200690 nc_assert(!ret);
Michal Vasko7d255882017-02-09 13:35:08 +0100691 ret = nc_server_ssh_endpt_add_hostkey("main_ssh", "key_rsa", -1);
Michal Vasko64b31a22016-03-03 11:00:00 +0100692 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100693
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100694 /* client ready */
695 ret = write(pipes[clients * 2 + 1], "ssh_ready", 9);
Michal Vasko64b31a22016-03-03 11:00:00 +0100696 nc_assert(ret == 9);
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100697 ++clients;
698
Michal Vasko734360b2016-02-08 15:38:25 +0100699 /* for ssh_endpt_del_authkey */
Michal Vasko17dfda92016-12-01 14:06:16 +0100700 ret = nc_server_ssh_add_authkey_path(TESTS_DIR"/data/key_ecdsa.pub", "test2");
Michal Vasko338f8472016-10-13 15:01:27 +0200701 nc_assert(!ret);
702
703 ret = nc_server_add_endpt("secondary", NC_TI_LIBSSH);
Michal Vasko64b31a22016-03-03 11:00:00 +0100704 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100705#endif
706
Radek Krejci53691be2016-02-22 13:58:37 +0100707#ifdef NC_ENABLED_TLS
Michal Vasko4c1fb492017-01-30 14:31:07 +0100708 /* set callbacks */
709 nc_server_tls_set_server_cert_clb(clb_server_cert, NULL, NULL);
710 nc_server_tls_set_trusted_cert_list_clb(clb_trusted_cert_lists, NULL, NULL);
711
Michal Vasko734360b2016-02-08 15:38:25 +0100712 /* do first, so that client can connect on TLS */
Michal Vasko338f8472016-10-13 15:01:27 +0200713 ret = nc_server_add_endpt("main_tls", NC_TI_OPENSSL);
Michal Vaskoe2713da2016-08-22 16:06:40 +0200714 nc_assert(!ret);
Michal Vasko338f8472016-10-13 15:01:27 +0200715 ret = nc_server_endpt_set_address("main_tls", "0.0.0.0");
Michal Vasko64b31a22016-03-03 11:00:00 +0100716 nc_assert(!ret);
Michal Vasko338f8472016-10-13 15:01:27 +0200717 ret = nc_server_endpt_set_port("main_tls", 6501);
Michal Vasko64b31a22016-03-03 11:00:00 +0100718 nc_assert(!ret);
Michal Vasko4c1fb492017-01-30 14:31:07 +0100719 ret = nc_server_tls_endpt_set_server_cert("main_tls", "main_cert");
Michal Vasko64b31a22016-03-03 11:00:00 +0100720 nc_assert(!ret);
Michal Vasko4c1fb492017-01-30 14:31:07 +0100721 ret = nc_server_tls_endpt_add_trusted_cert_list("main_tls", "client_cert_list");
Michal Vasko338f8472016-10-13 15:01:27 +0200722 nc_assert(!ret);
723 ret = nc_server_tls_endpt_add_ctn("main_tls", 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 Vasko64b31a22016-03-03 11:00:00 +0100724 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100725
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100726 /* client ready */
727 ret = write(pipes[clients * 2 + 1], "tls_ready", 9);
Michal Vasko64b31a22016-03-03 11:00:00 +0100728 nc_assert(ret == 9);
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100729 ++clients;
730
Michal Vasko734360b2016-02-08 15:38:25 +0100731 /* for tls_endpt_del_ctn */
Michal Vasko3cf4aaa2017-02-01 15:03:36 +0100732 ret = nc_server_tls_endpt_add_ctn("main_tls", 1, "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 Vasko338f8472016-10-13 15:01:27 +0200733 nc_assert(!ret);
734
735 ret = nc_server_add_endpt("quaternary", NC_TI_OPENSSL);
Michal Vasko64b31a22016-03-03 11:00:00 +0100736 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100737#endif
738
Michal Vasko734360b2016-02-08 15:38:25 +0100739 /* threads'n'stuff */
740 ret = 0;
741 for (i = 0; i < thread_count; ++i) {
742 ret += pthread_create(&tids[i], NULL, thread_funcs[i], NULL);
743 }
Michal Vasko64b31a22016-03-03 11:00:00 +0100744 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100745
746 /* cleanup */
747 for (i = 0; i < thread_count; ++i) {
748 pthread_join(tids[i], NULL);
749 }
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100750 for (i = 0; i < client_count; ++i) {
751 waitpid(pids[i], NULL, 0);
752 close(pipes[i * 2 + 1]);
753 }
Michal Vasko734360b2016-02-08 15:38:25 +0100754
755 pthread_barrier_destroy(&barrier);
756
Michal Vasko734360b2016-02-08 15:38:25 +0100757 nc_server_destroy();
758 ly_ctx_destroy(ctx, NULL);
759
Michal Vasko734360b2016-02-08 15:38:25 +0100760 return 0;
761}