dh_test.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 /* $Id$ */
00018 
00019 /* ! \file */
00020 
00021 #include <config.h>
00022 
00023 #include <atf-c.h>
00024 
00025 #include <unistd.h>
00026 
00027 #include <isc/util.h>
00028 #include <isc/string.h>
00029 
00030 #include <dns/name.h>
00031 #include <dst/result.h>
00032 
00033 #include "../dst_internal.h"
00034 
00035 #include "dnstest.h"
00036 
00037 #ifdef OPENSSL
00038 
00039 ATF_TC(isc_dh_computesecret);
00040 ATF_TC_HEAD(isc_dh_computesecret, tc) {
00041         atf_tc_set_md_var(tc, "descr", "OpenSSL DH_compute_key() failure");
00042 }
00043 ATF_TC_BODY(isc_dh_computesecret, tc) {
00044         dst_key_t *key = NULL;
00045         isc_buffer_t buf;
00046         unsigned char array[1024];
00047         isc_result_t ret;
00048         dns_fixedname_t fname;
00049         dns_name_t *name;
00050 
00051         UNUSED(tc);
00052 
00053         ret = dns_test_begin(NULL, ISC_FALSE);
00054         ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
00055 
00056         dns_fixedname_init(&fname);
00057         name = dns_fixedname_name(&fname);
00058         isc_buffer_constinit(&buf, "dh.", 3);
00059         isc_buffer_add(&buf, 3);
00060         ret = dns_name_fromtext(name, &buf, NULL, 0, NULL);
00061         ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
00062 
00063         ret = dst_key_fromfile(name, 18602, DST_ALG_DH,
00064                                DST_TYPE_PUBLIC | DST_TYPE_KEY,
00065                                "./", mctx, &key);
00066         ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
00067 
00068         isc_buffer_init(&buf, array, sizeof(array));
00069         ret = dst_key_computesecret(key, key, &buf);
00070         ATF_REQUIRE_EQ(ret, DST_R_NOTPRIVATEKEY);
00071         ret = key->func->computesecret(key, key, &buf);
00072         ATF_REQUIRE_EQ(ret, DST_R_COMPUTESECRETFAILURE);
00073 
00074         dst_key_free(&key);
00075         dns_test_end();
00076 }
00077 #else
00078 ATF_TC(untested);
00079 ATF_TC_HEAD(untested, tc) {
00080         atf_tc_set_md_var(tc, "descr", "skipping OpenSSL DH test");
00081 }
00082 ATF_TC_BODY(untested, tc) {
00083         UNUSED(tc);
00084         atf_tc_skip("OpenSSL DH not compiled in");
00085 }
00086 #endif
00087 /*
00088  * Main
00089  */
00090 ATF_TP_ADD_TCS(tp) {
00091 #ifdef OPENSSL
00092         ATF_TP_ADD_TC(tp, isc_dh_computesecret);
00093 #else
00094         ATF_TP_ADD_TC(tp, untested);
00095 #endif
00096         return (atf_no_error());
00097 }

Generated on Tue Apr 28 17:41:01 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha