26 Commits
Author SHA1 Message Date
Gus Cairo 9ad2ac038e Add visionOS support (#244) 2025-04-08 13:35:11 +00:00
Gus Cairo 4c305e3205 Add macCatalyst to available platforms (#242) 2025-04-08 13:25:54 +01:00
Gus Cairo bd5987524c Replace platforms from Package manifest with availability guards (#232)
Minimum deployment versions in package manifests can be problematic for
libraries, because changing them or adding them to an existing package
that doesn't already use them forces SemVer breaking majors.

Furthermore, depending on a new library that specifies minimum
deployment targets would force the adopting library to also have to add
these platforms to its manifest (which would in turn force a major).

This PR removes the platforms stanza from the package manifest and
replaces it with availability guards where necessary.
`swift-certificates` needed the platforms stanza because `swift-crypto`
forced it onto its adopters. After
https://github.com/apple/swift-crypto/pull/331, this isn't needed
anymore.
2025-03-10 14:31:15 +00:00
Gus Cairo a65f903b02 Import FoundationEssentials instead of Foundation when available (#227)
`FoundationEssentials` is more lightweight than `Foundation`, and so we
should switch to importing it when possible.
2025-02-24 14:17:11 +00:00
Nicolas Bachschmidt 41066b1c60 Fix a small error in AlgorithmIdentifier description and add missing cases (#222)
This PR adds missing cases and fixes a small typo.

I haven't added tests, as `AlgorithmIdentifier` is internal API.
2025-01-20 10:01:21 +00:00
Cory Benfield 27c6b0fcfa Add support for Ed25519 certificates (#205)
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
2024-10-30 13:30:13 +00:00
Cory Benfield 387fb97cf6 Stop implicitly tagging DistinguishedName (#188)
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.
2024-08-15 20:11:51 +01:00
David Zech 5afc92197a Add Expanded CMS Support (#151)
* Support BER Encoded CMS
* Support Attached CMS
* Support Signed Attributes CMS
2023-10-25 16:19:41 +01:00
Alexander Cyon 216a8a1166 Fix typos in Sources and Tests (#133)
* Fix typos in Sources and Tests

* Address PR review comments

* Second attempt to rectify tab instead of spaces.
2023-09-04 10:34:25 +01:00
David Nadoba 45ad9935c7 Adopt apple/swift-format (#121)
* Adopt `apple/swift-format`

* install swift-format

* set `UseSynthesizedInitializer` to `false` until bug is fixed https://github.com/apple/swift-format/issues/591

* fix license header

* Fix license header
2023-08-16 11:17:34 +01:00
David Nadoba 619756c18f Add custom String representation to Certificate and related types (#116)
* `Custom[String|DebugString]Convertible` conformance

* save progress

* Apply new learned rules

debugDescription should be usable in structural display

* remove unused init

* remove unused properties

* Some fixups before review

* change description a bit around and respect RFC 2253

* add addition test

* fix license header and tests

* update allocation counters
2023-08-09 08:30:09 +01:00
David Nadoba edf406c600 Add integer initialisers on Certificate.SerialNumber (#106)
* Add integer initialisers on `Certificate.SerialNumber`

`Certificate.SerialNumber` can now be constructed from any `FixedWidthInteger` and also from `StaticBigInt`

* `StaticBigInt` is only available in Swift 5.8

* Do not realloc storage if we trim leading zeros
2023-06-30 12:15:07 +01:00
Cory Benfield e37cd21724 We aren't supporting PSS for now. (#93)
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.
2023-06-12 06:44:06 -07:00
David Nadoba 31c9ff1698 Police uniqueness of Certificate.Extensions (#84)
* Police uniqueness of `Certificate.Extensions`

* use array storage

* Use linear scan to find duplicates

* Improve linear scan and remove `update(_:insertAt:)`

* fix tests

* remove `for` argument label and add test
2023-06-01 12:57:22 +01:00
Cory Benfield 6874b181f2 Make constructing Dates cheaper (#86)
* 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
2023-05-25 14:14:56 +01:00
Cory Benfield 3ad34c910e Make expiry checking cheaper. (#85)
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.
2023-05-18 12:50:30 +01:00
Cory Benfield 18b6614b15 Fix signature comparison (#77)
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.
2023-04-27 10:31:20 +01:00
David Nadoba ac767dc442 Support PEM serialisation and parsing of Certificate, Certificate.PublicKey and Certificate.PrivateKey (#71)
* Support PEM serialisation and parsing for `Certificate`, `Certificate.PublicKey` and `Certificate.PrivateKey`

* Fix Linux build

* Fix tests on Linux

and required watchOS version

* run ./scripts/update_cmakelists.sh

* add proper support for private RSA keys

* Fix review comments

* replace `as Any` with `String(describing:)`
2023-04-24 13:20:19 +01:00
Cory Benfield 46b2236f9c Tweak the ECDSA signature representation (#50)
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.
2023-03-30 14:07:12 +01: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 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 b408daf0f8 Update to swift-asn1 new error type 2023-02-06 11:02:45 +00:00
David Nadoba 4feb081b42 Fix soundness
File extension of the CONTRIBUTORS file is `.txt` not `.md`.
Add missing license header to some files.
2022-11-30 11:28:42 +01:00
David Nadoba 763ea6435a Add docker compose files and scripts for CI
and use correct license header name
2022-11-28 11:38:15 +01:00
Cory Benfield f303709f60 Update to new ASN.1 API 2022-11-18 16:24:04 +00:00
Cory Benfield 42be2505cc Initial commit 2022-11-16 15:50:52 +01:00