Skip to content

Commit 37a7069

Browse files
committed
Wrap ZitiIdentity.key and its tests with CZITI_TEST_INSECURE_KEYS
1 parent 29ecfd4 commit 37a7069

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

CZitiTests/ZitiIdentityTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class ZitiIdentityTests: XCTestCase {
8686
XCTAssertEqual(decoded.startDisabled, true)
8787
}
8888

89+
#if CZITI_TEST_INSECURE_KEYS
8990
func testKeyDefaultsToNil() throws {
9091
let id = ZitiIdentity(id: "x", ztAPIs: ["https://ctrl:1280"])
9192
XCTAssertNil(id.key)
@@ -104,6 +105,7 @@ class ZitiIdentityTests: XCTestCase {
104105
let decoded = try JSONDecoder().decode(ZitiIdentity.self, from: data)
105106
XCTAssertEqual(decoded.key, pem)
106107
}
108+
#endif
107109

108110
func testDecodeOldZidWithoutKeyField() throws {
109111
// Existing .zid files in the wild never have a key field. Must still decode.
@@ -112,6 +114,5 @@ class ZitiIdentityTests: XCTestCase {
112114
"""
113115
let decoded = try JSONDecoder().decode(ZitiIdentity.self, from: json.data(using: .utf8)!)
114116
XCTAssertEqual(decoded.id, "legacy")
115-
XCTAssertNil(decoded.key)
116117
}
117118
}

lib/ZitiIdentity.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,12 @@ import Foundation
5353
/// Certificates (PEM)
5454
@objc public var certs:String?
5555

56-
/// Private key (PEM).
57-
///
58-
/// Only populated by builds compiled with `CZITI_TEST_INSECURE_KEYS`. Release builds
59-
/// keep the private key in the keychain and leave this field nil. If this field is
60-
/// populated in a loaded identity, `Ziti.run()` (in an insecure-keys build) will use
61-
/// it directly instead of reading from the keychain. This field is never populated
62-
/// or read by release builds.
56+
#if CZITI_TEST_INSECURE_KEYS
57+
/// Private key (PEM). Only present in builds compiled with `CZITI_TEST_INSECURE_KEYS`.
58+
/// The enrollment flow writes the ephemeral key here so `Ziti.run()` can use it
59+
/// without touching the data protection keychain.
6360
@objc public var key:String?
61+
#endif
6462

6563
/// CA pool verified as part of enrollment that can be used to establish trust with of the Ziti controller
6664
@objc public var ca:String?

0 commit comments

Comments
 (0)