Modern Apps git

← xtool.git

Tie cert to host computer instead of device

Commit
d69da9520d5906c683fc9f77296634e60227ab61
Author
kabiroberai <[email protected]>
When
2020-08-15 20:11 UTC (6 years ago)
Parents
734c5b7
We might want to store the cert on the backend in the future, to allow using multiple computers without ending up revoking the cert on other devices

Diff

Supersign/DeveloperServices/Certificates/DeveloperServicesFetchCertificateOperation.swift
diff --git a/Supersign/DeveloperServices/Certificates/DeveloperServicesFetchCertificateOperation.swift b/Supersign/DeveloperServices/Certificates/DeveloperServicesFetchCertificateOperation.swiftindex d0e67c3..011db35 100644--- a/Supersign/DeveloperServices/Certificates/DeveloperServicesFetchCertificateOperation.swift+++ b/Supersign/DeveloperServices/Certificates/DeveloperServicesFetchCertificateOperation.swift@@ -45,8 +45,8 @@ public struct DeveloperServicesFetchCertificateOperation: DeveloperServicesOpera             platform: context.platform,             teamID: context.teamID,             csr: csr,-            machineName: context.deviceName,-            machineID: context.udid+            machineName: "Supercharge: \(context.deviceName)",+            machineID: context.client.deviceInfo.deviceID         )         context.client.send(request) { result in             guard let partialCert = result.get(withErrorHandler: completion) else { return }@@ -75,11 +75,15 @@ public struct DeveloperServicesFetchCertificateOperation: DeveloperServicesOpera     }      private func revokeCreateSaveCertificate(-        certificate: DeveloperServicesCertificate,+        certificates: [DeveloperServicesCertificate],         completion: @escaping (Result<SigningInfo, Swift.Error>) -> Void     ) {-        let request = DeveloperServicesRevokeCertificateRequest(teamID: context.teamID, certificateID: certificate.id)-        context.client.send(request) { result in+        let grouper = RequestGrouper<EmptyResponse, Swift.Error>()+        certificates.forEach {+            let request = DeveloperServicesRevokeCertificateRequest(teamID: context.teamID, certificateID: $0.id)+            grouper.add { context.client.send(request, completion: $0) }+        }+        grouper.onComplete { result in             guard result.get(withErrorHandler: completion) != nil else { return }             self.createAndSaveCertificate(completion: completion)         }@@ -92,8 +96,11 @@ public struct DeveloperServicesFetchCertificateOperation: DeveloperServicesOpera         context.client.send(request) { result in             guard let certificates = result.get(withErrorHandler: completion) else { return } -            guard let certificate = certificates.first(where: { $0.attributes.machineID == self.context.udid }) else {-                return self.createAndSaveCertificate(completion: completion)+            guard let certificate = certificates.first(where: {+                $0.attributes.machineID == self.context.client.deviceInfo.deviceID+            }) else {+                // we need to revoke existing certs, otherwise it doesn't always let us make a new one+                return self.revokeCreateSaveCertificate(certificates: certificates, completion: completion)             }              guard let signingInfo = self.context.signingInfoManager[self.context.teamID],@@ -101,7 +108,7 @@ public struct DeveloperServicesFetchCertificateOperation: DeveloperServicesOpera                 certificate.attributes.serialNumber.rawValue == serialNumber,                 certificate.attributes.expiry > Date()                 else { return self.revokeCreateSaveCertificate(-                    certificate: certificate, completion: completion+                    certificates: [certificate], completion: completion                 ) }              completion(.success(signingInfo))