2014-10-17 15:55:37 -07:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2014-10-17 15:55:37 -07:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2020-09-14 16:20:40 -07:00
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2014-10-17 15:55:37 -07:00
|
|
|
*/
|
|
|
|
|
2018-10-24 09:01:48 -07:00
|
|
|
#if HAVE_CMOCKA
|
2014-10-17 15:55:37 -07:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <sched.h> /* IWYU pragma: keep */
|
|
|
|
#include <setjmp.h>
|
2018-10-24 09:01:48 -07:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-10-17 15:55:37 -07:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2018-10-24 09:01:48 -07:00
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
|
|
|
|
2014-10-17 15:55:37 -07:00
|
|
|
#include <isc/string.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <isc/util.h>
|
2014-10-17 15:55:37 -07:00
|
|
|
|
2020-03-09 16:17:26 +01:00
|
|
|
#include <pk11/site.h>
|
|
|
|
|
2014-10-17 15:55:37 -07:00
|
|
|
#include <dns/name.h>
|
2019-07-30 21:08:40 +02:00
|
|
|
|
2020-03-09 16:17:26 +01:00
|
|
|
#include <dst/result.h>
|
|
|
|
|
2014-10-17 15:55:37 -07:00
|
|
|
#include "../dst_internal.h"
|
|
|
|
#include "dnstest.h"
|
|
|
|
|
2018-06-18 11:43:45 +02:00
|
|
|
#if USE_OPENSSL
|
2018-10-24 09:01:48 -07:00
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
_setup(void **state) {
|
2018-10-24 09:01:48 -07:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, false);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
return (0);
|
2014-10-17 15:55:37 -07:00
|
|
|
}
|
2018-10-24 09:01:48 -07:00
|
|
|
|
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
_teardown(void **state) {
|
2018-10-24 09:01:48 -07:00
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OpenSSL DH_compute_key() failure */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
dh_computesecret(void **state) {
|
|
|
|
dst_key_t *key = NULL;
|
|
|
|
isc_buffer_t buf;
|
|
|
|
unsigned char array[1024];
|
|
|
|
isc_result_t result;
|
2014-10-17 15:55:37 -07:00
|
|
|
dns_fixedname_t fname;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_name_t *name;
|
2014-10-17 15:55:37 -07:00
|
|
|
|
2018-10-24 09:01:48 -07:00
|
|
|
UNUSED(state);
|
2014-10-17 15:55:37 -07:00
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
name = dns_fixedname_initname(&fname);
|
2014-10-17 15:55:37 -07:00
|
|
|
isc_buffer_constinit(&buf, "dh.", 3);
|
|
|
|
isc_buffer_add(&buf, 3);
|
2018-10-24 09:01:48 -07:00
|
|
|
result = dns_name_fromtext(name, &buf, NULL, 0, NULL);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2014-10-17 15:55:37 -07:00
|
|
|
|
2018-10-24 09:01:48 -07:00
|
|
|
result = dst_key_fromfile(name, 18602, DST_ALG_DH,
|
2020-02-12 13:59:18 +01:00
|
|
|
DST_TYPE_PUBLIC | DST_TYPE_KEY, "./", dt_mctx,
|
|
|
|
&key);
|
2018-10-24 09:01:48 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2014-10-17 15:55:37 -07:00
|
|
|
|
|
|
|
isc_buffer_init(&buf, array, sizeof(array));
|
2018-10-24 09:01:48 -07:00
|
|
|
result = dst_key_computesecret(key, key, &buf);
|
|
|
|
assert_int_equal(result, DST_R_NOTPRIVATEKEY);
|
|
|
|
result = key->func->computesecret(key, key, &buf);
|
|
|
|
assert_int_equal(result, DST_R_COMPUTESECRETFAILURE);
|
2014-10-17 15:55:37 -07:00
|
|
|
|
|
|
|
dst_key_free(&key);
|
2018-06-18 11:43:45 +02:00
|
|
|
}
|
|
|
|
#endif /* USE_OPENSSL */
|
2018-10-24 09:01:48 -07:00
|
|
|
|
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-06-18 11:43:45 +02:00
|
|
|
#if USE_OPENSSL
|
2018-10-24 09:01:48 -07:00
|
|
|
const struct CMUnitTest tests[] = {
|
2020-02-12 13:59:18 +01:00
|
|
|
cmocka_unit_test_setup_teardown(dh_computesecret, _setup,
|
|
|
|
_teardown),
|
2018-10-24 09:01:48 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
return (cmocka_run_group_tests(tests, NULL, NULL));
|
2020-02-13 21:48:23 +01:00
|
|
|
#else /* if USE_OPENSSL */
|
2018-10-24 09:01:48 -07:00
|
|
|
print_message("1..0 # Skipped: dh test broken with PKCS11");
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if USE_OPENSSL */
|
2014-10-17 15:55:37 -07:00
|
|
|
}
|
2018-10-24 09:01:48 -07:00
|
|
|
|
|
|
|
#else /* HAVE_CMOCKA */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-10-24 09:01:48 -07:00
|
|
|
printf("1..0 # Skipped: cmocka not available\n");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if HAVE_CMOCKA */
|