blob: 89b7674048bfaaf5c04b0aa73f40d13d3b98add2 [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 *
Michal Vasko734360b2016-02-08 15:38:25 +0100142ssh_endpt_set_auth_methods_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_auth_methods("main_ssh", NC_SSH_AUTH_PUBLICKEY | NC_SSH_AUTH_PASSWORD | NC_SSH_AUTH_INTERACTIVE);
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_attempts_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_attempts("main_ssh", 2);
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_timeout_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_timeout("main_ssh", 5);
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_add_authkey_thread(void *arg)
185{
186 (void)arg;
187 int ret;
188
189 pthread_barrier_wait(&barrier);
190
Michal Vasko17dfda92016-12-01 14:06:16 +0100191 ret = nc_server_ssh_add_authkey_path(TESTS_DIR"/data/key_rsa.pub", "test3");
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_del_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_del_authkey(TESTS_DIR"/data/key_ecdsa.pub", NULL, 0, "test2");
Michal Vasko64b31a22016-03-03 11:00:00 +0100206 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100207
208 return NULL;
209}
210
Michal Vasko693eb112016-02-18 13:28:49 +0100211static int
Radek Krejci90a84a22017-05-25 13:53:00 +0200212ssh_hostkey_check_clb(const char *hostname, ssh_session session, void *priv)
Michal Vasko693eb112016-02-18 13:28:49 +0100213{
214 (void)hostname;
215 (void)session;
Radek Krejci90a84a22017-05-25 13:53:00 +0200216 (void)priv;
Michal Vasko693eb112016-02-18 13:28:49 +0100217
218 return 0;
219}
220
Michal Vasko734360b2016-02-08 15:38:25 +0100221static void *
222ssh_client_thread(void *arg)
223{
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100224 int ret, read_pipe = *(int *)arg;
225 char buf[9];
Michal Vasko734360b2016-02-08 15:38:25 +0100226 struct nc_session *session;
227
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100228 ret = read(read_pipe, buf, 9);
Michal Vasko64b31a22016-03-03 11:00:00 +0100229 nc_assert(ret == 9);
230 nc_assert(!strncmp(buf, "ssh_ready", 9));
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100231
Michal Vasko693eb112016-02-18 13:28:49 +0100232 /* skip the knownhost check */
Radek Krejci90a84a22017-05-25 13:53:00 +0200233 nc_client_ssh_set_auth_hostkey_check_clb(ssh_hostkey_check_clb, NULL);
Michal Vasko734360b2016-02-08 15:38:25 +0100234
Michal Vasko693eb112016-02-18 13:28:49 +0100235 ret = nc_client_ssh_set_username("test");
Michal Vasko64b31a22016-03-03 11:00:00 +0100236 nc_assert(!ret);
Michal Vasko693eb112016-02-18 13:28:49 +0100237
238 ret = nc_client_ssh_add_keypair(TESTS_DIR"/data/key_dsa.pub", TESTS_DIR"/data/key_dsa");
Michal Vasko64b31a22016-03-03 11:00:00 +0100239 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100240
241 nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PUBLICKEY, 1);
242 nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PASSWORD, -1);
243 nc_client_ssh_set_auth_pref(NC_SSH_AUTH_INTERACTIVE, -1);
244
Michal Vasko693eb112016-02-18 13:28:49 +0100245 session = nc_connect_ssh("127.0.0.1", 6001, NULL);
Michal Vasko64b31a22016-03-03 11:00:00 +0100246 nc_assert(session);
Michal Vasko734360b2016-02-08 15:38:25 +0100247
Michal Vaskoe1a64ec2016-03-01 12:21:58 +0100248 nc_session_free(session, NULL);
Michal Vasko734360b2016-02-08 15:38:25 +0100249
Michal Vaskoe2713da2016-08-22 16:06:40 +0200250 fprintf(stdout, "SSH client finished.\n");
251
Michal Vasko734360b2016-02-08 15:38:25 +0100252 nc_thread_destroy();
253 return NULL;
254}
255
Radek Krejci53691be2016-02-22 13:58:37 +0100256#endif /* NC_ENABLED_SSH */
Michal Vasko734360b2016-02-08 15:38:25 +0100257
Radek Krejci53691be2016-02-22 13:58:37 +0100258#ifdef NC_ENABLED_TLS
Michal Vasko734360b2016-02-08 15:38:25 +0100259
Michal Vasko4c1fb492017-01-30 14:31:07 +0100260static int
261clb_server_cert(const char *name, void *UNUSED(user_data), char **cert_path, char **cert_data, char **privkey_path,
262 char **privkey_data, int *privkey_data_rsa)
263{
264 if (!strcmp(name, "server_cert1")) {
Michal Vasko346ac562018-11-05 08:47:18 +0100265 *cert_data = strdup("MIIEQDCCAygCCQCV65JgDvfWkTANBgkqhkiG9w0BAQsFADBjMQswCQYDVQQGEwJD\n"
266 "WjETMBEGA1UECAwKU29tZS1TdGF0ZTENMAsGA1UEBwwEQnJubzEPMA0GA1UECgwG\n"
267 "Q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0GCSqGSIb3DQEBCwUAA4IBAQAXWHf/MG8RPCyA0rC3RwxmM70ndyKPIJoL4ggU\n"
283 "VgkN66BdpsE4UlWdlp0XL3aauMPxzLn9rq1yRtoHWT4/ucL9iEa6B295JBNjkgW+\n"
284 "ct9/y8060P9BUhY1DTv5DLzitsA4bjRaraIevjATDPfsbHFx9DTNrS5pXHIFbRcz\n"
285 "y3WniYXTKhpfM6m+1X8ogImE968DG8RqAW5YZZtrZW0VF/dhlQp20jEX/8Rv33Bp\n"
286 "RhNEIhPnYAquKCesMMclUtPW+5n2z8rgj5t/ETv4wc5QegpyPfdHNq09bGKB10Sy\n"
287 "sGvC6hP9GKU3R2Jhxih/t88O3WoisFQ8+Tf9s2LuSxUV0bzp");
Michal Vasko4c1fb492017-01-30 14:31:07 +0100288 *privkey_data = strdup("MIIJKAIBAAKCAgEA6ojtjfDmvyQP1ZkIwBpr97eKDuebvpoglRHRdvVuTpf/gU1V\n"
289 "ArAQmwGh05i6lm8TkVl1noMlIxLJDcWslaeVn6KyvsX0HhsQtXwqPqwka5UCv6al\n"
290 "wf/ivAvcNpcX1j0t/uIGCI4dSiKnzQCyf0FTirzQkjrDZUd3meDhNQTruCalGV4g\n"
291 "fNWIq3e1oGuwAn1tLlu9oTrE4HzMpgbNEU6wNmsSqpwGxUhYLoSaM7b0dLmqP+Zc\n"
292 "zSS0Uac0PFNkehGQ2CYIT80f580o4XGtoLCUUGkp6YCTL4Z2CeBEaJABWjDIDH+d\n"
293 "KYIUBqUpz4Th12gXAP+h+3qI6+9eppeHrfrzARDsfLjwUNxQJse1QSArjAytf0FK\n"
294 "tGHrORc7W0TiCFvR0zaoUNLTKk7enTiRQ9rfWZOAu44fUvPCaXDE6zXXeaVgoKCo\n"
295 "4VHlho36erUcjlEBM+jk28IykbZGtBb6igKvYa1tPSgeYm/zJoFVjQcnr14uci/f\n"
296 "t1+Na+hOIEoEEiKxcAPk2b2vBKNlRIW7WLJ3u7ZiuQEJTNm6+3cE4+lfwaB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
327 "nwrHSLk7HdKhnwGsLPduuRRH8q0n/osnoOutSQroE0n41UyIv2ZNccRwNmSzQcai\n"
328 "rBu2dSz02hlsh2otNl5IuGpOqXyPjXBpW4qGD6n2tH7THALnLC0BHtTSQVQsJsRM\n"
329 "3gX39LoiWvLDp2qJvplm6rTpi8Rgap6rZSqHe1yNKIxxD2vlr/WY9SMgLXYASO4S\n"
330 "SBz9wfGOmQIPk6KXNJkdV4kC7nNjIi75iwLLCgjHgUiHTrDq5sWekpeNnUoWsinb\n"
331 "Tsdsjnv3zHG9GyiClyLGxMbs4M5eyYECggEBAKuC8ZMpdIrjk6tERYB6g0LnQ7mW\n"
332 "8XYbDFAmLYMLs9yfG2jcjVbsW9Kugsr+3poUUv/q+hNO3jfY4HazhZDa0MalgNPo\n"
333 "Swr/VNRnkck40x2ovFb989J7yl++zTrnIrax9XRH1V0cNu+Kj7OMwZ2RRfbNv5JB\n"
334 "dOZPvkfqyIKFmbQgYbtD66rHuzNOfJpzqr/WVLO57/zzW8245NKG2B6B0oXkei/K\n"
335 "qDY0DAbHR3i3EOj1NPtVI1FC/xX8R9BREaid458bqoHJKuInrGcBjaUI9Cvymv8T\n"
336 "bstUgD6NPbJR4Sm6vrLeUqzjWZP3t1+Z6DjXmnpR2vvhMU/FWb//21p/88o=");
337 *privkey_data_rsa = 1;
338 return 0;
339 } else if (!strcmp(name, "main_cert")) {
340 *cert_path = strdup(TESTS_DIR"/data/server.crt");
341 *privkey_path = strdup(TESTS_DIR"/data/server.key");
342 return 0;
343 }
344
345 return 1;
346}
347
348static int
349clb_trusted_cert_lists(const char *name, void *UNUSED(user_data), char ***cert_paths, int *cert_path_count,
350 char ***cert_data, int *cert_data_count)
351{
352 if (!strcmp(name, "trusted_cert_list1")) {
Michal Vaskoad0bcb52017-03-22 11:55:47 +0100353 *cert_data = malloc(sizeof **cert_data);
Michal Vasko346ac562018-11-05 08:47:18 +0100354 (*cert_data)[0] = strdup("MIIDnDCCAoSgAwIBAgIJAIjf7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g2Dumw8paqZC+Qv+Ib/NKquS1lO2Ry1wHBtXzn5K\n"
370 "KHHyM1bWMDaDszirw2+pp22VdRrPZNA9NWXheEDYOLyQekyL2CfidhxhaXvUZyWg\n"
371 "alLyF2XRZ5/jAT+NjfWw39EmWPUGk13Jm83OaFc1VdrXNCiD0sGCQ+BTCllDinQv\n"
372 "R08yzd4fzA3YXthvX1dBu1SvqQAGOS7gssRCyv9uWI6MXta25X91eY1ZMz1euJ04\n"
373 "mB8EdyYiZc0kzrb9dv5d0g==");
Michal Vasko4c1fb492017-01-30 14:31:07 +0100374 *cert_data_count = 1;
375 return 0;
376 } else if (!strcmp(name, "client_cert_list")) {
Michal Vasko75ff74b2017-03-21 15:34:34 +0100377 *cert_paths = malloc(sizeof **cert_paths);
Michal Vasko4c1fb492017-01-30 14:31:07 +0100378 (*cert_paths)[0] = strdup(TESTS_DIR"/data/client.crt");
379 *cert_path_count = 1;
380 return 0;
381 }
382
383 return 1;
384}
385
Michal Vasko734360b2016-02-08 15:38:25 +0100386static void *
Michal Vasko338f8472016-10-13 15:01:27 +0200387endpt_set_address_thread(void *arg)
Michal Vasko734360b2016-02-08 15:38:25 +0100388{
389 (void)arg;
390 int ret;
391
392 pthread_barrier_wait(&barrier);
393
Michal Vasko338f8472016-10-13 15:01:27 +0200394 ret = nc_server_endpt_set_address("quaternary", "0.0.0.0");
Michal Vasko64b31a22016-03-03 11:00:00 +0100395 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100396
397 return NULL;
398}
399
400static void *
Michal Vasko338f8472016-10-13 15:01:27 +0200401endpt_set_port_thread(void *arg)
Michal Vasko734360b2016-02-08 15:38:25 +0100402{
403 (void)arg;
404 int ret;
405
406 pthread_barrier_wait(&barrier);
407
Michal Vasko338f8472016-10-13 15:01:27 +0200408 ret = nc_server_endpt_set_port("quaternary", 6003);
Michal Vasko64b31a22016-03-03 11:00:00 +0100409 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100410
411 return NULL;
412}
413
414static void *
Michal Vasko4c1fb492017-01-30 14:31:07 +0100415tls_endpt_set_server_cert_thread(void *arg)
Michal Vasko734360b2016-02-08 15:38:25 +0100416{
417 (void)arg;
418 int ret;
419
420 pthread_barrier_wait(&barrier);
421
Michal Vasko4c1fb492017-01-30 14:31:07 +0100422 ret = nc_server_tls_endpt_set_server_cert("quaternary", "server_cert1");
Michal Vasko64b31a22016-03-03 11:00:00 +0100423 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100424
425 nc_thread_destroy();
426 return NULL;
427}
428
429static void *
Michal Vasko4c1fb492017-01-30 14:31:07 +0100430tls_endpt_add_trusted_cert_list_thread(void *arg)
Michal Vasko734360b2016-02-08 15:38:25 +0100431{
432 (void)arg;
433 int ret;
434
435 pthread_barrier_wait(&barrier);
436
Michal Vasko4c1fb492017-01-30 14:31:07 +0100437 ret = nc_server_tls_endpt_add_trusted_cert_list("quaternary", "trusted_cert_list1");
Michal Vasko64b31a22016-03-03 11:00:00 +0100438 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100439
440 nc_thread_destroy();
441 return NULL;
442}
443
444static void *
445tls_endpt_set_trusted_ca_paths_thread(void *arg)
446{
447 (void)arg;
448 int ret;
449
450 pthread_barrier_wait(&barrier);
451
Michal Vaskob477b222016-02-09 14:30:15 +0100452 ret = nc_server_tls_endpt_set_trusted_ca_paths("quaternary", TESTS_DIR"/data/serverca.pem", "data");
Michal Vasko64b31a22016-03-03 11:00:00 +0100453 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100454
455 nc_thread_destroy();
456 return NULL;
457}
458
459static void *
Michal Vasko4c1fb492017-01-30 14:31:07 +0100460tls_endpt_del_trusted_cert_list_thread(void *arg)
Michal Vasko734360b2016-02-08 15:38:25 +0100461{
462 (void)arg;
463
464 pthread_barrier_wait(&barrier);
465
Michal Vasko4c1fb492017-01-30 14:31:07 +0100466 nc_server_tls_endpt_del_trusted_cert_list("quaternary", "trusted_cert_list1");
Michal Vasko734360b2016-02-08 15:38:25 +0100467
468 return NULL;
469}
470
471static void *
472tls_endpt_set_crl_paths_thread(void *arg)
473{
474 (void)arg;
475 int ret;
476
477 pthread_barrier_wait(&barrier);
478
479 ret = nc_server_tls_endpt_set_crl_paths("quaternary", NULL, "data");
Michal Vasko64b31a22016-03-03 11:00:00 +0100480 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100481
482 nc_thread_destroy();
483 return NULL;
484}
485
486static void *
487tls_endpt_clear_crls_thread(void *arg)
488{
489 (void)arg;
490
491 pthread_barrier_wait(&barrier);
492
493 nc_server_tls_endpt_clear_crls("quaternary");
494
495 return NULL;
496}
497
498static void *
499tls_endpt_add_ctn_thread(void *arg)
500{
501 (void)arg;
502 int ret;
503
504 pthread_barrier_wait(&barrier);
505
Michal Vasko3cf4aaa2017-02-01 15:03:36 +0100506 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 +0100507 NC_TLS_CTN_SAN_IP_ADDRESS, NULL);
Michal Vasko64b31a22016-03-03 11:00:00 +0100508 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100509
510 return NULL;
511}
512
513static void *
514tls_endpt_del_ctn_thread(void *arg)
515{
516 (void)arg;
517 int ret;
518
519 pthread_barrier_wait(&barrier);
520
Michal Vasko338f8472016-10-13 15:01:27 +0200521 ret = nc_server_tls_endpt_del_ctn("main_tls", -1, NULL, NC_TLS_CTN_SAN_ANY, NULL);
Michal Vasko64b31a22016-03-03 11:00:00 +0100522 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100523
524 return NULL;
525}
526
527static void *
528tls_client_thread(void *arg)
529{
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100530 int ret, read_pipe = *(int *)arg;
531 char buf[9];
Michal Vasko734360b2016-02-08 15:38:25 +0100532 struct nc_session *session;
533
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100534 ret = read(read_pipe, buf, 9);
Michal Vasko64b31a22016-03-03 11:00:00 +0100535 nc_assert(ret == 9);
536 nc_assert(!strncmp(buf, "tls_ready", 9));
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100537
Michal Vaskob477b222016-02-09 14:30:15 +0100538 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 +0100539 nc_assert(!ret);
Michal Vaskobc2ae552016-02-09 14:38:47 +0100540 ret = nc_client_tls_set_trusted_ca_paths(NULL, TESTS_DIR"/data");
Michal Vasko64b31a22016-03-03 11:00:00 +0100541 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100542
543 session = nc_connect_tls("127.0.0.1", 6501, NULL);
Michal Vasko64b31a22016-03-03 11:00:00 +0100544 nc_assert(session);
Michal Vasko734360b2016-02-08 15:38:25 +0100545
Frank Rimplercb9274f2019-03-13 16:40:34 +0000546 /* verify some capabilities */
547 nc_assert( nc_session_cpblt(session, "urn:jmu:params:xml:ns:yang:module-a?module=module-a&deviations=module-a-dv,module-a-dv2") );
548
Michal Vaskoe1a64ec2016-03-01 12:21:58 +0100549 nc_session_free(session, NULL);
Michal Vasko734360b2016-02-08 15:38:25 +0100550
Michal Vaskoe2713da2016-08-22 16:06:40 +0200551 fprintf(stdout, "TLS client finished.\n");
552
Michal Vasko734360b2016-02-08 15:38:25 +0100553 nc_thread_destroy();
554 return NULL;
555}
556
Radek Krejci53691be2016-02-22 13:58:37 +0100557#endif /* NC_ENABLED_TLS */
Michal Vasko734360b2016-02-08 15:38:25 +0100558
559static void *(*thread_funcs[])(void *) = {
Radek Krejci53691be2016-02-22 13:58:37 +0100560#if defined(NC_ENABLED_SSH) || defined(NC_ENABLED_TLS)
Michal Vasko734360b2016-02-08 15:38:25 +0100561 server_thread,
562#endif
Radek Krejci53691be2016-02-22 13:58:37 +0100563#ifdef NC_ENABLED_SSH
Michal Vasko8727e432016-10-13 15:44:10 +0200564 add_endpt_thread,
565 del_endpt_thread,
Michal Vasko734360b2016-02-08 15:38:25 +0100566 ssh_endpt_set_hostkey_thread,
Michal Vasko734360b2016-02-08 15:38:25 +0100567 ssh_endpt_set_auth_methods_thread,
568 ssh_endpt_set_auth_attempts_thread,
569 ssh_endpt_set_auth_timeout_thread,
570 ssh_endpt_add_authkey_thread,
571 ssh_endpt_del_authkey_thread,
572#endif
Radek Krejci53691be2016-02-22 13:58:37 +0100573#ifdef NC_ENABLED_TLS
Michal Vasko8727e432016-10-13 15:44:10 +0200574 endpt_set_address_thread,
575 endpt_set_port_thread,
Michal Vasko4c1fb492017-01-30 14:31:07 +0100576 tls_endpt_set_server_cert_thread,
577 tls_endpt_add_trusted_cert_list_thread,
Michal Vasko734360b2016-02-08 15:38:25 +0100578 tls_endpt_set_trusted_ca_paths_thread,
Michal Vasko4c1fb492017-01-30 14:31:07 +0100579 tls_endpt_del_trusted_cert_list_thread,
Michal Vasko734360b2016-02-08 15:38:25 +0100580 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
587const int thread_count = sizeof thread_funcs / sizeof *thread_funcs;
588
Radek Krejci53691be2016-02-22 13:58:37 +0100589#if defined(NC_ENABLED_SSH) && defined(NC_ENABLED_TLS)
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100590const int client_count = 2;
591pid_t pids[2];
592int pipes[4];
Michal Vasko734360b2016-02-08 15:38:25 +0100593#else
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100594const int client_count = 1;
595pid_t pids[1];
596int pipes[2];
597#endif
598
599static void
600client_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 Vasko7f1c0ef2016-03-11 11:13:06 +0100610 ret = nc_client_set_schema_searchpath(TESTS_DIR"/../schemas");
Michal Vasko64b31a22016-03-03 11:00:00 +0100611 nc_assert(!ret);
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100612
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 Vasko734360b2016-02-08 15:38:25 +0100619 }
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100620 /* 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 Vasko7f1c0ef2016-03-11 11:13:06 +0100632 ret = nc_client_set_schema_searchpath(TESTS_DIR"/../schemas");
Michal Vasko64b31a22016-03-03 11:00:00 +0100633 nc_assert(!ret);
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100634
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 Vasko734360b2016-02-08 15:38:25 +0100646#endif
647}
648
649int
650main(void)
651{
652 struct ly_ctx *ctx;
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100653 int ret, i, clients = 0;
Michal Vasko734360b2016-02-08 15:38:25 +0100654 pthread_t tids[thread_count];
655
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100656 nc_verbosity(NC_VERB_VERBOSE);
657
658 client_fork();
Michal Vasko734360b2016-02-08 15:38:25 +0100659
Radek Krejci3222b7d2017-09-21 16:04:30 +0200660 ctx = ly_ctx_new(TESTS_DIR"/../schemas", 0);
Michal Vasko64b31a22016-03-03 11:00:00 +0100661 nc_assert(ctx);
Michal Vasko734360b2016-02-08 15:38:25 +0100662 ly_ctx_load_module(ctx, "ietf-netconf", NULL);
Frank Rimplercb9274f2019-03-13 16:40:34 +0000663
664 /* load some application models with deviations */
665 nc_assert( ly_ctx_load_module(ctx, "module-a", NULL) );
666 nc_assert( ly_ctx_load_module(ctx, "module-a-dv", NULL) );
667 nc_assert( ly_ctx_load_module(ctx, "module-a-dv2", NULL) );
668
Michal Vasko734360b2016-02-08 15:38:25 +0100669 nc_server_init(ctx);
670
671 pthread_barrier_init(&barrier, NULL, thread_count);
672
Radek Krejci53691be2016-02-22 13:58:37 +0100673#ifdef NC_ENABLED_SSH
Michal Vasko4c1fb492017-01-30 14:31:07 +0100674 /* set callback */
675 nc_server_ssh_set_hostkey_clb(clb_hostkeys, NULL, NULL);
676
Michal Vasko734360b2016-02-08 15:38:25 +0100677 /* do first, so that client can connect on SSH */
Michal Vasko338f8472016-10-13 15:01:27 +0200678 ret = nc_server_add_endpt("main_ssh", NC_TI_LIBSSH);
Michal Vaskoe2713da2016-08-22 16:06:40 +0200679 nc_assert(!ret);
Michal Vasko338f8472016-10-13 15:01:27 +0200680 ret = nc_server_endpt_set_address("main_ssh", "0.0.0.0");
Michal Vasko64b31a22016-03-03 11:00:00 +0100681 nc_assert(!ret);
Michal Vasko338f8472016-10-13 15:01:27 +0200682 ret = nc_server_endpt_set_port("main_ssh", 6001);
Michal Vasko64b31a22016-03-03 11:00:00 +0100683 nc_assert(!ret);
Michal Vasko17dfda92016-12-01 14:06:16 +0100684 ret = nc_server_ssh_add_authkey_path(TESTS_DIR"/data/key_dsa.pub", "test");
Michal Vasko338f8472016-10-13 15:01:27 +0200685 nc_assert(!ret);
Michal Vasko7d255882017-02-09 13:35:08 +0100686 ret = nc_server_ssh_endpt_add_hostkey("main_ssh", "key_rsa", -1);
Michal Vasko64b31a22016-03-03 11:00:00 +0100687 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100688
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100689 /* client ready */
690 ret = write(pipes[clients * 2 + 1], "ssh_ready", 9);
Michal Vasko64b31a22016-03-03 11:00:00 +0100691 nc_assert(ret == 9);
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100692 ++clients;
693
Michal Vasko734360b2016-02-08 15:38:25 +0100694 /* for ssh_endpt_del_authkey */
Michal Vasko17dfda92016-12-01 14:06:16 +0100695 ret = nc_server_ssh_add_authkey_path(TESTS_DIR"/data/key_ecdsa.pub", "test2");
Michal Vasko338f8472016-10-13 15:01:27 +0200696 nc_assert(!ret);
697
698 ret = nc_server_add_endpt("secondary", NC_TI_LIBSSH);
Michal Vasko64b31a22016-03-03 11:00:00 +0100699 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100700#endif
701
Radek Krejci53691be2016-02-22 13:58:37 +0100702#ifdef NC_ENABLED_TLS
Michal Vasko4c1fb492017-01-30 14:31:07 +0100703 /* set callbacks */
704 nc_server_tls_set_server_cert_clb(clb_server_cert, NULL, NULL);
705 nc_server_tls_set_trusted_cert_list_clb(clb_trusted_cert_lists, NULL, NULL);
706
Michal Vasko734360b2016-02-08 15:38:25 +0100707 /* do first, so that client can connect on TLS */
Michal Vasko338f8472016-10-13 15:01:27 +0200708 ret = nc_server_add_endpt("main_tls", NC_TI_OPENSSL);
Michal Vaskoe2713da2016-08-22 16:06:40 +0200709 nc_assert(!ret);
Michal Vasko338f8472016-10-13 15:01:27 +0200710 ret = nc_server_endpt_set_address("main_tls", "0.0.0.0");
Michal Vasko64b31a22016-03-03 11:00:00 +0100711 nc_assert(!ret);
Michal Vasko338f8472016-10-13 15:01:27 +0200712 ret = nc_server_endpt_set_port("main_tls", 6501);
Michal Vasko64b31a22016-03-03 11:00:00 +0100713 nc_assert(!ret);
Michal Vasko4c1fb492017-01-30 14:31:07 +0100714 ret = nc_server_tls_endpt_set_server_cert("main_tls", "main_cert");
Michal Vasko64b31a22016-03-03 11:00:00 +0100715 nc_assert(!ret);
Michal Vasko4c1fb492017-01-30 14:31:07 +0100716 ret = nc_server_tls_endpt_add_trusted_cert_list("main_tls", "client_cert_list");
Michal Vasko338f8472016-10-13 15:01:27 +0200717 nc_assert(!ret);
Michal Vasko346ac562018-11-05 08:47:18 +0100718 ret = nc_server_tls_endpt_add_ctn("main_tls", 0, "02:B3:9F:26:65:76:6B:CC:FC:86:8E:D4:1A:81:64:0F:92:EB:18:AE:FF", NC_TLS_CTN_SPECIFIED, "test");
Michal Vasko64b31a22016-03-03 11:00:00 +0100719 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100720
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100721 /* client ready */
722 ret = write(pipes[clients * 2 + 1], "tls_ready", 9);
Michal Vasko64b31a22016-03-03 11:00:00 +0100723 nc_assert(ret == 9);
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100724 ++clients;
725
Michal Vasko734360b2016-02-08 15:38:25 +0100726 /* for tls_endpt_del_ctn */
Michal Vasko3cf4aaa2017-02-01 15:03:36 +0100727 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 +0200728 nc_assert(!ret);
729
730 ret = nc_server_add_endpt("quaternary", NC_TI_OPENSSL);
Michal Vasko64b31a22016-03-03 11:00:00 +0100731 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100732#endif
733
Michal Vasko734360b2016-02-08 15:38:25 +0100734 /* threads'n'stuff */
735 ret = 0;
736 for (i = 0; i < thread_count; ++i) {
737 ret += pthread_create(&tids[i], NULL, thread_funcs[i], NULL);
738 }
Michal Vasko64b31a22016-03-03 11:00:00 +0100739 nc_assert(!ret);
Michal Vasko734360b2016-02-08 15:38:25 +0100740
741 /* cleanup */
742 for (i = 0; i < thread_count; ++i) {
743 pthread_join(tids[i], NULL);
744 }
Michal Vaskoa7b8ca52016-03-01 12:09:29 +0100745 for (i = 0; i < client_count; ++i) {
746 waitpid(pids[i], NULL, 0);
747 close(pipes[i * 2 + 1]);
748 }
Michal Vasko734360b2016-02-08 15:38:25 +0100749
750 pthread_barrier_destroy(&barrier);
751
Michal Vasko734360b2016-02-08 15:38:25 +0100752 nc_server_destroy();
753 ly_ctx_destroy(ctx, NULL);
754
Michal Vasko734360b2016-02-08 15:38:25 +0100755 return 0;
756}