b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl/*
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl Authors:
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl Pavel Reichl <preichl@redhat.com>
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl Copyright (C) 2014 Red Hat
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl Test for the NSS Responder ID-SID mapping interface
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl This program is free software; you can redistribute it and/or modify
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl it under the terms of the GNU General Public License as published by
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl the Free Software Foundation; either version 3 of the License, or
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl (at your option) any later version.
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl This program is distributed in the hope that it will be useful,
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl but WITHOUT ANY WARRANTY; without even the implied warranty of
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl GNU General Public License for more details.
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl You should have received a copy of the GNU General Public License
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl along with this program. If not, see <http://www.gnu.org/licenses/>.
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl*/
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl#include "util/util.h"
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl#include "util/sss_ssh.h"
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl#include "tests/cmocka/common_mock.h"
462db32918a05097652f8232cd6c8d78a826e63cLukas Slebodnik#include "test_utils.h"
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichluint8_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";
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichluint8_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";
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichluint8_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";
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichluint8_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";
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichluint8_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";
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichlvoid test_textual_public_key(void **state)
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl{
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl TALLOC_CTX *mem_ctx;
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl errno_t ret;
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl char *res;
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl struct sss_ssh_pubkey pkey_null_terminated = {
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl .data = key_data_noLF,
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl .data_len = sizeof(key_data_noLF)
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl };
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl struct sss_ssh_pubkey pkey = {
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl .data = key_data_noLF,
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl .data_len = sizeof(key_data_noLF) - 1 /* ignore trailling '\0' */
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl };
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl struct sss_ssh_pubkey pkey_LF = {
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl .data = key_data_LF,
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl .data_len = sizeof(key_data_LF) - 1 /* ignore trailling '\0' */
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl };
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl struct sss_ssh_pubkey pkey_LFLF = {
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl .data = key_data_LFLF,
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl .data_len = sizeof(key_data_LFLF) - 1 /* ignore trailling '\0' */
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl };
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl struct sss_ssh_pubkey pkey_CRLF = {
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl .data = key_data_CRLF,
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl .data_len = sizeof(key_data_CRLF) - 1 /* ignore trailling '\0' */
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl };
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl struct sss_ssh_pubkey pkey_CR_somewhere = {
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl .data = key_data_CR_somewhere,
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl .data_len = sizeof(key_data_CR_somewhere) - 1 /* ignore traill. '\0' */
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl };
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl mem_ctx = talloc_new(NULL);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl assert_non_null(mem_ctx);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl check_leaks_push(mem_ctx);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl ret = sss_ssh_format_pubkey(mem_ctx, &pkey, &res);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl assert_int_equal(ret, EOK);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl talloc_free(res);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl ret = sss_ssh_format_pubkey(mem_ctx, &pkey_LF, &res);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl assert_int_equal(ret, EOK);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl talloc_free(res);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl ret = sss_ssh_format_pubkey(mem_ctx, &pkey_LFLF, &res);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl assert_int_equal(ret, EINVAL);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl ret = sss_ssh_format_pubkey(mem_ctx, &pkey_null_terminated, &res);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl assert_int_equal(ret, EINVAL);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl ret = sss_ssh_format_pubkey(mem_ctx, &pkey_CRLF, &res);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl assert_int_equal(ret, EINVAL);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl ret = sss_ssh_format_pubkey(mem_ctx, &pkey_CR_somewhere, &res);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl assert_int_equal(ret, EINVAL);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl assert_true(check_leaks_pop(mem_ctx) == true);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl talloc_free(mem_ctx);
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl}