00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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 }