Commit 4bfbe9db authored by Daniel Salzman's avatar Daniel Salzman

rrset-dump: add key length to DNSKEY comment

parent 7cf00157
......@@ -1250,21 +1250,64 @@ static void wire_unknown_to_str(rrset_dump_params_t *p)
p->ret = 0;
}
static size_t dnskey_len(const uint8_t *rdata,
const size_t rdata_len)
{
// Check for empty rdata and empty key.
if (rdata_len <= 4) {
return 0;
}
const uint8_t *key = rdata + 4;
const size_t len = rdata_len - 4;
switch (rdata[3]) {
case KNOT_DNSSEC_ALG_DSA:
case KNOT_DNSSEC_ALG_DSA_NSEC3_SHA1:
return (64 + 8 * key[0]) * 8;
case KNOT_DNSSEC_ALG_RSAMD5:
case KNOT_DNSSEC_ALG_RSASHA1:
case KNOT_DNSSEC_ALG_RSASHA1_NSEC3_SHA1:
case KNOT_DNSSEC_ALG_RSASHA256:
case KNOT_DNSSEC_ALG_RSASHA512:
if (key[0] == 0) {
if (len < 3) {
return 0;
}
uint16_t exp;
memcpy(&exp, key + 1, sizeof(uint16_t));
return (len - 3 - ntohs(exp)) * 8;
} else {
return (len - 1 - key[0]) * 8;
}
case KNOT_DNSSEC_ALG_ECC_GOST:
return 512;
case KNOT_DNSSEC_ALG_ECDSAP256SHA256:
return 256;
case KNOT_DNSSEC_ALG_ECDSAP384SHA384:
return 384;
default:
return 0;
}
}
static void dnskey_info(const uint8_t *rdata,
const size_t rdata_len,
char *out,
const size_t out_len)
{
const uint8_t sep = *(rdata + 1) & 0x01;
const uint8_t sep = rdata[1] & 0x01;
const uint16_t key_tag = knot_keytag(rdata, rdata_len);
const size_t key_len = dnskey_len(rdata, rdata_len);
const uint8_t alg_id = rdata[3];
lookup_table_t *alg = NULL;
alg = lookup_by_id(knot_dnssec_alg_names, *(rdata + 3));
alg = lookup_by_id(knot_dnssec_alg_names, alg_id);
int ret = snprintf(out, out_len, "%s, alg = %s, id = %u ",
int ret = snprintf(out, out_len, "%s, %s (%zub), id = %u",
sep ? "KSK" : "ZSK",
alg ? alg->name : "UNKNOWN",
key_tag );
key_len, key_tag );
if (ret <= 0) { // Truncated return is acceptable. Just check for errors.
out[0] = '\0';
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment