Skip to content

Commit 5c05fab

Browse files
authored
Proper fix for 'SecureEnclave' issue in cmake build (#68)
Motivation: #67 introduced a temporary workaround to unblock cmake build on macOS, but we have a proper fix now (apple/swift-crypto#177). Modifications: - Revert #67 - Take new version of `swift-crypto` containing apple/swift-crypto#177
1 parent 6ec9235 commit 5c05fab

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ if(BUILD_SHARED_LIBS)
3737
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
3838
endif()
3939

40-
## Uncomment line below to include code that provides Secure Enclave support
41-
##add_compile_definitions(INCLUDE_SECURE_ENCLAVE_SUPPORT)
42-
4340
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
4441
find_package(dispatch CONFIG)
4542
find_package(Foundation CONFIG)

Package.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
import PackageDescription
1717
import class Foundation.ProcessInfo
1818

19-
var swiftSettings: [SwiftSetting] = []
20-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
21-
swiftSettings.append(.define("INCLUDE_SECURE_ENCLAVE_SUPPORT"))
22-
#endif
23-
2419
let package = Package(
2520
name: "swift-certificates",
2621
platforms: [
@@ -44,8 +39,7 @@ let package = Package(
4439
],
4540
exclude: [
4641
"CMakeLists.txt",
47-
],
48-
swiftSettings: swiftSettings),
42+
]),
4943
.testTarget(
5044
name: "X509Tests",
5145
dependencies: [
@@ -67,7 +61,7 @@ let package = Package(
6761
// we can depend on local versions of our dependencies instead of fetching them remotely.
6862
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
6963
package.dependencies += [
70-
.package(url: "https://github.com/apple/swift-crypto.git", from: "2.4.0"),
64+
.package(url: "https://github.com/apple/swift-crypto.git", from: "2.5.0"),
7165
.package(url: "https://github.com/apple/swift-asn1.git", .upToNextMinor(from: "0.7.0")),
7266
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
7367
]

Sources/X509/CertificatePrivateKey.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the SwiftCertificates open source project
44
//
5-
// Copyright (c) 2022-2023 Apple Inc. and the SwiftCertificates project authors
5+
// Copyright (c) 2022 Apple Inc. and the SwiftCertificates project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -63,7 +63,7 @@ extension Certificate {
6363
self.backing = .rsa(rsa)
6464
}
6565

66-
#if INCLUDE_SECURE_ENCLAVE_SUPPORT
66+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
6767
/// Construct a private key wrapping a SecureEnclave.P256 private key.
6868
/// - Parameter secureEnclaveP256: The SecureEnclave.P256 private key to wrap.
6969
@inlinable
@@ -87,7 +87,7 @@ extension Certificate {
8787
case .rsa(let rsa):
8888
let padding = try _RSA.Signing.Padding(forSignatureAlgorithm: signatureAlgorithm)
8989
return try rsa.signature(for: bytes, digestAlgorithm: digestAlgorithm, padding: padding)
90-
#if INCLUDE_SECURE_ENCLAVE_SUPPORT
90+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
9191
case .secureEnclaveP256(let secureEnclaveP256):
9292
return try secureEnclaveP256.signature(for: bytes, digestAlgorithm: digestAlgorithm)
9393
#endif
@@ -107,7 +107,7 @@ extension Certificate {
107107
return PublicKey(p521.publicKey)
108108
case .rsa(let rsa):
109109
return PublicKey(rsa.publicKey)
110-
#if INCLUDE_SECURE_ENCLAVE_SUPPORT
110+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
111111
case .secureEnclaveP256(let secureEnclaveP256):
112112
return PublicKey(secureEnclaveP256.publicKey)
113113
#endif
@@ -125,7 +125,7 @@ extension Certificate {
125125
if !algorithm.isRSA {
126126
throw CertificateError.unsupportedSignatureAlgorithm(reason: "Cannot use \(algorithm) with RSA key \(self)")
127127
}
128-
#if INCLUDE_SECURE_ENCLAVE_SUPPORT
128+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
129129
case .secureEnclaveP256:
130130
if !algorithm.isECDSA {
131131
throw CertificateError.unsupportedSignatureAlgorithm(reason: "Cannot use \(algorithm) with ECDSA key \(self)")
@@ -154,7 +154,7 @@ extension Certificate.PrivateKey {
154154
case p384(Crypto.P384.Signing.PrivateKey)
155155
case p521(Crypto.P521.Signing.PrivateKey)
156156
case rsa(_CryptoExtras._RSA.Signing.PrivateKey)
157-
#if INCLUDE_SECURE_ENCLAVE_SUPPORT
157+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
158158
case secureEnclaveP256(SecureEnclave.P256.Signing.PrivateKey)
159159
#endif
160160

@@ -169,7 +169,7 @@ extension Certificate.PrivateKey {
169169
return l.rawRepresentation == r.rawRepresentation
170170
case (.rsa(let l), .rsa(let r)):
171171
return l.derRepresentation == r.derRepresentation
172-
#if INCLUDE_SECURE_ENCLAVE_SUPPORT
172+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
173173
case (.secureEnclaveP256(let l), .secureEnclaveP256(let r)):
174174
return l.dataRepresentation == r.dataRepresentation
175175
#endif
@@ -193,7 +193,7 @@ extension Certificate.PrivateKey {
193193
case .rsa(let digest):
194194
hasher.combine(3)
195195
hasher.combine(digest.derRepresentation)
196-
#if INCLUDE_SECURE_ENCLAVE_SUPPORT
196+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
197197
case .secureEnclaveP256(let digest):
198198
hasher.combine(4)
199199
hasher.combine(digest.dataRepresentation)

Sources/X509/Digests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ extension P256.Signing.PrivateKey {
154154
}
155155
}
156156

157-
#if INCLUDE_SECURE_ENCLAVE_SUPPORT
157+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
158158
extension SecureEnclave.P256.Signing.PrivateKey {
159159
@inlinable
160160
func signature<Bytes: DataProtocol>(for bytes: Bytes, digestAlgorithm: AlgorithmIdentifier) throws -> Certificate.Signature {

0 commit comments

Comments
 (0)