2017-07-07 23:19:05 +10:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2017-07-07 23:19:05 +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
|
|
|
|
* file, You can obtain one at http://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.
|
2017-07-07 23:19:05 +10:00
|
|
|
*/
|
|
|
|
|
2017-09-06 10:57:40 -07:00
|
|
|
/*! \file */
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
#include <config.h>
|
2017-09-06 10:57:40 -07:00
|
|
|
|
2017-07-07 23:19:05 +10:00
|
|
|
#include <atf-c.h>
|
2017-07-08 00:47:59 +10:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2017-09-06 10:57:40 -07:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2017-07-07 23:19:05 +10:00
|
|
|
#include <isc/mem.h>
|
2017-07-08 00:47:59 +10:00
|
|
|
#include <isc/print.h>
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
#include <dns/rdatalist.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/tsig.h>
|
|
|
|
|
2017-09-06 10:57:40 -07:00
|
|
|
#include "../tsig_p.h"
|
|
|
|
|
2017-07-07 23:19:05 +10:00
|
|
|
#include "dnstest.h"
|
|
|
|
|
2017-09-06 10:57:40 -07:00
|
|
|
#define TEST_ORIGIN "test"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Individual unit tests
|
|
|
|
*/
|
|
|
|
|
2017-07-07 23:19:05 +10:00
|
|
|
static int debug = 0;
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
add_mac(dst_context_t *tsigctx, isc_buffer_t *buf) {
|
|
|
|
dns_rdata_any_tsig_t tsig;
|
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
|
|
|
isc_buffer_t databuf;
|
|
|
|
isc_region_t r;
|
|
|
|
isc_result_t result;
|
|
|
|
unsigned char tsigbuf[1024];
|
|
|
|
|
|
|
|
isc_buffer_usedregion(buf, &r);
|
|
|
|
dns_rdata_fromregion(&rdata, dns_rdataclass_any,
|
|
|
|
dns_rdatatype_tsig, &r);
|
|
|
|
isc_buffer_init(&databuf, tsigbuf, sizeof(tsigbuf));
|
|
|
|
CHECK(dns_rdata_tostruct(&rdata, &tsig, NULL));
|
|
|
|
isc_buffer_putuint16(&databuf, tsig.siglen);
|
|
|
|
isc_buffer_putmem(&databuf, tsig.signature, tsig.siglen);
|
|
|
|
isc_buffer_usedregion(&databuf, &r);
|
|
|
|
result = dst_context_adddata(tsigctx, &r);
|
|
|
|
dns_rdata_freestruct(&tsig);
|
|
|
|
cleanup:
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
add_tsig(dst_context_t *tsigctx, dns_tsigkey_t *key, isc_buffer_t *target) {
|
|
|
|
dns_compress_t cctx;
|
|
|
|
dns_rdata_any_tsig_t tsig;
|
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
|
|
|
dns_rdatalist_t rdatalist;
|
|
|
|
dns_rdataset_t rdataset;
|
|
|
|
isc_buffer_t *dynbuf = NULL;
|
|
|
|
isc_buffer_t databuf;
|
|
|
|
isc_buffer_t sigbuf;
|
|
|
|
isc_region_t r;
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
isc_stdtime_t now;
|
|
|
|
unsigned char tsigbuf[1024];
|
|
|
|
unsigned int count;
|
2017-12-22 08:58:20 +11:00
|
|
|
unsigned int sigsize = 0;
|
2018-04-17 08:29:14 -07:00
|
|
|
bool invalidate_ctx = false;
|
2017-07-07 23:19:05 +10:00
|
|
|
|
2017-09-27 10:27:09 +10:00
|
|
|
memset(&tsig, 0, sizeof(tsig));
|
|
|
|
|
2017-07-07 23:19:05 +10:00
|
|
|
CHECK(dns_compress_init(&cctx, -1, mctx));
|
2018-04-17 08:29:14 -07:00
|
|
|
invalidate_ctx = true;
|
2017-07-07 23:19:05 +10:00
|
|
|
|
2017-09-27 10:27:09 +10:00
|
|
|
tsig.common.rdclass = dns_rdataclass_any;
|
2017-07-07 23:19:05 +10:00
|
|
|
tsig.common.rdtype = dns_rdatatype_tsig;
|
|
|
|
ISC_LINK_INIT(&tsig.common, link);
|
|
|
|
dns_name_init(&tsig.algorithm, NULL);
|
|
|
|
dns_name_clone(key->algorithm, &tsig.algorithm);
|
|
|
|
|
|
|
|
isc_stdtime_get(&now);
|
|
|
|
tsig.timesigned = now;
|
|
|
|
tsig.fudge = DNS_TSIG_FUDGE;
|
|
|
|
tsig.originalid = 50;
|
|
|
|
tsig.error = dns_rcode_noerror;
|
|
|
|
tsig.otherlen = 0;
|
|
|
|
tsig.other = NULL;
|
|
|
|
|
|
|
|
isc_buffer_init(&databuf, tsigbuf, sizeof(tsigbuf));
|
|
|
|
isc_buffer_putuint48(&databuf, tsig.timesigned);
|
|
|
|
isc_buffer_putuint16(&databuf, tsig.fudge);
|
|
|
|
isc_buffer_usedregion(&databuf, &r);
|
|
|
|
CHECK(dst_context_adddata(tsigctx, &r));
|
|
|
|
|
|
|
|
CHECK(dst_key_sigsize(key->key, &sigsize));
|
|
|
|
tsig.signature = (unsigned char *) isc_mem_get(mctx, sigsize);
|
|
|
|
if (tsig.signature == NULL)
|
|
|
|
CHECK(ISC_R_NOMEMORY);
|
|
|
|
isc_buffer_init(&sigbuf, tsig.signature, sigsize);
|
|
|
|
CHECK(dst_context_sign(tsigctx, &sigbuf));
|
|
|
|
tsig.siglen = isc_buffer_usedlength(&sigbuf);
|
2017-12-22 08:58:20 +11:00
|
|
|
ATF_CHECK_EQ(sigsize, tsig.siglen);
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
CHECK(isc_buffer_allocate(mctx, &dynbuf, 512));
|
|
|
|
CHECK(dns_rdata_fromstruct(&rdata, dns_rdataclass_any,
|
|
|
|
dns_rdatatype_tsig, &tsig, dynbuf));
|
|
|
|
dns_rdatalist_init(&rdatalist);
|
|
|
|
rdatalist.rdclass = dns_rdataclass_any;
|
|
|
|
rdatalist.type = dns_rdatatype_tsig;
|
|
|
|
ISC_LIST_APPEND(rdatalist.rdata, &rdata, link);
|
|
|
|
dns_rdataset_init(&rdataset);
|
|
|
|
CHECK(dns_rdatalist_tordataset(&rdatalist, &rdataset));
|
|
|
|
CHECK(dns_rdataset_towire(&rdataset, &key->name, &cctx,
|
|
|
|
target, 0, &count));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fixup additional record count.
|
|
|
|
*/
|
|
|
|
((unsigned char*)target->base)[11]++;
|
|
|
|
if (((unsigned char*)target->base)[11] == 0)
|
|
|
|
((unsigned char*)target->base)[10]++;
|
|
|
|
cleanup:
|
|
|
|
if (tsig.signature != NULL)
|
|
|
|
isc_mem_put(mctx, tsig.signature, sigsize);
|
|
|
|
if (dynbuf != NULL)
|
|
|
|
isc_buffer_free(&dynbuf);
|
|
|
|
if (invalidate_ctx)
|
|
|
|
dns_compress_invalidate(&cctx);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
printmessage(dns_message_t *msg) {
|
|
|
|
isc_buffer_t b;
|
|
|
|
char *buf = NULL;
|
|
|
|
int len = 1024;
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
|
|
|
|
if (!debug)
|
|
|
|
return;
|
|
|
|
|
|
|
|
do {
|
|
|
|
buf = isc_mem_get(mctx, len);
|
2017-09-27 10:27:09 +10:00
|
|
|
if (buf == NULL)
|
|
|
|
return;
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
isc_buffer_init(&b, buf, len);
|
|
|
|
result = dns_message_totext(msg, &dns_master_style_debug,
|
|
|
|
0, &b);
|
|
|
|
if (result == ISC_R_NOSPACE) {
|
|
|
|
isc_mem_put(mctx, buf, len);
|
|
|
|
len *= 2;
|
|
|
|
} else if (result == ISC_R_SUCCESS)
|
|
|
|
printf("%.*s\n", (int) isc_buffer_usedlength(&b), buf);
|
|
|
|
} while (result == ISC_R_NOSPACE);
|
|
|
|
|
|
|
|
if (buf != NULL)
|
|
|
|
isc_mem_put(mctx, buf, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
render(isc_buffer_t *buf, unsigned flags, dns_tsigkey_t *key,
|
|
|
|
isc_buffer_t **tsigin, isc_buffer_t **tsigout,
|
|
|
|
dst_context_t *tsigctx)
|
|
|
|
{
|
|
|
|
dns_message_t *msg = NULL;
|
|
|
|
dns_compress_t cctx;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &msg);
|
|
|
|
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
|
|
|
"dns_message_create: %s",
|
|
|
|
dns_result_totext(result));
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE(msg != NULL);
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
msg->id = 50;
|
|
|
|
msg->rcode = dns_rcode_noerror;
|
|
|
|
msg->flags = flags;
|
|
|
|
|
2017-08-08 19:43:39 +05:30
|
|
|
/*
|
|
|
|
* XXXMPA: this hack needs to be replaced with use of
|
|
|
|
* dns_message_reply() at some point.
|
|
|
|
*/
|
|
|
|
if ((flags & DNS_MESSAGEFLAG_QR) != 0)
|
|
|
|
msg->verified_sig = 1;
|
|
|
|
|
2017-07-07 23:19:05 +10:00
|
|
|
if (tsigin == tsigout)
|
|
|
|
msg->tcp_continuation = 1;
|
|
|
|
|
|
|
|
if (tsigctx == NULL) {
|
|
|
|
result = dns_message_settsigkey(msg, key);
|
|
|
|
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
|
|
|
"dns_message_settsigkey: %s",
|
|
|
|
dns_result_totext(result));
|
|
|
|
|
|
|
|
result = dns_message_setquerytsig(msg, *tsigin);
|
|
|
|
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
|
|
|
"dns_message_setquerytsig: %s",
|
|
|
|
dns_result_totext(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
result = dns_compress_init(&cctx, -1, mctx);
|
|
|
|
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
|
|
|
"dns_compress_init: %s",
|
|
|
|
dns_result_totext(result));
|
|
|
|
|
|
|
|
result = dns_message_renderbegin(msg, &cctx, buf);
|
|
|
|
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
|
|
|
"dns_message_renderbegin: %s",
|
|
|
|
dns_result_totext(result));
|
|
|
|
|
|
|
|
result = dns_message_renderend(msg);
|
|
|
|
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
|
|
|
"dns_message_renderend: %s",
|
|
|
|
dns_result_totext(result));
|
|
|
|
|
|
|
|
if (tsigctx != NULL) {
|
|
|
|
isc_region_t r;
|
|
|
|
|
|
|
|
isc_buffer_usedregion(buf, &r);
|
|
|
|
result = dst_context_adddata(tsigctx, &r);
|
2017-09-27 10:27:09 +10:00
|
|
|
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
|
|
|
"dst_context_adddata: %s",
|
|
|
|
dns_result_totext(result));
|
2017-07-07 23:19:05 +10:00
|
|
|
} else {
|
|
|
|
if (tsigin == tsigout && *tsigin != NULL)
|
|
|
|
isc_buffer_free(tsigin);
|
|
|
|
|
|
|
|
result = dns_message_getquerytsig(msg, mctx, tsigout);
|
|
|
|
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
|
|
|
"dns_message_getquerytsig: %s",
|
|
|
|
dns_result_totext(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_compress_invalidate(&cctx);
|
|
|
|
dns_message_destroy(&msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that a simulated three message TCP sequence where the first
|
|
|
|
* and last messages contain TSIGs but the intermediate message doesn't
|
|
|
|
* correctly verifies.
|
|
|
|
*/
|
|
|
|
ATF_TC(tsig_tcp);
|
|
|
|
ATF_TC_HEAD(tsig_tcp, tc) {
|
|
|
|
atf_tc_set_md_var(tc, "descr", "test tsig tcp-continuation validation");
|
|
|
|
}
|
|
|
|
ATF_TC_BODY(tsig_tcp, tc) {
|
|
|
|
const dns_name_t *tsigowner = NULL;
|
|
|
|
dns_fixedname_t fkeyname;
|
|
|
|
dns_message_t *msg = NULL;
|
|
|
|
dns_name_t *keyname;
|
|
|
|
dns_tsig_keyring_t *ring = NULL;
|
|
|
|
dns_tsigkey_t *key = NULL;
|
|
|
|
isc_buffer_t *buf = NULL;
|
|
|
|
isc_buffer_t *querytsig = NULL;
|
|
|
|
isc_buffer_t *tsigin = NULL;
|
|
|
|
isc_buffer_t *tsigout = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
unsigned char secret[16] = { 0 };
|
|
|
|
dst_context_t *tsigctx = NULL;
|
|
|
|
dst_context_t *outctx = NULL;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
result = dns_test_begin(stderr, true);
|
2017-07-07 23:19:05 +10:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/* isc_log_setdebuglevel(lctx, 99); */
|
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
keyname = dns_fixedname_initname(&fkeyname);
|
2017-07-07 23:19:05 +10:00
|
|
|
result = dns_name_fromstring(keyname, "test", 0, NULL);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = dns_tsigkeyring_create(mctx, &ring);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = dns_tsigkey_create(keyname, dns_tsig_hmacsha256_name,
|
2018-04-17 08:29:14 -07:00
|
|
|
secret, sizeof(secret), false,
|
2017-07-07 23:19:05 +10:00
|
|
|
NULL, 0, 0, mctx, ring, &key);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE(key != NULL);
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create request.
|
|
|
|
*/
|
|
|
|
result = isc_buffer_allocate(mctx, &buf, 65535);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
render(buf, 0, key, &tsigout, &querytsig, NULL);
|
|
|
|
isc_buffer_free(&buf);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create response message 1.
|
|
|
|
*/
|
|
|
|
result = isc_buffer_allocate(mctx, &buf, 65535);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
render(buf, DNS_MESSAGEFLAG_QR, key, &querytsig, &tsigout, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process response message 1.
|
|
|
|
*/
|
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_create: %s",
|
|
|
|
dns_result_totext(result));
|
|
|
|
ATF_REQUIRE(msg != NULL);
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
result = dns_message_settsigkey(msg, key);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_settsigkey: %s",
|
|
|
|
dns_result_totext(result));
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
result = dns_message_parse(msg, buf, 0);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_parse: %s",
|
|
|
|
dns_result_totext(result));
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
printmessage(msg);
|
|
|
|
|
|
|
|
result = dns_message_setquerytsig(msg, querytsig);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
|
|
|
|
"dns_message_setquerytsig: %s",
|
|
|
|
dns_result_totext(result));
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
result = dns_tsig_verify(buf, msg, NULL, NULL);
|
|
|
|
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
|
|
|
"dns_tsig_verify: %s",
|
|
|
|
dns_result_totext(result));
|
|
|
|
ATF_CHECK_EQ(msg->verified_sig, 1);
|
|
|
|
ATF_CHECK_EQ(msg->tsigstatus, dns_rcode_noerror);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that we have a TSIG in the first message.
|
|
|
|
*/
|
|
|
|
ATF_REQUIRE(dns_message_gettsig(msg, &tsigowner) != NULL);
|
|
|
|
|
|
|
|
result = dns_message_getquerytsig(msg, mctx, &tsigin);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
|
|
|
|
"dns_message_getquerytsig: %s",
|
|
|
|
dns_result_totext(result));
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
tsigctx = msg->tsigctx;
|
|
|
|
msg->tsigctx = NULL;
|
|
|
|
isc_buffer_free(&buf);
|
|
|
|
dns_message_destroy(&msg);
|
|
|
|
|
2018-04-04 09:44:50 +02:00
|
|
|
result = dst_context_create(key->key, mctx, DNS_LOGCATEGORY_DNSSEC,
|
2018-04-17 08:29:14 -07:00
|
|
|
false, 0, &outctx);
|
2017-07-07 23:19:05 +10:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE(outctx != NULL);
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start digesting.
|
|
|
|
*/
|
|
|
|
result = add_mac(outctx, tsigout);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create response message 2.
|
|
|
|
*/
|
|
|
|
result = isc_buffer_allocate(mctx, &buf, 65535);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
render(buf, DNS_MESSAGEFLAG_QR, key, &tsigout, &tsigout, outctx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process response message 2.
|
|
|
|
*/
|
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_create: %s",
|
|
|
|
dns_result_totext(result));
|
|
|
|
ATF_REQUIRE(msg != NULL);
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
msg->tcp_continuation = 1;
|
|
|
|
msg->tsigctx = tsigctx;
|
|
|
|
tsigctx = NULL;
|
|
|
|
|
|
|
|
result = dns_message_settsigkey(msg, key);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_settsigkey: %s",
|
|
|
|
dns_result_totext(result));
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
result = dns_message_parse(msg, buf, 0);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_parse: %s",
|
|
|
|
dns_result_totext(result));
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
printmessage(msg);
|
|
|
|
|
|
|
|
result = dns_message_setquerytsig(msg, tsigin);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
|
|
|
|
"dns_message_setquerytsig: %s",
|
|
|
|
dns_result_totext(result));
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
result = dns_tsig_verify(buf, msg, NULL, NULL);
|
|
|
|
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
|
|
|
"dns_tsig_verify: %s",
|
|
|
|
dns_result_totext(result));
|
2017-08-08 19:43:39 +05:30
|
|
|
ATF_CHECK_EQ(msg->verified_sig, 0);
|
2017-07-07 23:19:05 +10:00
|
|
|
ATF_CHECK_EQ(msg->tsigstatus, dns_rcode_noerror);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that we don't have a TSIG in the second message.
|
|
|
|
*/
|
|
|
|
tsigowner = NULL;
|
|
|
|
ATF_REQUIRE(dns_message_gettsig(msg, &tsigowner) == NULL);
|
|
|
|
|
|
|
|
tsigctx = msg->tsigctx;
|
|
|
|
msg->tsigctx = NULL;
|
|
|
|
isc_buffer_free(&buf);
|
|
|
|
dns_message_destroy(&msg);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create response message 3.
|
|
|
|
*/
|
|
|
|
result = isc_buffer_allocate(mctx, &buf, 65535);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
render(buf, DNS_MESSAGEFLAG_QR, key, &tsigout, &tsigout, outctx);
|
|
|
|
|
|
|
|
result = add_tsig(outctx, key, buf);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "add_tsig: %s",
|
|
|
|
dns_result_totext(result));
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Process response message 3.
|
|
|
|
*/
|
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_create: %s",
|
|
|
|
dns_result_totext(result));
|
|
|
|
ATF_REQUIRE(msg != NULL);
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
msg->tcp_continuation = 1;
|
|
|
|
msg->tsigctx = tsigctx;
|
|
|
|
tsigctx = NULL;
|
|
|
|
|
|
|
|
result = dns_message_settsigkey(msg, key);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_settsigkey: %s",
|
|
|
|
dns_result_totext(result));
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
result = dns_message_parse(msg, buf, 0);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_parse: %s",
|
|
|
|
dns_result_totext(result));
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
printmessage(msg);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that we had a TSIG in the third message.
|
|
|
|
*/
|
|
|
|
ATF_REQUIRE(dns_message_gettsig(msg, &tsigowner) != NULL);
|
|
|
|
|
|
|
|
result = dns_message_setquerytsig(msg, tsigin);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
|
|
|
|
"dns_message_setquerytsig: %s",
|
|
|
|
dns_result_totext(result));
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
result = dns_tsig_verify(buf, msg, NULL, NULL);
|
|
|
|
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
|
|
|
"dns_tsig_verify: %s",
|
|
|
|
dns_result_totext(result));
|
|
|
|
ATF_CHECK_EQ(msg->verified_sig, 1);
|
|
|
|
ATF_CHECK_EQ(msg->tsigstatus, dns_rcode_noerror);
|
|
|
|
|
|
|
|
if (tsigin != NULL)
|
|
|
|
isc_buffer_free(&tsigin);
|
|
|
|
|
|
|
|
result = dns_message_getquerytsig(msg, mctx, &tsigin);
|
2017-07-19 14:34:15 +10:00
|
|
|
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
|
|
|
|
"dns_message_getquerytsig: %s",
|
|
|
|
dns_result_totext(result));
|
2017-07-07 23:19:05 +10:00
|
|
|
|
|
|
|
isc_buffer_free(&buf);
|
|
|
|
dns_message_destroy(&msg);
|
|
|
|
|
|
|
|
if (outctx != NULL)
|
|
|
|
dst_context_destroy(&outctx);
|
|
|
|
if (querytsig != NULL)
|
|
|
|
isc_buffer_free(&querytsig);
|
|
|
|
if (tsigin != NULL)
|
|
|
|
isc_buffer_free(&tsigin);
|
|
|
|
if (tsigout != NULL)
|
|
|
|
isc_buffer_free(&tsigout);
|
2017-12-12 13:20:56 +11:00
|
|
|
dns_tsigkey_detach(&key);
|
2017-07-07 23:19:05 +10:00
|
|
|
if (ring != NULL)
|
|
|
|
dns_tsigkeyring_detach(&ring);
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
2017-09-06 10:57:40 -07:00
|
|
|
ATF_TC(algvalid);
|
|
|
|
ATF_TC_HEAD(algvalid, tc) {
|
|
|
|
atf_tc_set_md_var(tc, "descr", "Tests the dns__tsig_algvalid function");
|
|
|
|
}
|
|
|
|
ATF_TC_BODY(algvalid, tc) {
|
|
|
|
UNUSED(tc);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algvalid(DST_ALG_HMACMD5), true);
|
2017-09-06 10:57:40 -07:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algvalid(DST_ALG_HMACSHA1), true);
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algvalid(DST_ALG_HMACSHA224), true);
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algvalid(DST_ALG_HMACSHA256), true);
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algvalid(DST_ALG_HMACSHA384), true);
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algvalid(DST_ALG_HMACSHA512), true);
|
2017-09-06 10:57:40 -07:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algvalid(DST_ALG_GSSAPI), false);
|
2017-09-06 10:57:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ATF_TC(algfromname);
|
|
|
|
ATF_TC_HEAD(algfromname, tc) {
|
|
|
|
atf_tc_set_md_var(tc, "descr", "Tests the dns__tsig_algfromname function");
|
|
|
|
}
|
|
|
|
ATF_TC_BODY(algfromname, tc) {
|
|
|
|
UNUSED(tc);
|
|
|
|
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algfromname(DNS_TSIG_HMACMD5_NAME), DST_ALG_HMACMD5);
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algfromname(DNS_TSIG_HMACSHA1_NAME), DST_ALG_HMACSHA1);
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algfromname(DNS_TSIG_HMACSHA224_NAME), DST_ALG_HMACSHA224);
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algfromname(DNS_TSIG_HMACSHA256_NAME), DST_ALG_HMACSHA256);
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algfromname(DNS_TSIG_HMACSHA384_NAME), DST_ALG_HMACSHA384);
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algfromname(DNS_TSIG_HMACSHA512_NAME), DST_ALG_HMACSHA512);
|
|
|
|
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algfromname(DNS_TSIG_GSSAPI_NAME), DST_ALG_GSSAPI);
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algfromname(DNS_TSIG_GSSAPIMS_NAME), DST_ALG_GSSAPI);
|
|
|
|
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algfromname(dns_rootname), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ATF_TC(algnamefromname);
|
|
|
|
ATF_TC_HEAD(algnamefromname, tc) {
|
|
|
|
atf_tc_set_md_var(tc, "descr", "Tests the dns__tsig_algnamefromname function");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper function to create a dns_name_t from a string and see if
|
|
|
|
* the dns__tsig_algnamefromname function can correctly match it against the
|
|
|
|
* static table of known algorithms.
|
|
|
|
*/
|
|
|
|
static void test_name(const char *name_string, const dns_name_t *expected) {
|
|
|
|
dns_name_t name;
|
|
|
|
dns_name_init(&name, NULL);
|
|
|
|
ATF_CHECK_EQ(dns_name_fromstring(&name, name_string, 0, mctx), ISC_R_SUCCESS);
|
|
|
|
ATF_REQUIRE_EQ_MSG(dns__tsig_algnamefromname(&name), expected, "%s", name_string);
|
|
|
|
dns_name_free(&name, mctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
ATF_TC_BODY(algnamefromname, tc) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
result = dns_test_begin(stderr, true);
|
2017-09-06 10:57:40 -07:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/* test the standard algorithms */
|
|
|
|
test_name("hmac-md5.sig-alg.reg.int", DNS_TSIG_HMACMD5_NAME);
|
|
|
|
test_name("hmac-sha1", DNS_TSIG_HMACSHA1_NAME);
|
|
|
|
test_name("hmac-sha224", DNS_TSIG_HMACSHA224_NAME);
|
|
|
|
test_name("hmac-sha256", DNS_TSIG_HMACSHA256_NAME);
|
|
|
|
test_name("hmac-sha384", DNS_TSIG_HMACSHA384_NAME);
|
|
|
|
test_name("hmac-sha512", DNS_TSIG_HMACSHA512_NAME);
|
|
|
|
|
|
|
|
test_name("gss-tsig", DNS_TSIG_GSSAPI_NAME);
|
|
|
|
test_name("gss.microsoft.com", DNS_TSIG_GSSAPIMS_NAME);
|
|
|
|
|
|
|
|
/* try another name that isn't a standard algorithm name */
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algnamefromname(dns_rootname), NULL);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
ATF_TC(algallocated);
|
|
|
|
ATF_TC_HEAD(algallocated, tc) {
|
|
|
|
atf_tc_set_md_var(tc, "descr", "Tests the dns__tsig_algallocated function");
|
|
|
|
}
|
|
|
|
ATF_TC_BODY(algallocated, tc) {
|
|
|
|
|
|
|
|
/* test the standard algorithms */
|
2018-04-17 08:29:14 -07:00
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algallocated(DNS_TSIG_HMACMD5_NAME), false);
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algallocated(DNS_TSIG_HMACSHA1_NAME), false);
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algallocated(DNS_TSIG_HMACSHA224_NAME), false);
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algallocated(DNS_TSIG_HMACSHA256_NAME), false);
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algallocated(DNS_TSIG_HMACSHA384_NAME), false);
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algallocated(DNS_TSIG_HMACSHA512_NAME), false);
|
2017-09-06 10:57:40 -07:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algallocated(DNS_TSIG_HMACSHA512_NAME), false);
|
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algallocated(DNS_TSIG_HMACSHA512_NAME), false);
|
2017-09-06 10:57:40 -07:00
|
|
|
|
|
|
|
/* try another name that isn't a standard algorithm name */
|
2018-04-17 08:29:14 -07:00
|
|
|
ATF_REQUIRE_EQ(dns__tsig_algallocated(dns_rootname), true);
|
2017-09-06 10:57:40 -07:00
|
|
|
}
|
|
|
|
|
2017-07-07 23:19:05 +10:00
|
|
|
/*
|
|
|
|
* Main
|
|
|
|
*/
|
|
|
|
ATF_TP_ADD_TCS(tp) {
|
|
|
|
ATF_TP_ADD_TC(tp, tsig_tcp);
|
2017-09-06 10:57:40 -07:00
|
|
|
ATF_TP_ADD_TC(tp, algvalid);
|
|
|
|
ATF_TP_ADD_TC(tp, algfromname);
|
|
|
|
ATF_TP_ADD_TC(tp, algnamefromname);
|
|
|
|
ATF_TP_ADD_TC(tp, algallocated);
|
|
|
|
|
2017-07-07 23:19:05 +10:00
|
|
|
return (atf_no_error());
|
|
|
|
}
|