tsig.c revision e552b980379e3a7ffce1411a939c62e27f953133
/*
* Copyright (C) 1999 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/*
* $Id: tsig.c,v 1.24 1999/10/27 19:59:34 bwelling Exp $
* Principal Author: Brian Wellington
*/
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <isc/assertions.h>
#include <dns/keyvalues.h>
#include <dns/rdatalist.h>
#include <dns/rdataset.h>
#include <dns/rdatastruct.h>
#include <dns/confkeys.h>
/* XXXBEW If an unsorted list isn't good enough, this can be updated */
static isc_rwlock_t tsiglock;
{
isc_buffer_t b, nameb;
char namestr[1025];
isc_region_t r;
if (length > 0)
return (ISC_R_NOTFOUND);
else
return (ISC_R_NOMEMORY);
if (ret != ISC_R_SUCCESS)
goto cleanup_key;
if (ret != ISC_R_SUCCESS)
goto cleanup_name;
if (ret != ISC_R_SUCCESS)
goto cleanup_algorithm;
isc_buffer_used(&nameb, &r);
if (length > 0) {
isc_buffer_add(&b, length);
if (ret != ISC_R_SUCCESS)
goto cleanup_algorithm;
ret = ISC_R_EXISTS;
goto cleanup_algorithm;
}
}
}
else
if (ret != ISC_R_SUCCESS) {
"isc_mutex_init() failed: %s",
return (DNS_R_UNEXPECTED);
}
return (ISC_R_SUCCESS);
return (ret);
}
void
return;
}
}
}
void
}
unsigned char data[128];
isc_region_t r, r2;
/* If this is a response, there should be a query tsig */
return (DNS_R_EXPECTEDTSIG);
tsig = (dns_rdata_any_tsig_t *)
return (ISC_R_NOMEMORY);
if (ret != ISC_R_SUCCESS)
goto cleanup_struct;
if (ret != ISC_R_SUCCESS)
goto cleanup_algorithm;
if (!dns_tsigkey_empty(key)) {
if (ret != ISC_R_SUCCESS)
goto cleanup_algorithm;
}
if (is_response(msg)) {
if (!dns_tsigkey_empty(key)) {
isc_buffer_available(&databuf, &r);
return (ISC_R_NOSPACE);
isc_buffer_used(&databuf, &r);
NULL);
if (ret != ISC_R_SUCCESS)
goto cleanup_algorithm;
}
}
else
}
else {
goto cleanup_other;
}
0xFFFFFFFF));
}
unsigned char header[DNS_MESSAGE_HEADERLEN];
unsigned int sigsize;
/* Digest the header */
isc_buffer_used(&headerbuf, &r);
if (ret != ISC_R_SUCCESS)
goto cleanup_other;
/* Digest the remainder of the message */
if (ret != ISC_R_SUCCESS)
goto cleanup_other;
if (msg->tcp_continuation == 0) {
/* Digest the name, class, ttl, alg */
NULL);
if (ret != ISC_R_SUCCESS)
goto cleanup_other;
isc_buffer_used(&databuf, &r);
NULL);
if (ret != ISC_R_SUCCESS)
goto cleanup_other;
NULL);
if (ret != ISC_R_SUCCESS)
goto cleanup_other;
}
/* Digest the timesigned and fudge */
32));
0xFFFFFFFF));
}
else {
(isc_uint16_t)(querysigned >>
32));
0xFFFFFFFF));
}
isc_buffer_used(&databuf, &r);
if (ret != ISC_R_SUCCESS)
goto cleanup_other;
if (msg->tcp_continuation == 0) {
/* Digest the error and other data length */
isc_buffer_used(&databuf, &r);
NULL);
if (ret != ISC_R_SUCCESS)
goto cleanup_other;
/* Digest the error and other data */
if (ret != ISC_R_SUCCESS)
goto cleanup_other;
}
}
if (ret != ISC_R_SUCCESS)
goto cleanup_other;
goto cleanup_other;
}
&sigbuf);
if (ret != ISC_R_SUCCESS)
goto cleanup_signature;
}
else {
}
if (ret != ISC_R_SUCCESS)
goto cleanup_signature;
if (ret != ISC_R_SUCCESS) {
goto cleanup_signature;
}
if (ret != ISC_R_SUCCESS) {
goto cleanup_dynbuf;
}
if (ret != ISC_R_SUCCESS)
goto cleanup_dynbuf;
if (ret != ISC_R_SUCCESS)
goto cleanup_dynbuf;
if (ret != ISC_R_SUCCESS)
goto cleanup_dynbuf;
if (ret != ISC_R_SUCCESS)
goto cleanup_dynbuf;
return (ISC_R_SUCCESS);
return (ret);
}
unsigned char data[32];
unsigned char header[DNS_MESSAGE_HEADERLEN];
/* There should be a TSIG record... */
return (DNS_R_EXPECTEDTSIG);
/*
* If this is a response and there's no key or query TSIG, there
* shouldn't be one on the response.
*/
if (is_response(msg) &&
return (DNS_R_UNEXPECTEDTSIG);
/*
* If we're here, we know the message is well formed and contains a
* TSIG record.
*/
if (ret != ISC_R_SUCCESS)
return (ret);
if (ret != ISC_R_SUCCESS)
return (ret);
tsig = (dns_rdata_any_tsig_t *)
return (ISC_R_NOMEMORY);
if (ret != ISC_R_SUCCESS)
goto cleanup_emptystruct;
/* Do the key name and algorithm match that of the query? */
if (is_response(msg) &&
{
return (DNS_R_TSIGVERIFYFAILURE);
}
/* Find dns_tsigkey_t based on keyname */
if (ret != ISC_R_SUCCESS) {
/*
* this key must be deleted later - an empty key can be found
* by calling dns_tsigkey_empty()
*/
if (ret != ISC_R_SUCCESS)
goto cleanup_struct;
return (DNS_R_TSIGVERIFYFAILURE);
}
/* Is the time ok? */
if (ret != ISC_R_SUCCESS)
goto cleanup_key;
return (DNS_R_TSIGVERIFYFAILURE);
}
if (ret != ISC_R_SUCCESS)
goto cleanup_key;
if (is_response(msg)) {
isc_buffer_used(&databuf, &r);
NULL);
if (ret != ISC_R_SUCCESS)
goto cleanup_key;
if (ret != ISC_R_SUCCESS)
goto cleanup_key;
}
}
/* Extract the header */
isc_buffer_used(source, &r);
/* Decrement the additional field counter */
/* Put in the original id */
/* Digest the modified header */
&sig_r);
if (ret != ISC_R_SUCCESS)
goto cleanup_key;
/* Digest all non-TSIG records. */
if (ret != ISC_R_SUCCESS)
goto cleanup_key;
/* Digest the key name */
if (ret != ISC_R_SUCCESS)
goto cleanup_key;
isc_buffer_used(&databuf, &r);
if (ret != ISC_R_SUCCESS)
goto cleanup_key;
/* Digest the key algorithm */
if (ret != ISC_R_SUCCESS)
goto cleanup_key;
>> 32));
& 0xFFFFFFFF));
isc_buffer_used(&databuf, &r);
&sig_r);
if (ret != ISC_R_SUCCESS)
goto cleanup_key;
}
if (ret == DST_R_VERIFYFINALFAILURE) {
return (DNS_R_TSIGVERIFYFAILURE);
}
else if (ret != ISC_R_SUCCESS)
goto cleanup_key;
}
{
return (DNS_R_TSIGVERIFYFAILURE);
}
if (is_response(msg)) {
/* XXXBEW Log a message */
return (ISC_R_SUCCESS);
}
else
return (DNS_R_TSIGERRORSET);
}
return (ISC_R_SUCCESS);
}
return (ret);
}
unsigned char data[32];
unsigned char header[DNS_MESSAGE_HEADERLEN];
if (ret == ISC_R_SUCCESS) {
if (ret != ISC_R_SUCCESS)
return (ret);
tsig = (dns_rdata_any_tsig_t *)
return (ISC_R_NOMEMORY);
if (ret != ISC_R_SUCCESS)
goto cleanup_emptystruct;
/* Do the key name and algorithm match that of the query? */
{
return (DNS_R_TSIGVERIFYFAILURE);
}
/* Is the time ok? */
if (ret != ISC_R_SUCCESS)
goto cleanup_struct;
return (DNS_R_TSIGVERIFYFAILURE);
}
}
if (ret != ISC_R_SUCCESS)
goto cleanup_struct;
isc_buffer_used(&databuf, &r);
&r, NULL);
if (ret != ISC_R_SUCCESS)
goto cleanup_struct;
if (ret != ISC_R_SUCCESS)
goto cleanup_struct;
}
}
/* Extract the header */
isc_buffer_used(source, &r);
/* Decrement the additional field counter if necessary */
if (has_tsig) {
}
/* Put in the original id */
/* Digest the modified header */
NULL);
if (ret != ISC_R_SUCCESS)
goto cleanup_struct;
/* Digest all non-TSIG records. */
if (has_tsig)
else
if (ret != ISC_R_SUCCESS)
goto cleanup_struct;
/* Digest the time signed and fudge */
if (has_tsig) {
>> 32));
& 0xFFFFFFFF));
isc_buffer_used(&databuf, &r);
NULL);
&sig_r);
if (ret == DST_R_VERIFYFINALFAILURE) {
return (DNS_R_TSIGVERIFYFAILURE);
}
else if (ret != ISC_R_SUCCESS)
goto cleanup_struct;
}
return (ISC_R_SUCCESS);
return (ret);
}
{
{
return (ISC_R_SUCCESS);
}
}
return (ISC_R_NOTFOUND);
}
static isc_result_t
int secretlen = 0;
/* Create the key name */
ISC_TRUE, &keynamebuf);
if (ret != ISC_R_SUCCESS)
goto failure;
/* Create the algorithm */
else {
if (ret != ISC_R_SUCCESS)
goto failure;
}
goto failure;
}
goto failure;
}
if (ret != ISC_R_SUCCESS)
goto failure;
if (ret != ISC_R_SUCCESS)
goto failure;
if (ret != ISC_R_SUCCESS)
goto failure;
if (ret != ISC_R_SUCCESS)
goto failure;
}
return (ISC_R_SUCCESS);
return (ret);
}
unsigned char data[32];
if (ret != ISC_R_SUCCESS) {
"isc_rwlock_init() failed: %s",
return (DNS_R_UNEXPECTED);
}
if (ret != ISC_R_SUCCESS)
return (ret);
if (dns_tsig_hmacmd5_name == NULL)
return (ISC_R_NOMEMORY);
if (ret != ISC_R_SUCCESS)
goto failure;
if (ret != ISC_R_SUCCESS)
goto failure;
}
return (ISC_R_SUCCESS);
return (ret);
}
void
dns_tsig_destroy() {
while (!ISC_LIST_EMPTY(tsigkeys)) {
}
}