blob: 5511da94b3c00b810fc899109453426918914152 [file] [log] [blame]
romanc1d2b092023-02-02 08:58:27 +01001/**
2 * @file test_auth.c
3 * @author Roman Janota <xjanot04@fit.vutbr.cz>
4 * @brief libnetconf2 Linux PAM keyboard-interactive authentication test
5 *
6 * @copyright
7 * Copyright (c) 2022 CESNET, z.s.p.o.
8 *
9 * This source code is licensed under BSD 3-Clause License (the "License").
10 * You may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * https://opensource.org/licenses/BSD-3-Clause
14 */
15
16#include <errno.h>
17#include <pthread.h>
18#include <setjmp.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22
23#include <cmocka.h>
24
25#include <config_server.h>
26#include <libnetconf.h>
27#include <libyang/libyang.h>
28#include <log.h>
29#include <session_client.h>
30#include <session_server.h>
31
32#include "tests/config.h"
33
roman83683fb2023-02-24 09:15:23 +010034#define NC_ACCEPT_TIMEOUT 2000
35#define NC_PS_POLL_TIMEOUT 2000
romanc1d2b092023-02-02 08:58:27 +010036
37struct ly_ctx *ctx;
38
39struct test_state {
romanc1d2b092023-02-02 08:58:27 +010040 pthread_barrier_t barrier;
41};
42
43const char *data =
44 "<netconf-server xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-server\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
45 " <listen yang:operation=\"create\">\n"
46 " <idle-timeout>10</idle-timeout>\n"
47 " <endpoint>\n"
48 " <name>default-ssh</name>\n"
49 " <ssh>\n"
50 " <tcp-server-parameters>\n"
51 " <local-address>127.0.0.1</local-address>\n"
52 " <local-port>10005</local-port>\n"
53 " </tcp-server-parameters>\n"
54 " <ssh-server-parameters>\n"
55 " <server-identity>\n"
56 " <host-key>\n"
57 " <name>key</name>\n"
58 " <public-key>\n"
59 " <local-definition>\n"
60 " <public-key-format xmlns:ct=\"urn:ietf:params:xml:ns:yang:ietf-crypto-types\">ct:ssh-public-key-format</public-key-format>\n"
61 " <public-key>MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA6ojtjfDmvyQP1ZkIwBpr97eKDuebvpoglRHRdvVuTpf/gU1VArAQmwGh05i6lm8TkVl1noMlIxLJDcWslaeVn6KyvsX0HhsQtXwqPqwka5UCv6alwf/ivAvcNpcX1j0t/uIGCI4dSiKnzQCyf0FTirzQkjrDZUd3meDhNQTruCalGV4gfNWIq3e1oGuwAn1tLlu9oTrE4HzMpgbNEU6wNmsSqpwGxUhYLoSaM7b0dLmqP+ZczSS0Uac0PFNkehGQ2CYIT80f580o4XGtoLCUUGkp6YCTL4Z2CeBEaJABWjDIDH+dKYIUBqUpz4Th12gXAP+h+3qI6+9eppeHrfrzARDsfLjwUNxQJse1QSArjAytf0FKtGHrORc7W0TiCFvR0zaoUNLTKk7enTiRQ9rfWZOAu44fUvPCaXDE6zXXeaVgoKCo4VHlho36erUcjlEBM+jk28IykbZGtBb6igKvYa1tPSgeYm/zJoFVjQcnr14uci/ft1+Na+hOIEoEEiKxcAPk2b2vBKNlRIW7WLJ3u7ZiuQEJTNm6+3cE4+lfwaBCBqBToE+dpzvoUXoMyFFReUFd1O5axu4fXgt00jMaOQxmE0v9OmR/pL/PWIflVF4Zz5yVONYaDVc7l+veY0oEZruEPJ0hlEgxuCzLrcMhjufl2qE2Q7fQIaav/1NqBVkCAwEAAQ==</public-key>\n"
62 " <private-key-format xmlns:ct=\"urn:ietf:params:xml:ns:yang:ietf-crypto-types\">ct:rsa-private-key-format</private-key-format>\n"
63 " <cleartext-private-key>MIIJKAIBAAKCAgEA6ojtjfDmvyQP1ZkIwBpr97eKDuebvpoglRHRdvVuTpf/gU1VArAQmwGh05i6lm8TkVl1noMlIxLJDcWslaeVn6KyvsX0HhsQtXwqPqwka5UCv6alwf/ivAvcNpcX1j0t/uIGCI4dSiKnzQCyf0FTirzQkjrDZUd3meDhNQTruCalGV4gfNWIq3e1oGuwAn1tLlu9oTrE4HzMpgbNEU6wNmsSqpwGxUhY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bHWnds5H1shoFPNtYTvWBL/gfPHjIc+H23zsiu3XlZAoIBAC2xB/Pnpoi9vOUMiqFH36AXtYa1DURy+AqCFlYlClMvb7YgvQ1w1eJvnwrHSLk7HdKhnwGsLPduuRRH8q0n/osnoOutSQroE0n41UyIv2ZNccRwNmSzQcairBu2dSz02hlsh2otNl5IuGpOqXyPjXBpW4qGD6n2tH7THALnLC0BHtTSQVQsJsRM3gX39LoiWvLDp2qJvplm6rTpi8Rgap6rZSqHe1yNKIxxD2vlr/WY9SMgLXYASO4SSBz9wfGOmQIPk6KXNJkdV4kC7nNjIi75iwLLCgjHgUiHTrDq5sWekpeNnUoWsinbTsdsjnv3zHG9GyiClyLGxMbs4M5eyYECggEBAKuC8ZMpdIrjk6tERYB6g0LnQ7mW8XYbDFAmLYMLs9yfG2jcjVbsW9Kugsr+3poUUv/q+hNO3jfY4HazhZDa0MalgNPoSwr/VNRnkck40x2ovFb989J7yl++zTrnIrax9XRH1V0cNu+Kj7OMwZ2RRfbNv5JBdOZPvkfqyIKFmbQgYbtD66rHuzNOfJpzqr/WVLO57/zzW8245NKG2B6B0oXkei/KqDY0DAbHR3i3EOj1NPtVI1FC/xX8R9BREaid458bqoHJKuInrGcBjaUI9Cvymv8TbstUgD6NPbJR4Sm6vrLeUqzjWZP3t1+Z6DjXmnpR2vvhMU/FWb//21p/88o=</cleartext-private-key>\n"
64 " </local-definition>\n"
65 " </public-key>\n"
66 " </host-key>\n"
67 " </server-identity>\n"
68 " <client-authentication>\n"
69 " <users>\n"
70 " <user>\n"
71 " <name>test_pk</name>\n"
72 " <public-keys>\n"
73 " <local-definition>\n"
74 " <public-key>\n"
75 " <name>test</name>\n"
76 " <public-key-format xmlns:ct=\"urn:ietf:params:xml:ns:yang:ietf-crypto-types\">ct:ssh-public-key-format</public-key-format>\n"
77 " <public-key>AAAAB3NzaC1yc2EAAAADAQABAAABAQDPavVALiM7QwTIUAndO8E9GOkSDQWjuEwkzbJ3kOBPa7kkq71UOZFeecDjFb9eipkljfFys/JYHGQaYVF8/svT0KV5h7HlutRdF6yvqSEbjpbTORb27pdHX3iFEyDCwCIoq9vMeX+wyXnteyn01GpIL0ig0WAnvkqX/SPjuplX5ZItUSr0MhXM7fNSX50BD6G8IO0/djUcdMUcjTjGv73SxB9ZzLvxnhXuUJbzEJJJLj6qajyEIVaJSa73vA33JCD8qzarrsuITojVLPDFmeHwSAoB5dP86yop6e6ypuXzKxxef6yNXcE8oTj8UFYBIXsgIP2nBvWk41EaK0Vk3YFl</public-key>\n"
78 " </public-key>\n"
79 " </local-definition>\n"
80 " </public-keys>\n"
81 " </user>\n"
82 " <user>\n"
83 " <name>test_int</name>\n"
84 " <keyboard-interactive xmlns=\"urn:cesnet:libnetconf2-netconf-server\">\n"
85 " <pam-config-file-name>netconf.conf</pam-config-file-name>\n"
86 " <pam-config-file-dir>" BUILD_DIR "/tests</pam-config-file-dir>\n"
87 " </keyboard-interactive>\n"
88 " </user>\n"
89 " <user>\n"
90 " <name>test_pw</name>\n"
91 " <password>$6$xyz$lomVe5tZ2Gz9uSKKywzXuPcHhqjIByhBbqdUTx/jAwUnw7JRp7QHd4ORiEVqxeZg1NEJkHux.mETo9BFPSh1x.</password>\n"
92 " </user>\n"
93 " <user>\n"
94 " <name>test_none</name>\n"
95 " <none/>\n"
96 " </user>\n"
97 " </users>\n"
98 " </client-authentication>\n"
99 " <transport-params>\n"
100 " <host-key>\n"
101 " <host-key-alg xmlns:sshpka=\"urn:ietf:params:xml:ns:yang:iana-ssh-public-key-algs\">sshpka:rsa-sha2-512</host-key-alg>\n"
102 " </host-key>\n"
103 " <key-exchange>\n"
104 " <key-exchange-alg xmlns:sshkea=\"urn:ietf:params:xml:ns:yang:iana-ssh-key-exchange-algs\">sshkea:curve25519-sha256</key-exchange-alg>\n"
105 " </key-exchange>\n"
106 " <encryption>\n"
107 " <encryption-alg xmlns:sshea=\"urn:ietf:params:xml:ns:yang:iana-ssh-encryption-algs\">sshea:aes256-ctr</encryption-alg>\n"
108 " </encryption>\n"
109 " <mac>\n"
110 " <mac-alg xmlns:sshma=\"urn:ietf:params:xml:ns:yang:iana-ssh-mac-algs\">sshma:hmac-sha2-512</mac-alg>\n"
111 " </mac>\n"
112 " </transport-params>\n"
113 " </ssh-server-parameters>\n"
114 " </ssh>\n"
115 " </endpoint>\n"
116 " </listen>\n"
117 "</netconf-server>\n";
118
119static void *
120server_thread(void *arg)
121{
122 int ret;
123 NC_MSG_TYPE msgtype;
124 struct nc_session *session;
125 struct nc_pollsession *ps;
126 struct test_state *state = arg;
127
128 (void) arg;
129
130 ps = nc_ps_new();
131 assert_non_null(ps);
132
133 /* accept a session and add it to the poll session structure */
134 pthread_barrier_wait(&state->barrier);
135 msgtype = nc_accept(NC_ACCEPT_TIMEOUT, ctx, &session);
136 assert_int_equal(msgtype, NC_MSG_HELLO);
137
138 ret = nc_ps_add_session(ps, session);
139 assert_int_equal(ret, 0);
140
141 do {
142 ret = nc_ps_poll(ps, NC_PS_POLL_TIMEOUT, NULL);
143 assert_int_equal(ret & NC_PSPOLL_RPC, NC_PSPOLL_RPC);
144 } while (!(ret & NC_PSPOLL_SESSION_TERM));
145
146 nc_ps_clear(ps, 1, NULL);
147 nc_ps_free(ps);
148 nc_thread_destroy();
149 return NULL;
150}
151
152static int
153ssh_hostkey_check_clb(const char *hostname, ssh_session session, void *priv)
154{
155 (void)hostname;
156 (void)session;
157 (void)priv;
158 /* skip the knownhost check */
159
160 return 0;
161}
162
163static char *
164auth_interactive(const char *auth_name, const char *instruction, const char *prompt, int echo, void *priv)
165{
166 (void) instruction;
167 (void) echo;
168 (void) auth_name;
169 (void) priv;
170
171 /* send the replies to keyboard-interactive authentication */
172 if (strstr(prompt, "backwards")) {
173 return strdup("tni_tset");
174 } else if (strstr(prompt, "1+1")) {
175 return strdup("2");
176 } else {
177 return NULL;
178 }
179}
180
181static void *
182client_thread_interactive(void *arg)
183{
184 int ret;
185 struct nc_session *session = NULL;
186 struct test_state *state = arg;
187
188 ret = nc_client_set_schema_searchpath(MODULES_DIR);
189 assert_int_equal(ret, 0);
190
191 ret = nc_client_ssh_set_username("test_int");
192 assert_int_equal(ret, 0);
193
194 /* set keyboard-interactive authentication callback */
195 nc_client_ssh_set_auth_interactive_clb(auth_interactive, NULL);
196
197 nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PUBLICKEY, -1);
198 nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PASSWORD, -1);
199 nc_client_ssh_set_auth_pref(NC_SSH_AUTH_INTERACTIVE, 1);
200
201 pthread_barrier_wait(&state->barrier);
202 session = nc_connect_ssh("127.0.0.1", 10005, NULL);
203 assert_non_null(session);
204
205 nc_session_free(session, NULL);
206 nc_thread_destroy();
207 return NULL;
208}
209
210static void
211test_nc_auth_interactive(void **state)
212{
213 int ret, i;
214 pthread_t tids[2];
215
216 assert_non_null(state);
217
218 ret = pthread_create(&tids[0], NULL, client_thread_interactive, *state);
219 assert_int_equal(ret, 0);
220 ret = pthread_create(&tids[1], NULL, server_thread, *state);
221 assert_int_equal(ret, 0);
222
223 for (i = 0; i < 2; i++) {
224 pthread_join(tids[i], NULL);
225 }
226}
227
228static char *
229auth_password(const char *username, const char *hostname, void *priv)
230{
231 (void) hostname;
232 (void) priv;
233
234 /* send the replies to keyboard-interactive authentication */
235 if (!strcmp(username, "test_pw")) {
236 return strdup("testpw");
237 } else {
238 return NULL;
239 }
240}
241
242static void *
243client_thread_password(void *arg)
244{
245 int ret;
246 struct nc_session *session = NULL;
247 struct test_state *state = arg;
248
249 ret = nc_client_set_schema_searchpath(MODULES_DIR);
250 assert_int_equal(ret, 0);
251
252 ret = nc_client_ssh_set_username("test_pw");
253 assert_int_equal(ret, 0);
254
255 nc_client_ssh_set_auth_password_clb(auth_password, NULL);
256
257 nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PUBLICKEY, -1);
258 nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PASSWORD, 1);
259 nc_client_ssh_set_auth_pref(NC_SSH_AUTH_INTERACTIVE, -1);
260
261 pthread_barrier_wait(&state->barrier);
262 session = nc_connect_ssh("127.0.0.1", 10005, NULL);
263 assert_non_null(session);
264
265 nc_session_free(session, NULL);
266 nc_thread_destroy();
267 return NULL;
268}
269
270static void
271test_nc_auth_password(void **state)
272{
273 int ret, i;
274 pthread_t tids[2];
275
276 assert_non_null(state);
277
278 ret = pthread_create(&tids[0], NULL, client_thread_password, *state);
279 assert_int_equal(ret, 0);
280 ret = pthread_create(&tids[1], NULL, server_thread, *state);
281 assert_int_equal(ret, 0);
282
283 for (i = 0; i < 2; i++) {
284 pthread_join(tids[i], NULL);
285 }
286}
287
288static void *
289client_thread_pubkey(void *arg)
290{
291 int ret;
292 struct nc_session *session = NULL;
293 struct test_state *state = arg;
294
295 ret = nc_client_set_schema_searchpath(MODULES_DIR);
296 assert_int_equal(ret, 0);
297
298 ret = nc_client_ssh_set_username("test_pk");
299 assert_int_equal(ret, 0);
300
301 nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PUBLICKEY, 1);
302 nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PASSWORD, -1);
303 nc_client_ssh_set_auth_pref(NC_SSH_AUTH_INTERACTIVE, -1);
304
305 ret = nc_client_ssh_add_keypair(TESTS_DIR "/data/key_rsa.pub", TESTS_DIR "/data/key_rsa");
306 assert_int_equal(ret, 0);
307
308 pthread_barrier_wait(&state->barrier);
309 session = nc_connect_ssh("127.0.0.1", 10005, NULL);
310 assert_non_null(session);
311
312 nc_session_free(session, NULL);
313 nc_thread_destroy();
314 return NULL;
315}
316
317static void
318test_nc_auth_pubkey(void **state)
319{
320 int ret, i;
321 pthread_t tids[2];
322
323 assert_non_null(state);
324
325 ret = pthread_create(&tids[0], NULL, client_thread_pubkey, *state);
326 assert_int_equal(ret, 0);
327 ret = pthread_create(&tids[1], NULL, server_thread, *state);
328 assert_int_equal(ret, 0);
329
330 for (i = 0; i < 2; i++) {
331 pthread_join(tids[i], NULL);
332 }
333}
334
335static void *
336client_thread_none(void *arg)
337{
338 int ret;
339 struct nc_session *session = NULL;
340 struct test_state *state = arg;
341
342 ret = nc_client_set_schema_searchpath(MODULES_DIR);
343 assert_int_equal(ret, 0);
344
345 ret = nc_client_ssh_set_username("test_none");
346 assert_int_equal(ret, 0);
347
348 pthread_barrier_wait(&state->barrier);
349 session = nc_connect_ssh("127.0.0.1", 10005, NULL);
350 assert_non_null(session);
351
352 nc_session_free(session, NULL);
353 nc_thread_destroy();
354 return NULL;
355}
356
357static void
358test_nc_auth_none(void **state)
359{
360 int ret, i;
361 pthread_t tids[2];
362
363 assert_non_null(state);
364
365 ret = pthread_create(&tids[0], NULL, client_thread_none, *state);
366 assert_int_equal(ret, 0);
367 ret = pthread_create(&tids[1], NULL, server_thread, *state);
368 assert_int_equal(ret, 0);
369
370 for (i = 0; i < 2; i++) {
371 pthread_join(tids[i], NULL);
372 }
373}
374
375static int
376setup_f(void **state)
377{
378 int ret;
379 struct lyd_node *tree;
380 struct test_state *test_state;
381
382 nc_verbosity(NC_VERB_VERBOSE);
383
384 /* init barrier */
385 test_state = malloc(sizeof *test_state);
386 assert_non_null(test_state);
387
388 ret = pthread_barrier_init(&test_state->barrier, NULL, 2);
389 assert_int_equal(ret, 0);
390
391 *state = test_state;
392
393 ret = ly_ctx_new(MODULES_DIR, 0, &ctx);
394 assert_int_equal(ret, 0);
395
396 ret = nc_server_init_ctx(&ctx);
397 assert_int_equal(ret, 0);
398
399 ret = nc_server_config_load_modules(&ctx);
400 assert_int_equal(ret, 0);
401
402 /* parse yang data */
403 ret = lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_NO_STATE | LYD_PARSE_STRICT, LYD_VALIDATE_NO_STATE, &tree);
404 assert_int_equal(ret, 0);
405
406 /* configure the server based on the data */
407 ret = nc_server_config_setup(tree);
408 assert_int_equal(ret, 0);
409
410 /* initialize client */
411 nc_client_init();
412
413 ret = nc_server_init();
414 assert_int_equal(ret, 0);
415
416 /* skip the knownhost check */
417 nc_client_ssh_set_auth_hostkey_check_clb(ssh_hostkey_check_clb, NULL);
418
419 lyd_free_all(tree);
420
421 return 0;
422}
423
424static int
425teardown_f(void **state)
426{
427 int ret = 0;
428 struct test_state *test_state;
429
430 assert_non_null(state);
431 test_state = *state;
432
433 ret = pthread_barrier_destroy(&test_state->barrier);
434 assert_int_equal(ret, 0);
435
436 free(*state);
437 nc_client_destroy();
438 nc_server_destroy();
439 ly_ctx_destroy(ctx);
440
441 return 0;
442}
443
444int
445main(void)
446{
447 const struct CMUnitTest tests[] = {
448 cmocka_unit_test_setup_teardown(test_nc_auth_interactive, setup_f, teardown_f),
449 cmocka_unit_test_setup_teardown(test_nc_auth_pubkey, setup_f, teardown_f),
450 cmocka_unit_test_setup_teardown(test_nc_auth_password, setup_f, teardown_f),
451 cmocka_unit_test_setup_teardown(test_nc_auth_none, setup_f, teardown_f)
452 };
453
454 setenv("CMOCKA_TEST_ABORT", "1", 1);
455 return cmocka_run_group_tests(tests, NULL, NULL);
456}