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

test: add dns resolver tests #265

Merged
merged 6 commits into from
Nov 1, 2019
Merged

Conversation

tynes
Copy link
Contributor

@tynes tynes commented Oct 8, 2019

This PR includes a test that purchases names and then writes one of each of the different Handshake records into the tree. A DNS stub resolver then queries for the name and asserts on the correct data being returned.

The DNSSEC test tests that all resource records sets in the answer and authority sections are signed. If all resource record sets in the additional section were signed as well, it could cause problems because there could potentially be many signatures and would force the DNS server to fall back to TCP. Ideally a different authentication mechanism is devised, because the DNSSEC key is public information anyways.

@boymanjor happy to split this up into smaller PRs if it would make it easier to review

Closes #264

@codecov-io
Copy link

codecov-io commented Oct 8, 2019

Codecov Report

Merging #265 into master will increase coverage by 3.6%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #265     +/-   ##
=========================================
+ Coverage   54.86%   58.47%   +3.6%     
=========================================
  Files         129      129             
  Lines       35786    35790      +4     
  Branches     6032     6032             
=========================================
+ Hits        19635    20929   +1294     
+ Misses      16151    14861   -1290
Impacted Files Coverage Δ
lib/dns/records.js 77.23% <100%> (+66.43%) ⬆️
lib/dns/resource.js 78.8% <100%> (+59.07%) ⬆️
lib/utils/binary.js 56.41% <0%> (-2.57%) ⬇️
lib/node/fullnode.js 56.16% <0%> (+0.45%) ⬆️
lib/dns/key.js 100% <0%> (+18.18%) ⬆️
lib/dns/server.js 58.51% <0%> (+26.59%) ⬆️
lib/dns/compress.js 78.22% <0%> (+28.04%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a323da8...4ea41aa. Read the comment docs.

lib/dns/records.js Outdated Show resolved Hide resolved
lib/dns/resource.js Outdated Show resolved Hide resolved
lib/dns/resource.js Outdated Show resolved Hide resolved
lib/node/rpc.js Outdated Show resolved Hide resolved
lib/dns/records.js Outdated Show resolved Hide resolved
lib/dns/server.js Outdated Show resolved Hide resolved
@tynes tynes force-pushed the dns-server-tests branch 2 times, most recently from 3f7b677 to 27e9b8c Compare October 9, 2019 22:00
@tynes
Copy link
Contributor Author

tynes commented Oct 10, 2019

I think the question that we need to answer is if all Resource Record sets in the response need to be authenticated. I do not feel like it is acceptable to have only part of the response authenticated. Based on experience playing with dig, I have only gotten RRSIG records back in the answer section. When there are additional records included, there is no RRSIG record that commits to them.

I suppose the combination of sig0 and DNSSEC helps, but the signing keys are public. Resolving Handshake names over the clearweb should be considered just as safe as resolving traditional DNS over clearweb (not safe). hsd should consider using DNS over HTTPS or another type of encryption scheme for its DNS resolution. It is particularly important to prevent man in the middle attacks, especially if cryptocurrency addresses can be resolved.

I think moving forwards with this PR, I can remove the DNSSEC checks in the tests and then remove the additional DNSSEC code and then open an issue to determine how we want to be authenticate our requests. @boymanjor thoughts?

test/dns-test.js Show resolved Hide resolved
test/dns-test.js Show resolved Hide resolved

/**
* Build a name to query for the types
* that require additional labels.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to turn this into a helper function as I think I'd find it useful building applications on top of Handshake. Not quite sure where it would live or how to generalize it correctly - notice that it uses a magic index into an array.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could it be part of utils or some common package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to check through hsd and bns to make sure that it already doesn't exist. Would the fn signature be:

name (str), hsd resource (Resource), dns type (int) -> List[str] (list of query strings)

A Resource can have multiple query strings depending on the Records inside of it, but this also may not return the name number of strings in the return value as the number of Records in the Resource which may be confusing to a library consumer.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK if we not maybe test/util/common is a good place.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should leave this as a specific test helper for now. We can abstract this into a proper library method when the functionality is needed elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok this makes sense to me. Its not clearly documented anywhere in the Handshake docs that you need to use a particular domain name (with subdomains) to query for some of the rr types. Maybe the bns stub resolver could be extended for this repo where its wrapped with an easier to use API that will handle these cases as well as use handshake native types instead of dns rr types. I could imagine that being very helpful for onboarding new developers, especially if it works in the browser.

@tynes tynes marked this pull request as ready for review October 14, 2019 21:03
@boymanjor boymanjor changed the title DNS End to End DNSSEC Tests test: include e2e dnssec tests Oct 16, 2019
test/dns-test.js Outdated Show resolved Hide resolved
test/dns-test.js Outdated Show resolved Hide resolved
test/dns-test.js Outdated Show resolved Hide resolved
test/dns-test.js Outdated Show resolved Hide resolved
test/dns-test.js Outdated Show resolved Hide resolved
test/dns-test.js Outdated Show resolved Hide resolved
test/dns-test.js Outdated Show resolved Hide resolved
test/dns-test.js Outdated Show resolved Hide resolved
Copy link
Contributor

@boymanjor boymanjor left a comment

Choose a reason for hiding this comment

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

@tynes I think this is basically ready to go. I left a comment about separating out the TXT record signing into a separate PR. I also think we can clean up the commit history. Basically this PR adds the helper types and then introduces the tests. All other commits can be squashed once we pull out the signing logic. I'd say don't worry about cleaning things up until everything thing that this depends on is merged.

lib/dns/resource.js Outdated Show resolved Hide resolved
lib/dns/resource.js Outdated Show resolved Hide resolved

/**
* Build a name to query for the types
* that require additional labels.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should leave this as a specific test helper for now. We can abstract this into a proper library method when the functionality is needed elsewhere.

@tynes
Copy link
Contributor Author

tynes commented Oct 30, 2019

I also think we can clean up the commit history.

I can rebase on master and rebase out a bunch of the intermediate commits after #292 gets merged.

Thanks for the review @boymanjor

Note that I wanted to add SIG0 validation to this PR as well, I started in #289 but ran into a bug with KEY records. Right now I do not see a way to validate the SIG0 signature without being able to query for the key, which the RFC defines KEY as the RR type used to return the SIG0 key. The authoritative resolver doesn't have logic for KEY RR types at the name .

See: https://github.com/handshake-org/hsd/blob/master/lib/dns/server.js#L228

@tynes
Copy link
Contributor Author

tynes commented Oct 31, 2019

Needs rebase now that 91f1c27 has been merged

@tynes tynes force-pushed the dns-server-tests branch 6 times, most recently from 58ef2ea to 54d495a Compare November 1, 2019 19:06
Mark Tyneway added 2 commits November 1, 2019 12:29
This data structure maps the Handshake
record types to the DNS protocol record
types. It is required for dynamic mapping
between the two. Use this to determine
which DNS query type to send to get back
the appropriate Handshake record type.
@tynes
Copy link
Contributor Author

tynes commented Nov 1, 2019

@boymanjor Has been rebased to remove intermediate commits

@boymanjor boymanjor changed the title test: include e2e dnssec tests test: add dns resolver tests Nov 1, 2019
Copy link
Contributor

@boymanjor boymanjor left a comment

Choose a reason for hiding this comment

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

LGTM

@boymanjor boymanjor merged commit 060b36a into handshake-org:master Nov 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DNSSEC doesn't sign Handshake Onion records
5 participants