mirror of
https://github.com/apple/swift-certificates
synced 2026-11-25 04:37:48 +00:00
## 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`.