bf01e8179cbb2be476805340636098deda7e1366Sumit Bose/*
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose SSSD
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose Certificates - Utilities tests
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose Authors:
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose Sumit Bose <sbose@redhat.com>
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose Copyright (C) 2015 Red Hat
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose This program is free software; you can redistribute it and/or modify
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose it under the terms of the GNU General Public License as published by
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose the Free Software Foundation; either version 3 of the License, or
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose (at your option) any later version.
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose This program is distributed in the hope that it will be useful,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose GNU General Public License for more details.
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose You should have received a copy of the GNU General Public License
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose*/
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose#include "config.h"
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose#include <popt.h>
0d5bb38364a6976e9c85d6349aa13a04d181a090Sumit Bose#ifdef HAVE_LIBCRYPTO
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose#include <openssl/objects.h>
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose#include <openssl/crypto.h>
0d5bb38364a6976e9c85d6349aa13a04d181a090Sumit Bose#endif
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose#include "util/cert.h"
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose#include "tests/cmocka/common_mock.h"
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose#include "util/crypto/nss/nss_util.h"
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose#include "util/crypto/sss_crypto.h"
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#ifdef HAVE_TEST_CA
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#include "tests/test_CA/SSSD_test_cert_pubsshkey_0001.h"
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#include "tests/test_CA/SSSD_test_cert_x509_0001.h"
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#else
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#define SSSD_TEST_CERT_0001 ""
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#define SSSD_TEST_CERT_SSH_KEY_0001 ""
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#endif
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose/* TODO: create a certificate for this test */
bf01e8179cbb2be476805340636098deda7e1366Sumit Boseconst uint8_t test_cert_der[] = {
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x30, 0x82, 0x04, 0x09, 0x30, 0x82, 0x02, 0xf1, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x09,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x34, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x09, 0x49, 0x50, 0x41, 0x2e,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x44, 0x45, 0x56, 0x45, 0x4c, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x15,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x20, 0x41, 0x75, 0x74, 0x68,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x6f, 0x72, 0x69, 0x74, 0x79, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x35, 0x30, 0x34, 0x32, 0x38, 0x31,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x30, 0x32, 0x31, 0x31, 0x31, 0x5a, 0x17, 0x0d, 0x31, 0x37, 0x30, 0x34, 0x32, 0x38, 0x31, 0x30,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x32, 0x31, 0x31, 0x31, 0x5a, 0x30, 0x32, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x0a,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x0c, 0x09, 0x49, 0x50, 0x41, 0x2e, 0x44, 0x45, 0x56, 0x45, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x03, 0x55, 0x04, 0x03, 0x0c, 0x13, 0x69, 0x70, 0x61, 0x2d, 0x64, 0x65, 0x76, 0x65, 0x6c, 0x2e,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x69, 0x70, 0x61, 0x2e, 0x64, 0x65, 0x76, 0x65, 0x6c, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xb2, 0x32, 0x92, 0xab, 0x47, 0xb8,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x0c, 0x13, 0x54, 0x4a, 0x1f, 0x1e, 0x29, 0x06, 0xff, 0xd0, 0x50, 0xcb, 0xf7, 0x5f, 0x79, 0x91,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x65, 0xb1, 0x39, 0x01, 0x83, 0x6a, 0xad, 0x9e, 0x77, 0x3b, 0xf3, 0x0d, 0xd7, 0xb9, 0xf6, 0xdc,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x9e, 0x4a, 0x49, 0xa7, 0xd0, 0x66, 0x72, 0xcc, 0xbf, 0x77, 0xd6, 0xde, 0xa9, 0xfe, 0x67, 0x96,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0xcc, 0x49, 0xf1, 0x37, 0x23, 0x2e, 0xc4, 0x50, 0xf4, 0xeb, 0xba, 0x62, 0xd4, 0x23, 0x4d, 0xf3,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x37, 0x38, 0x82, 0xee, 0x3b, 0x3f, 0x2c, 0xd0, 0x80, 0x9b, 0x17, 0xaa, 0x9b, 0xeb, 0xa6, 0xdd,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0xf6, 0x15, 0xff, 0x06, 0xb2, 0xce, 0xff, 0xdf, 0x8a, 0x9e, 0x95, 0x85, 0x49, 0x1f, 0x84, 0xfd,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x81, 0x26, 0xce, 0x06, 0x32, 0x0d, 0x36, 0xca, 0x7c, 0x15, 0x81, 0x68, 0x6b, 0x8f, 0x3e, 0xb3,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0xa2, 0xfc, 0xae, 0xaf, 0xc2, 0x44, 0x58, 0x15, 0x95, 0x40, 0xfc, 0x56, 0x19, 0x91, 0x80, 0xed,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x42, 0x11, 0x66, 0x04, 0xef, 0x3c, 0xe0, 0x76, 0x33, 0x4b, 0x83, 0xfa, 0x7e, 0xb4, 0x47, 0xdc,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0xfb, 0xed, 0x46, 0xa5, 0x8d, 0x0a, 0x66, 0x87, 0xa5, 0xef, 0x7b, 0x74, 0x62, 0xac, 0xbe, 0x73,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x36, 0xc9, 0xb4, 0xfe, 0x20, 0xc4, 0x81, 0xf3, 0xfe, 0x78, 0x19, 0xa8, 0xd0, 0xaf, 0x7f, 0x81,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x72, 0x24, 0x61, 0xd9, 0x76, 0x93, 0xe3, 0x0b, 0xd2, 0x4f, 0x19, 0x17, 0x33, 0x57, 0xd4, 0x82,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0xb0, 0xf1, 0xa8, 0x03, 0xf6, 0x01, 0x99, 0xa9, 0xb8, 0x8c, 0x83, 0xc9, 0xba, 0x19, 0x87, 0xea,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0xd6, 0x3b, 0x06, 0xeb, 0x4c, 0xf7, 0xf1, 0xe5, 0x28, 0xa9, 0x10, 0xb6, 0x46, 0xde, 0xe1, 0xe1,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x3f, 0xc1, 0xcc, 0x72, 0xbe, 0x2a, 0x43, 0xc6, 0xf6, 0xd0, 0xb5, 0xa0, 0xc4, 0x24, 0x6e, 0x4f,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0xbd, 0xec, 0x22, 0x8a, 0x07, 0x11, 0x3d, 0xf9, 0xd3, 0x15, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x82, 0x01, 0x26, 0x30, 0x82, 0x01, 0x22, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x30, 0x16, 0x80, 0x14, 0xf2, 0x9d, 0x42, 0x4e, 0x0f, 0xc4, 0x48, 0x25, 0x58, 0x2f, 0x1c, 0xce,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x0f, 0xa1, 0x3f, 0x22, 0xc8, 0x55, 0xc8, 0x91, 0x30, 0x3b, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x05, 0x07, 0x01, 0x01, 0x04, 0x2f, 0x30, 0x2d, 0x30, 0x2b, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x05, 0x07, 0x30, 0x01, 0x86, 0x1f, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x69, 0x70, 0x61,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x2d, 0x63, 0x61, 0x2e, 0x69, 0x70, 0x61, 0x2e, 0x64, 0x65, 0x76, 0x65, 0x6c, 0x2f, 0x63, 0x61,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x2f, 0x6f, 0x63, 0x73, 0x70, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x04, 0x03, 0x02, 0x04, 0xf0, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x16, 0x30, 0x14,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x05, 0x07, 0x03, 0x02, 0x30, 0x74, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x6d, 0x30, 0x6b, 0x30,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x69, 0xa0, 0x31, 0xa0, 0x2f, 0x86, 0x2d, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x69, 0x70,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x61, 0x2d, 0x63, 0x61, 0x2e, 0x69, 0x70, 0x61, 0x2e, 0x64, 0x65, 0x76, 0x65, 0x6c, 0x2f, 0x69,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x70, 0x61, 0x2f, 0x63, 0x72, 0x6c, 0x2f, 0x4d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x43, 0x52, 0x4c,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x2e, 0x62, 0x69, 0x6e, 0xa2, 0x34, 0xa4, 0x32, 0x30, 0x30, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x55, 0x04, 0x0a, 0x0c, 0x05, 0x69, 0x70, 0x61, 0x63, 0x61, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x55, 0x04, 0x03, 0x0c, 0x15, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x0e, 0x04, 0x16, 0x04, 0x14, 0x2d, 0x2b, 0x3f, 0xcb, 0xf5, 0xb2, 0xff, 0x32, 0x2c, 0xa8, 0xc2,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x1c, 0xdd, 0xbd, 0x8c, 0x80, 0x1e, 0xdd, 0x31, 0x82, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x9a, 0x47, 0x2e,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x50, 0xa7, 0x4d, 0x1d, 0x53, 0x0f, 0xc9, 0x71, 0x42, 0x0c, 0xe5, 0xda, 0x7d, 0x49, 0x64, 0xe7,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0xab, 0xc8, 0xdf, 0xdf, 0x02, 0xc1, 0x87, 0xd1, 0x5b, 0xde, 0xda, 0x6f, 0x2b, 0xe4, 0xf0, 0xbe,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0xba, 0x09, 0xdf, 0x02, 0x85, 0x0b, 0x8a, 0xe6, 0x9b, 0x06, 0x7d, 0x69, 0x38, 0x6c, 0x72, 0xff,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x4c, 0x7b, 0x2a, 0x0d, 0x3f, 0x23, 0x2f, 0x16, 0x46, 0xff, 0x05, 0x93, 0xb0, 0xea, 0x24, 0x28,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0xd7, 0x12, 0xa1, 0x57, 0xb8, 0x59, 0x19, 0x25, 0xf3, 0x43, 0x0a, 0xd3, 0xfd, 0x0f, 0x37, 0x8d,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0xb8, 0xca, 0x15, 0xe7, 0x48, 0x8a, 0xa0, 0xc7, 0xc7, 0x4b, 0x7f, 0x01, 0x3c, 0x58, 0xd7, 0x37,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0xe5, 0xff, 0x7d, 0x2b, 0x01, 0xac, 0x0d, 0x9f, 0x51, 0x6a, 0xe5, 0x40, 0x24, 0xe6, 0x5e, 0x55,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x0d, 0xf7, 0xb8, 0x2f, 0x42, 0xac, 0x6d, 0xe5, 0x29, 0x6b, 0xc6, 0x0b, 0xa4, 0xbf, 0x19, 0xbd,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x39, 0x27, 0xee, 0xfe, 0xc5, 0xb3, 0xdb, 0x62, 0xd4, 0xbe, 0xd2, 0x47, 0xba, 0x96, 0x30, 0x5a,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0xfd, 0x62, 0x00, 0xb8, 0x27, 0x5d, 0x2f, 0x3a, 0x94, 0x0b, 0x95, 0x35, 0x85, 0x40, 0x2c, 0xbc,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x67, 0xdf, 0x8a, 0xf9, 0xf1, 0x7b, 0x19, 0x96, 0x3e, 0x42, 0x48, 0x13, 0x23, 0x04, 0x95, 0xa9,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x6b, 0x11, 0x33, 0x81, 0x47, 0x5a, 0x83, 0x72, 0xf6, 0x20, 0xfa, 0x8e, 0x41, 0x7b, 0x8f, 0x77,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x47, 0x7c, 0xc7, 0x5d, 0x46, 0xf4, 0x4f, 0xfd, 0x81, 0x0a, 0xae, 0x39, 0x27, 0xb6, 0x6a, 0x26,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x63, 0xb1, 0xd3, 0xbf, 0x55, 0x83, 0x82, 0x9b, 0x36, 0x6c, 0x33, 0x64, 0x0f, 0x50, 0xc0, 0x55,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0x94, 0x13, 0xc3, 0x85, 0xf4, 0xd5, 0x71, 0x65, 0xd0, 0xc0, 0xdd, 0xfc, 0xe6, 0xec, 0x9c, 0x5b,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose0xf0, 0x11, 0xb5, 0x2c, 0xf3, 0x48, 0xc1, 0x36, 0x8c, 0xa2, 0x96, 0x48, 0x84};
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose#define TEST_CERT_PEM "-----BEGIN CERTIFICATE-----\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"MIIECTCCAvGgAwIBAgIBCTANBgkqhkiG9w0BAQsFADA0MRIwEAYDVQQKDAlJUEEu\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"REVWRUwxHjAcBgNVBAMMFUNlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNTA0Mjgx\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"MDIxMTFaFw0xNzA0MjgxMDIxMTFaMDIxEjAQBgNVBAoMCUlQQS5ERVZFTDEcMBoG\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"A1UEAwwTaXBhLWRldmVsLmlwYS5kZXZlbDCCASIwDQYJKoZIhvcNAQEBBQADggEP\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"ADCCAQoCggEBALIykqtHuAwTVEofHikG/9BQy/dfeZFlsTkBg2qtnnc78w3Xufbc\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"nkpJp9Bmcsy/d9beqf5nlsxJ8TcjLsRQ9Ou6YtQjTfM3OILuOz8s0ICbF6qb66bd\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"9hX/BrLO/9+KnpWFSR+E/YEmzgYyDTbKfBWBaGuPPrOi/K6vwkRYFZVA/FYZkYDt\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"QhFmBO884HYzS4P6frRH3PvtRqWNCmaHpe97dGKsvnM2ybT+IMSB8/54GajQr3+B\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"ciRh2XaT4wvSTxkXM1fUgrDxqAP2AZmpuIyDyboZh+rWOwbrTPfx5SipELZG3uHh\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"P8HMcr4qQ8b20LWgxCRuT73sIooHET350xUCAwEAAaOCASYwggEiMB8GA1UdIwQY\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"MBaAFPKdQk4PxEglWC8czg+hPyLIVciRMDsGCCsGAQUFBwEBBC8wLTArBggrBgEF\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"BQcwAYYfaHR0cDovL2lwYS1jYS5pcGEuZGV2ZWwvY2Evb2NzcDAOBgNVHQ8BAf8E\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"BAMCBPAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMHQGA1UdHwRtMGsw\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"aaAxoC+GLWh0dHA6Ly9pcGEtY2EuaXBhLmRldmVsL2lwYS9jcmwvTWFzdGVyQ1JM\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"LmJpbqI0pDIwMDEOMAwGA1UECgwFaXBhY2ExHjAcBgNVBAMMFUNlcnRpZmljYXRl\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"IEF1dGhvcml0eTAdBgNVHQ4EFgQULSs/y/Wy/zIsqMIc3b2MgB7dMYIwDQYJKoZI\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"hvcNAQELBQADggEBAJpHLlCnTR1TD8lxQgzl2n1JZOeryN/fAsGH0Vve2m8r5PC+\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"ugnfAoULiuabBn1pOGxy/0x7Kg0/Iy8WRv8Fk7DqJCjXEqFXuFkZJfNDCtP9DzeN\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"uMoV50iKoMfHS38BPFjXN+X/fSsBrA2fUWrlQCTmXlUN97gvQqxt5Slrxgukvxm9\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"OSfu/sWz22LUvtJHupYwWv1iALgnXS86lAuVNYVALLxn34r58XsZlj5CSBMjBJWp\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"axEzgUdag3L2IPqOQXuPd0d8x11G9E/9gQquOSe2aiZjsdO/VYOCmzZsM2QPUMBV\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"lBPDhfTVcWXQwN385uycW/ARtSzzSME2jKKWSIQ=\n" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"-----END CERTIFICATE-----\n"
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
5231ba679402eeb0705a3ecd41f97fdd67d42a69David Kupka#define TEST_CERT_PEM_WITH_METADATA "Bag Attributes\n" \
5231ba679402eeb0705a3ecd41f97fdd67d42a69David Kupka" friendlyName: ipa-devel\n" \
5231ba679402eeb0705a3ecd41f97fdd67d42a69David Kupka" localKeyID: 8E 0D 04 1F BC 13 73 54 00 8F 65 57 D7 A8 AF 34 0C 18 B3 99\n" \
5231ba679402eeb0705a3ecd41f97fdd67d42a69David Kupka"subject= /O=IPA.DEVEL/CN=ipa-devel.ipa.devel\n" \
5231ba679402eeb0705a3ecd41f97fdd67d42a69David Kupka"issuer= /O=IPA.DEVEL/CN=Certificate Authority\n" \
5231ba679402eeb0705a3ecd41f97fdd67d42a69David KupkaTEST_CERT_PEM
5231ba679402eeb0705a3ecd41f97fdd67d42a69David Kupka
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose#define TEST_CERT_DERB64 \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"MIIECTCCAvGgAwIBAgIBCTANBgkqhkiG9w0BAQsFADA0MRIwEAYDVQQKDAlJUEEu" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"REVWRUwxHjAcBgNVBAMMFUNlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNTA0Mjgx" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"MDIxMTFaFw0xNzA0MjgxMDIxMTFaMDIxEjAQBgNVBAoMCUlQQS5ERVZFTDEcMBoG" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"A1UEAwwTaXBhLWRldmVsLmlwYS5kZXZlbDCCASIwDQYJKoZIhvcNAQEBBQADggEP" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"ADCCAQoCggEBALIykqtHuAwTVEofHikG/9BQy/dfeZFlsTkBg2qtnnc78w3Xufbc" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"nkpJp9Bmcsy/d9beqf5nlsxJ8TcjLsRQ9Ou6YtQjTfM3OILuOz8s0ICbF6qb66bd" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"9hX/BrLO/9+KnpWFSR+E/YEmzgYyDTbKfBWBaGuPPrOi/K6vwkRYFZVA/FYZkYDt" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"QhFmBO884HYzS4P6frRH3PvtRqWNCmaHpe97dGKsvnM2ybT+IMSB8/54GajQr3+B" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"ciRh2XaT4wvSTxkXM1fUgrDxqAP2AZmpuIyDyboZh+rWOwbrTPfx5SipELZG3uHh" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"P8HMcr4qQ8b20LWgxCRuT73sIooHET350xUCAwEAAaOCASYwggEiMB8GA1UdIwQY" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"MBaAFPKdQk4PxEglWC8czg+hPyLIVciRMDsGCCsGAQUFBwEBBC8wLTArBggrBgEF" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"BQcwAYYfaHR0cDovL2lwYS1jYS5pcGEuZGV2ZWwvY2Evb2NzcDAOBgNVHQ8BAf8E" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"BAMCBPAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMHQGA1UdHwRtMGsw" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"aaAxoC+GLWh0dHA6Ly9pcGEtY2EuaXBhLmRldmVsL2lwYS9jcmwvTWFzdGVyQ1JM" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"LmJpbqI0pDIwMDEOMAwGA1UECgwFaXBhY2ExHjAcBgNVBAMMFUNlcnRpZmljYXRl" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"IEF1dGhvcml0eTAdBgNVHQ4EFgQULSs/y/Wy/zIsqMIc3b2MgB7dMYIwDQYJKoZI" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"hvcNAQELBQADggEBAJpHLlCnTR1TD8lxQgzl2n1JZOeryN/fAsGH0Vve2m8r5PC+" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"ugnfAoULiuabBn1pOGxy/0x7Kg0/Iy8WRv8Fk7DqJCjXEqFXuFkZJfNDCtP9DzeN" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"uMoV50iKoMfHS38BPFjXN+X/fSsBrA2fUWrlQCTmXlUN97gvQqxt5Slrxgukvxm9" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"OSfu/sWz22LUvtJHupYwWv1iALgnXS86lAuVNYVALLxn34r58XsZlj5CSBMjBJWp" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"axEzgUdag3L2IPqOQXuPd0d8x11G9E/9gQquOSe2aiZjsdO/VYOCmzZsM2QPUMBV" \
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose"lBPDhfTVcWXQwN385uycW/ARtSzzSME2jKKWSIQ="
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bosestruct test_state {
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose void *dummy;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose};
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bosestatic int setup(void **state)
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose{
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose struct test_state *ts = NULL;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_true(leak_check_setup());
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose ts = talloc(global_talloc_context, struct test_state);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_non_null(ts);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose check_leaks_push(ts);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose *state = (void *)ts;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose return 0;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose}
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bosestatic int teardown(void **state)
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose{
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose struct test_state *ts = talloc_get_type_abort(*state, struct test_state);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_non_null(ts);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_true(check_leaks_pop(ts));
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose talloc_free(ts);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_true(leak_check_teardown());
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose return 0;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose}
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bosevoid test_sss_cert_der_to_pem(void **state)
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose{
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose int ret;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose char *pem_str;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose size_t pem_size;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose struct test_state *ts = talloc_get_type_abort(*state, struct test_state);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_non_null(ts);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose ret = sss_cert_der_to_pem(NULL, NULL, 0, NULL, NULL);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_int_equal(ret, EINVAL);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose ret = sss_cert_der_to_pem(ts, test_cert_der, sizeof(test_cert_der),
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose &pem_str, &pem_size);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_int_equal(ret, EOK);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_int_equal(sizeof(TEST_CERT_PEM) - 1, pem_size);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_string_equal(pem_str, TEST_CERT_PEM);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose talloc_free(pem_str);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose}
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bosevoid test_sss_cert_pem_to_der(void **state)
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose{
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose int ret;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose uint8_t *der;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose size_t der_size;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose struct test_state *ts = talloc_get_type_abort(*state, struct test_state);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_non_null(ts);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose ret = sss_cert_pem_to_der(NULL, NULL, NULL, NULL);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_int_equal(ret, EINVAL);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose ret = sss_cert_pem_to_der(ts, TEST_CERT_PEM, &der, &der_size);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_int_equal(ret, EOK);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_int_equal(sizeof(test_cert_der), der_size);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_memory_equal(der, test_cert_der, der_size);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose talloc_free(der);
5231ba679402eeb0705a3ecd41f97fdd67d42a69David Kupka
5231ba679402eeb0705a3ecd41f97fdd67d42a69David Kupka /* https://pagure.io/SSSD/sssd/issue/3354
5231ba679402eeb0705a3ecd41f97fdd67d42a69David Kupka https://tools.ietf.org/html/rfc7468#section-2 */
5231ba679402eeb0705a3ecd41f97fdd67d42a69David Kupka ret = sss_cert_pem_to_der(ts, TEST_CERT_PEM_WITH_METADATA, &der, &der_size);
5231ba679402eeb0705a3ecd41f97fdd67d42a69David Kupka assert_int_equal(ret, EOK);
5231ba679402eeb0705a3ecd41f97fdd67d42a69David Kupka assert_int_equal(sizeof(test_cert_der), der_size);
5231ba679402eeb0705a3ecd41f97fdd67d42a69David Kupka assert_memory_equal(der, test_cert_der, der_size);
5231ba679402eeb0705a3ecd41f97fdd67d42a69David Kupka
5231ba679402eeb0705a3ecd41f97fdd67d42a69David Kupka talloc_free(der);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose}
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bosevoid test_sss_cert_derb64_to_pem(void **state)
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose{
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose int ret;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose char *pem_str;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose size_t pem_size;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose struct test_state *ts = talloc_get_type_abort(*state, struct test_state);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_non_null(ts);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose ret = sss_cert_derb64_to_pem(NULL, NULL, NULL, NULL);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_int_equal(ret, EINVAL);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose ret = sss_cert_derb64_to_pem(ts, TEST_CERT_DERB64, &pem_str, &pem_size);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_int_equal(ret, EOK);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_int_equal(sizeof(TEST_CERT_PEM) - 1, pem_size);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_string_equal(pem_str, TEST_CERT_PEM);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose talloc_free(pem_str);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose}
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bosevoid test_sss_cert_pem_to_derb64(void **state)
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose{
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose int ret;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose char *derb64;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose struct test_state *ts = talloc_get_type_abort(*state, struct test_state);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_non_null(ts);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose ret = sss_cert_pem_to_derb64(NULL, NULL, NULL);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_int_equal(ret, EINVAL);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose ret = sss_cert_pem_to_derb64(ts, TEST_CERT_PEM, &derb64);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_int_equal(ret, EOK);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_string_equal(derb64, TEST_CERT_DERB64);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose talloc_free(derb64);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose}
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bosevoid test_bin_to_ldap_filter_value(void **state)
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose{
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose int ret;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose size_t c;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose char *str;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose struct test_state *ts = talloc_get_type_abort(*state, struct test_state);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_non_null(ts);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose struct test_data {
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose uint8_t blob[5];
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose const char *str;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose } test_data[] = {
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose {{0x01, 0x02, 0x03, 0x04, 0x05}, "\\01\\02\\03\\04\\05"},
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose {{0x00, 0x00, 0x00, 0x00, 0x00}, "\\00\\00\\00\\00\\00"},
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose {{0xff, 0xff, 0xff, 0xff, 0xff}, "\\ff\\ff\\ff\\ff\\ff"},
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose {{0xca, 0xfe, 0xc0, 0xff, 0xee}, "\\ca\\fe\\c0\\ff\\ee"},
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose {{0}, NULL}
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose };
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose ret = bin_to_ldap_filter_value(ts, NULL, 0, NULL);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_int_equal(ret, EINVAL);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose for (c = 0; test_data[c].str != NULL; c++) {
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose ret = bin_to_ldap_filter_value(ts, test_data[c].blob, 5, &str);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_int_equal(ret, EOK);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_string_equal(str, test_data[c].str);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose talloc_free(str);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose }
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose}
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bosevoid test_sss_cert_derb64_to_ldap_filter(void **state)
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose{
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose int ret;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose char *filter;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose struct test_state *ts = talloc_get_type_abort(*state, struct test_state);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_non_null(ts);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
b341ee51cffd98b642b9c68a417f8a7504e303a1Sumit Bose ret = sss_cert_derb64_to_ldap_filter(ts, NULL, NULL, NULL, NULL, NULL);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_int_equal(ret, EINVAL);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose ret = sss_cert_derb64_to_ldap_filter(ts, "AAECAwQFBgcICQ==", "attrName",
b341ee51cffd98b642b9c68a417f8a7504e303a1Sumit Bose NULL, NULL, &filter);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_int_equal(ret, EOK);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose assert_string_equal(filter,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose "(attrName=\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09)");
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose talloc_free(filter);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose}
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bosevoid test_cert_to_ssh_key(void **state)
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose{
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose int ret;
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose uint8_t *key;
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose size_t key_size;
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose uint8_t *exp_key;
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose size_t exp_key_size;
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose uint8_t *der;
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose size_t der_size;
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose struct cert_verify_opts cert_verify_opts = { .do_ocsp = false,
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose .do_verification = true };
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose struct test_state *ts = talloc_get_type_abort(*state, struct test_state);
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose assert_non_null(ts);
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose der = sss_base64_decode(ts, SSSD_TEST_CERT_0001, &der_size);
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose assert_non_null(der);
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose exp_key = sss_base64_decode(ts, SSSD_TEST_CERT_SSH_KEY_0001, &exp_key_size);
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose assert_non_null(exp_key);
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose ret = cert_to_ssh_key(ts, "sql:" ABS_BUILD_DIR "/src/tests/test_CA/p11_nssdb",
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose der, der_size, &cert_verify_opts, &key, &key_size);
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose assert_int_equal(ret, EOK);
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose assert_int_equal(key_size, exp_key_size);
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose assert_memory_equal(key, exp_key, exp_key_size);
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose talloc_free(der);
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose talloc_free(key);
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose talloc_free(exp_key);
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose}
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Boseint main(int argc, const char *argv[])
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose{
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose poptContext pc;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose int opt;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose int ret;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose struct poptOption long_options[] = {
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose POPT_AUTOHELP
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose SSSD_DEBUG_OPTS
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose POPT_TABLEEND
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose };
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose const struct CMUnitTest tests[] = {
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose cmocka_unit_test_setup_teardown(test_sss_cert_der_to_pem,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose setup, teardown),
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose cmocka_unit_test_setup_teardown(test_sss_cert_pem_to_der,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose setup, teardown),
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose cmocka_unit_test_setup_teardown(test_sss_cert_derb64_to_pem,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose setup, teardown),
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose cmocka_unit_test_setup_teardown(test_sss_cert_pem_to_derb64,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose setup, teardown),
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose cmocka_unit_test_setup_teardown(test_bin_to_ldap_filter_value,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose setup, teardown),
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose cmocka_unit_test_setup_teardown(test_sss_cert_derb64_to_ldap_filter,
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose setup, teardown),
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#ifdef HAVE_TEST_CA
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose cmocka_unit_test_setup_teardown(test_cert_to_ssh_key,
4de84af23db74e13e867985c9093f394c9fa8d51Sumit Bose setup, teardown),
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#endif
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose };
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose debug_level = SSSDBG_INVALID;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose pc = poptGetContext(argv[0], argc, argv, long_options, 0);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose while((opt = poptGetNextOpt(pc)) != -1) {
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose switch(opt) {
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose default:
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose fprintf(stderr, "\nInvalid option %s: %s\n\n",
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose poptBadOption(pc, 0), poptStrerror(opt));
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose poptPrintUsage(pc, stderr, 0);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose return 1;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose }
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose }
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose poptFreeContext(pc);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose DEBUG_CLI_INIT(debug_level);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose ret = cmocka_run_group_tests(tests, NULL, NULL);
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
0d5bb38364a6976e9c85d6349aa13a04d181a090Sumit Bose#ifdef HAVE_LIBCRYPTO
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz CRYPTO_cleanup_all_ex_data(); /* to make Valgrind happy */
0d5bb38364a6976e9c85d6349aa13a04d181a090Sumit Bose#endif
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose#ifdef HAVE_NSS
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Cleanup NSS and NSPR to make Valgrind happy. */
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose nspr_nss_cleanup();
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose#endif
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose return ret;
bf01e8179cbb2be476805340636098deda7e1366Sumit Bose}