Skip to content

Commit 398293d

Browse files
authored
Added new VerificationResult.verifiedOnDevice (#2379)
This will be used to represent data that has been created and verified locally.
1 parent c4d422d commit 398293d

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

Sources/Security/VerificationResult.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ internal enum VerificationResult: Int {
5454
/// Entitlements were verified with our server.
5555
case verified = 1
5656

57+
/// Entitlements were created and verified on device through `StoreKit 2`.
58+
case verifiedOnDevice = 3
59+
5760
/// Entitlement verification failed, possibly due to a MiTM attack.
5861
/// ### Related Symbols
5962
/// - ``ErrorCode/signatureVerificationFailed``
@@ -77,20 +80,23 @@ extension VerificationResult {
7780
switch (cachedResult, responseResult) {
7881
case (.notRequested, .notRequested),
7982
(.verified, .verified),
83+
(.verifiedOnDevice, .verifiedOnDevice),
8084
(.failed, .failed):
8185
return cachedResult
8286

83-
case (.verified, .notRequested): return .notRequested
84-
case (.verified, .failed): return .failed
87+
case (.verified, .notRequested), (.verifiedOnDevice, .notRequested): return .notRequested
88+
case (.verified, .failed), (.verifiedOnDevice, .failed): return .failed
8589

86-
case (.notRequested, .verified): return .verified
90+
case (.notRequested, .verified), (.notRequested, .verifiedOnDevice): return responseResult
8791
case (.notRequested, .failed): return .failed
8892

8993
case (.failed, .notRequested): return .notRequested
9094
// If the cache verification failed, the etag won't be used
9195
// so the response would only be a 200 and not 304.
9296
// Therefore the cache verification error can be ignored
93-
case (.failed, .verified): return .verified
97+
case (.failed, .verified), (.failed, .verifiedOnDevice): return responseResult
98+
99+
case (.verifiedOnDevice, .verified), (.verified, .verifiedOnDevice): return responseResult
94100
}
95101
}
96102

Tests/APITesters/ObjCAPITester/ObjCAPITester/RCVerificationResultAPI.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ + (void)checkAPI {
1717
switch (result) {
1818
case RCVerificationResultNotRequested:
1919
case RCVerificationResultVerified:
20+
case RCVerificationResultVerifiedOnDevice:
2021
case RCVerificationResultFailed:
2122
break;
2223
}

Tests/APITesters/SwiftAPITester/SwiftAPITester/VerificationResultAPI.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func checkVerificationResultAPI(_ mode: EntitlementVerificationMode = .disabled,
2424
switch result {
2525
case .notRequested,
2626
.verified,
27+
.verifiedOnDevice,
2728
.failed:
2829
break
2930

Tests/UnitTests/Security/SigningTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,28 +297,37 @@ class SigningTests: TestCase {
297297
func testVerificationResultWithSameCachedAndResponseResult() {
298298
expect(VerificationResult.from(cache: .notRequested, response: .notRequested)) == .notRequested
299299
expect(VerificationResult.from(cache: .verified, response: .verified)) == .verified
300+
expect(VerificationResult.from(cache: .verifiedOnDevice, response: .verifiedOnDevice)) == .verifiedOnDevice
300301
expect(VerificationResult.from(cache: .failed, response: .failed)) == .failed
301302
}
302303

303304
func testVerificationNotRequestedCachedResult() {
304305
expect(VerificationResult.from(cache: .notRequested,
305306
response: .verified)) == .verified
307+
expect(VerificationResult.from(cache: .notRequested,
308+
response: .verifiedOnDevice)) == .verifiedOnDevice
306309
expect(VerificationResult.from(cache: .notRequested,
307310
response: .failed)) == .failed
308311
}
309312

310313
func testVerifiedCachedResult() {
311314
expect(VerificationResult.from(cache: .verified,
312315
response: .notRequested)) == .notRequested
316+
expect(VerificationResult.from(cache: .verifiedOnDevice,
317+
response: .notRequested)) == .notRequested
313318
expect(VerificationResult.from(cache: .verified,
314319
response: .failed)) == .failed
320+
expect(VerificationResult.from(cache: .verifiedOnDevice,
321+
response: .failed)) == .failed
315322
}
316323

317324
func testFailedVerificationCachedResult() {
318325
expect(VerificationResult.from(cache: .failed,
319326
response: .notRequested)) == .notRequested
320327
expect(VerificationResult.from(cache: .failed,
321328
response: .verified)) == .verified
329+
expect(VerificationResult.from(cache: .failed,
330+
response: .verifiedOnDevice)) == .verifiedOnDevice
322331
}
323332

324333
}

0 commit comments

Comments
 (0)