Files
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
..