tsig.c revision 3f6dc1703f76a24b34ed3bc839447291c33ca837
/*
* 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.16 1999/10/08 18:36:51 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>
/* 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[1024];
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;
if (length > 0) {
isc_buffer_add(&b, length);
if (ret != ISC_R_SUCCESS)
goto cleanup_algorithm;
}
else
return (ISC_R_SUCCESS);
return (ret);
}
/* Caller must be sure that this key is not in use. */
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;
}
}
if (!dns_tsigkey_empty(key)) {
unsigned char header[DNS_MESSAGE_HEADERLEN];
/* 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 */
}
else {
querysigned >> 32);
querysigned & 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;
}
}
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;
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) {
}
/* XXX 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) {
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);
}
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) {
return (ret);
}
return (ISC_R_SUCCESS);
}
void
dns_tsig_destroy() {
while (!ISC_LIST_EMPTY(tsigkeys)) {
}
}