mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
Supports resigning apps with multiple app groups
This commit is contained in:
@@ -1117,7 +1117,7 @@ NSNotificationName const ALTDeviceManagerDeviceDidDisconnectNotification = @"ALT
|
|||||||
NSString *name = [NSString stringWithCString:device_name encoding:NSUTF8StringEncoding];
|
NSString *name = [NSString stringWithCString:device_name encoding:NSUTF8StringEncoding];
|
||||||
NSString *identifier = [NSString stringWithCString:udid encoding:NSUTF8StringEncoding];
|
NSString *identifier = [NSString stringWithCString:udid encoding:NSUTF8StringEncoding];
|
||||||
|
|
||||||
ALTDevice *altDevice = [[ALTDevice alloc] initWithName:name identifier:identifier];
|
ALTDevice *altDevice = [[ALTDevice alloc] initWithName:name identifier:identifier type:ALTDeviceTypeiPhone];
|
||||||
[connectedDevices addObject:altDevice];
|
[connectedDevices addObject:altDevice];
|
||||||
|
|
||||||
if (device_name != NULL)
|
if (device_name != NULL)
|
||||||
|
|||||||
@@ -362,56 +362,69 @@ extension FetchProvisioningProfilesOperation
|
|||||||
entitlements[key] = value
|
entitlements[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Handle apps belonging to more than one app group.
|
guard let applicationGroups = entitlements[.appGroups] as? [String] else { return completionHandler(.success(appID)) }
|
||||||
guard let applicationGroups = entitlements[.appGroups] as? [String], let groupIdentifier = applicationGroups.first else {
|
|
||||||
return completionHandler(.success(appID))
|
|
||||||
}
|
|
||||||
|
|
||||||
func finish(_ result: Result<ALTAppGroup, Error>)
|
|
||||||
{
|
|
||||||
switch result
|
|
||||||
{
|
|
||||||
case .failure(let error): completionHandler(.failure(error))
|
|
||||||
case .success(let group):
|
|
||||||
// Assign App Group
|
|
||||||
// TODO: Determine whether app already belongs to app group.
|
|
||||||
|
|
||||||
ALTAppleAPI.shared.add(appID, to: group, team: team, session: session) { (success, error) in
|
|
||||||
let result = result.map { _ in appID }
|
|
||||||
completionHandler(result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dispatch onto global queue to prevent appGroupsLock deadlock.
|
// Dispatch onto global queue to prevent appGroupsLock deadlock.
|
||||||
DispatchQueue.global().async {
|
DispatchQueue.global().async {
|
||||||
let adjustedGroupIdentifier = groupIdentifier + "." + team.identifier
|
|
||||||
|
|
||||||
// Ensure we're not concurrently fetching and updating app groups,
|
// Ensure we're not concurrently fetching and updating app groups,
|
||||||
// which can lead to race conditions such as adding an app group twice.
|
// which can lead to race conditions such as adding an app group twice.
|
||||||
self.appGroupsLock.lock()
|
self.appGroupsLock.lock()
|
||||||
|
|
||||||
|
func finish(_ result: Result<ALTAppID, Error>)
|
||||||
|
{
|
||||||
|
self.appGroupsLock.unlock()
|
||||||
|
completionHandler(result)
|
||||||
|
}
|
||||||
|
|
||||||
ALTAppleAPI.shared.fetchAppGroups(for: team, session: session) { (groups, error) in
|
ALTAppleAPI.shared.fetchAppGroups(for: team, session: session) { (groups, error) in
|
||||||
switch Result(groups, error)
|
switch Result(groups, error)
|
||||||
{
|
{
|
||||||
case .failure(let error):
|
case .failure(let error): finish(.failure(error))
|
||||||
self.appGroupsLock.unlock()
|
case .success(let fetchedGroups):
|
||||||
completionHandler(.failure(error))
|
let dispatchGroup = DispatchGroup()
|
||||||
|
|
||||||
case .success(let groups):
|
var groups = [ALTAppGroup]()
|
||||||
if let group = groups.first(where: { $0.groupIdentifier == adjustedGroupIdentifier })
|
var errors = [Error]()
|
||||||
|
|
||||||
|
for groupIdentifier in applicationGroups
|
||||||
{
|
{
|
||||||
self.appGroupsLock.unlock()
|
let adjustedGroupIdentifier = groupIdentifier + "." + team.identifier
|
||||||
finish(.success(group))
|
|
||||||
|
if let group = fetchedGroups.first(where: { $0.groupIdentifier == adjustedGroupIdentifier })
|
||||||
|
{
|
||||||
|
groups.append(group)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
dispatchGroup.enter()
|
||||||
|
|
||||||
// Not all characters are allowed in group names, so we replace periods with spaces (like Apple does).
|
// Not all characters are allowed in group names, so we replace periods with spaces (like Apple does).
|
||||||
let name = "AltStore " + groupIdentifier.replacingOccurrences(of: ".", with: " ")
|
let name = "AltStore " + groupIdentifier.replacingOccurrences(of: ".", with: " ")
|
||||||
|
|
||||||
ALTAppleAPI.shared.addAppGroup(withName: name, groupIdentifier: adjustedGroupIdentifier, team: team, session: session) { (group, error) in
|
ALTAppleAPI.shared.addAppGroup(withName: name, groupIdentifier: adjustedGroupIdentifier, team: team, session: session) { (group, error) in
|
||||||
self.appGroupsLock.unlock()
|
switch Result(group, error)
|
||||||
finish(Result(group, error))
|
{
|
||||||
|
case .success(let group): groups.append(group)
|
||||||
|
case .failure(let error): errors.append(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatchGroup.leave()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatchGroup.notify(queue: .global()) {
|
||||||
|
if let error = errors.first
|
||||||
|
{
|
||||||
|
finish(.failure(error))
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ALTAppleAPI.shared.assign(appID, to: Array(groups), team: team, session: session) { (success, error) in
|
||||||
|
let result = Result(success, error)
|
||||||
|
finish(result.map { _ in appID })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
Dependencies/AltSign
vendored
2
Dependencies/AltSign
vendored
Submodule Dependencies/AltSign updated: 5905038272...db6cadf021
Reference in New Issue
Block a user