125 Commits
Author SHA1 Message Date
David Nadoba a798625e5e Parallelise test cases (#49)
Test methods inside a single XCTestCase class do not run in parallel. This PR splits the long running test methods (all over 1 second) into separate classes so XCTest can run them in parallel.

This speeds up test execution from 57 seconds to 15 seconds (~4x speedup).
0.2.0
2023-03-23 10:31:35 +00:00
David Nadoba 1166febcbf Add leeway to the OCSP time verification (#48) 2023-03-22 08:07:30 -07:00
Cory Benfield f6a1b1b418 Add support for policing critical extensions (#47)
* 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
2023-03-22 07:02:58 -07:00
David Nadoba 4a67b473a1 Build OCSP Response certificate chain and verify signature (#43)
OCSP responses are signed and we must validate the signature. This PR adds support for that.
2023-03-21 09:51:10 -07:00
David Nadoba 7fff85a91e Follow casing from Swift API Design Guidelines (#46)
* Follow casing from Swift API Design Guidelines

* revert ASN.1 definitions back to casing of the specification
2023-03-21 16:39:09 +00:00
Cory Benfield 55105af86b Produce functional NameConstraints (#45)
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.
2023-03-20 10:54:29 +00:00
Cory Benfield 83af4ff3ca Add directory name constraints. (#44)
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.
2023-03-16 15:37:20 +00:00
Cory Benfield 7816361861 Add support for name constraints on URIs (#42)
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.
2023-03-16 13:54:00 +00:00
Cory Benfield 383d0c4c7c Improve our handling of trailing periods. (#41)
We incorrectly considered a trailing period to be a match-all clause.
It's not. Make the code a little less clever to compensate.
2023-03-16 09:21:03 +00:00
Cory Benfield 9b2f1c6797 Add support for IP address constraints. (#38)
This patch adds more partial name constraints support, this time for IP
address constraints.
2023-03-14 17:58:17 +00:00
David Nadoba 88a30b349c Fix Certificate.SerialNumber.init() (#40)
`Certificate.SerialNumber.init()` could produce a number where the first byte(s) could be zero(s). We strip them during encoding and will not and can’t reconstruct them after decoding. Therefore a serial number might no longer be equal to itself after a de/serialisation roundtrip. We have observed this behaviour to cause problems in the OCSP test suite with random test failures. This fixes it.
2023-03-14 17:54:06 +00:00
Cory Benfield 740e2e0bd3 Update Swift Crypto and fix RSA keys (#39)
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.
2023-03-14 14:16:50 +00:00
Cory Benfield 54f7367ea5 Add support for handling domain name constraints. (#37)
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.
2023-03-10 11:23:30 +00:00
Cory Benfield d05bd7819f Add BasicConstraints enforcement to RF5280Policy (#36)
This patch adds support for enforcing BasicConstraints in the RFC 5280
policy.
2023-03-08 17:17:29 +00:00
Cory Benfield 54b9711034 Avoid re-serializing certificates (#35)
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.
0.1.0
2023-03-08 13:30:34 +00:00
Cory Benfield 30319b615c Merge pull request #34 from Lukasa/cb-expiry
Add initial RFC5280 policy.
2023-03-07 10:15:02 +00:00
Cory Benfield 6410b6928d New files for Cmake 2023-03-07 10:11:20 +00:00
Cory Benfield f0cafaed95 Test that the right policy does the rejecting 2023-03-07 10:09:10 +00:00
Cory Benfield 111a9f9985 Add initial RFC5280 policy.
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.
2023-03-06 14:55:19 +00:00
Cory Benfield 4ac8b1d517 Merge pull request #23 from apple/cb-generate-cms-sigs
CMS Signing support
2023-03-06 14:01:19 +00:00
Cory Benfield 04d4c4fc01 CMake 2023-03-06 13:45:03 +00:00
Cory Benfield 78c495a58d Apply code review feedback 2023-03-06 13:44:54 +00:00
Cory Benfield 5b7666f8ef Support additional intermediates 2023-03-06 13:44:54 +00:00
Cory Benfield d1cd7fe8c2 Provide the signer 2023-03-06 13:44:54 +00:00
Cory Benfield e61c4ecf0a CMS Signing support
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.
2023-03-06 13:44:54 +00:00
Cory Benfield a7735a35f9 Merge pull request #24 from apple/cb-leafs-as-roots
Handle leaves as trust roots
2023-03-06 13:00:56 +00:00
David Nadoba 0abd90a675 Merge branch 'main' into cb-leafs-as-roots 2023-03-06 13:11:30 +01:00
Boris Bügling 5dad2bc2ea Fix CMake build (#33)
When building against a build tree artifact for Foundation, we need to add the build tree artifacts of dispatch as that is an exposed dependency for Foundation.
2023-03-03 17:20:40 -08:00
Boris BüglingandYim Lee 75c7f1c7c8 Fix CMake for X509 (#32)
Co-authored-by: Yim Lee <yim_lee@apple.com>
2023-03-02 17:38:58 -08:00
Yim Lee 4f9218f7f7 Explicitly import _Concurrency (#31)
Motivation:
Swift CI disables implicit concurrency, so build fails without the import.

Modification:
Add explicit import for `_Concurrency`.
2023-03-02 14:38:08 -08:00
Yim Lee 95ff310423 Setup CMake build (#29) 2023-03-02 14:11:09 -08:00
Yim Lee 73f1ba10d6 Use OSS swift-asn1 (#28) 2023-03-02 13:25:54 -08:00
tomer doron 17a0c13351 Create CONTRIBUTING.md (#27)
* Create CONTRIBUTING.md
2023-03-01 21:41:15 -08:00
tomer doron 73165337ed Create CODE_OF_CONDUCT.md (#26)
* Create CODE_OF_CONDUCT.md
2023-03-01 21:28:52 -08:00
Cory Benfield 2473e5b258 Merge pull request #25 from apple/cb-readme
Add README and collateral
2023-03-01 12:20:42 +00:00
Cory Benfield 229051f3ad Code-review feedback 2023-03-01 11:16:35 +00:00
Cory Benfield 941e966ccf Add README and collateral 2023-03-01 10:35:09 +00:00
Cory Benfield 2afba510e7 Handle leaves as trust roots
In some cases, we will have the leaf certificate in the trust root
store. In this case, we can immediately pass that on to policy
verification.
2023-03-01 10:24:45 +00:00
Cory Benfield c59fbdbf1f Merge pull request #21 from apple/cb-enable-rsa-signing
Enable RSA signing support.
2023-02-13 17:09:40 +00:00
David Nadoba a531509713 Merge branch 'main' into cb-enable-rsa-signing 2023-02-13 16:24:19 +01:00
Cory Benfield cd04b642b2 Merge pull request #22 from apple/dn-ocsp-flaky-tests
Add better diagnostics if an OCSP test fails
2023-02-13 11:20:17 +00:00
Cory Benfield b1fa515ddc Merge branch 'main' into dn-ocsp-flaky-tests 2023-02-13 11:18:38 +00:00
David Nadoba 49ca2455c8 Add better diagnostics if an OCSP test fails 2023-02-13 12:04:25 +01:00
David Nadoba 56f28e4932 Add better error message 2023-02-13 11:58:16 +01:00
Cory Benfield dc9a93f359 Merge branch 'main' into cb-enable-rsa-signing 2023-02-13 08:28:19 +00:00
Cory Benfield 8458a4ff72 Enable RSA signing support.
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.
2023-02-10 16:55:39 +00:00
Cory Benfield dee25004e8 Merge pull request #19 from apple/dn-set-of
Properly support SET OF fields.
2023-02-10 14:12:45 +00:00
David Nadoba 0abe1f8330 Remove unused errors 2023-02-10 12:09:53 +01:00
David Nadoba d56fa0890a use released version 2023-02-10 11:58:53 +01:00
Cory Benfield fdd742b243 Merge branch 'main' into dn-set-of 2023-02-09 09:58:41 +00:00