1 /* $NetBSD: dh_test.c,v 1.1.1.1 2015/07/08 15:38:04 christos Exp $ */
2
3 /*
4 * Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 /* Id */
20
21 /* ! \file */
22
23 #include <config.h>
24
25 #include <atf-c.h>
26
27 #include <unistd.h>
28
29 #include <isc/util.h>
30 #include <isc/string.h>
31
32 #include <dns/name.h>
33 #include <dst/result.h>
34
35 #include "../dst_internal.h"
36
37 #include "dnstest.h"
38
39 #ifdef OPENSSL
40
41 ATF_TC(isc_dh_computesecret);
ATF_TC_HEAD(isc_dh_computesecret,tc)42 ATF_TC_HEAD(isc_dh_computesecret, tc) {
43 atf_tc_set_md_var(tc, "descr", "OpenSSL DH_compute_key() failure");
44 }
ATF_TC_BODY(isc_dh_computesecret,tc)45 ATF_TC_BODY(isc_dh_computesecret, tc) {
46 dst_key_t *key = NULL;
47 isc_buffer_t buf;
48 unsigned char array[1024];
49 isc_result_t ret;
50 dns_fixedname_t fname;
51 dns_name_t *name;
52
53 UNUSED(tc);
54
55 ret = dns_test_begin(NULL, ISC_FALSE);
56 ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
57
58 dns_fixedname_init(&fname);
59 name = dns_fixedname_name(&fname);
60 isc_buffer_constinit(&buf, "dh.", 3);
61 isc_buffer_add(&buf, 3);
62 ret = dns_name_fromtext(name, &buf, NULL, 0, NULL);
63 ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
64
65 ret = dst_key_fromfile(name, 18602, DST_ALG_DH,
66 DST_TYPE_PUBLIC | DST_TYPE_KEY,
67 "./", mctx, &key);
68 ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
69
70 isc_buffer_init(&buf, array, sizeof(array));
71 ret = dst_key_computesecret(key, key, &buf);
72 ATF_REQUIRE_EQ(ret, DST_R_NOTPRIVATEKEY);
73 ret = key->func->computesecret(key, key, &buf);
74 ATF_REQUIRE_EQ(ret, DST_R_COMPUTESECRETFAILURE);
75
76 dst_key_free(&key);
77 dns_test_end();
78 }
79 #else
80 ATF_TC(untested);
ATF_TC_HEAD(untested,tc)81 ATF_TC_HEAD(untested, tc) {
82 atf_tc_set_md_var(tc, "descr", "skipping OpenSSL DH test");
83 }
ATF_TC_BODY(untested,tc)84 ATF_TC_BODY(untested, tc) {
85 UNUSED(tc);
86 atf_tc_skip("OpenSSL DH not compiled in");
87 }
88 #endif
89 /*
90 * Main
91 */
ATF_TP_ADD_TCS(tp)92 ATF_TP_ADD_TCS(tp) {
93 #ifdef OPENSSL
94 ATF_TP_ADD_TC(tp, isc_dh_computesecret);
95 #else
96 ATF_TP_ADD_TC(tp, untested);
97 #endif
98 return (atf_no_error());
99 }
100