Skip to content

Commit

Permalink
Fix: handle both cert cases
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Aug 5, 2024
1 parent e775708 commit a374350
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
10 changes: 8 additions & 2 deletions LCJITLessSetupViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,23 @@ - (void)loadView {
return;
}

NSData *certPassword = [LCUtils keychainItem:@"signingCertificatePassword" ofStore:@"com.SideStore.SideStore"];
/* TODO: support AltStore
if (!certData) {
certData = [LCUtils keychainItem:@"signingCertificate" ofStore:@"com.rileytestut.AltStore"];
}
*/
NSData *certData = [LCUtils keychainItem:@"signingCertificate" ofStore:@"com.SideStore.SideStore"];
if (!certData) {
[self showDialogTitle:@"Error" message:@"Failed to find certificate data" handler:nil];
return;
}
LCUtils.certificateData = certData;

NSData *certPassword = [LCUtils keychainItem:@"signingCertificatePassword" ofStore:@"com.SideStore.SideStore"];
if (!certPassword) {
[self showDialogTitle:@"Error" message:@"Failed to find certificate password" handler:nil];
return;
}

LCUtils.certificatePassword = [NSString stringWithUTF8String:certPassword.bytes];

NSError *error;
Expand Down
1 change: 1 addition & 0 deletions LCUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

+ (NSData *)certificateData;
+ (NSString *)certificatePassword;
+ (void)setCertificateData:(NSData *)data;
+ (void)setCertificatePassword:(NSString *)password;

+ (NSData *)keychainItem:(NSString *)key ofStore:(NSString *)store;
Expand Down
32 changes: 21 additions & 11 deletions LCUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ @implementation LCUtils

#pragma mark Certificate password

+ (NSString *)appGroupPath {
return [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:self.appGroupID].path;
}

+ (NSData *)keychainItem:(NSString *)key ofStore:(NSString *)store {
NSDictionary *dict = @{
(id)kSecClass: (id)kSecClassGenericPassword,
Expand All @@ -27,22 +31,28 @@ + (NSData *)keychainItem:(NSString *)key ofStore:(NSString *)store {
}
}

+ (void)setCertificatePassword:(NSString *)certPassword {
[NSUserDefaults.standardUserDefaults setObject:certPassword forKey:@"LCCertificatePassword"];
+ (void)setCertificateData:(NSData *)certData {
[NSUserDefaults.standardUserDefaults setObject:certData forKey:@"LCCertificateData"];
}

+ (NSString *)certificatePassword {
return [NSUserDefaults.standardUserDefaults objectForKey:@"LCCertificatePassword"];
+ (NSData *)certificateDataFile {
NSURL *appGroupPath = [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:self.appGroupID];
NSURL *url = [appGroupPath URLByAppendingPathComponent:@"Apps/com.SideStore.SideStore/App.app/ALTCertificate.p12"];
return [NSData dataWithContentsOfURL:url];
}

+ (NSData *)certificateData {
static NSData *result;
if (!result) {
NSURL *appGroupPath = [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:self.appGroupID];
NSURL *url = [appGroupPath URLByAppendingPathComponent:@"Apps/com.SideStore.SideStore/App.app/ALTCertificate.p12"];
result = [NSData dataWithContentsOfURL:url];
}
return result;
// Prefer certificate file over keychain data
return self.certificateDataFile ?: [NSUserDefaults.standardUserDefaults objectForKey:@"LCCertificateData"];
}

+ (void)setCertificatePassword:(NSString *)certPassword {
[NSUserDefaults.standardUserDefaults setObject:certPassword forKey:@"LCCertificatePassword"];
}

+ (NSString *)certificatePassword {
// Certificate file requires password, whereas data doesn't
return self.certificateDataFile ? [NSUserDefaults.standardUserDefaults objectForKey:@"LCCertificatePassword"] : @"";
}

+ (void)removeCodeSignatureFromBundleURL:(NSURL *)appURL {
Expand Down

0 comments on commit a374350

Please sign in to comment.