69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek/*
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek SSSD
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek Crypto tests
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek Author: Jakub Hrozek <jhrozek@redhat.com>
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek Copyright (C) Red Hat, Inc 2010
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek This program is free software; you can redistribute it and/or modify
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek it under the terms of the GNU General Public License as published by
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek (at your option) any later version.
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek This program is distributed in the hope that it will be useful,
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek GNU General Public License for more details.
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek You should have received a copy of the GNU General Public License
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek*/
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek#include <stdlib.h>
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek#include <popt.h>
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek#include <check.h>
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek#include "util/util.h"
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek#include "tests/common_check.h"
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek/* interfaces under test */
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek#include "util/crypto/sss_crypto.h"
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek#include "util/crypto/nss/nss_util.h"
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozekstatic TALLOC_CTX *test_ctx = NULL;
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek#ifdef HAVE_NSS
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub HrozekSTART_TEST(test_nss_init)
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek{
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek int ret;
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek ret = nspr_nss_init();
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek fail_if(ret != EOK);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek ret = nspr_nss_cleanup();
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek fail_if(ret != EOK);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek}
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub HrozekEND_TEST
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek#endif
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
96d239e83e671b82525cec760cf0bcaa5ee1c249Lukas SlebodnikSTART_TEST(test_sss_password_encrypt_decrypt)
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek{
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek const char *password[] = { "test123", /* general */
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek "12345678901234567", /* just above blocksize */
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek "", /* empty */
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek NULL}; /* sentinel */
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek int i;
172c07013d1ea99447a780fd36f49d5c3a76981bJakub Hrozek char *obfpwd = NULL;
172c07013d1ea99447a780fd36f49d5c3a76981bJakub Hrozek char *ctpwd = NULL;
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek int ret;
172c07013d1ea99447a780fd36f49d5c3a76981bJakub Hrozek int expected;
172c07013d1ea99447a780fd36f49d5c3a76981bJakub Hrozek
e07a94a66985b674c5df11ca466792902164c4e2George McCollister#if defined(HAVE_NSS) || defined(HAVE_LIBCRYPTO)
172c07013d1ea99447a780fd36f49d5c3a76981bJakub Hrozek expected = EOK;
172c07013d1ea99447a780fd36f49d5c3a76981bJakub Hrozek#else
172c07013d1ea99447a780fd36f49d5c3a76981bJakub Hrozek#error Unknown crypto back end
172c07013d1ea99447a780fd36f49d5c3a76981bJakub Hrozek#endif
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek test_ctx = talloc_new(NULL);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek fail_if(test_ctx == NULL);
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek ck_leaks_push(test_ctx);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek for (i=0; password[i]; i++) {
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek ret = sss_password_encrypt(test_ctx, password[i], strlen(password[i])+1,
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek AES_256, &obfpwd);
172c07013d1ea99447a780fd36f49d5c3a76981bJakub Hrozek fail_if(ret != expected);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek ret = sss_password_decrypt(test_ctx, obfpwd, &ctpwd);
172c07013d1ea99447a780fd36f49d5c3a76981bJakub Hrozek fail_if(ret != expected);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
172c07013d1ea99447a780fd36f49d5c3a76981bJakub Hrozek fail_if(ctpwd && strcmp(password[i], ctpwd) != 0);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek talloc_free(obfpwd);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek talloc_free(ctpwd);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek }
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek ck_leaks_pop(test_ctx);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek talloc_free(test_ctx);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek}
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub HrozekEND_TEST
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan CholastaSTART_TEST(test_hmac_sha1)
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta{
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta const char *message = "test message";
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta const char *keys[] = {
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta "short",
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta "proper6789012345678901234567890123456789012345678901234567890123",
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta "longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong",
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta NULL };
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta const char *results[] = {
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta "\x2b\x27\x53\x07\x17\xd8\xc0\x8f\x97\x27\xdd\xb3\xec\x41\xd8\xa3\x94\x97\xaa\x35",
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta "\x37\xe7\x0a\x6f\x71\x0b\xa9\x93\x81\x53\x8f\x5c\x06\x83\x44\x2f\xc9\x41\xe3\xed",
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta "\xbd\x99\xa7\x7f\xfc\x5e\xde\x04\x32\x7f\x7b\x71\x4d\xc0\x3f\x51\x2d\x25\x01\x28",
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta NULL };
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta unsigned char out[SSS_SHA1_LENGTH];
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta int ret, expected;
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta int i;
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta
e07a94a66985b674c5df11ca466792902164c4e2George McCollister#if defined(HAVE_NSS) || defined(HAVE_LIBCRYPTO)
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta expected = EOK;
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta#else
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta#error Unknown crypto back end
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta#endif
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta for (i = 0; keys[i]; i++) {
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta ret = sss_hmac_sha1((const unsigned char *)keys[i], strlen(keys[i]),
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta (const unsigned char *)message, strlen(message),
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta out);
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta fail_if(ret != expected);
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta fail_if(ret == EOK && memcmp(out, results[i], SSS_SHA1_LENGTH) != 0);
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta }
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta}
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan CholastaEND_TEST
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta
e07a94a66985b674c5df11ca466792902164c4e2George McCollisterSTART_TEST(test_base64_encode)
e07a94a66985b674c5df11ca466792902164c4e2George McCollister{
e07a94a66985b674c5df11ca466792902164c4e2George McCollister const unsigned char obfbuf[] = "test";
e07a94a66985b674c5df11ca466792902164c4e2George McCollister const char expected[] = "dGVzdA==";
e07a94a66985b674c5df11ca466792902164c4e2George McCollister char *obfpwd = NULL;
e07a94a66985b674c5df11ca466792902164c4e2George McCollister
e07a94a66985b674c5df11ca466792902164c4e2George McCollister test_ctx = talloc_new(NULL);
e07a94a66985b674c5df11ca466792902164c4e2George McCollister fail_if(test_ctx == NULL);
e07a94a66985b674c5df11ca466792902164c4e2George McCollister /* Base64 encode the buffer */
e07a94a66985b674c5df11ca466792902164c4e2George McCollister obfpwd = sss_base64_encode(test_ctx, obfbuf, strlen((const char*)obfbuf));
e07a94a66985b674c5df11ca466792902164c4e2George McCollister fail_if(obfpwd == NULL);
e07a94a66985b674c5df11ca466792902164c4e2George McCollister fail_if(strcmp(obfpwd,expected) != 0);
e07a94a66985b674c5df11ca466792902164c4e2George McCollister
e07a94a66985b674c5df11ca466792902164c4e2George McCollister talloc_free(test_ctx);
e07a94a66985b674c5df11ca466792902164c4e2George McCollister}
e07a94a66985b674c5df11ca466792902164c4e2George McCollisterEND_TEST
e07a94a66985b674c5df11ca466792902164c4e2George McCollister
e07a94a66985b674c5df11ca466792902164c4e2George McCollisterSTART_TEST(test_base64_decode)
e07a94a66985b674c5df11ca466792902164c4e2George McCollister{
e07a94a66985b674c5df11ca466792902164c4e2George McCollister unsigned char *obfbuf = NULL;
e07a94a66985b674c5df11ca466792902164c4e2George McCollister size_t obflen;
e07a94a66985b674c5df11ca466792902164c4e2George McCollister const char b64encoded[] = "dGVzdA==";
e07a94a66985b674c5df11ca466792902164c4e2George McCollister const unsigned char expected[] = "test";
e07a94a66985b674c5df11ca466792902164c4e2George McCollister
e07a94a66985b674c5df11ca466792902164c4e2George McCollister test_ctx = talloc_new(NULL);
e07a94a66985b674c5df11ca466792902164c4e2George McCollister fail_if(test_ctx == NULL);
e07a94a66985b674c5df11ca466792902164c4e2George McCollister /* Base64 decode the buffer */
e07a94a66985b674c5df11ca466792902164c4e2George McCollister obfbuf = sss_base64_decode(test_ctx, b64encoded, &obflen);
e07a94a66985b674c5df11ca466792902164c4e2George McCollister fail_if(!obfbuf);
e07a94a66985b674c5df11ca466792902164c4e2George McCollister fail_if(obflen != strlen((const char*)expected));
e07a94a66985b674c5df11ca466792902164c4e2George McCollister fail_if(memcmp(obfbuf, expected, obflen) != 0);
e07a94a66985b674c5df11ca466792902164c4e2George McCollister
e07a94a66985b674c5df11ca466792902164c4e2George McCollister talloc_free(test_ctx);
e07a94a66985b674c5df11ca466792902164c4e2George McCollister}
e07a94a66985b674c5df11ca466792902164c4e2George McCollisterEND_TEST
e07a94a66985b674c5df11ca466792902164c4e2George McCollister
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas SlebodnikSTART_TEST(test_sss_encrypt_decrypt)
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik{
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik uint8_t key[] = {
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik };
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik size_t key_len = sizeof(key); /* need to be 32 */
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik const char input_text[] = "Secret text";
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik const size_t input_text_len = sizeof(input_text) - 1;
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik uint8_t *cipher_text;
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik size_t cipher_text_len;
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik uint8_t *plain_text;
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik size_t plain_text_len;
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik int ret;
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik test_ctx = talloc_new(NULL);
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik fail_if(test_ctx == NULL);
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik ret = sss_encrypt(test_ctx, AES256CBC_HMAC_SHA256, key, key_len,
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik (const uint8_t *)input_text, input_text_len,
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik &cipher_text, &cipher_text_len);
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik fail_if(ret != 0);
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik fail_if(cipher_text_len == 0);
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik ret = memcmp(input_text, cipher_text, input_text_len);
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik fail_if(ret == 0, "Input and encrypted text has common prefix");
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik ret = sss_decrypt(test_ctx, AES256CBC_HMAC_SHA256, key, key_len,
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik cipher_text, cipher_text_len,
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik &plain_text, &plain_text_len);
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik fail_if(ret != 0);
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik fail_if(plain_text_len != input_text_len);
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik ret = memcmp(plain_text, input_text, input_text_len);
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik fail_if(ret != 0, "input text is not the same as de-encrypted text");
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik talloc_free(test_ctx);
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik}
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas SlebodnikEND_TEST
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub HrozekSuite *crypto_suite(void)
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek{
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek Suite *s = suite_create("sss_crypto");
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek TCase *tc = tcase_create("sss crypto tests");
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek tcase_add_checked_fixture(tc, ck_leak_check_setup, ck_leak_check_teardown);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek /* Do some testing */
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek#ifdef HAVE_NSS
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek tcase_add_test(tc, test_nss_init);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek#endif
96d239e83e671b82525cec760cf0bcaa5ee1c249Lukas Slebodnik tcase_add_test(tc, test_sss_password_encrypt_decrypt);
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta tcase_add_test(tc, test_hmac_sha1);
e07a94a66985b674c5df11ca466792902164c4e2George McCollister tcase_add_test(tc, test_base64_encode);
e07a94a66985b674c5df11ca466792902164c4e2George McCollister tcase_add_test(tc, test_base64_decode);
65c85654d9b32a866caa01c28fe743eeb0bdef67Lukas Slebodnik tcase_add_test(tc, test_sss_encrypt_decrypt);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek /* Add all test cases to the test suite */
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek suite_add_tcase(s, tc);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek return s;
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek}
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozekint main(int argc, const char *argv[])
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek{
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek int opt;
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek poptContext pc;
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek int number_failed;
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek struct poptOption long_options[] = {
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek POPT_AUTOHELP
66c238caf7a35701ea7b8bc8a3c15424c9867e9fJan Zeleny { "debug-level", 'd', POPT_ARG_INT, &debug_level, 0, "Set debug level", NULL },
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek POPT_TABLEEND
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek };
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
49dd8ee2834d9477418961dbaffa4a03cfa9fd1eRené Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
89caf5edcc99f5731e89bd51e6ffaad3ec11c304Pavel Březina debug_level = SSSDBG_INVALID;
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek while((opt = poptGetNextOpt(pc)) != -1) {
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek switch(opt) {
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek default:
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek fprintf(stderr, "\nInvalid option %s: %s\n\n",
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek poptBadOption(pc, 0), poptStrerror(opt));
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek poptPrintUsage(pc, stderr, 0);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek return 1;
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek }
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek }
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek poptFreeContext(pc);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
6b57784f0f175275fd900eca21c77415e3a5ea52Jakub Hrozek DEBUG_CLI_INIT(debug_level);
89caf5edcc99f5731e89bd51e6ffaad3ec11c304Pavel Březina
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek tests_set_cwd();
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek Suite *s = crypto_suite();
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek SRunner *sr = srunner_create(s);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek srunner_run_all(sr, CK_ENV);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek number_failed = srunner_ntests_failed(sr);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek srunner_free(sr);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek return (number_failed == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek}