Motivation
We have a check that requires that the bit strings for Ed25519
signatures don't have any padding bits. That check is good, but the same
check should have been applied to all the signatures, and it wasn't.
There is no particular security risk with this: while it allows moderate
signature malleability (as we accept multiple signatures that have
different bits as equally valid), there is no way we can conceive of to
launch an attack based on this malleability: the signature itself needs
to remain valid. The only note is that the representation differs.
Modifications
Centralise the check and apply it to all the code paths. Make sure the
OCSP code doesn't lose track of whether there was any padding.
Add tests for the OCSP verifier and the signature code directly.
Result
No more signature malleability.
Motivation
While conceptually it is possible for verifier policies to have isolated
conformance, in practice the way PolicyBuilder is implemented makes that
nearly impossible. Given that the utility of an isolated VerifierPolicy
is very limited, let's just disallow it.
Modifications
Require VerifierPolicy to have a SendableMetatype
Result
Easier to build correct compositions over PolicyBuilder
Motivation
While Ed25519 is not available in the WebPKI, there
are a number of contexts where it's an appropriate
signature algorithm for X.509. In those contexts,
we should allow the signature algorithm.
Modifications
Add support for Ed25519 keys and signatures.
Add unit tests
Result
Ed25519 support in the X509 certs
DistinguishedName was incorrectly marked DERImplicitlyTaggable,
but it isn't. DistinguishedName is our name for Name, which is
an untagged choice type. Untagged choice types can never be
implicitly tagged.
Motivation
To make Swift Certificates useful for the Web PKI it's vital
that we can validate that a particular certificate is authoritative
for a specific domain. This requires a new verifier policy.
Modifications
Added ServerIdentityPolicy
Added tests
Result
We can validate the identity of remote servers.
Motivation
RDNAttribute Values are mostly strings, and it's useful to be able
to convert them. This patch adds that support.
Modifications
Add support for converting RDN attribute values into Strings.
Result
Easier to work with distinguished names.
RSA PSS isn't really deployed in the WebPKI, and with the recent
interest in post-quantum crypto it seems unlikely a new RSA padding
mode will be specified. Let's not allude to trying to support it.
The "from parts" Certificate constructor has existed for a while. As noted
in the docstring, it was originally added for testing and validation
purposes. However, it's not very useful for that purpose.
For one thing, many of the constitutuent parts are not actually directly
constructible. For example, one cannot create a Signature type directly.
For another thing, invalid Certificate handling tests probably want to be
able to construct Certificates that are invalid in a number of interesting
ways, and so will want to use the DER representation to do so.
As a result, this intializer is not broadly useful: even this library
doesn't use it for testing. Let's remove it.
* Make constructing Dates cheaper
Translating between Date and Time is expensive when we use
DateComponents, because we jump through ICU unnecessarily. We can
move over to standard UTC date math instead, which makes this
process vastly cheaper.
* CMakelists
* Code review
Currently, certificate verification is severely bottlenecked on
expiry checking. This bottleneck is almost entirely caused by converting
Time objects into Date objects via DateComponents.
We can reduce the cost of this by doing fewer transformations. Instead
of converting all the Time objects to Dates, we can convert a Date to
a GeneralizedTime and then do all comparisons in GeneralizedTime space.
This vastly reduces the cost of cert validation.
We've had a test floating around for a while that was validating that
we parsed signatures properly, but the test never confirmed that
the parsed signature was valid, only that Crypto accepted it.
This patch improves that situation.
* Add support for Certificate Signing Requests
This patch adds support for working with Certificate Signing Requests to
swift-certificates.
CSRs are a common feature of X.509 based PKIs. They're used to encapsulate
a number of details about the certificate being requested, and are
typically handed to CAs in exchange for a certificate. Their purpose is
to prove possession of a private key, and optionally some other useful
pieces of data.
This patch provides a complete representation of the CSR type, as well as
semantic types to cover the attributes that can be applied to a CSR.
Additionally, CSR signature validation is also available.
* Code review
* Fix up equality and hashing
* Count matters too
* Comment explaining XOR
This patch fixes up an issue where a signature produced from raw form
will have a different in-memory representation from the same one
deserialized from the network.
There are some use-cases where interrogating the structure of a CMS
signature is necessary. This patch adds an SPI for looking at a CMS
signature.
As with the rest of our CMS operations, we're not willing to commit to
an API shape yet, so this patch doesn't provide one. Instead, users need
to opt-in to using the unstable API.
In many circumstances it may be useful to extract the underlying public
key from a Certificate.PublicKey. This patch adds support for optionally
unwrapping the key into the various base types.
Our current basic constraints checking policy requires the presence of
the basic constraints extension to be a CA. That's too aggressive in the
face of the ongoing persistence of v1 certs, both in the root store and
in the wider ecosystem of devices. We can safely tolerate v1
certificates in almost all cases.
In general, disabling expiry checking is not a useful thing to do: it
weakens security posture for no reason. In some testing use-cases or
unusual product cases, however, it's valuable to do this. This patch
adds support for ripping out expiry checking.
We had an issue with name constraints where we lost a layer of SEQUENCE
in the parse and serialization. That meant we couldn't parse real name
constraints.
This patch modifies the ECDSA signature representation internally to
avoid eagerly creating the Crypto type. This is necessary because we
can't actually know what key created the signature when we parse it.
As a result we have to defer actually doing that until we actually get a
key type, at which point we can create the underlying key type.
This is a bit less efficient for us overall, but it solves a long-tail
problem in the WebPKI that is more likely to increase in frequency over
time.
* Add support for policing critical extensions
We are required to ensure that we do not validate chains that contain
certificates with extensions marked critical that we do not understand.
Because we allow pluggable policies which can handle arbitrary
extensions, we need a way to ask verifier policy objects what extensions
they can handle.
This patch adds support for policies to express that set, as well as for
the verifier to ensure that certificates that have critical extensions
we cannot understand are not used for chain building. This is integrated
early into chain building to reject unsatisfiable chains, and works
transparently.
This PR also updates the tests to meet this new standard, including
applying the RFC 5280 policy liberally throughout the test suite.
* Don't forget the leaf!
* Rename property
* Remove Sendable
This patch ties together the various checks we have already written into
a single NameConstraintsPolicy, and attaches it to the RFC5280Policy.
This includes defining the logic for traversing names, as well as for
managing the excluded and permitted subtrees.
Unfortunately, this patch is giant. I wish I could do more about it, but
fundamentally the majority of the code it adds is tests, and those tests
are all necessary.
Just to round things out we can add directory name constraints. There's
nominally a fairly complex algorithm for validating directory name
constraints, but most implementations don't bother, instead falling back
to direct matches.
This is the last of the major constraint types we intend to support
initially in name constraints. Mostly URIs leverage the domain name
support, but we do have a need to parse URIs in order to extract their
host component.
This updates Swift Crypto to 2.4.0 and fixes RSA key serialization on
all platforms. It also adds a defensive check that we only accept
appropriately-formatted RSA keys, and some regression tests.
This PR adds support for handling domain name constraints. Specifically,
it adds the infrastructure for doing so, but doesn't wire it up into a
useful policy. This will follow in a later PR.
When we decode a certificate, we produce an in-memory representation.
This representation is something we are capable of encoding. If we
re-encode that directly, we can produce an output that is different to
the one we injested. This happens when there are objects that can be
canonicalised, such as replacing an explicit ASN1 NULL with an absent
field where both are considered equivalent.
This patch rewrites the code to ensure that we preserve the bytes of the
certificate that we deserialized. This allows us to write them back
unchanged, ensuring that certificates can round-trip through this
library without modification.
A side-effect of this change is that we need to essentially encode the
certificate on construction whenever we build them in memory. That's not
a big deal, but it is a bit of an annoyance.
This is the first of a series of PRs that adds support for RFC 5280
policies as a single verifier policy. For now we take the low hanging
fruit, expiry.
This patch adds support for basic CMS operations. We aren't sure that
the API surface here is right, so for now we're going to provide this
under an SPI guard so that we can make any amendments we might need.
Motivation
We omitted RSA signing in the initial implementation. We should support
it.
As part of this, we need to decouple the idea that we know what the
digest algorithm is based solely on the key type. There's no particular
reason not to support ECDSA with SHA256 when using a P521 key, so we
need to tolerate that as well.
Modifications
- Explicitly pass the signature algorithm to our various cryptographic
operations.
- Add a Digest type to handle the various digest types we create.
- Add tests for the various cross products.
Results
RSA signing works, as do weirder flavours of ECDSA.