diff --git a/Sources/CAltSign/Signing/ALTSigner.mm b/Sources/CAltSign/Signing/ALTSigner.mm index de95396..d2059a8 100644 --- a/Sources/CAltSign/Signing/ALTSigner.mm +++ b/Sources/CAltSign/Signing/ALTSigner.mm @@ -116,23 +116,23 @@ std::string CertificatesContent(ALTCertificate *altCertificate) { NSData *altCertificateP12Data = [altCertificate p12Data]; - + BIO *inputP12Buffer = BIO_new(BIO_s_mem()); BIO_write(inputP12Buffer, altCertificateP12Data.bytes, (int)altCertificateP12Data.length); - + auto inputP12 = d2i_PKCS12_bio(inputP12Buffer, NULL); - + // Extract key + certificate from .p12. EVP_PKEY *key; X509 *certificate; PKCS12_parse(inputP12, "", &key, &certificate, NULL); - + // Prepare certificate chain of trust. auto *certificates = sk_X509_new(NULL); - + BIO *rootCertificateBuffer = BIO_new_mem_buf(AppleRootCertificateData, (int)strlen(AppleRootCertificateData)); BIO *wwdrCertificateBuffer = nil; - + unsigned long issuerHash = X509_issuer_name_hash(certificate); if (issuerHash == 0x817d2f7a) { @@ -144,41 +144,41 @@ // Use latest WWDR certificate. wwdrCertificateBuffer = BIO_new_mem_buf(AppleWWDRCertificateData, (int)strlen(AppleWWDRCertificateData)); } - + auto rootCertificate = PEM_read_bio_X509(rootCertificateBuffer, NULL, NULL, NULL); if (rootCertificate != NULL) { sk_X509_push(certificates, rootCertificate); } - + auto wwdrCertificate = PEM_read_bio_X509(wwdrCertificateBuffer, NULL, NULL, NULL); if (wwdrCertificate != NULL) { sk_X509_push(certificates, wwdrCertificate); } - + // Create new .p12 in memory with private key and certificate chain. char emptyString[] = ""; auto outputP12 = PKCS12_create(emptyString, emptyString, key, certificate, certificates, 0, 0, 0, 0, 0); - + BIO *outputP12Buffer = BIO_new(BIO_s_mem()); i2d_PKCS12_bio(outputP12Buffer, outputP12); - + char *buffer = NULL; NSUInteger size = BIO_get_mem_data(outputP12Buffer, &buffer); - + NSData *p12Data = [NSData dataWithBytes:buffer length:size]; - + // Free .p12 structures PKCS12_free(inputP12); PKCS12_free(outputP12); - + BIO_free(wwdrCertificateBuffer); BIO_free(rootCertificateBuffer); - + BIO_free(inputP12Buffer); BIO_free(outputP12Buffer); - + std::string output((const char *)p12Data.bytes, (size_t)p12Data.length); return output; } @@ -198,17 +198,17 @@ - (instancetype)initWithTeam:(ALTTeam *)team certificate:(ALTCertificate *)certi _team = team; _certificate = certificate; } - + return self; } - (NSProgress *)signAppAtURL:(NSURL *)appURL provisioningProfiles:(NSArray *)profiles completionHandler:(void (^)(BOOL success, NSError *error))completionHandler -{ +{ NSProgress *progress = [NSProgress discreteProgressWithTotalUnitCount:1]; - + NSURL *ipaURL = nil; NSURL *appBundleURL = nil; - + void (^finish)(BOOL, NSError *) = ^(BOOL success, NSError *error) { if (ipaURL != nil) { @@ -218,23 +218,23 @@ - (NSProgress *)signAppAtURL:(NSURL *)appURL provisioningProfiles:(NSArray *entitlementsByFileURL = [NSMutableDictionary dictionary]; - + ALTProvisioningProfile *(^profileForApp)(ALTApplication *) = ^ALTProvisioningProfile *(ALTApplication *app) { // Assume for now that apps don't have 100s of app extensions 🤷‍♂️ for (ALTProvisioningProfile *profile in profiles) @@ -306,20 +306,20 @@ - (NSProgress *)signAppAtURL:(NSURL *)appURL provisioningProfiles:(NSArray *filteredEntitlements = [profile.entitlements mutableCopy]; for (NSString *entitlement in profile.entitlements) { @@ -368,13 +368,13 @@ - (NSProgress *)signAppAtURL:(NSURL *)appURL provisioningProfiles:(NSArray"]; [entitlements insertString:additionalEntitlements atIndex:entitlementsStartRange.location + entitlementsStartRange.length]; } - + NSURL *resolvedURL = [app.fileURL URLByResolvingSymlinksInPath]; entitlementsByFileURL[resolvedURL] = entitlements; - + return nil; }; - + NSError *prepareError = prepareApp(application); if (prepareError != nil) { finish(NO, prepareError); return; } - + for (ALTApplication *appExtension in application.appExtensions) { NSError *error = prepareApp(appExtension); @@ -416,25 +416,25 @@ - (NSProgress *)signAppAtURL:(NSURL *)appURL provisioningProfiles:(NSArray std::string { NSString *filename = [NSString stringWithCString:path.c_str() encoding:NSUTF8StringEncoding]; - + NSURL *fileURL = nil; - + if (filename.length == 0) { fileURL = application.fileURL; @@ -443,9 +443,9 @@ - (NSProgress *)signAppAtURL:(NSURL *)appURL provisioningProfiles:(NSArray