Line data Source code
1 : /*
2 : Authors:
3 : Pavel Reichl <preichl@redhat.com>
4 :
5 : Copyright (C) 2014 Red Hat
6 :
7 : Test for the NSS Responder ID-SID mapping interface
8 :
9 : This program is free software; you can redistribute it and/or modify
10 : it under the terms of the GNU General Public License as published by
11 : the Free Software Foundation; either version 3 of the License, or
12 : (at your option) any later version.
13 :
14 : This program is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : GNU General Public License for more details.
18 :
19 : You should have received a copy of the GNU General Public License
20 : along with this program. If not, see <http://www.gnu.org/licenses/>.
21 : */
22 :
23 : #include "util/util.h"
24 : #include "util/sss_ssh.h"
25 : #include "tests/cmocka/common_mock.h"
26 : #include "test_utils.h"
27 :
28 : uint8_t key_data_noLF[] = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfymad64oZkWa6q3xLXmCt/LfCRnd6yZSDp7UK6Irx5/Dv69dEKK2kBGL9Wfn+3ZDa6ov2XZrBmUthh8KOJvTw72+axox3kcJ5HwOYZCMeKbcr10RNScGuHErA1HhjTY6M9L8d0atVH2QIxw7ZHoVVnTHC4U4+541YfJkNUiOUIj65cFFZm9ULp32ZPrK+j2wW+XZkHhrZeFMlg4x4fe5FocO6ik1eqLxBejo7tMy+1m3R2a795AIguf6vNWeE5aNMd4pcmPcZHb3JOq3ItzE/3lepXD/3wqMt36EqNykBVE7aJj+LVkcEgjP9CDDsg9j9NB+AuWYmIYqrHW/Rg/vJ developer@sssd.dev.work";
29 :
30 : uint8_t key_data_LF[] = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfymad64oZkWa6q3xLXmCt/LfCRnd6yZSDp7UK6Irx5/Dv69dEKK2kBGL9Wfn+3ZDa6ov2XZrBmUthh8KOJvTw72+axox3kcJ5HwOYZCMeKbcr10RNScGuHErA1HhjTY6M9L8d0atVH2QIxw7ZHoVVnTHC4U4+541YfJkNUiOUIj65cFFZm9ULp32ZPrK+j2wW+XZkHhrZeFMlg4x4fe5FocO6ik1eqLxBejo7tMy+1m3R2a795AIguf6vNWeE5aNMd4pcmPcZHb3JOq3ItzE/3lepXD/3wqMt36EqNykBVE7aJj+LVkcEgjP9CDDsg9j9NB+AuWYmIYqrHW/Rg/vJ developer@sssd.dev.work\n";
31 :
32 : uint8_t key_data_LFLF[] = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfymad64oZkWa6q3xLXmCt/LfCRnd6yZSDp7UK6Irx5/Dv69dEKK2kBGL9Wfn+3ZDa6ov2XZrBmUthh8KOJvTw72+axox3kcJ5HwOYZCMeKbcr10RNScGuHErA1HhjTY6M9L8d0atVH2QIxw7ZHoVVnTHC4U4+541YfJkNUiOUIj65cFFZm9ULp32ZPrK+j2wW+XZkHhrZeFMlg4x4fe5FocO6ik1eqLxBejo7tMy+1m3R2a795AIguf6vNWeE5aNMd4pcmPcZHb3JOq3ItzE/3lepXD/3wqMt36EqNykBVE7aJj+LVkcEgjP9CDDsg9j9NB+AuWYmIYqrHW/Rg/vJ developer@sssd.dev.work\n\n";
33 :
34 : uint8_t key_data_CRLF[] = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfymad64oZkWa6q3xLXmCt/LfCRnd6yZSDp7UK6Irx5/Dv69dEKK2kBGL9Wfn+3ZDa6ov2XZrBmUthh8KOJvTw72+axox3kcJ5HwOYZCMeKbcr10RNScGuHErA1HhjTY6M9L8d0atVH2QIxw7ZHoVVnTHC4U4+541YfJkNUiOUIj65cFFZm9ULp32ZPrK+j2wW+XZkHhrZeFMlg4x4fe5FocO6ik1eqLxBejo7tMy+1m3R2a795AIguf6vNWeE5aNMd4pcmPcZHb3JOq3ItzE/3lepXD/3wqMt36EqNykBVE7aJj+LVkcEgjP9CDDsg9j9NB+AuWYmIYqrHW/Rg/vJ developer@sssd.dev.work\r\n";
35 :
36 : uint8_t key_data_CR_somewhere[] = "ssh-rsa AA\rAAB3NzaC1yc2EAAAADAQABAAABAQDfymad64oZkWa6q3xLXmCt/LfCRnd6yZSDp7UK6Irx5/Dv69dEKK2kBGL9Wf+3ZDa6ov2XZrBmUthh8KOJvTw72+axox3kcJ5HwOYZCMeKbcr10RNScGuHErA1HhjTY6M9L8d0atVH2QIxw7ZHoVVnTHC4U4+541YfJkNUiOUIj65cFFZm9ULp32ZPrK+j2wW+XZkHhrZeFMlg4x4fe5FocO6ik1eqLxBejo7tMy+1m3R2a795AIguf6vNWeE5aNMd4pcmPcZHb3JOq3ItzE/3lepXD/3wqMt36EqNykBVE7aJj+LVkcEgjP9CDDsg9j9NB+AuWYmIYqrHW/Rg/vJ developer@sssd.dev.work\n";
37 :
38 1 : void test_textual_public_key(void **state)
39 : {
40 : TALLOC_CTX *mem_ctx;
41 : errno_t ret;
42 : char *res;
43 :
44 1 : struct sss_ssh_pubkey pkey_null_terminated = {
45 : .data = key_data_noLF,
46 : .data_len = sizeof(key_data_noLF)
47 : };
48 :
49 1 : struct sss_ssh_pubkey pkey = {
50 : .data = key_data_noLF,
51 : .data_len = sizeof(key_data_noLF) - 1 /* ignore trailling '\0' */
52 : };
53 :
54 1 : struct sss_ssh_pubkey pkey_LF = {
55 : .data = key_data_LF,
56 : .data_len = sizeof(key_data_LF) - 1 /* ignore trailling '\0' */
57 : };
58 :
59 1 : struct sss_ssh_pubkey pkey_LFLF = {
60 : .data = key_data_LFLF,
61 : .data_len = sizeof(key_data_LFLF) - 1 /* ignore trailling '\0' */
62 : };
63 :
64 1 : struct sss_ssh_pubkey pkey_CRLF = {
65 : .data = key_data_CRLF,
66 : .data_len = sizeof(key_data_CRLF) - 1 /* ignore trailling '\0' */
67 : };
68 :
69 1 : struct sss_ssh_pubkey pkey_CR_somewhere = {
70 : .data = key_data_CR_somewhere,
71 : .data_len = sizeof(key_data_CR_somewhere) - 1 /* ignore traill. '\0' */
72 : };
73 :
74 1 : mem_ctx = talloc_new(NULL);
75 1 : assert_non_null(mem_ctx);
76 1 : check_leaks_push(mem_ctx);
77 :
78 1 : ret = sss_ssh_format_pubkey(mem_ctx, &pkey, &res);
79 1 : assert_int_equal(ret, EOK);
80 1 : talloc_free(res);
81 :
82 1 : ret = sss_ssh_format_pubkey(mem_ctx, &pkey_LF, &res);
83 1 : assert_int_equal(ret, EOK);
84 1 : talloc_free(res);
85 :
86 1 : ret = sss_ssh_format_pubkey(mem_ctx, &pkey_LFLF, &res);
87 1 : assert_int_equal(ret, EINVAL);
88 :
89 1 : ret = sss_ssh_format_pubkey(mem_ctx, &pkey_null_terminated, &res);
90 1 : assert_int_equal(ret, EINVAL);
91 :
92 1 : ret = sss_ssh_format_pubkey(mem_ctx, &pkey_CRLF, &res);
93 1 : assert_int_equal(ret, EINVAL);
94 :
95 1 : ret = sss_ssh_format_pubkey(mem_ctx, &pkey_CR_somewhere, &res);
96 1 : assert_int_equal(ret, EINVAL);
97 :
98 1 : assert_true(check_leaks_pop(mem_ctx) == true);
99 1 : talloc_free(mem_ctx);
100 1 : }
|