256 Commits
Author SHA1 Message Date
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
David Nadoba 5194b38d36 Fix Sendable warnings from latest main compiler (#166)
* Fix `Sendable` warnings on main

* remove `@preconcurrency` from `import _CryptoExtras`

* move documentation to extensions
2024-03-21 18:14:07 +00:00
David Nadoba d71e4c4261 CountryName should be a PrintableString RDNA (#165) 2024-03-21 16:38:30 +01:00
George Barnett 074848243e Raise minimum Swift version to 5.8 (#164) 2024-03-11 08:52:35 +00:00
Saleem AbdulrasoolandYim Lee f53dbc4512 build: add support to vendor dependencies (#158)
* build: add support to vendor dependencies

When building swift-crypto outside of the toolchain (e.g. to build LSP),
it is convenient to support vendoring dependencies.  Add support for
falling back to local builds of the dependencies when not provided as an
existing build.

* Apply suggestions from code review

Co-authored-by: Yim Lee <yim_lee@apple.com>

---------

Co-authored-by: Yim Lee <yim_lee@apple.com>
2024-01-31 15:08:37 -08:00
Si Beaumont 000be99464 Add missing availability guards in tests (#159) 2023-12-15 08:25:02 -08:00
David NadobaandCory Benfield bc566f8884 Simplify the internal representation of RDN.Attribute.Value (#156)
* Simplify the internal representation of RDNAttribute.Value

Motivation

The 1.1.0 release included a patch (#154) that supported converting
RDNAttribute values into strings. This patch missed that the `.any`
case may also have strings in it.

While investigating this limitation, I realised that the constructor
function was excessively complex. While it attempted to coerce based
on extra information in the ASN.1 specification, it always fell back
into the `.any` case. This meant that as a practical matter we always
took the same few paths, and so could safely simplify the code.

Modifications

Simplify DER decoding of RDNAttribute.Values.
Introspect the .any cases for UTF8 strings and Printable strings
when converting to String.

Result

Faster construction, more flexible representation.

* normalise `RDN.Value.Storage` representation

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
1.2.0
2023-12-05 16:15:19 -08:00
David Nadoba 66143b83e0 Move ExpressibleByArrayLiteral conformance of _TinyArray to the declaring module (#157)
Motivation

Nightly compilers start complaining about retroactive conformances.

Modifications

- move conformance to declaring module
- optimise code to not allocate

Result

no warning, optimal generated code for:

```swift
func foo1(int: Int) -> _TinyArray<Int> {
    [int]
}
```

compiles down to:
```
output.foo1(int: Swift.Int) -> output._TinyArray<Swift.Int>:
        mov     rax, rdi
        xor     edx, edx
        ret
```

https://godbolt.org/z/a91fPe6or
2023-12-05 18:19:37 +00:00
Saleem AbdulrasoolandCory Benfield 12e07730f9 build: support building in Debug mode on Windows (#153)
With this tweak, we should be able to build the package in debug mode
even on Windows. We always use the release mode DLL form of the C/C++
runtime on Windows and can build the Swift code in Debug or Release mode
optimizations.

Co-authored-by: Cory Benfield <lukasa@apple.com>
1.1.0
2023-12-01 05:13:59 -08:00
Cory Benfield 4ff26ad6cc Support converting RDNAttribute values into Strings (#154)
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.
2023-12-01 05:03:37 -08:00
Saleem Abdulrasool 0369bc0313 build: simplify build rules (NFC) (#152)
Swift currently requires 3.19.x to build.  Bump the CMake minimum
version to 3.19 to allow us to remove some workarounds from earlier
releases.
2023-11-28 14:51:42 +00: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
David Nadoba 3c33085404 Support loading trust root CAs on Linux (#136)
* Support loading trust roots on Linux

* Fix linux

* run `swift-format`

* Apply review feedback

* Implement `_TinyArray2`

* fix tests

* Update benchmarks for _TinyArray2

* run swift-format

* use two properties instead of TinyArray2

* remove usage of `_TinyArray2` and rename `insert` to `append`

* remove TinyArray2 and rename TinyArray1 back to just TinyArray

* run swift-format

* fix tests

* Fix review comments
2023-10-18 14:01:10 +01:00
David Nadoba 3956075d19 Align swift-format configuration with other projects (#150)
* Align `swift-format` configuration with other projects

No code change. We already followed these rules.

* UseSynthesizedInitializer still needs to be set to false

The fix for https://github.com/apple/swift-format/issues/591 is not in `509.0.0` but only in `main`: https://github.com/apple/swift-format/commit/b896e0f8c74dd6e0d9780cd4a086714637be6acc
2023-10-16 15:37:22 +01:00
Yim Lee b6de7e7235 Remove note from README about API instability (#149)
I think we can remove that note now that the library has 1.0.0 tag.
2023-10-13 08:58:41 +01:00
Rick Newton-Rogers efc568c52c Add CI pipeline for Swift 5.10 (#145)
Motivation:

Now that Swift 5.9 is GM we should update the CI pipelines

Modifications:

* Add a 5.10 nightly docker compose file
* Update the 5.9 compose file to stop using nightlies
* Update benchmark thresholds

Result:

Remove add CI support for 5.10
2023-10-04 17:42:02 +01:00