-
Notifications
You must be signed in to change notification settings - Fork 88
Custom private key #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Juice805
wants to merge
35
commits into
apple:main
Choose a base branch
from
Juice805:custom-private-key
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Custom private key #282
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
7ada70d
Certificate.Signer
Juice805 fc55fb1
AsyncSigner
Juice805 418294d
use some instead of any
Juice805 32ccb78
public signature init
Juice805 e8c95ad
Add CSR initializers
Juice805 5054744
Signer → SignatureProvider
Juice805 b344fd4
Certificate.SignatureProvider → Certificate.PrivateKeyProtocol
Juice805 2623976
Fix CSR inits
Juice805 f4eea46
formatting
Juice805 d4db0e6
rename file to match protocol name
Juice805 3797b50
adopt Hashable
Juice805 7265cfc
Move protocols to root level
Juice805 5a1fec4
Drop PrivateKey protocol conformance
Juice805 0807f83
Rename file to match
Juice805 3dc6e3b
Merge CustomPrivateKey protocols
Juice805 939f1f9
CustomPrivateKey backs Certificate.PrivateKey
Juice805 0df7335
signSynchronously
Juice805 2f2bb60
require PEMSerializable adoption
Juice805 bdaa274
Update Sources/X509/CustomPrivateKey.swift
Juice805 d5aee23
explicit self
Juice805 327fd88
always import import SwiftASN1 for CustomPrivateKey
Juice805 6269c6d
differentiate async and sync intializers
Juice805 0bb57aa
Update docs to match new arg names
Juice805 b9e729a
Make signAsynchronously default implementation
Juice805 84da6ba
Async method bytes must be sendable
Juice805 ee0f956
an initializer would be a good idea
Juice805 64c9352
CustomPrivateKeyTests
Juice805 ec20d98
verify defaultSignatureAlgorithm is forwarded properly
Juice805 8a254cd
switch to swift-testing for new tests
Juice805 93cc152
Merge branch 'main' into custom-private-key
Lukasa 19eb2fc
add supportedSignatureAlgorithms to `CustomPrivateKey`
Juice805 b1faac8
Add missing `@Test` macros
Juice805 048e7b4
Remove `@inlinable` from protocol definition
Juice805 405c8e5
add `@inlinable` to default signAsynchronously implementation
Juice805 4d583ad
Add note regarding `signAsynchronously`
Juice805 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the SwiftCertificates open source project | ||
| // | ||
| // Copyright (c) 2025 Apple Inc. and the SwiftCertificates project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of SwiftCertificates project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #if canImport(FoundationEssentials) | ||
| import FoundationEssentials | ||
| #else | ||
| import Foundation | ||
| #endif | ||
| import SwiftASN1 | ||
|
|
||
| @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) | ||
| public protocol CustomPrivateKey: Sendable, Hashable, PEMSerializable { | ||
|
|
||
| /// Obtain the ``Certificate/PublicKey-swift.struct`` corresponding to | ||
| /// this private key. | ||
| var publicKey: Certificate.PublicKey { get } | ||
|
|
||
| var defaultSignatureAlgorithm: Certificate.SignatureAlgorithm { get } | ||
|
|
||
| /// Return a list of all supported signature types for this private key. The ordering is not a comment on the | ||
| /// preference or security of the contained algorithms. | ||
| var supportedSignatureAlgorithms: [Certificate.SignatureAlgorithm] { get } | ||
|
|
||
| /// Use the private key to sign the provided bytes with a given signature algorithm. | ||
| /// | ||
| /// - Parameters: | ||
| /// - bytes: The data to create the signature for. | ||
| /// - signatureAlgorithm: The signature algorithm to use. | ||
| /// - Returns: The signature. | ||
| func signSynchronously( | ||
| bytes: some DataProtocol, | ||
| signatureAlgorithm: Certificate.SignatureAlgorithm | ||
| ) throws -> Certificate.Signature | ||
|
|
||
| /// Use the private key to sign the provided bytes asynchronously with a given signature algorithm. | ||
| /// | ||
| /// The default implementation calls ``signSynchronously(bytes:signatureAlgorithm:)`` and returns the result. | ||
| /// Conforming types may override this method to provide a specialized asynchronous implementation. | ||
| /// | ||
| /// - Parameters: | ||
| /// - bytes: The data to create the signature for. | ||
| /// - signatureAlgorithm: The signature algorithm to use. | ||
| /// - Returns: The signature. | ||
Juice805 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| func signAsynchronously( | ||
| bytes: some DataProtocol & Sendable, | ||
| signatureAlgorithm: Certificate.SignatureAlgorithm | ||
| ) async throws -> Certificate.Signature | ||
|
|
||
| } | ||
|
|
||
| @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) | ||
| extension CustomPrivateKey { | ||
|
|
||
| @inlinable | ||
| public func signAsynchronously( | ||
Juice805 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| bytes: some DataProtocol & Sendable, | ||
| signatureAlgorithm: Certificate.SignatureAlgorithm | ||
| ) async throws -> Certificate.Signature { | ||
| try self.signSynchronously(bytes: bytes, signatureAlgorithm: signatureAlgorithm) | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is an async only private key supposed to implement this function? Should it throw or block instead?
Should this be separate protocols for async and sync keys?
some documentation/guidance for conforming types and callers of this function would be good.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my original implementation. I believe the concern was it could lead to too much api duplication.
I will add documentation to guide the developer to throw an error in the case of unsupported synchronous signing.