Skip to content

Commit 11f9f8d

Browse files
committed
Update the way we use keychain
1 parent 30204ff commit 11f9f8d

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

Core/Sources/CodeiumService/CodeiumAuthService.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import KeychainAccess
44

55
public final class CodeiumAuthService {
66
public init() {}
7-
let codeiumKeyKey = "codeiumKey"
7+
let codeiumKeyKey = "codeiumAuthKey"
88
let keychain: Keychain = {
99
let info = Bundle.main.infoDictionary
1010
return Keychain(service: keychainService, accessGroup: keychainAccessGroup)
11+
.attributes([
12+
kSecUseDataProtectionKeychain as String: true,
13+
])
1114
}()
1215

1316
var key: String? { try? keychain.getString(codeiumKeyKey) }

Core/Sources/ServiceUpdateMigration/ServiceUpdateMigrator.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import Configs
12
import Foundation
23
import GitHubCopilotService
4+
import KeychainAccess
35
import Preferences
46

57
extension UserDefaultPreferenceKeys {
@@ -13,7 +15,7 @@ extension UserDefaultPreferenceKeys {
1315

1416
public struct ServiceUpdateMigrator {
1517
public init() {}
16-
18+
1719
public func migrate() async throws {
1820
let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "0"
1921

@@ -24,7 +26,11 @@ public struct ServiceUpdateMigrator {
2426
func migrate(from oldVersion: String, to currentVersion: String) async throws {
2527
guard let old = Int(oldVersion) else { return }
2628
if old <= 135 {
27-
try migrateFromLowerThanOrEqualToVersion135()
29+
try migrateFromLowerThanOrEqualToVersion135()
30+
}
31+
32+
if old <= 170 {
33+
try migrateFromLowerThanOrEqualToVersion170()
2834
}
2935
}
3036
}
@@ -73,3 +79,17 @@ func migrateFromLowerThanOrEqualToVersion135() throws {
7379
)
7480
}
7581

82+
func migrateFromLowerThanOrEqualToVersion170() throws {
83+
let oldKeychain = Keychain(service: keychainService, accessGroup: keychainAccessGroup)
84+
let newKeychain = oldKeychain.attributes([
85+
kSecUseDataProtectionKeychain as String: true,
86+
])
87+
88+
if (try? oldKeychain.contains("codeiumKey")) ?? false,
89+
let key = try? oldKeychain.getString("codeiumKey")
90+
{
91+
try newKeychain.set(key, key: "codeiumAuthKey")
92+
try? oldKeychain.set("", key: "codeiumKey")
93+
}
94+
}
95+

0 commit comments

Comments
 (0)