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
2025-05-05 12:21:20 +01:00
2025-05-05 12:21:20 +01:00
2024-10-21 16:01:05 +01:00
2023-09-21 14:17:49 +01:00
2023-03-01 10:35:09 +00:00
2022-11-16 15:50:52 +01:00
2023-08-16 11:17:34 +01:00
2025-05-05 12:21:20 +01:00

swift-certificates

A library for working with X.509 certificates.

Overview

X.509 certificates are a commonly-used identity format to cryptographically attest to the identity of an actor in a system. They form part of the X.509 standard created by the ITU-T for defining a public key infrastructure (PKI). X.509-style PKIs are commonly used in cases where it is necessary to delegate the authority to attest to an actor's identity to a small number of trusted parties (called Certificate Authorities).

The most common usage of X.509 certificates today is as part of the WebPKI, where they are used to secure TLS connections to websites. X.509 certificates are also used in a wide range of other TLS-based communications, as well as in code signing infrastructure.

This module makes it possible to serialize, deserialize, create, and interact with X.509 certificates. This is an essential building-block for a wide range of PKI applications. It enables building verifiers, interacting with certificate authorities, authenticating peers, and more. It also ships with a default verifier and a number of built-in verifier policies.

Supported Swift Versions

This library will support the latest stable Swift version and the two versions prior.

Getting Started

To use swift-certificates, add the following dependency to your Package.swift:

dependencies: [
    .package(url: "https://github.com/apple/swift-certificates.git", .upToNextMajor(from: "1.0.0"))
]

You can then add the specific product dependency to your target:

dependencies: [
    .product(name: "X509", package: "swift-certificates"),
]

For detailed usage and API documentation, check the documentation.

Benchmarks

Benchmarks for swift-certificates are in a separate Swift Package in the Benchmarks subfolder of this repository. They use the package-benchmark plugin. Benchmarks depends on the jemalloc memory allocation library, which is used by package-benchmark to capture memory allocation statistics. An installation guide can be found in the Getting Started article of package-benchmark. Afterwards you can run the benchmarks from CLI by going to the Benchmarks subfolder (e.g. cd Benchmarks) and invoking:

swift package benchmark

For more information please refer to swift package benchmark --help or the documentation of package-benchmark.

S
Description
Mirror of github.com/apple/swift-certificates
Readme Apache-2.0
3.1 MiB
0 Stars 1 Watchers 0 Forks
Languages
Swift 99.1%
CMake 0.8%