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

Loading, storing, and generating DNSSEC keys #406

Merged
merged 69 commits into from
Nov 5, 2024
Merged

Loading, storing, and generating DNSSEC keys #406

merged 69 commits into from
Nov 5, 2024

Conversation

bal-e
Copy link
Contributor

@bal-e bal-e commented Oct 7, 2024

This PR defines an ergonomic basis for DNSSEC signing.

The following features are supported:

  • Keys can be generated.
  • Keys can be parsed from or serialized to the conventional BIND format.
  • Keys can be used to sign byte sequences.
  • Public keys can be parsed from or serialized to DNSKEY records.

Cryptographic primitives are implemented using Ring or OpenSSL, at the user's choice. Note that OpenSSL supports more algorithms. For simplicity, a combined key type is provided which uses Ring where possible and falls back to OpenSSL for other algorithms.

Signatures can be created using the following algorithms:

  • RSA/SHA-1: support is prohibited as per RFC 8624.
  • RSA/SHA-256 (also with Ring, for 2048-bit or larger keys).
  • RSA/SHA-512: support is not recommended as per RFC 8624.
  • ECDSA P-256/SHA-256 (also with Ring).
  • ECDSA P-384/SHA-384 (also with Ring).
  • Ed25519 (also with Ring).
  • Ed448.

In DNSSEC, keys are associated with important metadata, such as who they belong to and how they can be used (Zone Signing Keys sign resource records, while Key Signing Keys sign Zone Signing Keys). This implementations provides low-level or "raw" types which do not include this metadata, as well as higher-level types which do include it.

  • sign::generic::SecretKey: A generic representation of a secret key. It does not support any cryptographic operations itself.
  • sign::{openssl,ring,common}::SecretKey: A secret key that supports cryptographic operations and that can be used for signing.
  • sign::Signer: A secret key associated with important metadata.
  • validate::RawPublicKey: A generic representation of a public key.
  • validate::Key: A public key associated with important metadata.

The actual signing functionality is provided by the sign::SignRaw trait. This provides a synchronous sign_raw() function, which should be used for on-CPU signing operations. In the future, an asynchronous signing interface will be provided, for use with off-CPU signing operations (e.g. via HSMs).

@bal-e bal-e marked this pull request as draft October 7, 2024 14:57
@bal-e bal-e self-assigned this Oct 7, 2024
@bal-e bal-e added breaking A PR that includes a breaking change. unstable feature labels Oct 7, 2024
@bal-e bal-e force-pushed the dnssec-key branch 2 times, most recently from 005b7e7 to 90af63d Compare October 9, 2024 10:27
@bal-e bal-e marked this pull request as ready for review October 9, 2024 18:31
@bal-e bal-e requested review from partim and ximon18 October 9, 2024 18:31
ximon18 added a commit that referenced this pull request Oct 11, 2024
… query-zone.rs code to silence compile errors for now).
Copy link
Member

@ximon18 ximon18 left a comment

Choose a reason for hiding this comment

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

Some incomplete initial review feedback.

.github/workflows/ci.yml Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
src/sign/generic.rs Outdated Show resolved Hide resolved
src/sign/generic.rs Outdated Show resolved Hide resolved
src/sign/generic.rs Outdated Show resolved Hide resolved
src/sign/mod.rs Outdated Show resolved Hide resolved
src/sign/generic.rs Outdated Show resolved Hide resolved
src/sign/openssl.rs Outdated Show resolved Hide resolved
src/sign/openssl.rs Outdated Show resolved Hide resolved
src/sign/openssl.rs Outdated Show resolved Hide resolved
src/validate.rs Outdated Show resolved Hide resolved
src/validate.rs Outdated Show resolved Hide resolved
@bal-e bal-e force-pushed the dnssec-key branch 2 times, most recently from 569693a to f65c5cc Compare October 16, 2024 13:23
src/validate.rs Outdated Show resolved Hide resolved
arya dradjica added 11 commits October 24, 2024 16:13
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' 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.
There are probably lots of bugs in this implementation, I'll add some
tests soon.
Also fixes 'cargo clippy' issues, particularly with the MSRV.
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.
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.
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.
arya dradjica added 2 commits October 24, 2024 16:13
The 'Dnskey' impl of 'fmt::Display' was no longer accurate to the zone
file format because 'SecAlg' now prints '<code>(<mnemonic>)'.
arya dradjica added 2 commits October 25, 2024 11:59
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.
@bal-e bal-e requested a review from ximon18 October 25, 2024 10:43
src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@ximon18 ximon18 left a comment

Choose a reason for hiding this comment

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

I've looked at the RustDoc and given some feedback in comments on this PR.

I have not yet reviewed the actual code in its current form.

.github/workflows/ci.yml Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
src/sign/bytes.rs Show resolved Hide resolved
src/sign/mod.rs Show resolved Hide resolved
src/sign/bytes.rs Outdated Show resolved Hide resolved
src/sign/bytes.rs Outdated Show resolved Hide resolved
src/sign/ring.rs Show resolved Hide resolved
src/sign/mod.rs Outdated Show resolved Hide resolved
src/sign/mod.rs Outdated Show resolved Hide resolved
@bal-e bal-e requested a review from ximon18 November 5, 2024 10:55
@ximon18
Copy link
Member

ximon18 commented Nov 5, 2024

I've looked at the RustDoc and given some feedback in comments on this PR.

I have not yet reviewed the actual code in its current form.

This code is getting more eyes on it and being exercised at points of use in other work we are doing so with that combined with previous reviews I've done of this PR I'm fine to merge this.

@bal-e
Copy link
Contributor Author

bal-e commented Nov 5, 2024

Awesome, thanks for all the reviews @ximon18!

@bal-e bal-e merged commit 8e8d616 into main Nov 5, 2024
26 checks passed
@bal-e
Copy link
Contributor Author

bal-e commented Nov 5, 2024

I'll leave the branch up for a bit because it could mess with other PRs iirc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking A PR that includes a breaking change. needs-review unstable feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants