205 Commits
Author SHA1 Message Date
Cory Benfield 8d6849435f Correctly require no padding bits in bit strings for signatures (#329)
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.
2026-11-20 16:23:44 +00:00
Franz Busch 8789d7e78f Guard Security.framework usage with canImport(Security) (#327)
The certificate validation code only needs the `Security` framework, not
`Darwin`.
2026-11-09 10:17:52 +01:00
Jeff LenamonandRaphael Hiesgen ff86b924ea Treat a /0 ipAddress name constraint as covering the whole address space (#317)
### Motivation

`NameConstraintsPolicy` read an all-zero CIDR mask as matching nothing.
An all-zero mask constrains no bits, so it matches every address: the
CA/Browser Forum Baseline Requirements express "this subordinate CA must
not issue for IP addresses" as `excludedSubtrees` of `0.0.0.0/0` and
`::/0`, and against this code those exclusions constrained nothing, so a
leaf with an IP SAN under such a CA verified.

### Modifications

The leading-zero shortcut in `isValidCIDRMask` is removed and the
general leading-ones-then-zeros check decides. The two
`IPAddressNameTests` rows that pinned the old reading now expect a
match. `testAllZeroMaskIsValidCIDRMask` asserts the IPv4 and IPv6
all-zero masks directly, and two `RFC5280PolicyTests1` tests run
`RFC5280Policy` with `0.0.0.0/0` and `::/0` as permitted and as excluded
subtrees. All of them fail on main.

### Result

A `/0` iPAddress constraint covers the whole address space, as RFC 5280
4.2.1.10 defines it. `swift test` passes under the CI flags (`-Xswiftc
-warnings-as-errors --explicit-target-dependency-import-check error
-Xswiftc -require-explicit-sendable`) on Swift 6.1.2; `swift-format lint
--strict` is clean on the changed files.

---------

Co-authored-by: Raphael Hiesgen <r_hiesgen@apple.com>
2026-09-22 14:03:05 +01:00
9ad45b63b0 Make _TinyArray compatible with library evolution (#313)
### Motivation:

Building `_CertificateInternals` with library evolution enabled fails
because `_TinyArray` and its `@usableFromInline` storage are referenced
from `@inlinable` code while their layout and cases are not fixed.

### Modifications:

- Marked `_TinyArray` as `@frozen`.
- Marked its nested `Storage` enum as `@frozen`.

### Result:

`_CertificateInternals` now builds with library evolution enabled in
both Swift 5 and Swift 6 language modes.

Co-authored-by: Volodymyr Klymenko <ceo@build-succeeded.io>
Co-authored-by: Cory Benfield <lukasa@apple.com>
Co-authored-by: Raphael Hiesgen <r_hiesgen@apple.com>
2026-09-18 13:58:44 +00:00
emaloney c8aece90ea Fix CMSSignerInfo's unsignedAttrs tag (#307)
### Motivation

`CMSSignerInfo` could not round-trip `unsignedAttrs`: it serializes them
as `[1] IMPLICIT SET` but the DER and BER parsers asked for the inner
set with implicit tag `[0]`, so parsing any SignerInfo with unsigned
attributes threw `unexpectedFieldType: [1]`.

### Changes

Fixes issue #306 by:

- Correcting the `unsignedAttrs` inner set identifier from `[0]` to
`[1]` in the DER and BER initializers of `CMSSignerInfo`.
- Adding a round-trip unit test for a `CMSSignerInfo` carrying
`unsignedAttrs`.

### Result

`unsignedAttrs` now round-trip correctly; no behavior change to the
(already correct) serialized output.
2026-08-27 20:07:04 +01:00
Aryan Shah 449dbbecd0 Reject chains where directoryName name constraints are involved (#305)
### Motivation:

[`NameConstraintsPolicy`](https://github.com/apple/swift-certificates/blob/a12bcbc0df9770fe3b0439f38f16b74f37c896c7/Sources/X509/Verifier/RFC5280/NameConstraintsPolicy.swift#L24)
(used as part of
[`RFC5280Policy`](https://github.com/apple/swift-certificates/blob/a12bcbc0df9770fe3b0439f38f16b74f37c896c7/Sources/X509/Verifier/RFC5280/RFC5280Policy.swift#L144))
determines whether a certificate is valid under the `directoryName` name
constraints that are present in its issuing CA's `nameConstraints`
extension. It currently does so by [checking for *exact*
equality](https://github.com/apple/swift-certificates/blob/a12bcbc0df9770fe3b0439f38f16b74f37c896c7/Sources/X509/Verifier/RFC5280/DirectoryNames.swift#L23-L26)
between the constraint (which appears in either the `permittedSubtrees`
or `excludedSubtrees` field) and the certificate's subject DN (or any
`directoryName` value in its SAN).

However, per [RFC 5280
§4.2.1.10](https://www.rfc-editor.org/rfc/rfc5280#section-4.2.1.10) and
[§7.1](https://www.rfc-editor.org/rfc/rfc5280#section-7.1), a
subordinate certificate's DN is within the subtree if it has at least as
many RDNs as the subtree DN and the two DNs *match* when trailing RDNs
in the subordinate's DN are ignored. Additionally, per [RFC 5280
§7.1](https://www.rfc-editor.org/rfc/rfc5280#section-7.1), DN attribute
values must first be normalized through the [LDAP
StringPrep](https://www.rfc-editor.org/rfc/rfc4518) algorithm before
being compared. `NameConstraintsPolicy` only checks exact equality; it
does not check whether the subordinate's DN is *within the subtree* per
[RFC 5280 §7.1](https://www.rfc-editor.org/rfc/rfc5280#section-7.1) nor
applies the StringPrep normalization.

We currently do not correctly validate directoryName name constraints.
Performing the validation correctly involves implementing a complex
algorithm. We should therefore just reject chains where directoryName
name constraints are involved.

### Modifications:

- Removed the `directoryNameMatchesConstraint` method.
- Updated `NameConstraintsPolicy` to simply reject chains involving a
`directoryName` name constraint on both the `permittedSubtrees` and
`excludedSubtrees` path.
- Updated all existing directoryName name constraints tests to now
assert for failure.

### Result:

We now fail-safe on chains involving directoryName name constraints.
2026-07-17 11:30:03 +01:00
eaa10d47d1 documentation updates (#296)
- **Fix stale DocC disambiguation hash for PrivateKey init**
- **Fix documentation errors, typos, and a bug in
CertificateStore.appending**
- **code example fixes within the existing articles:**
- **Lots of smaller fixes across the board - some copy/pasta errors,
consistency in usage, typos and grammar issues - added documentation
comments where missing to get all public types covered - applied
internal style guidelines for representing the types**

---------

Co-authored-by: David Nadoba <dnadoba@gmail.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
Co-authored-by: Raphael <josephnoir@users.noreply.github.com>
2026-06-15 13:04:58 -07:00
Benedek Kozma bde8ca32a0 Remove Foundation import (#297)
#227
2026-04-28 19:49:37 +01:00
LamTrinh.Dev e9312a35a3 Fix typo in SignatureAlgorithm error message. (#295)
## Summary
- Fixed typo in `SignatureAlgorithm.swift:180`: "unsupprted" →
"unsupported"

  ## Details
The error message thrown when an unsupported signature algorithm value
is encountered contained a spelling error. This has been corrected.

  ## Test plan
  - Existing tests continue to pass
- The error message is only shown when an invalid algorithm is used, so
no new tests are needed
2026-04-17 19:59:50 +00:00
Justin OrozandCory Benfield 24ccdeeeed Custom private key (#282)
## Motivation:

In some cases a developer may want to sign a certificate using a method
other than a private key. For example: if a private key is protected by
hardware which signs asynchronously.

## Modifications:

- Create `CustomPrivateKey` protocol
- Create `async` initializers for `Certificate` and
`CertificateSigningRequest`.
- `CustomPrivateKey` can now back a`Certificate.PrivateKey`
- Make `Certificate.Signature` initializer public

## Result:

Developers can now sign a certificate with greater flexibility.

## Alternatives Considered:

### Implementations

#### Pass the `CustomPrivateKey` into `Certificate` and
`CertificateSigningRequest` initializers directly.
There is concern this could add too much duplication of api.

### Various names for the protocol:
- `Certificate.PrivateKeyProtocol` and
`Certificate.AsyncPrivateKeyProtocol`
- `Certificate.Signer`/`Certificate.AsyncSigner`
- `Certificate.SignatureProvider`/`Certificate.AsyncSignatureProvider`

---------

Co-authored-by: Cory Benfield <cbenfield@apple.com>
2026-02-10 14:29:41 +00:00
Sergey Cheperis 7d5f6124c9 Pass additionalIntermediateCertificates through to signWithSigningTime (#289)
When `signingTime` was provided to `CMS.sign`, the
`additionalIntermediateCertificates`
parameter was not being forwarded to `signWithSigningTime`, causing
signature verification
to fail for certificates that require an intermediate CA chain.

Fixes #287
2026-01-05 15:43:18 +00:00
RaphaelandCory Benfield 133a347911 Add validation function for raw signatures (#284)
### Motivation

Signatures can be performed on any kind of data, e.g., to prove
ownership of the private key for a given certificate. This data usually
comes as a blob of bytes.

### Modification

Add a signature verification function that operates on bytes represented
by the `DataProtocol`. The bytes are converted to the signature type
matching the key and share an implementation with the verification
function for `Certificate.Signature`.

### Result

Easy validation of signatures represented as bytes.

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-11-27 18:05:16 +00:00
George Barnett 48d7c83a47 Don't hold a lock over a continuation in Promise (#286)
Motivation:

The various 'withMumbleContinuation' APIs are supposed to be invoked
synchronously with the caller. This assumption allows a lock to be
acquired before the call and released from the body of the
'withMumbleContinuation' after e.g. storing the continuation. However
this isn't the case and the job may be re-enqueued on the executor
meaning that this is pattern is vulnerable to deadlocks.

Modifications:

- Drop and reacquire the lock in Promise
- Avoid resuming continuations while holding the lock

Result:

Lower chance of deadlock
2025-11-25 08:52:23 +00:00
Raphael 23b6a15b5d Expose supported signature algorithms for private keys (#281)
### Motivation:

When loading a private key from disk as a `Certificate.PrivateKey` there
is no straight forward way to query the supported signature algorithms.
For signature algorithm negotiation, the raw values defined in RFC are
useful as well.

### Modifications:

Add a new property to query the supported signature algorithms for a
given key. Add a new property that translates a signature algorithm to
the respective value defined in RFC 8446.

### Results:

Working with certificate private keys and signature algorithms gets
easier.
2025-11-18 14:16:22 +00:00
aryan-25 a8b8f71614 Fix LockStorage warning (#279)
### Motivation:
`LockStorage` has a redundant `@available(*, unavailable)` annotation
for `Sendable` conformance. Since `LockStorage` inherits from
`ManagedBuffer`, which is [already
non-Sendable](https://github.com/swiftlang/swift/blob/d7bb1fe25f4f50a08d9f6ec54768e08c90c17c9d/stdlib/public/core/ManagedBuffer.swift#L72),
this annotation is unnecessary and results in a warning.

### Modifications:
Removed the redundant non-Sendable annotation in `LockStorage`

### Result:
swift-certificates compiles warning-free
2025-10-20 11:11:31 +01:00
aryan-25 f4cd9e78a1 Update RFC5280Policy and OCSPVerifierPolicy initializers (#276)
### Motivation:
New initializers for `ExpiryPolicy`, `RFC5280Policy`, and
`OCSPVerifierPolicy` were introduced in #266. These initializers were
added to prevent users from specifying `Date.now` as the time to
validate certificate expiry against. For context, the problem was that
`Date.now` would be evaluated at initialization, but validation could
occur at a later stage, at which point the validation time would become
stale.

These initializers had a `fixedValidationTime: Date? = nil` argument,
where a non-`nil` value denoted a *fixed* time to validate against, and
a `nil` value denoted that the current time, evaluated at the point of
validation, would be used for validation (the common case). Although the
dangers of specifying `fixedValidationTime = .now` were documented, in
practice, it is very easy for users to miss this and continue using the
API in an incorrect way.

Given that most users will validate certificate expiry against the
current time, we want to default to this and remove the validation time
argument from the public initializers entirely. Users who want to
specify a fixed predetermined time **must explicitly opt-in** by using
`@_spi(FixedExpiryValidationTime)` to access the initializers that have
a *non-optional* `fixedExpiryValidationTime` argument.

### Modifications:
- Deprecated the initializers of `RFC5280Policy` and
`OCSPVerifierPolicy` and introduced two new initializers for each: one
without a validation time argument (common case), and one with a
*non-optional* validation time argument guarded behind an SPI
- Updated the initializers of `ExpiryPolicy` (an internal type)
- Additional changes:
  - Updated test cases to use new initializers
  - Updated examples in documentation to use new initializers

### Result:
`RFC5280Policy` and `OCSPVerifierPolicy` can be used more safely
2025-10-13 11:17:12 +01:00
Raphael 4b092f1516 Introduce a validated certificate chain type (#272)
### Motivation:

The certificate chain returned by validation has properties that are
currently not expressed in the API. Introducing a type that does so
allows other APIs to build on these properties.

### Modifications:

* Add a new `ValidatedCertificateChain` type and use it as a result type
for certificate validation. Since a validated chain always has at least
a leaf and a root, the type gives direct access to them.
* Deprecate the previous validate function and introduce a replacement.
Update use of the now-deprecated API and duplicate tests to include both
APIs.

### Result:

Certificate validation returns a type that conceptually holds meaning.
2025-09-12 12:49:58 +01:00
Cory Benfield 20c451f1ad Require VerifierPolicy not have isolated conformance (#269)
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
2025-08-28 10:32:31 +01:00
Rafael Cepeda c059d9c9d0 Explicit sendable changes (#265)
Performed the necessary changes to enable compiler flag
`-require-explicit-sendable`. Also enabled this flag in macOS CI.
2025-07-31 15:35:39 +01:00
Gus Cairo 70297c3d42 Improve the performance of Certificate's equal and hash implementations (#267)
Right now, `Certificate` uses the default implementations of `hash` and
`==`, which are member-wise.

We can make this more efficient by only comparing the raw bytes for the
TBS certificate, the signature, and the signature's algorithm.
2025-07-18 15:07:07 +01:00
aryan-25 a78498b1c7 Use current time by default during validation in RFC5280Policy and OCSPPolicy (#266)
## Motivation:

The initializers of `RFC5280Policy` and `OCSPPolicy` require a
validation time as an argument. If this argument is set to `Date.now`,
the timestamp would be captured at the point of initialization. As such,
if the validation method is invoked on the policy instance long after
initialization, the timestamp can become stale at that point. This means
that the validation function could incorrectly determine a certificate
(`RFC5280Policy`) or an OCSP response (`OCSPPolicy`) to be valid, when
it has actually expired by the time the validation is performed.

This is not an issue in common use-cases where the policy is initialized
(with `validationTime` set to `.now`) inside a `PolicyBuilder` closure,
because the closure is evaluated at the point of validation. However,
some use-cases may initialize the policy independently; the issue can
potentially arise here.

## Modifications:

This patch deprecates the current initializers of `RFC5280Policy` and
`OCSPPolicy` to guide users toward using a safer initializer which
requires a `fixedValidationTime: Date?` argument:
- Passing `nil` (default) will lead to the current time being obtained
*at the point of validation*. This will prevent the bug described above.
- Passing a specific `Date` instance preserves the ability to validate
against a fixed point in time, i.e. a time in the past or future, but
*not* the current time.

## Result:

Users now have the option to use a safer initializer to construct
`RFC5280Policy` and `OCSPPolicy`.
2025-07-15 16:28:47 +01:00
Andreas Bauer e3c198a6d8 Support singing via Certificate PrivateKey (#257)
This PR introduces two key changes to improve flexibility when working
with signatures in swift-certificates. Previously, it was only possible
to verify signatures using `Certificate.PrivateKey`, but not to generate
them.

- The internal `sign(bytes:signatureAlgorithm:)` method on
`Certificate.PrivateKey` is now public, allowing users to generate
signatures directly.
- `Certificate.Signature` gains a new `rawRepresentation` property that
exposes the raw byte representation of a signature.
2025-07-01 08:18:58 -07:00
Brian Maher ba4aeba31a Custom certificate store (#256)
This change adds support for implementing a `CustomCertificateStore` in
a backwards compatible way with minimal impact to performance. A custom
certificate store can be implemented, and then the new
`CertificateStore(custom:)` constructor can be used so that the custom
certificate store can be used interchangeably with a "normal"
certificate store.

Additionally, a test case verifies that this new protocol will work for
our use case. More specifically, the use case we have is for
normalization of distinguished names so that an exact match of
distinguished names is no longer required. For example, if
`printableString` should be used interchangeably with a `utf8String`.

This pull request has two commits:
- One that adds support for a `CustomCertificateStore`
- One that modifies the implementation to support `async` lookup of
certificiates.

The second change is not required for our use-case, however I would
expect that there may be a future use-case that requires looking up
certificates in a database, and supporting an `async` protocol would be
valuable. Also, the `verify()` method is already async, so supporting an
`async` lookup does not disrupt any existing public APIs.
2025-06-26 11:06:10 +01:00
Evan Wilde 9d7ff7720e Fix pthread use on FreeBSD (#253)
Much like OpenBSD, the FreeBSD pthread APIs are not imported with the
appropriate nullability annotations, so the base pthread mutex type
should be an optional value. Eventually we should provide API notes to
fix this issue, but that is not in place today.
See https://github.com/swiftlang/swift/issues/81407
2025-05-21 12:54:15 +01:00
Rick Newton-Rogers e7db922740 Drop Swift 5.9 (#250)
Motivation:

Swift 5.9 is no longer supported, we should bump the tools version and
remove it from our CI.

Modifications:

* Bump the Swift tools version to Swift 5.10
* Remove Swift 5.9 jobs where appropriate in main.yml, pull_request.yml

Result:

Code reflects our support window.
2025-05-05 12:21:20 +01:00
Gus Cairo 999fd70c78 Add new Certificate.PrivateKey init from PKCS8 DER bytes (#248)
This PR adds a new `init(derBytes:)` to initialise a private key in
PKCS8 format from an array of DER bytes.
2025-04-25 17:15:42 +01:00
Erik Gadireddi bdcbccd1bd Feature: Enhance RDN parsing to support IA5String (#236)
Add capability of converting RDN value of ASN1IA5String to String, if I
am correct all RFC expect that RDN value can be ASN1IA5String..
- additionally fix tests after this change
- added DN components emailAddress(E) and domainComponent(DC)
2025-04-10 14:00:00 +00:00
63d06f4504 Make the usual pthread changes for OpenBSD. (#239)
Co-authored-by: David Nadoba <d_nadoba@apple.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-04-09 10:35:15 +00:00
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
Rick Newton-Rogers 04113b4b6a Use centralized CMake checks (#235)
### Motivation:

We now have centrally-hosted CMake checks in the NIO repository which we
should use to reduce maintenance. The new checks also increase coverage
by performing a build with CMake as part of the checks.

### Modifications:

* Use the new workflow
* Commit formatting changes in the CMakeLists files from the new script
* Document how to update the CMakeLists files
* Remove the obsolete scripts

### Result:

Better CI coverage.
2025-03-17 11:17:06 +00:00
Rick Newton-RogersandCory Benfield 1d394dbc80 Add static SDK CI workflow (#234)
Add static SDK CI workflow which runs on commits to PRs, merges to main
and daily on main.

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-03-14 11:22:52 +00:00
Si Beaumont d608282ae5 Add missing availability annotations to fix iOS, watchOS, and tvOS builds (#233)
### Motivation

Currently this package doesn't build for the non-macOS Apple platforms.
For example, compiling for iOS fails with:

- `error: 'some' return types are only available in iOS 13.0.0 or newer`
- `error: Concurrency is only available in iOS 13.0.0 or newer`

Looks like a few types were missing the availability annotations when
this package switched to using them and dropping the minimum platform
requirement.

### Modifications

- Add missing annotations to restore build.

### Results

- Package now builds on iOS, tvOS, and watchOS.
- `struct NameConstraints`, `struct NameConstraintsValue` are marked
only available on iOS 13+ etc.
- `protocol OCSPRequester` is marked only available on iOS 13+ etc.
2025-03-13 10:23:22 +00: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 BachschmidtandDavid Nadoba dc098a9193 Make RDN.Attribute.Value conversion to ASN1Any public (#215)
When the value is not a printable or UTF8 string, it may be useful to be
able to access the underlying encoded bytes.

Co-authored-by: David Nadoba <d_nadoba@apple.com>
2025-02-19 14:01:07 +00:00
Chris McGee 48abd12804 Add back the _TinyArray.swift to the CMakeLists.txt to fix build errors (#226) 2025-02-18 17:21:05 +00:00
Nicolas BachschmidtandCory Benfield eaed0355dc Add default value for signature algorithm (#221)
Most of the time, the signature algorithm that should be used is
dictated by the type of the private key.

* Ed25519 keys support only one signature algorithm.
* RFC 5753 section 8 recommends that "[the P-256 curve] be used with
SHA-256; the P-384 curve be used with SHA-384; and the P-521 curve be
used with SHA-512".
* RSA keys support 4 signature algorithms. But most people use RSA with
SHA-256 and nobody should use RSA with SHA-1 anymore.

More over, Certificate.PrivateKey is opaque to the user, who may not
know what type of private key they're using and what the appropriate
signature algorithm is.

For those reasons, we add convenience wrappers around methods with a
signature algorithm to provide a reasonable default value.

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-01-27 11:03:56 +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
Nicolas BachschmidtandCory Benfield 88ced31d9d Use proper hash when computing message digest in signed attributes (#219)
Per [RFC 5652 §
11.2](https://datatracker.ietf.org/doc/html/rfc5652#section-11.2):

"For signed-data, the message digest is computed using the signer's
message digest algorithm."

Currently, when computing the signed attributes' message digest,
`CMS.sign` assumes the digest algorithm is SHA256, which is incorrect.
The behavior of `CMS.isValid` is already correct and doesn't need
updating. I've made `Digest` conform to `Sequence` to facilitate the
conversion/comparison of the message digest.

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-01-16 16:41:23 +00:00
Nicholas KimandNicholas Kim 821085981b Tag CMS signer identifier implicitly (#218)
As pointed out in
https://github.com/apple/swift-certificates/issues/203, the
SignerIdentifier in PKCS#7 CMS should be implicitly tagged while the
currently swift-certificates explicitly tags it. This PR contains
changes for SignerIdentifier of SubjectKeyIdentifier type to be
implicitly tagged.

[RFC 5652 §
12.1](https://datatracker.ietf.org/doc/html/rfc5652#section-12.1):
```
SignerIdentifier ::= CHOICE {
  issuerAndSerialNumber IssuerAndSerialNumber,
  subjectKeyIdentifier [0] SubjectKeyIdentifier }
  ```
  
  
  Resolves: https://github.com/apple/swift-certificates/issues/203

---------

Co-authored-by: Nicholas Kim <nicholas.kim@kakaobank.com>
2025-01-14 15:02:28 +00:00
Nicolas Bachschmidt 87d0a2752b Support certificates with invalid RDN attribute values (#214)
Some certificate authorities issue certificates with invalid RDN
attribute values. Certificates must use UTF8String instead of
PrintableString to represent strings that contains `*` or `@`, but
mistakes happen.

When a RDN attribute value is a PrintableString or UTF8String with an
invalid content, rather than rejecting the certificate, fall back to
storing the value as an Any.

## Rationale

Certificate authorities using the wrong string type is a common mistake.
For example, DigiCert issued intermediate certificates with invalid
ampersands to Wells Fargo & Company (golang/go#22970).

This PR adds *partial* support for certificates that contain invalid
PrintableString or UTF8String (less likely) values. When failing to
parse a PrintableString or UTF8String, the raw bytes are stored as an
Any (same as IA5String, BMPString, ...).

Though those certificates are now parsed without any error, they aren't
fully supported yet. Trying to convert the value to a String returns
`nil`, so the CN doesn't match. I don't know whether we should add
support for converting invalid PrintableString values (and
IA5String/BMPString/...) to String in the future. In the meantime,
developers who want to read the CN have access the raw Any value.
2024-12-17 18:25:36 +00:00
Clinton Nkwocha 5fd8063331 Enable strict concurrency (#213)
Motivation:

To catch potential data races at build time.

Modifications:

- Bump Swift tools version from 5.8 to 5.9 in Package.swift.
- Enable strict concurrency in Package.swift.
- Adjust the documentation section on the supported Swift versions.
- Implement minor fixes for the surfaced strict concurrency warnings.
- Add `-require-explicit-sendable` to the 6.0, nightly 6.0 and nightly
main CI checks.

Result:

Strict concurrency adoption.
2024-12-13 18:24:01 +00:00
Jon C. Thomason d4d564670a Add support for attached signatures (#201) (#206)
* Add support for attached signatures (#201)

* Relay detachment through with signing time

* Factor attachment into generateSignedData

* Adjust test coverage

* Test verifying an attached signature

* Test verifying an attached signature and timestamp

* Test failing detached signature as attached

* Test failing detached timed signature as attached

* Test accepting attached signature as detached

* Test accepting attached timed signature as detached
2024-11-22 10:54:27 +00:00
Luke Howard 2be7251a3a Android build fixes (#207) 2024-11-08 11:31:34 +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
Franz Busch c0b6a47ffe [CI] Adopt GitHub actions (#193) 2024-10-21 16:01:05 +01:00
Cory Benfield 1fbb6ef21f Avoid the macOS requirement. (#204) 2024-10-15 13:19:03 -07:00
d8799da503 Support SecKey Certificate private keys (#195)
Motivation:

I would like to create Certificates using a SecKey so that I can create certificates signed by hardware-backed keys. Currently, Swift Certificates requires the private key be provided in an exported representation, but this isn't possible when a SecKey is marked as non-exportable.

Modifications:

Adds a new SecKeyWrapper backing to Certificate.PrivateKey to support initalisation with SecKey. This wrapper struct handles key validation and signing operations by calling the appropriate SecKey interfaces. Adds additional tests to support new backing type.

Result:

Certifcate.PrivateKey can be initialised with a SecKey, allowing existing hardware-backed SecKey instances to be used as the issuer private key for new Certificate instances.

Co-authored-by: Rory Smith <rory.s@apple.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
2024-10-02 16:40:39 +01:00
finagolfin a846fc7149 Add support for Android (#183) 2024-09-12 02:35:46 -07:00