216 Commits
Author SHA1 Message Date
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
Franz Busch 01d7664523 Rename TinyArray.append benchmark (#142) 1.0.1 2023-09-25 10:11:14 -07:00
David Nadoba eddfe84a03 Remove Xcode specific benchmark documentation (#141)
It is now included in the official docs: https://github.com/ordo-one/package-benchmark/commit/070dee37abe72c0a3d7e0feff5dca3effd66b541
1.0.0
2023-09-25 02:22:19 -07:00
David Nadoba aa83add828 Update to swift-asn1 1.0.0 (#140)
and use `.git` suffix consistently for dependencies
2023-09-25 02:12:38 -07:00
David Nadoba 1cd75260e0 Update swift-format to 509.0.0 (#139) 2023-09-25 01:19:25 -07:00
David Nadoba fa95d35a65 Parse all WebPKI trust roots in Benchmarks (#138)
* Parse all WebPKI trust roots in Benchmarks

* swift-format
2023-09-25 08:09:22 +01:00
David Nadoba 2876baab8a Update allowed swift-crypto version range to 2.5.0..<4.0.0 (#137) 2023-09-22 16:00:34 +02:00
David Nadoba 7815247199 Adopt package-benchmark (#125)
* Add `package-benchmark`

* use local dependencies

* split into multiple targets

* fix benchmark plugin

* refactor file structure

* self review

* Fix review comment

* Apply review feedback

* use `scaledIterations`

* don’t require the parent folder to be named `swift-certificates`

* install jemalloc

* use new `metricP90AbsoluteThresholds` export format

* update metrics

* use automated threshold import

* merge main and update allocation counters

* adopt `swift-format` for benchmarks

* add license headers

* use latest threshold file format

* delete old integration tests

* use released version

* revork folder structure

and add BlackHole module

* crash in debug configuration

* swift-format

* update baselines

* Move to single target

* update swift-format script

* enable arc for `Verifier`

* update to `package-benchmark` `1.11.0`

* update to `package-benchmark` `1.11.1`

* update benchmark metrics

* update metrics captured

* include release count

* move `.benchmarkBaselines` to nested `.gitignore`

* swift-format

* Fix `.gitignore`

* Add documentation

* change wording

* remove version number

* remove benchmarks folder

* add uppercase Benchmarks folder

* fix formatting script

* update readme with new uppercase folder name

* update Benchmarks folder name in docker compose

* drop allocation limits
2023-09-21 14:17:49 +01:00
David Nadoba 50ec4771c2 Add the diagnosticCallback to CMS.isValidSignature (#135)
* Allow setting `diagnosticCallback ` for `CMS.isValidSignature`

* swift-format
2023-09-18 15:44:29 +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 ef10b819c7 Add Certificate.PrivateKey description (#132)
* Add `Certificate.PrivateKey` description

and update `Certificate.PublicKey` description to disambiguate from private keys.

* secure enclave is only a thing on darwin

* update tests
1.0.0-beta.1
2023-08-25 08:32:40 +01:00
David Nadoba 708eb05b1f Use beta release of swift-asn1 (#131)
* Use beta release of `swift-asn1`

* update swift-asn1 in integeration tests as well

* allocation have improved 🥳
2023-08-24 17:27:47 +01:00
Stefana-Ioana DrancaandDavid Nadoba 44a0c84fce Make PublicKey DERImplicitlyTaggable (#129)
Motivation:

PublicKey doesn't conform to DERImplicitlyTaggable which was an oversight during development.

Modifications:

Add conformance to DERImplicitlyTaggable, PEMSerializable, and PEMParsable.

Result:

PublicKey is DERImplicitlyTaggable.

Co-authored-by: David Nadoba <d_nadoba@apple.com>
2023-08-24 15:09:43 +01:00
David NadobaandCory Benfield 0a44251615 Fix preference of root certificates (#127)
Motivation

We prefer issuers that have a subject key identifier that matches the authority key identifier of the certificate for which were are searching for an issuer. However, currently we have flipped this sort order.

Modifications

Flip preference order
update test
add test which would previously fail

Result

We actually prefer certificates in the order described above.
Note that this is just a performance improvement.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2023-08-24 06:32:50 -07:00
David Nadoba 26832755b5 Refactor ASN1UTF8StringView to ASN1TaggedStringView and use it for printable strings (#128)
* Refactor `ASN1UTF8StringView` to `ASN1TaggedStringView` and use it for `printable` strings

* run swift-format

* fix comments
2023-08-24 14:13:58 +01:00
David Nadoba 92ffb4827b Add PolicyFailureReason to support lazy failure reason string interpolation (#126)
* Add `PolicyFailureReason` to support lazy failure reason string interpolation

* fix allocation test compilation

* update allocation counters
2023-08-21 20:01:19 +01:00
David Nadoba b69a931b43 remove deprecated API (#123) 2023-08-21 06:32:51 -07:00
David Nadoba 088a22943d Use valid ASN1ObjectIdentifier in tests (#124)
### Motivation
We have used `ASN1ObjectIdentifier` with just one component in tests but they need at least two components. `swift-asn1` has recently changed the initialiser to enforce this during initialisation time if initialised from a literal. Therefore our tests currently crash.

### Modifications
This PR changes all of our test `ASN1ObjectIdentifier`s to have at least two components.

### Results
Tests no longer crash
2023-08-18 02:23:30 -07:00
David Nadoba 1442890101 Allow RelativeDistinguishedNameConvertible to fail gracefully (#122) 2023-08-16 13:01:49 +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 NadobaandCory Benfield 98e0f85457 Do not count self-issued certificates against maxPathLength (#119)
Only non-self-issued certificates count against the maxPathLength limit.

RFC Section 4.2.1.9.  Basic Constraints:

> [...]
> The pathLenConstraint field is meaningful only if the cA boolean is
> asserted and the key usage extension, if present, asserts the
> keyCertSign bit (Section 4.2.1.3).  In this case, it gives the
> maximum number of non-self-issued intermediate certificates that may
> follow this certificate in a valid certification path.  (Note: The
> last certificate in the certification path is not an intermediate
> certificate, and is not included in this limit.  Usually, the last
> certificate is an end entity certificate, but it can be a CA
> certificate.)  A pathLenConstraint of zero indicates that no non-
> self-issued intermediate CA certificates may follow in a valid
> certification path.  Where it appears, the pathLenConstraint field
> MUST be greater than or equal to zero.  Where pathLenConstraint does
> not appear, no limit is imposed.
> [...]
> https://www.rfc-editor.org/rfc/rfc5280#section-4.2.1.9

Co-authored-by: Cory Benfield <lukasa@apple.com>
2023-08-10 03:58:44 -07:00
David Nadoba 21a8721886 Reject v1 Certificates with extensions (#118)
v1 certificates do not support extensions and any v1 certificate we encounter with extensions can’t be used to verify a chain.
2023-08-10 11:43:21 +01:00
David Nadoba 3c30a4a095 Use Certificate.description instead of dump for debugging flaky tests (#117) 2023-08-09 11:19:27 +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 583414dad1 Make debugDescription work well as part of a structural display (#115)
### Motivation

`debugDescription` name and documentation is confusing and should be changed but it is today expected to be suitable to be used as part of a structured display e.g. to be printed as part of `struct` or `enum` with associated values. Therefore it should have no unpaired parentheses, no unescaped quotes and no top-level commas.

### Modifications
- let `debugDescription` simply contain the same contents as `description` but suitable for structural display as described above.
- add a new `multilineDescription` which contains the same contents as the `description` but breaded down on multiple lines for better readability.
2023-08-07 11:48:43 +01:00
David Nadoba 8debe3f20d Add optional diagnostic information to Verifier (#113)
* work in progress

* remove generic

* save progress

* Add description

* Apply review feedback

* run `./scripts/update_cmakelists.sh`

* Conform to `CustomDebugStringConvertible` instead of `CustomStringConvertible`

* implement `CustomStringConvertible` for `VerificationDiagnostic`

* Apply review feedback

* Add more diagnostics

* Update tests

* Remove prototype code

* add `IssuerIsAlreadyInTheChain` diagnostics
2023-07-27 09:46:07 +01:00
David Nadoba 5f82c70d24 Make hashing a RDN.Attribute.Value.utf8String not allocate (#112)
* Make hashing a `RDN.Attribute.Value.utf8String` not allocate

* Precompute as much as possible

and fix bounds checking

* Update allocation counter
2023-07-20 09:59:29 +01:00
David Nadoba c13badf75a Add verifier allocation tests (#111)
* Add verifier allocation test

* update allocations
2023-07-17 17:04:40 +01:00
David Nadoba 1db96874fa Remove unused import (#110) 2023-07-10 05:13:21 -07:00
David Nadoba af42ab0d26 Remove unused test key (#109) 2023-07-10 13:04:36 +01:00
David NadobaandFranz Busch fb7b79f346 Allow OCSPRequester to fail OCSPVerifierPolicy (#108)
* Support hard failures from OCSPRequester

* rename error result methods to nonTerminalError and terminalError from softFailure and harFailure

* rename query result in tests as well

* Update Sources/X509/OCSP/OCSPPolicy.swift

Co-authored-by: Franz Busch <privat@franz-busch.de>

* Add warning

---------

Co-authored-by: Franz Busch <privat@franz-busch.de>
2023-07-06 14:50:21 +01:00
David Nadoba 1849f5274a Store String in RelativeDistinguishedName.Attribute instead of ASN1Any if possible (#104)
* Store `String` in `RelativeDistinguishedName.Attribute` instead of `ASN1Any` if possible

* Add Equatable and Hashable test

* fix typo

* remove trys

* Apply review feedback

* update allocation numbers
2023-07-06 14:10:54 +01:00
David Nadoba 290123d2e9 Do not allocate for RelativeDistinguishedNames with just a single attribute (#101)
* Setup allocation test framework

* Add allocation test that decodes all WebPKI Roots

* Replace _WebPKI with inline PEM strings

* Fix test

* implement `TinyArray`

* save progress with local ASN.1 dependency

465 allocs

* Implement lazySet in swift-certificates

* test on all WebPKI roots

* Revert "test on all WebPKI roots"

This reverts commit 4af11bb087.

* remove PerformanceTests

* Add tests for TinyArray

* revert changes

* delete unused test

* Implement TinyArray

* update cmake

* “Hide” enum and support storing arrays of exactly one element in `.arbitrary`

* Add allocation tests for TinyArray

* make arrays of different sizes

* Remove array optimisation

* run append in a loop

* Move _TinyArray into a separate module

and apply review feedback

* update cmake files

* remove unused Foundation import

* Allocations are lower by “1” on Linux

* import new module

* Add loop

* update allocation numbers for Linux

* replace with do/catch with try!

* Fix copyright

* update allocations

* Move lazySet to swift-asn1

* update allocation counters

* Fix `update-alloc-limits-to-last-completed-ci-build`

* Use concrete type
2023-07-05 11:47:57 +01:00
David Nadoba 405b3dd5ae Update to swift-asn1 0.10.0 (#107) 2023-07-04 03:28:15 -07: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
David Nadoba e8f5dadf79 Conform AuthorityInformationAccess to RangeReplaceableCollection (#105) 2023-06-29 06:22:43 -07:00
Max Desiatov 1beb546810 Add support for Musl libc (#103)
Since Musl is sufficiently different from Glibc (see https://wiki.musl-libc.org/functional-differences-from-glibc.html), it requires a different import, which now should be applied to files that have `import Glibc` in them.
2023-06-23 11:29:15 +01:00
David Nadoba 364b26d86d Add allocation test that parses all WebPKI roots (#97)
* Setup allocation test framework

* Add allocation test that decodes all WebPKI Roots

* Replace _WebPKI with inline PEM strings

* Fix test

* revert changes

* delete unused test

* Add loop

* update allocation numbers for Linux

* replace with do/catch with try!
2023-06-21 15:43:02 +01:00
Franz Busch 69def44d75 Use #if canImport(Darwin) where possible (#102) 2023-06-21 14:24:35 +02:00
David Nadoba 41dff30819 Implement TinyArray (#98)
* Implement TinyArray

* update cmake

* “Hide” enum and support storing arrays of exactly one element in `.arbitrary`

* Add allocation tests for TinyArray

* make arrays of different sizes

* Remove array optimisation

* run append in a loop

* Move _TinyArray into a separate module

and apply review feedback

* update cmake files

* remove unused Foundation import

* Allocations are lower by “1” on Linux
2023-06-20 01:51:53 -07:00
Tyler Thompson 3bf87fd9ee Added subjectPublicKeyInfoBytes to public keys (#100) 2023-06-20 10:40:29 +02:00