mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
Makes revoking optional (#675)
This commit is contained in:
@@ -524,16 +524,50 @@ private extension AuthenticationOperation
|
||||
|
||||
func replaceCertificate(from certificates: [ALTCertificate])
|
||||
{
|
||||
guard let certificate = certificates.first(where: { $0.machineName?.starts(with: "SideStore") == true }) ?? certificates.first else { return completionHandler(.failure(OperationError.notAuthenticated)) }
|
||||
let ourCertificates = certificates.filter { a in
|
||||
a.machineName?.starts(with: "SideStore") == true
|
||||
}
|
||||
|
||||
ALTAppleAPI.shared.revoke(certificate, for: team, session: session) { (success, error) in
|
||||
if let error = error, !success
|
||||
if ourCertificates.isEmpty {
|
||||
return requestCertificate()
|
||||
}
|
||||
|
||||
// We don't have private keys for any of the certificates,
|
||||
// so we need to revoke one and create a new one.
|
||||
var certsText = ""
|
||||
for certificate in ourCertificates {
|
||||
if let name = certificate.machineName {
|
||||
certsText.append("\(name)\n")
|
||||
}
|
||||
}
|
||||
|
||||
let alertController = UIAlertController(title: NSLocalizedString("Would you like to revoke your previous certificates?\n\(certsText)", comment: ""), message: nil, preferredStyle: .alert)
|
||||
|
||||
let noAction = UIAlertAction(title: NSLocalizedString("No", comment: ""), style: .default) { (action) in
|
||||
requestCertificate()
|
||||
}
|
||||
let yesAction = UIAlertAction(title: NSLocalizedString("Yes", comment: ""), style: .default) { (action) in
|
||||
for certificate in ourCertificates {
|
||||
ALTAppleAPI.shared.revoke(certificate, for: team, session: session) { (success, error) in
|
||||
if let error = error, !success
|
||||
{
|
||||
completionHandler(.failure(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
requestCertificate()
|
||||
}
|
||||
alertController.addAction(noAction)
|
||||
alertController.addAction(yesAction)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
if self.navigationController.presentingViewController != nil
|
||||
{
|
||||
completionHandler(.failure(error))
|
||||
self.navigationController.present(alertController, animated: true, completion: nil)
|
||||
}
|
||||
else
|
||||
{
|
||||
requestCertificate()
|
||||
self.presentingViewController?.present(alertController, animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -581,8 +615,6 @@ private extension AuthenticationOperation
|
||||
}
|
||||
else
|
||||
{
|
||||
// We don't have private keys for any of the certificates,
|
||||
// so we need to revoke one and create a new one.
|
||||
replaceCertificate(from: certificates)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user