2002-06-17 04:01:37 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2002-06-17 04:01:37 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +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.
|
2002-06-17 04:01:37 +00:00
|
|
|
*/
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
|
|
|
|
/*! \file */
|
2002-06-17 04:01:37 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <isc/buffer.h>
|
|
|
|
#include <isc/region.h>
|
2018-06-01 09:31:59 +02:00
|
|
|
#include <isc/md.h>
|
2002-06-17 04:01:37 +00:00
|
|
|
#include <isc/util.h>
|
|
|
|
|
|
|
|
#include <dns/ds.h>
|
|
|
|
#include <dns/fixedname.h>
|
|
|
|
#include <dns/name.h>
|
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdatastruct.h>
|
|
|
|
#include <dns/result.h>
|
|
|
|
|
|
|
|
#include <dst/dst.h>
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dns_ds_buildrdata(dns_name_t *owner, dns_rdata_t *key,
|
|
|
|
unsigned int digest_type, unsigned char *buffer,
|
|
|
|
dns_rdata_t *rdata)
|
|
|
|
{
|
|
|
|
dns_fixedname_t fname;
|
|
|
|
dns_name_t *name;
|
2018-06-01 09:31:59 +02:00
|
|
|
unsigned char digest[ISC_MAX_MD_SIZE];
|
|
|
|
unsigned int digestlen;
|
2002-06-17 04:01:37 +00:00
|
|
|
isc_region_t r;
|
|
|
|
isc_buffer_t b;
|
|
|
|
dns_rdata_ds_t ds;
|
2018-06-01 09:31:59 +02:00
|
|
|
isc_md_t *md;
|
|
|
|
isc_md_type_t md_type = 0;
|
|
|
|
isc_result_t ret;
|
2002-06-17 04:01:37 +00:00
|
|
|
|
2003-09-30 06:00:40 +00:00
|
|
|
REQUIRE(key != NULL);
|
2019-01-31 19:34:21 +00:00
|
|
|
REQUIRE(key->type == dns_rdatatype_dnskey ||
|
|
|
|
key->type == dns_rdatatype_cdnskey);
|
2003-09-30 06:00:40 +00:00
|
|
|
|
2018-06-01 09:31:59 +02:00
|
|
|
if (!dst_ds_digest_supported(digest_type)) {
|
2002-06-17 04:01:37 +00:00
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
2018-06-01 09:31:59 +02:00
|
|
|
}
|
2002-06-17 04:01:37 +00:00
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
name = dns_fixedname_initname(&fname);
|
2002-06-17 04:01:37 +00:00
|
|
|
(void)dns_name_downcase(owner, name, NULL);
|
|
|
|
|
|
|
|
memset(buffer, 0, DNS_DS_BUFFERSIZE);
|
|
|
|
isc_buffer_init(&b, buffer, DNS_DS_BUFFERSIZE);
|
|
|
|
|
2018-06-01 09:31:59 +02:00
|
|
|
md = isc_md_new();
|
|
|
|
if (md == NULL) {
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
}
|
|
|
|
|
2010-12-23 04:08:00 +00:00
|
|
|
switch (digest_type) {
|
|
|
|
case DNS_DSDIGEST_SHA1:
|
2018-06-01 09:31:59 +02:00
|
|
|
md_type = ISC_MD_SHA1;
|
2010-12-23 04:08:00 +00:00
|
|
|
break;
|
2012-05-02 23:20:17 +10:00
|
|
|
|
|
|
|
case DNS_DSDIGEST_SHA384:
|
2018-06-01 09:31:59 +02:00
|
|
|
md_type = ISC_MD_SHA384;
|
2012-05-02 23:20:17 +10:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DNS_DSDIGEST_SHA256:
|
2010-12-23 04:08:00 +00:00
|
|
|
default:
|
2018-06-01 09:31:59 +02:00
|
|
|
md_type = ISC_MD_SHA256;
|
2010-12-23 04:08:00 +00:00
|
|
|
break;
|
2006-02-21 23:49:51 +00:00
|
|
|
}
|
2002-06-17 04:01:37 +00:00
|
|
|
|
2018-06-01 09:31:59 +02:00
|
|
|
ret = isc_md_init(md, md_type);
|
|
|
|
if (ret != ISC_R_SUCCESS) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_name_toregion(name, &r);
|
|
|
|
|
|
|
|
ret = isc_md_update(md, r.base, r.length);
|
|
|
|
if (ret != ISC_R_SUCCESS) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_rdata_toregion(key, &r);
|
|
|
|
INSIST(r.length >= 4);
|
|
|
|
|
|
|
|
ret = isc_md_update(md, r.base, r.length);
|
|
|
|
if (ret != ISC_R_SUCCESS) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = isc_md_final(md, digest, &digestlen);
|
|
|
|
if (ret != ISC_R_SUCCESS) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2002-06-17 04:01:37 +00:00
|
|
|
ds.mctx = NULL;
|
|
|
|
ds.common.rdclass = key->rdclass;
|
|
|
|
ds.common.rdtype = dns_rdatatype_ds;
|
|
|
|
ds.algorithm = r.base[3];
|
2018-10-25 10:27:49 +02:00
|
|
|
ds.key_tag = dst_region_computeid(&r);
|
2006-02-21 23:49:51 +00:00
|
|
|
ds.digest_type = digest_type;
|
2002-06-17 04:01:37 +00:00
|
|
|
ds.digest = digest;
|
2018-06-01 09:31:59 +02:00
|
|
|
ds.length = digestlen;
|
2002-06-17 04:01:37 +00:00
|
|
|
|
2018-06-01 09:31:59 +02:00
|
|
|
ret = dns_rdata_fromstruct(rdata, key->rdclass, dns_rdatatype_ds,
|
|
|
|
&ds, &b);
|
|
|
|
end:
|
|
|
|
if (md != NULL) {
|
|
|
|
isc_md_free(md);
|
|
|
|
}
|
|
|
|
return (ret);
|
2002-06-17 04:01:37 +00:00
|
|
|
}
|