Commit Graph
548 Commits
Author SHA1 Message Date
arya dradjicaandGitHub 7c1667739d [resolver/stub] Allow adding connections dynamically (#440)
This can be used to side-step 'ResolvConf' and the underlying default
'multi_stream' connection type with a custom one, e.g. for testing.
2024-11-14 15:39:58 +01:00
Ximon EighteenandGitHub 6b842a7d10 Derive Arbitrary for some types via a new Cargo feature, to enable fuzz testing in downstream projects that use those types. (#441) 2024-11-14 15:11:56 +01:00
arya dradjicaandGitHub a23a5fd21e Key sizes for DNSSEC keys (#435)
* [validate] Implement 'key_size()'
* [validate] Ensure that RSA public keys don't have leading zeros when parsing DNSKEY records.
2024-11-08 13:10:40 +01:00
8e8d616ee2 Loading, storing, and generating DNSSEC keys (#406)
* [sign] Define 'KeyPair' and impl key export

A private key converted into a 'KeyPair' can be exported in the
conventional DNS format.  This is an important step in implementing
'ldns-keygen' using 'domain'.  It is up to the implementation modules
to provide conversion to and from 'KeyPair'; some impls (e.g. for HSMs)
won't support it at all.

* [sign] Define trait 'Sign'

'Sign' is a more generic version of 'sign::key::SigningKey' that does
not provide public key information.  It does not try to abstract over
all the functionality of a keypair, since that can depend on the
underlying cryptographic implementation.

* [sign] Implement parsing from the DNS format

There are probably lots of bugs in this implementation, I'll add some
tests soon.

* [sign] Provide some error information

Also fixes 'cargo clippy' issues, particularly with the MSRV.

* [sign] Move 'KeyPair' to 'generic::SecretKey'

I'm going to add a corresponding 'PublicKey' type, at which point it
becomes important to differentiate from the generic representations and
actual cryptographic implementations.

* [sign/generic] Add 'PublicKey'

* [sign] Rewrite the 'ring' module to use the 'Sign' trait

Key generation, for now, will only be provided by the OpenSSL backend
(coming soon).  However, generic keys (for RSA/SHA-256 or Ed25519) can
be imported into the Ring backend and used freely.

* Implement DNSSEC signing with OpenSSL

The OpenSSL backend supports import from and export to generic secret
keys, making the formatting and parsing machinery for them usable.  The
next step is to implement generation of keys.

* [sign/openssl] Implement key generation

* [sign/openssl] Test key generation and import/export

* [sign/openssl] Add support for ECDSA

* [sign/openssl] satisfy clippy

* [sign/openssl] Implement the 'Sign' trait

* Install OpenSSL in CI builds

* Ensure 'openssl' dep supports 3.x.x

* [workflows/ci] Use 'vcpkg' instead of vendoring OpenSSL

* Ensure 'openssl' dep exposes necessary interfaces

* [workflows/ci] Record location of 'vcpkg'

* [workflows/ci] Use a YAML def for 'VCPKG_ROOT'

* [workflows/ci] Fix a vcpkg triplet to use

* Upgrade openssl to 0.10.57 for bitflags 2.x

* [workflows/ci] Use dynamic linking for vcpkg openssl

* [workflows/ci] Correctly annotate 'vcpkg'

* [sign/openssl] Implement exporting public keys

* [sign/ring] Implement exporting public keys

* [sign/generic] Test (de)serialization for generic secret keys

There were bugs in the Base64 encoding/decoding that are not worth
trying to debug; there's a perfectly usable Base64 implementation in
the crate already.

* [sign] Thoroughly test import/export in both backends

I had to swap out the RSA key since 'ring' found it to be too small.

* [sign] Remove debugging code and satisfy clippy

* [sign] Account for CR LF in tests

* [sign/openssl] Fix bugs in the signing procedure

- RSA signatures were being made with an unspecified padding scheme.
- ECDSA signatures were being output in ASN.1 DER format, instead of
  the fixed-size format required by DNSSEC (and output by 'ring').
- Tests for signature failures are now added for both backends.

* Refactor the 'sign' module

Most functions have been renamed.  The public key types have been moved
to the 'validate' module (which 'sign' now depends on), and they have
been outfitted with conversions (e.g. to and from DNSKEY records).

Importing a generic key into an OpenSSL or Ring key now requires the
public key to also be available.  In both implementations, the pair are
checked for consistency -- this ensures that both are uncorrupted and
that keys have not been mixed up.  This also allows the Ring backend to
support ECDSA keys (although key generation is still difficult).

The 'PublicKey' and 'PrivateKey' enums now store their array data in
'Box'.  This has two benefits: it is easier to securely manage memory
on the heap (since the compiler will not copy it around the stack); and
the smaller sizes of the types is beneficial (although negligibly) to
performance.

* Move 'sign' and 'validate' to unstable feature gates

* [workflows/ci] Document the vcpkg env vars

* Rename public/secret key interfaces to '*Raw*'

This makes space for higher-level interfaces which track DNSKEY flags
information (and possibly key rollover information).

* [sign/ring] Store the RNG in an 'Arc'

* [validate] Enhance 'Signature' API

* [validate] Add high-level 'Key' type

* [sign/openssl] Pad ECDSA keys when exporting

Tests would spuriously fail when generated keys were only 31 bytes in
size.

* [validate] Implement 'Key::key_tag()'

This is more efficient than allocating a DNSKEY record and computing
the key tag there.

* [validate] Correct bit offsets for flags

* [validate] Implement support for digests

The test keys have been rotated and replaced with KSKs since they have
associated DS records I can verify digests against.  I also expanded
Ring's testing to include ECDSA keys.  The validate module tests SHA-1
keys as well, which aren't supported by 'sign'.

* [validate] Enhance BIND format conversion for 'Key'

Public keys in the BIND format can now have multiple lines (even with
comments).  Keys can also be directly written into the BIND format and
round-trips to and from the BIND format are now tested.

* [sign] Introduce 'SigningKey'

* [sign] Handle errors more responsibly

The 'openssl' and 'ring' modules should now follow the contributing
guidelines regarding module layout and formatting.

* [sign] correct doc link

* [sign/openssl] Replace panics with results

* remove 'sign/key'

* [sign] Introduce 'common' for abstracting backends

This is useful for abstracting over OpenSSL and Ring, so that Ring can
be used whenever possible while OpenSSL is used as a fallback.  This is
useful for clients that just wish to support everything.

* [sign/generic] add top-level doc comment

* [validate] debug bind format errors

* [validate] more debug statements

* [validate] format DNSKEYs using 'ZonefileFmt'

The 'Dnskey' impl of 'fmt::Display' was no longer accurate to the zone
file format because 'SecAlg' now prints '<code>(<mnemonic>)'.

* Reorganize crate features in 'Cargo.toml'

* [sign] Add key generation support for Ring

It's a bit hacky because it relies on specific byte indices within the
generated PKCS8 documents (internally, Ring basically just concatenates
bytes to form the documents, and we use the same indices).  However,
any change to the document format should be caught by the tests here.

* [sign] Make OpenSSL support optional

Now that Ring and OpenSSL support all mandatory algorithms, OpenSSL is
no longer required in order to provide signing functionality.

* [sign] Rename 'generic::SecretKey' to 'KeyBytes'

* [sign] Rename 'SecretKey' to 'KeyPair' in all impls

* [sign] Rename 'KeyBytes' to 'SecretKeyBytes'

For consistency with the upcoming 'PublicKeyBytes'.

* [validate] Rename 'RawPublicKey' to 'PublicKeyBytes'

* [sign/ring] Remove redundant imports

* [sign,validate] Add 'display_as_bind()' to key bytes types

* [sign,validate] remove unused imports

* [sign] Document everything

* [lib] Rewrite feature flag documentation

* [workflows/ci] Use 'apt-get' instead of 'apt'

* [sign] Clarify documentation as per @ximon18

* [sign] Use 'secrecy' to protect private keys

* [sign] Improve documentation and examples

---------

Co-authored-by: arya dradjica <arya@nlnetlabs.nl>
2024-11-05 13:57:55 +01:00
WeilenceandGitHub 196c5f5fe1 Add support for NAPTR record type (#427) 2024-11-04 09:54:21 +01:00
Ximon EighteenandGitHub bf95f3737d FIX: NSEC records should include themselves in the generated bitmap. (#417) 2024-10-31 22:04:49 +01:00
Terts DiepraamandGitHub 9a9624150d Internal message printer exposed as display_dig_style (#420)
* Internal message printer exposed as display_dig_style

* fix clippy lint

* rename MessagePrinter to DigPrinter and use if-let

* document display_dig_style and ZonefileFmt
2024-10-31 12:28:37 +01:00
Philip Homburg 984d16b6d8 Fix ReplyMessage (#429) 2024-10-29 14:10:30 +01:00
Philip Homburg b6d50d9a90 Fix bug where using UnknownRecord data fails when compressed names are present. 2024-10-29 13:35:20 +01:00
ed9824894d Restore 'Display' behaviour for 'SecAlg' etc (#428)
* Restore 'Display' behaviour for 'SecAlg' etc

The doc comment for 'int_enum_str_decimal' explicitly states that the
'FromStr' impl expects a decimal number and that the 'Display' impl
will also output a decimal number.  However, 'Display' was also adding
the mnemonic for the number.

* Print mnemonics for SecAlg etc. in ZonefileFmt comments

---------

Co-authored-by: arya dradjica <arya@nlnetlabs.nl>
2024-10-29 13:26:15 +01:00
Philip Homburg f13016e299 Qname router (#353) 2024-10-28 13:51:57 +01:00
Weilence 471eb72bdf HINFO display CPU and OS using quoted format 2024-10-27 22:49:08 +08:00
Terts DiepraamandGitHub dee14bdb30 Merge pull request #379 from NLnetLabs/ds-print-secalg-as-int
Add `ZonefileFmt` trait for printing records as zonefiles
2024-10-23 12:17:54 +02:00
Terts DiepraamandGitHub 403345d704 Merge pull request #419 from NLnetLabs/message-less-validation
Don't parse rdata in outgoing message as client
2024-10-23 11:40:30 +02:00
Terts Diepraam 9b63eda167 Remove dyn object from SimpleWriter and MultilineWriter 2024-10-23 11:39:36 +02:00
Terts Diepraam bbb002edf6 change manual write call to write! macro 2024-10-22 10:53:03 +02:00
Terts Diepraam dd21d8fa2e Don't parse rdata in outgoing message as client
This makes it possible to send UPDATE messages, which is necessary
for the reimplementation of ldns-update.
2024-10-22 10:42:35 +02:00
arya dradjicaandGitHub 97c0036110 Introduce HashCompressor for name compression (#396)
This PR adds a new name compressor that uses a hash map rather than a
tree.
2024-10-21 15:33:02 +02:00
Terts Diepraam 4f5084f548 fix rustfmt again 2024-10-16 16:22:33 +02:00
Terts Diepraam c30ad83942 fix rustfmt 2024-10-16 16:20:09 +02:00
Terts Diepraam baec4e630d Merge branch 'main' into ds-print-secalg-as-int 2024-10-16 16:16:56 +02:00
Terts Diepraam 5be54190ed rename more show occurrences to fmt 2024-10-16 15:51:21 +02:00
Martin Hoffmann 42f728f598 Fix doctest without std. 2024-10-14 16:20:27 +02:00
Martin HoffmannandGitHub a4007c16be Don’t use feature-gated StoredName alias in server middleware. (#414) 2024-10-14 15:58:03 +02:00
Martin Hoffmann 5e1ddb94d6 Make tsig module compile without std. 2024-10-14 15:44:40 +02:00
Martin Hoffmann 4b1101ab67 Prevent dead code warning for utils::config. 2024-10-14 15:43:10 +02:00
Martin HoffmannandGitHub 6b5de84b9a Fix serde impls to work with nostd. (#413)
This PR fixes issues that block building the "serde" feature without "std".

Specifically:

* Change the Serialize impls of ParsedName and ExtendedError to not build
  strings first.
* Added a Deserialize impl to base::net:nostd::Ipv6Addr and fixed the impl
  for Ipv4Addr.
2024-10-14 15:35:41 +02:00
Ximon EighteenandGitHub 0e16617a37 Fix compilation if only feature net is enabled. (#412) 2024-10-14 12:04:48 +02:00
Ximon EighteenandGitHub 9cc068d7ae Empty NSEC3 salt should be a dash in zone presentation format. (#407) 2024-10-10 10:49:50 +02:00
Ximon Eighteen 0004340da4 Revert "Empty NSEC3 salt should render in presentation format as a dash according to RFC 5155 section 3.3."
This reverts commit 95e8a5a74e0266824af0198a395bc87cb0729501.
2024-10-08 13:55:44 +02:00
Ximon Eighteen b8e6be57f0 Empty NSEC3 salt should render in presentation format as a dash according to RFC 5155 section 3.3. 2024-10-08 13:54:37 +02:00
Ximon EighteenandGitHub 26394b5986 Minor typo correction in RustDoc comment. 2024-10-08 10:28:49 +02:00
Ximon EighteenandGitHub 2266779d76 Correctly reserve space for OPT in EdnsMiddlewareSvc. (#403) 2024-10-07 14:22:25 +02:00
Ximon EighteenandGitHub 6eb4b846d4 Add and improve middleware related RustDocs. (#370) 2024-10-07 14:16:35 +02:00
Ximon EighteenandGitHub d9b689a942 Consistently refer to zonefile r/w as experimental. (#387) 2024-10-07 14:15:07 +02:00
Ximon EighteenandGitHub 146ad36799 Improved handling of errors while sending TCP responses. (#309)
- FIX: Abort a TCP connection if a fatal I/O error is detected when writing to the client, such as the client disconnected.
- FIX: Stop processing a response stream if the connection is shutting down or there is no space left in the response queue.
- Add a test that deliberately disconnects before the last response is received.
- Removed commented out code and fix some comments.
- Remove unnecessary ServiceError error variant.
- Fix a test bug whereby the test message bytes were accidentally offset by 2 meaning that the message header was wrongly perceived as having the QR bit set so requests were rejected as replies, never being handled and thus never having responses sent, which couldn't fail because the connection was closed... hence breaking the test.
2024-10-04 13:50:21 +02:00
Ximon EighteenandGitHub a7e37e795c Various EDNS middleware fixes and improved Stelline test: (#355)
- Reply with FORMERR if an OPT RR cannot be parsed.
- Don't reply with FORMERR if an edns-tcp-keepalive option is received via UDP, instead ignore it per RFC 7828 3.2.1.
- Only reserve space for an edns-tcp-keepalive option for TCP requests, not UDP requests.
- Always reserve space for an OPT RR in the response for any request that has an OPT RR, not just TCP requests.
- Disable TCP client retries in Stelline server tests otherwise a connection abort causes a retry which violates the test expectation.
2024-10-03 16:22:41 +02:00
Ximon EighteenandGitHub f111cc6316 Set the AA flag and include glue in responses. (#400)
This PR adds handling of the AA flag and additional records to zonetree
answer generation.
2024-10-03 15:28:51 +02:00
Ximon EighteenandGitHub 930786ed2e FIX: Servers should drop received DNS response messages, not propagate them for processing. (#381) 2024-10-03 13:34:55 +02:00
Ximon Eighteen 1c7be5d8d0 Minor corrections in code comments. 2024-10-03 13:31:46 +02:00
Ximon EighteenandGitHub 41d72b33e6 Usability tweaks (#397)
This PR adds a few trait impls and documentation.

Specifically:

* Add blanket `SendRequest` and `SendRequestMulti` impls for boxes.
* Add `Display` impl to `tsig::Key`.
* Add an `as_any` method and `Clone` and `Debug` impls to various zonetree
  types.
* Add `AsRef<dyn ZoneStore>` to `Zone`.
2024-10-03 12:33:58 +02:00
3b7ccb7197 Link to definition of DNS (#386)
* Link to definition of DNS
* Also spell out DNS.

---------

Co-authored-by: Martin Hoffmann <martin@nlnetlabs.nl>
2024-10-03 12:19:32 +02:00
Ximon Eighteen 3227bd185c Typo correction in RustDoc comment. 2024-10-03 10:25:15 +02:00
Ximon EighteenandGitHub a35412186b Extend MandatoryMiddlewareSvc with an RFC 9619 check for opcode QUERY with QDCOUNT > 1. (#365) 2024-10-02 21:54:21 +02:00
Ximon EighteenandGitHub 01fccdf942 Add XFR middleware. (#384)
Add XFR middleware and:
- Fixes a bug where the incorrect owner name was passed to the zone walker callback.
- New `ixfr-client.rs` example.
- Updated `serve-zone.rs` example demonstrating TSIG authenticated XFR and NOTIFY middlewares.
- Additional From impls for CallResult.
- Renames ZoneDiff to InMemoryZoneDiff.
- Renames ZoneDiffBuilder to InMemoryZoneDiffBuilder.
- Introduces new ZoneDiff and related traits.
- Adds AnswerContent::first().
2024-10-02 21:28:01 +02:00
Ximon EighteenandGitHub 56aa3e35b0 Fix zone walking to include non-leaf CNAMEs (#352)
Add code to emit the non-leaf CNAMEs to the zone walker callback operation.
2024-10-02 21:04:23 +02:00
Ximon EighteenandGitHub 279fc79f1c Enforce dgram max response size limit. (#398) 2024-10-02 20:57:18 +02:00
Ximon EighteenandGitHub 5b50a22b24 Make TSIG interop tests run as Rust integration tests. (#364) 2024-10-02 18:16:31 +02:00
Terts DiepraamandGitHub 58e6e6e4f3 Add serde::Serialize for AllRecordData. (#343)
This PR adds a `Serialize` impl to `AllRecordData` and as a consequence to
the OPT record and all OPT options, as well as `ParsedName`.
2024-10-02 18:07:26 +02:00
Terts DiepraamandGitHub 837bf9762d Ensure TSIG is the last record (#334)
This PR fixes the tsig module to reject messages with multiple TSIG records.
2024-10-02 17:46:00 +02:00