tsig.c revision 7077846f3bf941f626a8623bd29a56a5ce7a1e11
0e27506ce3135f9bd49e12564ad0e15256135118Automatic Updater * Copyright (C) 1999, 2000 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * purpose with or without fee is hereby granted, provided that the above
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * $Id: tsig.c,v 1.65 2000/05/27 00:24:07 bwelling Exp $
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * Principal Author: Brian Wellington
593cb00bd17e5e2ab0dcb7c635a9a81082dc5d0eAndreas Gustafsson#include <stdlib.h> /* Required for abs(). */
9aba20edee4e704433a464ae43b070b0775de506Mark Andrews#include <isc/string.h> /* Required for HP/UX (and others?) */
3e14b69d196a3ebeecc4662c426344dcfd7db678Andreas Gustafsson#define VALID_TSIG_KEY(x) ISC_MAGIC_VALID(x, TSIG_MAGIC)
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#define is_response(msg) (msg->flags & DNS_MESSAGEFLAG_QR)
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencedns_tsig_verify_tcp(isc_buffer_t *source, dns_message_t *msg);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssondns_tsigkey_create(dns_name_t *name, dns_name_t *algorithm,
9aba20edee4e704433a464ae43b070b0775de506Mark Andrews unsigned char *secret, int length, isc_boolean_t generated,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dns_tsig_keyring_t *ring, dns_tsigkey_t **key)
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (!dns_name_equal(algorithm, DNS_TSIG_HMACMD5_NAME))
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson tkey = (dns_tsigkey_t *) isc_mem_get(mctx, sizeof(dns_tsigkey_t));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dns_name_dup(name, mctx, &tkey->name);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dns_name_downcase(&tkey->name, &tkey->name, NULL);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dns_name_dup(algorithm, mctx, &tkey->algorithm);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dns_name_downcase(&tkey->algorithm, &tkey->algorithm, NULL);
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson tkey->creator = isc_mem_get(mctx, sizeof(dns_name_t));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dns_name_dup(algorithm, mctx, tkey->creator);
f621719829356f27e831507b75e88e8a655e48d8Danny Mayer isc_mem_put(mctx, tkey->creator, sizeof(dns_name_t));
19f4d25fd5b35b1375b0b9f13b66770ee4a66154Brian Wellington isc_rwlock_lock(&ring->lock, isc_rwlocktype_write);
19f4d25fd5b35b1375b0b9f13b66770ee4a66154Brian Wellington if (dns_name_equal(&tkey->name, &tmp->name) &&
2883651930dc85cacae940fe2a81277dfc14807dBrian Wellington isc_rwlock_unlock(&ring->lock, isc_rwlocktype_write);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson "isc_mutex_init() failed: %s",
9aba20edee4e704433a464ae43b070b0775de506Mark Andrews isc_mem_put(mctx, *key, sizeof(dns_tsigkey_t));
9aba20edee4e704433a464ae43b070b0775de506Mark Andrewsdns_tsigkey_attach(dns_tsigkey_t *source, dns_tsigkey_t **targetp) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 isc_rwlock_lock(&ring->lock, isc_rwlocktype_write);
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater isc_rwlock_unlock(&ring->lock, isc_rwlocktype_write);
42a5f9c8f535fb2a6d1cbfaa38533176e1f1667aBob Halley isc_mem_put(key->mctx, key->creator, sizeof(dns_name_t));
42a5f9c8f535fb2a6d1cbfaa38533176e1f1667aBob Halley isc_mem_put(key->mctx, key, sizeof(dns_tsigkey_t));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (tkey->refs > 0 || (!tkey->deleted && tkey->key != NULL)) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssondns_tsigkey_setdeleted(dns_tsigkey_t *key) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson REQUIRE(VALID_TSIG_KEY(dns_message_gettsigkey(msg)));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * If this is a response, there should be a query tsig.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (is_response(msg) && msg->querytsig == NULL)
ec7493d8d1966a3dc5f5306fc0a96519e0de6dceAndreas Gustafsson tsig.common.rdclass = dns_rdataclass_any;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence ret = dns_name_dup(&key->algorithm, mctx, &tsig.algorithm);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence isc_buffer_init(&databuf, data, sizeof(data));
2e715dbdc263f859c01b57a9d733c1dfbf28b90eBob Halley tsig.other = (unsigned char *)isc_mem_get(mctx, tsig.otherlen);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_init(&otherbuf, tsig.other, tsig.otherlen);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (!dns_tsigkey_empty(key) && tsig.error != dns_tsigerror_badsig) {
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson unsigned char header[DNS_MESSAGE_HEADERLEN];
692ae2fff922f1c072169d1ddda8e600cb572a9bMark Andrews ret = dst_key_sign(DST_SIGMODE_INIT, key->key, &ctx, NULL,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * If this is a response, digest the query signature.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_putuint16(&databuf, msg->querytsig->siglen);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_availableregion(&databuf, &r);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_add(&databuf, msg->querytsig->siglen);
e482a1c91ecb5e47bc26617bf310d6b5c41fad91Andreas Gustafsson ret = dst_key_sign(DST_SIGMODE_UPDATE, key->key, &ctx,
e482a1c91ecb5e47bc26617bf310d6b5c41fad91Andreas Gustafsson * Digest the header.
e482a1c91ecb5e47bc26617bf310d6b5c41fad91Andreas Gustafsson isc_buffer_init(&headerbuf, header, sizeof(header));
e482a1c91ecb5e47bc26617bf310d6b5c41fad91Andreas Gustafsson dns_message_renderheader(msg, &headerbuf);
e482a1c91ecb5e47bc26617bf310d6b5c41fad91Andreas Gustafsson ret = dst_key_sign(DST_SIGMODE_UPDATE, key->key, &ctx, &r,
47d89fcd4fb850b066f87dc3313afe1cfe92cd99Mark Andrews * Digest the remainder of the message.
47d89fcd4fb850b066f87dc3313afe1cfe92cd99Mark Andrews ret = dst_key_sign(DST_SIGMODE_UPDATE, key->key, &ctx, &r,
47d89fcd4fb850b066f87dc3313afe1cfe92cd99Mark Andrews * Digest the name, class, ttl, alg.
47d89fcd4fb850b066f87dc3313afe1cfe92cd99Mark Andrews ret = dst_key_sign(DST_SIGMODE_UPDATE, key->key, &ctx,
47d89fcd4fb850b066f87dc3313afe1cfe92cd99Mark Andrews isc_buffer_putuint16(&databuf, dns_rdataclass_any);
47d89fcd4fb850b066f87dc3313afe1cfe92cd99Mark Andrews ret = dst_key_sign(DST_SIGMODE_UPDATE, key->key, &ctx,
47d89fcd4fb850b066f87dc3313afe1cfe92cd99Mark Andrews ret = dst_key_sign(DST_SIGMODE_UPDATE, key->key, &ctx,
47d89fcd4fb850b066f87dc3313afe1cfe92cd99Mark Andrews /* Digest the timesigned and fudge */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_uint64_t querysigned = msg->querytsig->timesigned;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_putuint16(&databuf, tsig.fudge);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dst_key_sign(DST_SIGMODE_UPDATE, key->key, &ctx, &r,
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt * Digest the error and other data length.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dst_key_sign(DST_SIGMODE_UPDATE, key->key, &ctx,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Digest the error and other data.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dst_key_sigsize(key->key, &sigsize);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_init(&sigbuf, tsig.signature, tsig.siglen);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dst_key_sign(DST_SIGMODE_FINAL, key->key, &ctx, NULL,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dns_message_gettemprdata(msg, &rdata);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence ret = isc_buffer_allocate(msg->mctx, &dynbuf, 512);
c801dd02ed98321f3ccab93c159a1dce61961c58Bob Halley ret = dns_rdata_fromstruct(rdata, dns_rdataclass_any,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_mem_put(mctx, tsig.signature, tsig.siglen);
c801dd02ed98321f3ccab93c159a1dce61961c58Bob Halley msg->tsig = isc_mem_get(mctx, sizeof(dns_rdata_any_tsig_t));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dns_rdata_tostruct(rdata, msg->tsig, mctx);
e482a1c91ecb5e47bc26617bf310d6b5c41fad91Andreas Gustafsson ret = dns_message_gettempname(msg, &owner);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt ret = isc_buffer_allocate(mctx, &dynbuf, r.length);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence ret = dns_message_gettemprdatalist(msg, &datalist);
47d89fcd4fb850b066f87dc3313afe1cfe92cd99Mark Andrews ret = dns_message_gettemprdataset(msg, &dataset);
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson isc_mem_put(mctx, msg->tsig, sizeof *msg->tsig);
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson isc_mem_put(mctx, tsig.signature, tsig.siglen);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_mem_put(mctx, tsig.other, tsig.otherlen);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssondns_tsig_verify(isc_buffer_t *source, dns_message_t *msg,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dns_tsig_keyring_t *sring, dns_tsig_keyring_t *dring)
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson REQUIRE(tsigkey == NULL || VALID_TSIG_KEY(tsigkey));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson return(dns_tsig_verify_tcp(source, msg));
c801dd02ed98321f3ccab93c159a1dce61961c58Bob Halley * There should be a TSIG record...
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * If this is a response and there's no key or query TSIG, there
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * shouldn't be one on the response.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson (tsigkey == NULL || msg->querytsig == NULL))
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * If we're here, we know the message is well formed and contains a
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * TSIG record.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dns_rdataset_current(msg->tsigset, &rdata);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_mem_get(mctx, sizeof(dns_rdata_any_tsig_t));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dns_rdata_tostruct(&rdata, tsig, mctx);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Do the key name and algorithm match that of the query?
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence !dns_name_equal(&tsig->algorithm, &msg->querytsig->algorithm)))
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Get the current time.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Find dns_tsigkey_t based on keyname.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dns_tsigkey_find(&tsigkey, keyname,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dns_tsigkey_create(keyname, &tsig->algorithm,
421551db8a61283420b0b6aed4ac28f9d76b9770Andreas Gustafsson * Is the time ok?
421551db8a61283420b0b6aed4ac28f9d76b9770Andreas Gustafsson if (abs(now - tsig->timesigned) > tsig->fudge) {
421551db8a61283420b0b6aed4ac28f9d76b9770Andreas Gustafsson ret = dst_key_verify(DST_SIGMODE_INIT, key, &ctx, NULL,
421551db8a61283420b0b6aed4ac28f9d76b9770Andreas Gustafsson isc_buffer_init(&databuf, data, sizeof(data));
421551db8a61283420b0b6aed4ac28f9d76b9770Andreas Gustafsson isc_buffer_putuint16(&databuf, msg->querytsig->siglen);
421551db8a61283420b0b6aed4ac28f9d76b9770Andreas Gustafsson ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &ctx, &r,
bed7a352934efc8055902d83c750dca2d0cd6aaaAndreas Gustafsson ret = dst_key_verify(DST_SIGMODE_UPDATE, key,
421551db8a61283420b0b6aed4ac28f9d76b9770Andreas Gustafsson * Extract the header.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 memcpy(header, r.base, DNS_MESSAGE_HEADERLEN);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_region_consume(&r, DNS_MESSAGE_HEADERLEN);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Decrement the additional field counter.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson memcpy(&addcount, &header[DNS_MESSAGE_HEADERLEN - 2], 2);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff memcpy(&header[DNS_MESSAGE_HEADERLEN - 2], &addcount, 2);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Put in the original id.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Digest the modified header.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &ctx, &header_r,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Digest all non-TSIG records.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_usedregion(source, &source_r);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson r.base = source_r.base + DNS_MESSAGE_HEADERLEN;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff r.length = msg->sigstart - DNS_MESSAGE_HEADERLEN;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &ctx, &r,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Digest the key name.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &ctx, &r,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_init(&databuf, data, sizeof(data));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_putuint16(&databuf, tsig->common.rdclass);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence isc_buffer_putuint32(&databuf, msg->tsigset->ttl);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &ctx, &r,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Digest the key algorithm.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dns_name_toregion(&tsigkey->algorithm, &r);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &ctx, &r,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_putuint16(&databuf, (isc_uint16_t)(tsig->timesigned
d8e34837cd6c88c42b3ecdb9107a43ecf8252e79David Lawrence isc_buffer_putuint32(&databuf, (isc_uint32_t)(tsig->timesigned
d8e34837cd6c88c42b3ecdb9107a43ecf8252e79David Lawrence & 0xFFFFFFFF));
d8e34837cd6c88c42b3ecdb9107a43ecf8252e79David Lawrence isc_buffer_putuint16(&databuf, tsig->otherlen);
d8e34837cd6c88c42b3ecdb9107a43ecf8252e79David Lawrence ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &ctx, &r,
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &ctx, &r,
593cb00bd17e5e2ab0dcb7c635a9a81082dc5d0eAndreas Gustafsson ret = dst_key_verify(DST_SIGMODE_FINAL, key, &ctx, NULL,
593cb00bd17e5e2ab0dcb7c635a9a81082dc5d0eAndreas Gustafsson else if (tsig->error != dns_tsigerror_badsig &&
593cb00bd17e5e2ab0dcb7c635a9a81082dc5d0eAndreas Gustafsson /* XXXBEW Log a message */
593cb00bd17e5e2ab0dcb7c635a9a81082dc5d0eAndreas Gustafsson isc_mem_put(mctx, tsig, sizeof(dns_rdata_any_tsig_t));
593cb00bd17e5e2ab0dcb7c635a9a81082dc5d0eAndreas Gustafssondns_tsig_verify_tcp(isc_buffer_t *source, dns_message_t *msg) {
593cb00bd17e5e2ab0dcb7c635a9a81082dc5d0eAndreas Gustafsson isc_region_t r, source_r, header_r, sig_r;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson unsigned char header[DNS_MESSAGE_HEADERLEN];
593cb00bd17e5e2ab0dcb7c635a9a81082dc5d0eAndreas Gustafsson REQUIRE(dns_message_gettsigkey(msg) != NULL);
593cb00bd17e5e2ab0dcb7c635a9a81082dc5d0eAndreas Gustafsson dns_rdataset_current(msg->tsigset, &rdata);
674f1cfb1d7dfa92e52db950dbe80e60ef8f5cddBrian Wellington isc_mem_get(mctx, sizeof(dns_rdata_any_tsig_t));
593cb00bd17e5e2ab0dcb7c635a9a81082dc5d0eAndreas Gustafsson ret = dns_rdata_tostruct(&rdata, tsig, mctx);
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews * Do the key name and algorithm match that of the query?
e482a1c91ecb5e47bc26617bf310d6b5c41fad91Andreas Gustafsson if (!dns_name_equal(keyname, &tsigkey->name) ||
123a3dddc94534d3a6c6f81c118a5b63dc5994c3Andreas Gustafsson * Is the time ok?
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews if (abs(now - tsig->timesigned) > tsig->fudge) {
674f1cfb1d7dfa92e52db950dbe80e60ef8f5cddBrian Wellington ret = dst_key_verify(DST_SIGMODE_INIT, key, &msg->tsigctx,
593cb00bd17e5e2ab0dcb7c635a9a81082dc5d0eAndreas Gustafsson isc_buffer_init(&databuf, data, sizeof(data));
593cb00bd17e5e2ab0dcb7c635a9a81082dc5d0eAndreas Gustafsson isc_buffer_putuint16(&databuf, msg->querytsig->siglen);
593cb00bd17e5e2ab0dcb7c635a9a81082dc5d0eAndreas Gustafsson ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &msg->tsigctx,
593cb00bd17e5e2ab0dcb7c635a9a81082dc5d0eAndreas Gustafsson ret = dst_key_verify(DST_SIGMODE_UPDATE, key,
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews * Extract the header.
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews * Decrement the additional field counter if necessary.
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews memcpy(&addcount, &header[DNS_MESSAGE_HEADERLEN - 2], 2);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews memcpy(&header[DNS_MESSAGE_HEADERLEN - 2], &addcount, 2);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews * Put in the original id.
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews /* XXX Can TCP transfers be forwarded? How would that work? */
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews * Digest the modified header.
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &msg->tsigctx, &header_r,
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews * Digest all non-TSIG records.
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews r.base = source_r.base + DNS_MESSAGE_HEADERLEN;
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews r.length = msg->sigstart - DNS_MESSAGE_HEADERLEN;
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews r.length = source_r.length - DNS_MESSAGE_HEADERLEN;
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &msg->tsigctx, &r, NULL);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews * Digest the time signed and fudge.
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews isc_buffer_putuint16(&databuf, (isc_uint16_t)(tsig->timesigned
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews isc_buffer_putuint32(&databuf, (isc_uint32_t)(tsig->timesigned
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews & 0xFFFFFFFF));
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &msg->tsigctx,
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews ret = dst_key_verify(DST_SIGMODE_FINAL, key, &msg->tsigctx,
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews isc_mem_put(mctx, tsig, sizeof(dns_rdata_any_tsig_t));
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrewsdns_tsigkey_find(dns_tsigkey_t **tsigkey, dns_name_t *name,
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews dns_name_t *algorithm, dns_tsig_keyring_t *ring)
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews isc_rwlock_lock(&ring->lock, isc_rwlocktype_read);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews * The key has expired.
0874abad14e3e9ecfc3dc1a1a2b9969f2f027724Mark Andrews isc_rwlock_unlock(&ring->lock, isc_rwlocktype_read);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews isc_rwlock_unlock(&ring->lock, isc_rwlocktype_read);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson char *str = "\010HMAC-MD5\007SIG-ALG\003REG\003INT";
9aba20edee4e704433a464ae43b070b0775de506Mark Andrewsdns_tsigkeyring_create(isc_mem_t *mctx, dns_tsig_keyring_t **ring)
d99f88add1e61555e3193e9b33701c1a1ffa677aMichael Graff RUNTIME_CHECK(isc_once_do(&once, dns_tsig_inithmac) == ISC_R_SUCCESS);
9aba20edee4e704433a464ae43b070b0775de506Mark Andrews *ring = isc_mem_get(mctx, sizeof(dns_tsig_keyring_t));
9aba20edee4e704433a464ae43b070b0775de506Mark Andrews "isc_rwlock_init() failed: %s",
9aba20edee4e704433a464ae43b070b0775de506Mark Andrewsdns_tsigkeyring_destroy(dns_tsig_keyring_t **ring) {
9aba20edee4e704433a464ae43b070b0775de506Mark Andrews dns_tsigkey_t *key = ISC_LIST_HEAD((*ring)->keys);