Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dns/server: return KEY record with sig0 key #289

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/dns/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const {
NSRecord,
SOARecord,
NSECRecord,
KEYRecord,
types,
codes
} = wire;
Expand Down Expand Up @@ -270,6 +271,10 @@ class RootServer extends DNSServer {
res.answer.push(key.ds.deepClone());
key.signZSK(res.answer, types.DS);
break;
case types.KEY:
res.answer.push(this.toKEY());
key.signZSK(res.answer, types.KEY);
break;
default:
// Empty Proof:
res.authority.push(this.toNSEC());
Expand Down Expand Up @@ -449,6 +454,10 @@ class RootServer extends DNSServer {
rd.typeBitmap = TYPE_MAP;
return rr;
}

toKEY() {
return hsig.makeKey(this.key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this works with dig:

    const rr = hsig.makeKey(this.key);
    rr.data.algorithm = 4;
    return rr;

I suspect the PRIVATEDNS experimental algorithm code is not standardized, so dig parses it as a compression byte and fails.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it appears even with this we see:

;; Warning: Message parser reports malformed message packet.

Also, PRIVATEDNS is defined in RFC 4034: https://tools.ietf.org/html/rfc4034 so it should be considered standard. I believe a combination of the warning above and a invalid case in parsing leads to the error described above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so dig requires that the class in the answer section match the question section. So

rr.class = classes.IN;

solves the warning. The issue with parsing still exists.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, these are the offending lines:

if (algorithm == DNS_KEYALG_PRIVATEDNS) {
	dns_name_t name;
	dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
	dns_name_init(&name, NULL);
	RETERR(dns_name_fromwire(&name, source, dctx, options, target));
}

Is there a spec for how to handle PRIVATEDNS? Not sure what's going on here...

But if we are planning to use a different key other than the brontide key anyway, why not just use a key of the type ECDSAP256SHA256 like KSK and ZSK... that would avoid the experimental PRIVATEDNS case altogether which seems to be under/unspecified.

Copy link
Contributor

@tuxcanfly tuxcanfly Nov 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, so RFC 4034 says:

Algorithm number 253 is reserved for private use and will never be assigned to
a specific algorithm. The public key area in the DNSKEY RR and the signature
area in the RRSIG RR begin with a wire encoded domain name, which MUST NOT be
compressed. The domain name indicates the private algorithm to use, and the
remainder of the public key area is determined by that algorithm. Entities
should only use domain names they control to designate their private
algorithms.

https://tools.ietf.org/html/rfc4034#appendix-A.1.1

So for PRIVATEDNS algorithm, dig actually tries to parse the pubkey part of the KEY record as a algo name string first, followed by the actual pubkey. However, the code that parses this is interleaved with the compression decoding code (even though RFC says name will never be compressed), causing a bad label error if any byte falls in the range 128 - 192.

As a very simple test case to verify this, if you prefix the pubkey with a null byte, you can see that dig is able to parse the result without issues.

}
}

/**
Expand Down
10 changes: 8 additions & 2 deletions lib/node/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,20 @@ class Node extends EventEmitter {
*/

loadKey() {
if (this.memory || fs.unsupported)
let key = this.config.buf('identity-key');

// Create a new key in memory if no key
// was passed via config at runtime and
// there is no filesystem backend.
if (!key && (this.memory || fs.unsupported))
return this.genKey();

const filename = this.location('key');

let key = this.config.buf('identity-key');
let fresh = false;

// No key was passed in at runtime via config,
// try to read the key from hsd dot directory.
if (!key) {
try {
const data = fs.readFileSync(filename, 'utf8');
Expand Down