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

Refactor: use wire-formatted byte arrays to represent names internally, no more strings #90

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Commits on Sep 28, 2022

  1. Configuration menu
    Copy the full SHA
    80ff7b8 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    498e116 View commit details
    Browse the repository at this point in the history
  3. dns: refactor name_parse(): read wire format and keep in wire format

    This function used to convert wire-formatted byte arrays to strings.
    We are no longer using strings for names internally so this function
    got much simpler. All it really needs to do now is un-compress a name
    from a DNS message packet.
    
    Because this function is the main entry point for all names in the
    program, it is also critical to verify label and name size rules.
    Once names are ingested by name_parse() and stored in structs, we
    can for the most part assume they are valid.
    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    99081df View commit details
    Browse the repository at this point in the history
  4. dns: refactor name_serialize(): read and keep in wire format

    This function used to convert names from strings to wire-formatted
    byte arrays. We are no longer using strings for names internally so
    this function got much simpler. All it really needs to do now is
    compress a name into a DNS message by adding label pointers where
    necessary.
    
    Because this function is the main output point for names it is
    critical to verify label and name lengths when we write.
    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    9f9f33f View commit details
    Browse the repository at this point in the history
  5. dns: use dns-name-based hash map for label compression in serialize()

    hsk_dns_name_serialize() takes an argument hsk_dns_cmp_t which
    includes a generic map object hsk_map_t. This map is used to track
    names and labels as a message is being written, so compression
    pointers can be applied. Since names are byte arrays now and not
    strings this map needs to be reimplemented with corrected hash and
    equality functions.
    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    081fedd View commit details
    Browse the repository at this point in the history
  6. dns: implement to/from string (DNS presentation format) for names

    Internally, hnsd keeps all names in wire-formatted byte arrays.
    There are only a few places where the name must be converted to a
    printable string, which requires "presentation format" e.g. //DDD
    for unprintable characters, etc.
    
    To string:
     - Log messages that print names being resolved
     - libunbound's recursive resolver API
    
    From string:
     - Only needed for testing
       (hnsd doesn't accept strings as input nor use them internally)
    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    e7d7c4b View commit details
    Browse the repository at this point in the history
  7. dns: repurpose name_verify() to match hsd rules.verifyName()

    In addition to procesisng byte arrays instead of strings, repurpose
    this function to check a single label for validity as a Handshake TLD.
    
    The most important time to use it is when receiving a user's request.
    TLDs need to be valid before hashing and requesting Urkel proofs from
    full nodes.
    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    58fc525 View commit details
    Browse the repository at this point in the history
  8. dns: refactor label split/from/get for byte array instead of string

    These label utilities used to process strings but now we represent all
    names as byte arrays. For consistency, these functions always output
    in DNS wire format, even single labels. That means output always
    begins with a length byte and ends with a 0x00 terminator (aka ".")
    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    5d12bc9 View commit details
    Browse the repository at this point in the history
  9. ns: fix synth parsing in onrecv() and refactor for byte arrays

    In addition to refactoring hsk_ns_onrecv() to deal with names as
    byte arrays instead of strings, this fixes a bug where the root
    server wasn't properly handling requests for _synth by itself.
    
    Since a request for `_synth` has only one label, we should not
    request label with index -2 using hsk_dns_label_from()
    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    7184186 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    0dde592 View commit details
    Browse the repository at this point in the history
  11. pool: rename "name" to "tld" and update HNS namehash for byte arrays

    Update the name_hash function (which is used when requesting proofs
    from full nodes) since names are not strings any more. In addition,
    try to be consistent with variable naming. "name" could be multiple
    labels, "tld" is always one label and, in the context of pool,
    important for requesting and verifying Urkel proofs.
    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    15018c0 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    272f216 View commit details
    Browse the repository at this point in the history
  13. cache: goodbye char *name!

    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    da4f3bb View commit details
    Browse the repository at this point in the history
  14. dns: goodbye char *name!

    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    9d011d9 View commit details
    Browse the repository at this point in the history
  15. dnssec: goodbye char *name!

    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    406cd62 View commit details
    Browse the repository at this point in the history
  16. ns: goodbye char *name!

    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    c28676c View commit details
    Browse the repository at this point in the history
  17. pool: goodbye char *name!

    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    48e9ddd View commit details
    Browse the repository at this point in the history
  18. req: goodbye char *name!

    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    0b323c1 View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    40099a9 View commit details
    Browse the repository at this point in the history
  20. rs: goodbye char *name!

    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    62ab53b View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    60f7a23 View commit details
    Browse the repository at this point in the history
  22. dns: remove label compression from some record types data

    https://www.rfc-editor.org/rfc/rfc3597#section-4
    
    > To avoid such corruption, servers MUST NOT compress domain names
    > embedded in the RDATA of types that are class-specific or not well-
    > known.  This requirement was stated in [RFC1123] without defining
    > the term "well-known"; it is hereby specified that only the RR types
    > defined in [RFC1035] are to be considered "well-known"."
    
    This commit was checked against pdns:
    https://github.com/PowerDNS/pdns/blob/master/pdns/dnsrecords.cc
    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    d63f2e1 View commit details
    Browse the repository at this point in the history
  23. Configuration menu
    Copy the full SHA
    df6820a View commit details
    Browse the repository at this point in the history
  24. dns: prevent memory leak when reading invalid record data

    Before this commmit, if record data was invalid and ..._read() failed,
    we would `goto fail` which would call hsk_dns_rrs_uninit(). However,
    uninit() only frees rr objects if the rrset has a size > 0 and only
    frees that many rr objects.
    
    By calling hsk_dns_rrs_push() BEFORE ..._read() we increment that
    size value and that ensures that if there is a failure, the rr
    will be freed.
    
    The rr is already allocated and pushing its pointer into the rrset
    before we write its data doesn't affect anything else.
    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    f47ba8d View commit details
    Browse the repository at this point in the history
  25. Configuration menu
    Copy the full SHA
    e33e9c3 View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    f2a7445 View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    ca447c8 View commit details
    Browse the repository at this point in the history
  28. dns: read domain names from tld.h as bytes, not strings

    Also updates the hard-coded root zone,
    see handshake-org/hs-names#12
    pinheadmz committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    bf6108b View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    e307bb7 View commit details
    Browse the repository at this point in the history