/
InfoWindowController.m
457 lines (370 loc) · 13.9 KB
/
InfoWindowController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
//
// InfoWindowController.m
// WhatsYourSignExt
//
// Created by Patrick Wardle on 7/7/16.
// Copyright (c) 2016 Objective-See. All rights reserved.
//
#import "Item.h"
#import "Consts.h"
#import "Utilities.h"
#import "AppDelegate.h"
#import "InfoWindowController.h"
@implementation InfoWindowController
@synthesize icon;
@synthesize name;
@synthesize path;
@synthesize hashes;
@synthesize closeButton;
@synthesize signingIcon;
@synthesize entitlements;
@synthesize signingStatus;
@synthesize activityIndicator;
@synthesize entitlementsWindowController;
//automatically called when nib is loaded
// ->center window
-(void)awakeFromNib
{
//center
[self.window center];
return;
}
//automatically invoked when window is loaded
// ->set to white
-(void)windowDidLoad
{
//super
[super windowDidLoad];
//indicate title bar is transparent (too)
self.window.titlebarAppearsTransparent = YES;
//not in dark mode?
// make window white
if(YES != isDarkMode())
{
//make white
self.window.backgroundColor = NSColor.whiteColor;
}
//set name
self.name.stringValue = self.item.name;
//set path
self.path.stringValue = self.item.path;
//set icon
self.icon.image = [self.item getIcon];
//set type
self.type.stringValue = self.item.type.capitalizedString;
//show spinner
[self.activityIndicator setHidden:NO];
//start spinner
[self.activityIndicator startAnimation:nil];
//make it key window
[self.window makeKeyAndOrderFront:self];
//make window front
[NSApp activateIgnoringOtherApps:YES];
//make 'close' first responder
// calling this without a timeout sometimes fails :/
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
//and make it first responder
[self.window makeFirstResponder:self.closeButton];
});
return;
}
//process item's code signing info
// ->sets code signing icon, summary, and formats signing auths
-(void)processCodeSigningInfo
{
//signing icon
NSImage* csIcon = nil;
//summary (top)
NSMutableString* csSummary = nil;
//signing details (bottom)
NSMutableString* csDetails = nil;
//directory flag
BOOL isDirectory = NO;
//alloc string for summary
csSummary = [NSMutableString string];
//stop/hide spinner
[self.activityIndicator stopAnimation:nil];
//hide spinner
[self.activityIndicator setHidden:YES];
//start summary with item name
[csSummary appendString:[self.item.name stringByDeletingPathExtension]];
//process
switch([self.item.signingInfo[KEY_SIGNATURE_STATUS] intValue])
{
//happily signed
case errSecSuccess:
//init string for details
csDetails = [NSMutableString string];
//append to summary
[csSummary appendFormat:@" is validly signed"];
//no signing auths
// usually (always?) adhoc
if(0 == [self.item.signingInfo[KEY_SIGNING_AUTHORITIES] count])
{
//append to details
[csDetails appendString:@"signed, but no signing authorities (adhoc?)"];
}
//add each signing auth
else
{
//add signing auth
for(NSString* signingAuthority in self.item.signingInfo[KEY_SIGNING_AUTHORITIES])
{
//append to details
[csDetails appendString:[NSString stringWithFormat:@"› %@ \n", signingAuthority]];
}
}
//disk images/packages
// don't have much info about who signed it
if( (NSOrderedSame == [self.item.path.pathExtension caseInsensitiveCompare:@"dmg"]) ||
(NSOrderedSame == [self.item.path.pathExtension caseInsensitiveCompare:@"pkg"]) )
{
//set icon to default (signed)
csIcon = [NSImage imageNamed:@"signed"];
//is/was notarized?
if(nil != self.item.signingInfo[KEY_SIGNING_IS_NOTARIZED])
{
//notarized ok
if(errSecSuccess == [self.item.signingInfo[KEY_SIGNING_IS_NOTARIZED] integerValue])
{
//append to summary
[csSummary appendFormat:@" & notarized"];
}
//notarization revoked
else if(errSecCSRevokedNotarization == [self.item.signingInfo[KEY_SIGNING_IS_NOTARIZED] integerValue])
{
//append to summary
[csSummary appendFormat:@", but notarization revoked!"];
}
}
//done
break;
}
//item signed by apple
if(YES == [self.item.signingInfo[KEY_SIGNING_IS_APPLE] boolValue])
{
//set icon
csIcon = [NSImage imageNamed:@"signedApple"];
//set summary details
self.summaryDetails.stringValue = @"(Signer: Apple)";
}
//item signed, third party/ad hoc, etc
else
{
//set
csIcon = [NSImage imageNamed:@"signed"];
//from app store?
if(YES == [self.item.signingInfo[KEY_SIGNING_IS_APP_STORE] boolValue])
{
//set summary details
self.summaryDetails.stringValue = @"(Signer: Mac App Store)";
}
//developer id?
// but not from app store
else if(YES == [self.item.signingInfo[KEY_SIGNING_IS_APPLE_DEV_ID] boolValue])
{
//is/was notarized?
if(nil != self.item.signingInfo[KEY_SIGNING_IS_NOTARIZED])
{
//notarized ok
if(errSecSuccess == [self.item.signingInfo[KEY_SIGNING_IS_NOTARIZED] integerValue])
{
//append to summary
[csSummary appendFormat:@" & notarized"];
}
//notarization revoked
else if(errSecCSRevokedNotarization == [self.item.signingInfo[KEY_SIGNING_IS_NOTARIZED] integerValue])
{
//append to summary
[csSummary appendFormat:@", but notarization revoked!"];
}
}
//set summary details
self.summaryDetails.stringValue = @"(Signer: Apple Dev-ID)";
}
//something else
// ad hoc? 3rd-party?
else
{
//set summary details
self.summaryDetails.stringValue = @"(Signer 3rd-party (adhoc?))";
}
}
break;
//unsigned
case errSecCSUnsigned:
//set image
csIcon = [NSImage imageNamed:@"unsigned"];
//append to summary
[csSummary appendFormat:@" is not signed"];
//set details
csDetails = [NSMutableString stringWithString:@"Unsigned ('errSecCSUnsigned')"];
break;
//revoked
case CSSMERR_TP_CERT_REVOKED:
//set image
csIcon = [NSImage imageNamed:@"unsigned"];
//append to summary
[csSummary appendFormat:@" signed, but certificate revoked!"];
//init string for details
csDetails = [NSMutableString string];
//no signing auths
// usually (always?) adhoc
if(0 == [self.item.signingInfo[KEY_SIGNING_AUTHORITIES] count])
{
//append to details
[csDetails appendString:@"Unavailable, as certificate has been revoked"];
}
//add each signing auth
else
{
//add signing auth
for(NSString* signingAuthority in self.item.signingInfo[KEY_SIGNING_AUTHORITIES])
{
//append to details
[csDetails appendString:[NSString stringWithFormat:@"› %@ \n", signingAuthority]];
}
}
break;
//access denied
case kPOSIXErrorEACCES:
//set image
csIcon = [NSImage imageNamed:@"unknown"];
//append to summary
[csSummary appendFormat:@" could not be accessed"];
//details
csDetails = [@"" mutableCopy];
break;
//everything else
// other signing errors
default:
//set image
csIcon = [NSImage imageNamed:@"unknown"];
//append to summary
[csSummary appendFormat:@" has a signing issue"];
//set details
csDetails = [NSMutableString stringWithFormat:@"Unknown (status/error: %ld)", (long)[self.item.signingInfo[KEY_SIGNATURE_STATUS] integerValue]];
break;
}
//assign icon to outlet
self.signingIcon.image = csIcon;
//assign summary to outlet
if(0 != csSummary.length)
{
//set
self.summary.stringValue = csSummary;
}
//no hashes?
if(nil == self.item.hashes)
{
//bundle?
// give a more specific error msg
if( (YES == [[NSFileManager defaultManager] fileExistsAtPath:self.item.path isDirectory:&isDirectory]) &&
(YES == isDirectory) )
{
//set
self.hashes.stringValue = @"None (item is a directory)";
}
//generic error msg
else
{
//set
self.hashes.stringValue = @"?";
}
}
//create clickable 'show hashes' label
else
{
//create/set attributes string
self.hashes.attributedStringValue = [[NSMutableAttributedString alloc] initWithString:@"View Hashes" attributes:@{NSLinkAttributeName:[NSURL URLWithString:@"#"], NSForegroundColorAttributeName:[NSColor blueColor], NSUnderlineStyleAttributeName:[NSNumber numberWithInt:NSSingleUnderlineStyle]}];
//add click event handler
[self.hashes addGestureRecognizer:[[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(showHashes:)]];
}
//no entitlements?
if(0 == [self.item.signingInfo[KEY_SIGNING_ENTITLEMENTS] count])
{
//couldn't access?
if(kPOSIXErrorEACCES == [self.item.signingInfo[KEY_SIGNATURE_STATUS] intValue])
{
self.entitlements.stringValue = @"?";
}
//none for real
else
{
//set
self.entitlements.stringValue = @"None";
}
}
//create clickable 'show entitlements' label
else
{
//create/set attributes string
self.entitlements.attributedStringValue = [[NSMutableAttributedString alloc] initWithString:@"View Entitlements" attributes:@{NSLinkAttributeName:[NSURL URLWithString:@"#"], NSForegroundColorAttributeName:[NSColor blueColor], NSUnderlineStyleAttributeName:[NSNumber numberWithInt:NSSingleUnderlineStyle]}];
//add click event handler
[self.entitlements addGestureRecognizer:[[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(showEntitlements:)]];
}
//have signing auths?
if(0 != csDetails.length)
{
//set
self.signingStatus.stringValue = csDetails;
}
//none
else
{
//set signing auths
if(kPOSIXErrorEACCES == [self.item.signingInfo[KEY_SIGNATURE_STATUS] intValue])
{
self.signingStatus.stringValue = @"?";
}
//none for real
else
{
self.signingStatus.stringValue = @"None";
}
}
return;
}
//invoked when user clicks 'show entitlements'
// display entitlements window pane w/ dictionary
- (void)showHashes:(id)sender
{
//dbg msg
//logMsg(LOG_DEBUG, @"showing hashes");
//alloc sheet
self.hashesWindowController = [[HashesWindowController alloc] initWithWindowNibName:@"HashesWindow"];
//save signing info into iVar
self.hashesWindowController.hashes = self.item.hashes;
//show hashes
[self.window beginSheet:self.hashesWindowController.window completionHandler:^(NSModalResponse returnCode) {
//unset window controller
self.hashesWindowController = nil;
}];
return;
}
//invoked when user clicks 'show hashes'
// display hashe window pane w/ dictionary
- (void)showEntitlements:(id)sender
{
//dbg msg
//logMsg(LOG_DEBUG, @"showing entitlements");
//alloc sheet
self.entitlementsWindowController = [[EntitlementsWindowController alloc] initWithWindowNibName:@"EntitlementsWindow"];
//save signing info into iVar
self.entitlementsWindowController.signingInfo = self.item.signingInfo;
//show entitlements
[self.window beginSheet:self.entitlementsWindowController.window completionHandler:^(NSModalResponse returnCode) {
//unset window controller
self.entitlementsWindowController = nil;
}];
return;
}
//invoked when user clicks button
// trigger action such as opening product website, updating, etc
-(IBAction)closeButtonHandler:(id)sender
{
//always close window
[[self window] close];
return;
}
@end