Skip to content

Commit 450b6c7

Browse files
committed
Add more entitlement options, rename Apple ID to Apple Account, andadd debug toggle
1 parent 0c4bae3 commit 450b6c7

7 files changed

Lines changed: 177 additions & 60 deletions

File tree

iRAM-Plus/AppIDViewModel.swift

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Created by s s on 2025/3/15.
66
//
77
import SwiftUI
8+
import Foundation
89
import StosSign_API_NoCertificate
910
import StosSign_Auth
1011

@@ -35,6 +36,8 @@ class AppIDModel : ObservableObject, Hashable {
3536

3637
try await AppleAPI.shared.refreshAnisetteDataIfNeeded(for: session)
3738

39+
let enableExtendedVirtualAddressing = UserDefaults.standard.bool(forKey: "enableExtendedVirtualAddressing")
40+
3841
let dateFormatter = ISO8601DateFormatter()
3942
let httpHeaders = [
4043
"Content-Type": "application/vnd.api+json",
@@ -56,10 +59,67 @@ class AppIDModel : ObservableObject, Hashable {
5659
"X-Apple-I-TimeZone": session.anisetteData.timeZone.abbreviation()!
5760
] as [String : String];
5861

62+
// Build capabilities array based on settings
63+
var capabilities: [[String: Any]] = [
64+
[
65+
"relationships": [
66+
"capability": [
67+
"data": [
68+
"id": "INCREASED_MEMORY_LIMIT",
69+
"type": "capabilities"
70+
]
71+
]
72+
],
73+
"type": "bundleIdCapabilities",
74+
"attributes": [
75+
"settings": [],
76+
"enabled": true
77+
]
78+
]
79+
]
80+
81+
if enableExtendedVirtualAddressing {
82+
capabilities.append([
83+
"relationships": [
84+
"capability": [
85+
"data": [
86+
"id": "EXTENDED_VIRTUAL_ADDRESSING",
87+
"type": "capabilities"
88+
]
89+
]
90+
],
91+
"type": "bundleIdCapabilities",
92+
"attributes": [
93+
"settings": [],
94+
"enabled": true
95+
]
96+
])
97+
}
98+
99+
let requestBody: [String: Any] = [
100+
"data": [
101+
"relationships": [
102+
"bundleIdCapabilities": [
103+
"data": capabilities
104+
]
105+
],
106+
"id": appID.identifier,
107+
"attributes": [
108+
"hasExclusiveManagedCapabilities": false,
109+
"teamId": team.identifier,
110+
"bundleType": "bundle",
111+
"identifier": appID.bundleIdentifier,
112+
"seedId": team.identifier,
113+
"name": appID.name
114+
],
115+
"type": "bundleIds"
116+
]
117+
]
118+
59119
var request = URLRequest(url: URL(string: "https://developerservices2.apple.com/services/v1/bundleIds/\(appID.identifier)")!)
60120
request.httpMethod = "PATCH"
61121
request.allHTTPHeaderFields = httpHeaders
62-
request.httpBody = "{\"data\":{\"relationships\":{\"bundleIdCapabilities\":{\"data\":[{\"relationships\":{\"capability\":{\"data\":{\"id\":\"INCREASED_MEMORY_LIMIT\",\"type\":\"capabilities\"}}},\"type\":\"bundleIdCapabilities\",\"attributes\":{\"settings\":[],\"enabled\":true}}]}},\"id\":\"\(appID.identifier)\",\"attributes\":{\"hasExclusiveManagedCapabilities\":false,\"teamId\":\"\(team.identifier)\",\"bundleType\":\"bundle\",\"identifier\":\"\(appID.bundleIdentifier)\",\"seedId\":\"\(team.identifier)\",\"name\":\"\(appID.name)\"},\"type\":\"bundleIds\"}}".data(using: .utf8)
122+
request.httpBody = try JSONSerialization.data(withJSONObject: requestBody)
63123

64124
let (data, response) = try await URLSession.shared.data(for: request)
65125
let responseString = String(data: data, encoding: .utf8) ?? "Unable to decode response."
@@ -70,7 +130,12 @@ class AppIDModel : ObservableObject, Hashable {
70130
}
71131

72132
await MainActor.run {
73-
result = "✅ Success! Increased Memory Limit capability has been enabled.\n\nAPI Response:\n\(responseString)"
133+
var successMessage = "✅ Success! Increased Memory Limit capability has been enabled."
134+
if enableExtendedVirtualAddressing {
135+
successMessage += "\n\nExtended Virtual Addressing capability has also been enabled."
136+
}
137+
successMessage += "\n\nAPI Response:\n\(responseString)"
138+
result = successMessage
74139
}
75140

76141
}

iRAM-Plus/Keychain.swift

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,18 @@ public class Keychain
4545

4646
fileprivate let keychain = SystemKeychain(service: Bundle.main.bundleIdentifier!)
4747

48-
@KeychainItem(key: "appleIDEmailAddress")
49-
public var appleIDEmailAddress: String?
50-
51-
@KeychainItem(key: "appleIDPassword")
52-
public var appleIDPassword: String?
53-
54-
@KeychainItem(key: "signingCertificatePrivateKey")
55-
public var signingCertificatePrivateKey: Data?
56-
57-
@KeychainItem(key: "signingCertificateSerialNumber")
58-
public var signingCertificateSerialNumber: String?
59-
60-
@KeychainItem(key: "signingCertificate")
61-
public var signingCertificate: Data?
62-
63-
@KeychainItem(key: "signingCertificatePassword")
64-
public var signingCertificatePassword: String?
48+
@KeychainItem(key: "appleAccountEmailAddress")
49+
public var appleAccountEmailAddress: String?
6550

66-
@KeychainItem(key: "patreonAccessToken")
67-
public var patreonAccessToken: String?
51+
@KeychainItem(key: "appleAccountPassword")
52+
public var appleAccountPassword: String?
6853

69-
@KeychainItem(key: "patreonRefreshToken")
70-
public var patreonRefreshToken: String?
71-
72-
@KeychainItem(key: "patreonCreatorAccessToken")
73-
public var patreonCreatorAccessToken: String?
54+
// Old keychain keys for backward compatibility
55+
@KeychainItem(key: "appleIDEmailAddress")
56+
private var oldAppleIDEmailAddress: String?
7457

75-
@KeychainItem(key: "patreonAccountID")
76-
public var patreonAccountID: String?
58+
@KeychainItem(key: "appleIDPassword")
59+
private var oldAppleIDPassword: String?
7760

7861
@KeychainItem(key: "identifier")
7962
public var identifier: String?
@@ -87,10 +70,22 @@ public class Keychain
8770

8871
public func reset()
8972
{
90-
self.appleIDEmailAddress = nil
91-
self.appleIDPassword = nil
92-
self.signingCertificatePrivateKey = nil
93-
self.signingCertificateSerialNumber = nil
73+
self.appleAccountEmailAddress = nil
74+
self.appleAccountPassword = nil
75+
self.identifier = nil
76+
self.adiPb = nil
77+
}
78+
79+
public func migrateOldCredentials() {
80+
// If new keys are empty but old keys have values, migrate them
81+
if appleAccountEmailAddress == nil && oldAppleIDEmailAddress != nil {
82+
appleAccountEmailAddress = oldAppleIDEmailAddress
83+
oldAppleIDEmailAddress = nil // Clear old value after migration
84+
}
85+
if appleAccountPassword == nil && oldAppleIDPassword != nil {
86+
appleAccountPassword = oldAppleIDPassword
87+
oldAppleIDPassword = nil // Clear old value after migration
88+
}
9489
}
9590
}
9691

iRAM-Plus/LoginViewModel.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import StosSign_API_NoCertificate
99
import StosSign_Auth
1010

1111
class LoginViewModel: ObservableObject {
12-
@Published var appleID = ""
12+
@Published var appleAccount = ""
1313
@Published var password = ""
1414
@Published var needVerificationCode = false
1515
@Published var verificationCode = ""
@@ -90,7 +90,7 @@ class LoginViewModel: ObservableObject {
9090
guard let self else { return }
9191
if !self.needVerificationCode {
9292
self.verificationCodeHandler = nil
93-
self.appleID = ""
93+
self.appleAccount = ""
9494
self.password = ""
9595
self.verificationCode = ""
9696
self.isLoginInProgress = false
@@ -112,7 +112,7 @@ class LoginViewModel: ObservableObject {
112112
await MainActor.run {
113113
progressCallback?(0.4, "Authenticating with Apple")
114114
}
115-
let (account, session) = try await AppleAPI.shared.authenticate(appleID: appleID, password: password, anisetteData: anisetteData) { [weak self] completionHandler in
115+
let (account, session) = try await AppleAPI.shared.authenticate(appleID: appleAccount, password: password, anisetteData: anisetteData) { [weak self] completionHandler in
116116
guard let self else {
117117
completionHandler(nil)
118118
return
@@ -238,7 +238,7 @@ class LoginViewModel: ObservableObject {
238238
// Cleanup after successful 2FA
239239
await MainActor.run {
240240
verificationCodeHandler = nil
241-
appleID = ""
241+
appleAccount = ""
242242
password = ""
243243
needVerificationCode = false
244244
verificationCode = ""

iRAM-Plus/SideStoreAccount.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ enum SideStoreAccountImporter {
8686
throw SideStoreAccountImportError.invalidLocalUser
8787
}
8888

89-
Keychain.shared.appleIDEmailAddress = email
90-
Keychain.shared.appleIDPassword = password
89+
Keychain.shared.appleAccountEmailAddress = email
90+
Keychain.shared.appleAccountPassword = password
9191
Keychain.shared.adiPb = adiPB
9292
Keychain.shared.identifier = localUser
9393
AnisetteDataHelper.shared.resetClientInfo()

iRAM-Plus/WizardViewModel.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ class WizardViewModel: ObservableObject {
7575
@Published var saveLoginToKeychain = UserDefaults.standard.bool(forKey: "saveLoginToKeychain") {
7676
didSet {
7777
UserDefaults.standard.set(saveLoginToKeychain, forKey: "saveLoginToKeychain")
78+
// Clear keychain when toggle is turned off
79+
if !saveLoginToKeychain {
80+
Keychain.shared.appleAccountEmailAddress = nil
81+
Keychain.shared.appleAccountPassword = nil
82+
}
83+
}
84+
}
85+
@Published var enableExtendedVirtualAddressing = UserDefaults.standard.bool(forKey: "enableExtendedVirtualAddressing") {
86+
didSet {
87+
UserDefaults.standard.set(enableExtendedVirtualAddressing, forKey: "enableExtendedVirtualAddressing")
88+
}
89+
}
90+
@Published var enableDebugging = UserDefaults.standard.bool(forKey: "enableDebugging") {
91+
didSet {
92+
UserDefaults.standard.set(enableDebugging, forKey: "enableDebugging")
7893
}
7994
}
8095
@Published var anisetteServers: [AnisetteServer] = []
@@ -141,8 +156,8 @@ class WizardViewModel: ObservableObject {
141156
let sharedModel = DataManager.shared.model
142157
Keychain.shared.adiPb = nil
143158
Keychain.shared.identifier = nil
144-
Keychain.shared.appleIDPassword = nil
145-
Keychain.shared.appleIDEmailAddress = nil
159+
Keychain.shared.appleAccountPassword = nil
160+
Keychain.shared.appleAccountEmailAddress = nil
146161
AnisetteDataHelper.shared.resetClientInfo()
147162
sharedModel.session = nil
148163
sharedModel.account = nil
@@ -153,7 +168,7 @@ class WizardViewModel: ObservableObject {
153168
}
154169

155170
func resetLoginState() {
156-
loginViewModel.appleID = ""
171+
loginViewModel.appleAccount = ""
157172
loginViewModel.password = ""
158173
loginViewModel.needVerificationCode = false
159174
loginViewModel.verificationCode = ""

0 commit comments

Comments
 (0)