271 Commits
Author SHA1 Message Date
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.
1.8.0
2025-03-10 14:31:15 +00:00
Rick Newton-Rogers 6f6e9f8ad9 Only apply standard swift settings on valid targets (#231)
Only apply standard swift settings on valid targets. The current check
ignores plugins but that is not comprehensive enough.
2025-03-07 15:04:57 +00:00
Rick Newton-Rogers db0f068fb7 Delete Thresholds/nightly-6.1 symlink (#230)
Following on from https://github.com/apple/swift-certificates/pull/229
delete `Thresholds/nightly-6.1` which is no longer needed now that the
shared benchmarks workflow has been updated
2025-03-07 12:11:09 +00:00
Rick Newton-Rogers 18d5c3acf8 move nightly-next thresholds and add legacy symlink (#229)
Move nightly-next thresholds and add legacy symlink; see
https://github.com/apple/swift-nio/pull/3122
2025-03-03 15:49:38 +00:00
Rick Newton-Rogers a09d77ed59 Rename nightly_6_1 params to nightly_next (#228)
Rename nightly_6_1 params to nightly_next; see
https://github.com/apple/swift-nio/pull/3122
2025-03-03 14:49:31 +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
Rick Newton-Rogers 197ba89b06 CI use 6.1 nightlies (#225)
CI use 6.1 nightlies now that Swift development is happening in the 6.1
branch
2025-01-30 09:44:39 +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
David Nadoba 2c25efadd6 Move nightly-6.0 benchmark thresholds to 6.1 (#224)
6.0 nightly is gone. 6.1 was added somehow. Haven't found a PR for that
though. Not sure how that has changed.
2025-01-25 08:30:52 +00:00
b32a9bae3c fix amd64 support (#223)
Fix when "${CMAKE_SYSTEM_PROCESSOR}" is lowercase "amd64"

---------

Co-authored-by: David Nadoba <d_nadoba@apple.com>
Co-authored-by: David Nadoba <dnadoba@gmail.com>
2025-01-24 10:09:01 -08: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
Marc Prud'hommeaux 274f8668d3 Add Android import for IPAddressNameTests (#217)
Following on https://github.com/apple/swift-certificates/pull/183 and
https://github.com/apple/swift-certificates/pull/207, we need to `import
Android` in `IPAddressTests.swift` to get `inet_pton` and `in6_addr`.

With this addition, tests pass on Android again.
1.7.0
2025-01-08 10:55:15 +00:00
Franz Busch 608cef1b99 Update release.yml (#216)
Update the release.yml file with the latest label changes
2024-12-18 14:15:35 +01: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
Clinton NkwochaandCory Benfield d381c58a91 Fix flaky test CertificateTests.testCertificateDescription (#212)
Motivation:

The test fails when the local machine is not set to 24-hour time.

Modifications:

- Adjust the test to use dynamic time values based on Foundation's
`Date` instead of hard-coded time strings.

Result:

A non-flaky test.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2024-12-11 20:25:49 +00:00
Rick Newton-Rogers 62da4e684d Enable MemberImportVisibility check on all targets (#211)
Enable MemberImportVisibility check on all targets. Use a standard
string header and footer to bracket the new block for ease of updating
in the future with scripts.
2024-12-11 14:50:22 +00:00
Franz Busch 14e5b05d67 Aligning semantic version label check name (#210) 2024-11-28 12:54:14 +01: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
Rick Newton-Rogers 3705c35d9f unify scheduled and main yamls (#208) 2024-11-15 09:47:21 +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) 1.6.1 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>
1.6.0
2024-10-02 16:40:39 +01:00
finagolfin a846fc7149 Add support for Android (#183) 2024-09-12 02:35:46 -07:00
Mark SchallandFranz Busch abe0f0b248 Fixing SHA512 in comment (#196)
Co-authored-by: Franz Busch <f.busch@apple.com>
2024-09-11 05:37:44 -07:00
LamTrinh.Dev b1bef483a3 Replace file with filePath for location at OCSPPolicyVerifierTests.swift (#197) 2024-09-10 02:09:37 -07:00
LamTrinh.Dev ae364f8aeb Correct the link of sswg-security at SECURITY.md (#194)
* Correct the link of sswg-security at SECURITY.md

* Correct the link of sswg-security at SECURITY.md.
2024-09-09 02:52:31 -07:00
Franz Busch a7c8875b9f Add release.yml (#191) 2024-09-06 13:10:11 +01:00
Peter Adams 12aefb6230 Import crypto with preconcurrency flag (#187)
Motivation:

Crypto does not yet support concurrency.

Modifications:

Change Crypto imports where necessary to import
with preconcurrency flag.

Result:

Fewer warnings in swift 6.
2024-08-16 01:36:16 -07:00
Peter Adams eb5de35450 Use filePath for test assert location (#185)
Motivation:

This is consistent with what underlying assert does.
Swift 6 warns about this mismatch

Modifications:

Use filePath for test assert location

Result:

Consistency in test assert location reportin
2024-08-15 12:41:37 -07: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
Cory Benfield 17ef172a2a Up our scaling factor to kilo (#189)
This should help with our thresholds moving around so much.
2024-08-15 14:56:32 +01:00
aryan-25 2f797305c1 Add bridge between Certificate and Security.SecCertificate (#182)
* Add bridge between Certificate and Security.SecCertificate

* Add documentation for explaining the bridge between `Certificate` and `Security.SecCertificate`. Add `make` prefix to `SecCertificate` factory method.
1.5.0
2024-07-02 08:31:19 -07:00
Alex HoppenandDavid Nadoba 6bd8beeeb8 Update swift-syntax link to swiftlang/swift-syntax (#181)
Co-authored-by: David Nadoba <d_nadoba@apple.com>
2024-06-25 07:58:22 -07:00
Micah MooreandCory Benfield 44f2a33ec3 Adds support for including signing time in signedAttrs for CMS signing. (#176)
* Adds support for including signing time in signedAttrs for CMS signing.

Motivation:

Many CMS signing validations require the inclusion of signing time in signedAttrs (for example Apple Wallet's Pass CMS signing validation)

Modifications:

* Adds optional includeSigningTime flag to CMS.sign method (defaults to false)
* When includeSigningTime flag is true: includes signing-time (UTCTime ASN1Type), content-type, and message-digest signedAttrs and signs those instead of content bytes (as specified in RFC 5652 section 5.4)
* Adds contentType ASN1ObjectIdentifier
* Adds CMSSigningError (noTimeZone, invalidSigningDateComponent) for when includeSigningTime is true and unable to get UTC time zone or date components
* Adds tests for valid and invalid CMS signature when including signedAttrs

Result:

Providing the includeSigningTime = true flag to CMS.sign will cause signing-time, content-type, and message-digest signedAttrs to be included in the CMS signature and the signature bytes will represent signing those signedAttrs. Using CMS.sign without the flag (defaulting to false) should leave the previous CMS.sign behavior unchanged.

* Improvements to inclusion of signing time in signedAttrs of CMS signing.

Motivation:

Callers may want to provide their own signingTime (Date). Code improvements for inclusion of singing time in signedAttrs.

Modifications:

* Changes CMS.sign method to take Date? instead of Bool for signingTime so callers can provide their own signingTime Date
* Adds internal method CMS.signWithSigningTime to separate logic for CMS signing with signingTime in signedAttrs
* Uses Date.utcDate transformation to get DateComponents instead of manually constructing them within CMS.signWithSigningTime
* Removes CMSSigningError from CMSOperations as its no longer needed after removal of manual DateComponents construction
* Switches message digest SHA256 from using unsafe bytes to converting Sequence<UInt8> to ArraySlice directly

Result:

CMS.sign callers can now provide signingTime (Date). CMS.sign with signingTime signedAttrs code is improved.

* Adds explicit self to internal signing method calls within CMSOperations.

Motivation:

Conform to standards regaring usage of explicit self for internal methods calls.

Modifications:

* Adds explicit self to signWithSigningTime and serializeSignedData internal methods calls with CMSOperations

Result:

Internal CMSOperations method calls are now compliant to standards.

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2024-06-21 11:38:32 +01:00
Przemysław Lenart be1264c502 Add missing import statement. (#180) 2024-06-20 16:09:06 +01:00
Neil Jones 939a6cc484 add support for riscv64 (#179) 2024-06-17 21:26:37 +01:00
Cory Benfield 4688f24281 Our perf thresholds have changed (#178)
* Our perf thresholds have changed

* Apparently local runs don't match

* Stop using retain/release thresholds

* Remove retain/release counts
1.4.0
2024-06-07 16:27:37 +01:00
hamzahrmalikandCory Benfield d93756ba92 Allow OneOfPolicies and AllOfPolicies to take throwing policy builders, to match Verifier (#173)
* Allow OneOfPolicies and AllOfPolicies to take throwing policy builders, to match Verifier

* add tests

* avoid api break

* soundness

* fix

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2024-05-17 10:04:40 -07:00
Nicolas Bachschmidt 6f2dc4affc Use case-insensitive comparison when validating cert domain name (#175) 2024-05-15 13:58:23 -07:00
hamzahrmalik 83640c8097 Add OneOfPolicies and AllOfPolicies (#172)
Created a new OneOfPolicyBuilder
This is similar to the existing PolicyBuilder
The difference is that the new OneOfPolicyBuilder requires only one of the child policies to be valid, not necessarily all of them

A new struct, OneOfPolicies implements VerifierPolicy and can be constructed using OneOfPolicyBuilder

This can be used within a larger policy e.g.

let x = Verifier(rootCertificates: .init([])) {
    RFC5280Policy(validationTime: .init()) // this must be met
    OneOfPolicies {
        SomethingPolicy() // one of these 2 must be met
        SomethingElsePolicy() // one of these 2 must be met
    }
}
The verifyingCriticalExtensions of OneOfPolicies is intersection of the verifyingCriticalExtensions of each of the child policies, because the overall policy will only be guaranteed to verify an extension if every child policy does so, because we don't know which child policies will actually be evaluated (we stop evaluating when any one passes)

OneOfPolicies will only fail if all of the child policies fail. In this case, the failure reason will be a concatenation of all the child failure reasons, with the word 'and' in between them

This PR also introduces AllOfPolicies
This is to allow users to specify a set of policies which must always be set, as a single item within a OneOfPolicies
1.3.0
2024-05-01 16:48:25 +01:00
Cory Benfield 4975de4e97 Add support for validating server hostnames and IP addresses (#171)
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.
2024-04-22 16:24:19 +01:00
David Nadoba 3b760c831b Make testCertificateDescription independent of system date formatting settings (#170) 2024-04-08 09:10:34 -07:00
Cory Benfield b4f2d54e0d Remove now-breaking test vector test (#167)
This test no longer passes with Swift Crypto main, as it relies on
RSA 1024 which we now forbid
2024-03-25 11:17:34 -07:00