Browse Source

codesign retaininig signature works now

Kevin Bradley 11 months ago
parent
commit
17ced3b4ee

+ 1 - 1
bootstrapTool/Classes/HelperClass.h

@@ -6,7 +6,7 @@
 + (InputPackage *)packageForDeb:(NSString *)debFile;
 + (NSString *)octalFromSymbols:(NSString *)theSymbols;
 + (NSArray <StatusPackageModel*>*)statusInstalledPackagesFromFile:(NSString *)statusFile;
-+ (NSString *)singleLineReturnForProcess:(NSString *)call;
++ (NSString *)singleLineReturnForProcess:(NSString *)format, ...;
 + (NSArray *)arrayReturnForTask:(NSString *)taskBinary withArguments:(NSArray *)taskArguments;
 + (void)runProcess:(NSString *)call environment:(NSDictionary *)env currentPath:(NSString *)currentPath completion:(void(^)(NSString *output, NSInteger returnStatus))block;
 + (int)runCommand:(NSString *)call environment:(NSDictionary *)env currentPath:(NSString *)currentPath verbose:(BOOL)verbose;

+ 29 - 9
bootstrapTool/Classes/HelperClass.m

@@ -50,7 +50,7 @@
 }
 
 + (NSArray *)arrayReturnForTask:(NSString *)taskBinary withArguments:(NSArray *)taskArguments {
-    NSLog(@"%@ %@", taskBinary, [taskArguments componentsJoinedByString:@" "]);
+    DLog(@"%@ %@", taskBinary, [taskArguments componentsJoinedByString:@" "]);
     NSTask *task = [[NSTask alloc] init];
     NSPipe *pipe = [[NSPipe alloc] init];
     NSFileHandle *handle = [pipe fileHandleForReading];
@@ -70,8 +70,28 @@
     return [temp componentsSeparatedByString:@"\n"];
 }
 
-+ (NSString *)singleLineReturnForProcess:(NSString *)call {
-    return [[self returnForProcess:call] componentsJoinedByString:@"\n"];
++ (NSString *)singleLineReturnForProcess:(NSString *)format, ... {
+    DLog(@"singleLineReturnForProcess");
+    if (format==nil)
+        return nil;
+    char line[200];
+    va_list args;
+    va_start(args, format);
+    va_end(args);
+    NSString *newString = [[NSString alloc] initWithFormat:format arguments:args];
+    DLog(@"running process: %@", newString);
+    FILE* fp = popen([newString UTF8String], "r");
+    NSMutableString *lines = [[NSMutableString alloc]init];
+    if (fp) {
+        while (fgets(line, sizeof line, fp)) {
+            NSString *s = [NSString stringWithCString:line encoding:NSUTF8StringEncoding];
+            s = [s stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+            [lines appendString:s];
+            //[lines addObject:s];
+        }
+    }
+    pclose(fp);
+    return lines;
 }
 
 + (NSArray *)returnForProcess:(NSString *)call {
@@ -149,7 +169,7 @@
     //-rwxr-xr-x root/staff    10860 2011-02-02 03:55 ./Library/Frameworks/CydiaSubstrate.framework/Commands/cycc
     NSArray *lineObjects = [inputLine spaceDelimitedArray];
     
-    //NSLog(@"lineObjects: %@", lineObjects);
+    //DLog(@"lineObjects: %@", lineObjects);
     /*
      
      "drwxr-xr-x",
@@ -308,14 +328,14 @@
 }
 
 + (NSString *)octalFromSymbols:(NSString *)theSymbols {
-    //NSLog(@"%@ %s", self, _cmd);
+    //DLog(@"%@ %s", self, _cmd);
     NSString *U = [theSymbols substringWithRange:NSMakeRange(1, 3)];
     NSString *G = [theSymbols substringWithRange:NSMakeRange(4, 3)];
     NSString *O = [theSymbols substringWithRange:NSMakeRange(7, 3)];
-    //NSLog(@"fileTypeChar: %@", fileTypeChar);
-    //NSLog(@"U; %@", U);
-    //NSLog(@"G; %@", G);
-    //NSLog(@"O; %@", O);
+    //DLog(@"fileTypeChar: %@", fileTypeChar);
+    //DLog(@"U; %@", U);
+    //DLog(@"G; %@", G);
+    //DLog(@"O; %@", O);
     
     //USER
     

+ 7 - 36
bootstrapTool/Classes/InputPackage.m

@@ -246,18 +246,12 @@
     }
 }
 
-//FIXME: change to ldid
 - (void)codesignRetainingSignature:(NSString *)file {
-    NSString *jtp = [HelperClass singleLineReturnForProcess:@"/usr/bin/which jtool"];
-    if (jtp){
+    NSString *ldidPath = [self validLDIDPath];
+    if (ldidPath) {
         [FM removeItemAtPath:@"/tmp/ent.plist" error:nil];
-        [HelperClass singleLineReturnForProcess:[NSString stringWithFormat:@"%@ %@ --ent > /tmp/ent.plist", jtp, file]];
-        NSString *ents = [HelperClass singleLineReturnForProcess:@"/bin/cat /tmp/ent.plist"];
-        DLog(@"ents: %@", ents);
-        NSString *runCommand = [NSString stringWithFormat:@"%@ --sign platform %@ --ent /tmp/ent.plist --inplace", jtp, file];
-        DLog(@"running codesign command: %@", runCommand);
-        NSString *returnValue = [HelperClass singleLineReturnForProcess:runCommand];
-        DLog(@"returnValue: %@", returnValue);
+        [HelperClass singleLineReturnForProcess:[NSString stringWithFormat:@"%@ -e %@ > /tmp/ent.plist", ldidPath, file]];
+        [HelperClass singleLineReturnForProcess:[NSString stringWithFormat:@"%@ -S/tmp/ent.plist %@", ldidPath, file]];
     }
 }
 
@@ -271,30 +265,7 @@
 
 - (void)codesignIfNecessary:(NSString *)file {
     if ([self shouldCodesignFile:file]){
-        NSString *ldidPath = [self validLDIDPath];
-        if (ldidPath) {
-            NSString *runCommand = [NSString stringWithFormat:@"%@ -M %@", ldidPath, file];
-            DLog(@"running codesign command: %@", runCommand);
-            NSString *returnValue = [HelperClass singleLineReturnForProcess:runCommand];
-            DLog(@"returnValue: %@", returnValue);
-        }
-    }
-}
-
-- (void)oldcodesignIfNecessary:(NSString *)file {
-    if (![[[file pathExtension] lowercaseString] isEqualToString:@"dylib"]){
-        return;
-    }
-    NSString *jtp = [HelperClass singleLineReturnForProcess:@"/usr/bin/which jtool"];
-    if (jtp){
-        NSString *proc = [[HelperClass arrayReturnForTask:jtp withArguments:@[@"--sig", file]] componentsJoinedByString:@"\n"];
-        NSLog(@"proc: %@", proc);
-        if ([proc containsString:@"No Code Signing blob detected in this file"]){
-            NSString *runCommand = [NSString stringWithFormat:@"%@ --sign platform %@ --inplace", jtp, file];
-            NSLog(@"running codesign command: %@", runCommand);
-            NSString *returnValue = [HelperClass singleLineReturnForProcess:runCommand];
-            NSLog(@"returnValue: %@", returnValue);
-        }
+        [self codesignRetainingSignature:file];
     }
 }
 
@@ -302,7 +273,7 @@
     
     [self.files enumerateObjectsUsingBlock:^(InputPackageFile * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
         NSString *file = [thePath stringByAppendingPathComponent:obj.path];
-        NSLog(@"check sig file: %@", obj.path);
+        DLog(@"check sig file: %@", obj.path);
         [self flattenIfNecessary:file];
     }];
     
@@ -312,7 +283,7 @@
     if (self.skipSignatureChecks) { return; }
     [self.files enumerateObjectsUsingBlock:^(InputPackageFile * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
         NSString *file = [thePath stringByAppendingPathComponent:obj.path];
-        NSLog(@"check sig file: %@", file);
+        DLog(@"check sig file: %@", file);
         [self codesignIfNecessary:file];
     }];
     

+ 1 - 1
bootstrapTool/Classes/StatusPackageModel.m

@@ -29,7 +29,7 @@
     NSInteger i = 0;
     NSMutableDictionary *predicate = [NSMutableDictionary new];
     while ([stringScanner scanUpToCharactersFromSet:whitespaceAndPunctuationSet intoString:&name]) {
-        // NSLog(@"%@ pass %li", name, (long)i);
+        // DLog(@"%@ pass %li", name, (long)i);
         switch (i) {
             case 0 :
                 predicate[@"package"] = name;

+ 1 - 1
bootstrapTool/main.m

@@ -117,7 +117,7 @@ int main(int argc, char **argv) {
             argc -= optind;
             argv += optind;
             bootstrapPath = [NSString stringWithUTF8String:argv[0]];
-            NSLog(@"bootstrap path: %@?", bootstrapPath);
+            DLog(@"bootstrap path: %@?", bootstrapPath);
             //return 0;
         }