test_sss_ssh.c revision 462db32918a05097652f8232cd6c8d78a826e63c
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder/*
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder Authors:
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder Pavel Reichl <preichl@redhat.com>
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder Copyright (C) 2014 Red Hat
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder Test for the NSS Responder ID-SID mapping interface
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder This program is free software; you can redistribute it and/or modify
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder it under the terms of the GNU General Public License as published by
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder the Free Software Foundation; either version 3 of the License, or
99b26e2ab8ba89bc9a050c1524137eb6269e2753Christian Maeder (at your option) any later version.
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder
92ae4d5885ea837ffe3dae9b2de742f871229b94Christian Maeder This program is distributed in the hope that it will be useful,
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder but WITHOUT ANY WARRANTY; without even the implied warranty of
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maeder GNU General Public License for more details.
8d2321e17a34951fbd52f68e9f9f148f0890e471Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder You should have received a copy of the GNU General Public License
99b26e2ab8ba89bc9a050c1524137eb6269e2753Christian Maeder along with this program. If not, see <http://www.gnu.org/licenses/>.
736fe640b202e3fe7288fad8251d5b210c5d8d87Christian Maeder*/
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder#include "util/util.h"
d4263171d0ce2cbc390a7b44bff98e8b3c0f8ce7Christian Maeder#include "util/sss_ssh.h"
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder#include "tests/cmocka/common_mock.h"
e84c877ad38ce9312eab222a79f44da2015572d2Christian Maeder#include "test_utils.h"
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maederuint8_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";
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maederuint8_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";
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maeder
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maederuint8_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";
945e82ed7877917f3ab1657f555e71991372546aChristian Maeder
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maederuint8_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";
c208973c890b8f993297720fd0247bc7481d4304Christian Maeder
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maederuint8_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";
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maeder
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maedervoid test_textual_public_key(void **state)
7c99a6c982aaf61547de8054296c8055c8d1a13aSimon Ulbricht{
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maeder TALLOC_CTX *mem_ctx;
d97700a22b2585ece83b05f3fff945fdfd0c44b4Christian Maeder errno_t ret;
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder char *res;
ea5ccb1c6e89486a54e1f4bd95840147e96093edChristian Maeder
de8eee2014437ec4020be15cd363257f87e79943Christian Maeder struct sss_ssh_pubkey pkey_null_terminated = {
ea5ccb1c6e89486a54e1f4bd95840147e96093edChristian Maeder .data = key_data_noLF,
fd94a6f66ccb5cef99aa42069b61e4b8734dbd3fChristian Maeder .data_len = sizeof(key_data_noLF)
fd94a6f66ccb5cef99aa42069b61e4b8734dbd3fChristian Maeder };
fd94a6f66ccb5cef99aa42069b61e4b8734dbd3fChristian Maeder
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder struct sss_ssh_pubkey pkey = {
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder .data = key_data_noLF,
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder .data_len = sizeof(key_data_noLF) - 1 /* ignore trailling '\0' */
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder };
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder struct sss_ssh_pubkey pkey_LF = {
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder .data = key_data_LF,
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder .data_len = sizeof(key_data_LF) - 1 /* ignore trailling '\0' */
6a88f8edd881afaf4b865b01bfbb4faaf0e7a3c9Simon Ulbricht };
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder struct sss_ssh_pubkey pkey_LFLF = {
844c7d2ec3917393e139e53503757098d568713eSimon Ulbricht .data = key_data_LFLF,
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder .data_len = sizeof(key_data_LFLF) - 1 /* ignore trailling '\0' */
734a5ebd38032798f0ab908e2d52862c71b2c127Simon Ulbricht };
ea5ccb1c6e89486a54e1f4bd95840147e96093edChristian Maeder
c99b0eb6632087d502dd4269599c5aa68a148eebSimon Ulbricht struct sss_ssh_pubkey pkey_CRLF = {
c99b0eb6632087d502dd4269599c5aa68a148eebSimon Ulbricht .data = key_data_CRLF,
b99c9606f2faafeabb3fa8c596992143a561c787Simon Ulbricht .data_len = sizeof(key_data_CRLF) - 1 /* ignore trailling '\0' */
df67ddf64192bfcae6ece65255ad796a17cbe532Christian Maeder };
3e87e1dc85fa76cc6eaeb8eafbc0bea77af939f4Christian Maeder
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder struct sss_ssh_pubkey pkey_CR_somewhere = {
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder .data = key_data_CR_somewhere,
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder .data_len = sizeof(key_data_CR_somewhere) - 1 /* ignore traill. '\0' */
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder };
f675b8f0a612e37472640da57b48d795bef4427eChristian Maeder
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder mem_ctx = talloc_new(NULL);
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder assert_non_null(mem_ctx);
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder check_leaks_push(mem_ctx);
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder
dae8246f1f55b6a85e946fc1bfb6d32d556395f1Simon Ulbricht ret = sss_ssh_format_pubkey(mem_ctx, &pkey, &res);
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder assert_int_equal(ret, EOK);
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder talloc_free(res);
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder
f56cdf11927c31495bae642a9eb383212c90ba61Christian Maeder ret = sss_ssh_format_pubkey(mem_ctx, &pkey_LF, &res);
7710f7c3425e45af11af124ff37bec27229d24f7Christian Maeder assert_int_equal(ret, EOK);
2e2559f894aaa661b199e4fa00609f522bc5482aSimon Ulbricht talloc_free(res);
df67ddf64192bfcae6ece65255ad796a17cbe532Christian Maeder
be1ce1c2b2819ef32743136c13101f1927375311Christian Maeder ret = sss_ssh_format_pubkey(mem_ctx, &pkey_LFLF, &res);
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder assert_int_equal(ret, EINVAL);
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder ret = sss_ssh_format_pubkey(mem_ctx, &pkey_null_terminated, &res);
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder assert_int_equal(ret, EINVAL);
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder ret = sss_ssh_format_pubkey(mem_ctx, &pkey_CRLF, &res);
3e87e1dc85fa76cc6eaeb8eafbc0bea77af939f4Christian Maeder assert_int_equal(ret, EINVAL);
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder ret = sss_ssh_format_pubkey(mem_ctx, &pkey_CR_somewhere, &res);
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder assert_int_equal(ret, EINVAL);
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder assert_true(check_leaks_pop(mem_ctx) == true);
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder talloc_free(mem_ctx);
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder}
26acf851cacd7a31bdc9b25a42af9949942fa7c6Christian Maeder