Skip to content

Commit

Permalink
Merge 6207909 into 5503a88
Browse files Browse the repository at this point in the history
  • Loading branch information
russellhancox committed Jan 25, 2022
2 parents 5503a88 + 6207909 commit 9acd503
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions Source/santactl/Commands/SNTCommandFileInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ @interface SNTCommandFileInfo : SNTCommand <SNTCommandProtocol>
// Properties set from commandline flags
@property(nonatomic) BOOL recursive;
@property(nonatomic) BOOL jsonOutput;
@property(nonatomic) int *certIndex;
@property(nonatomic) NSNumber *certIndex;
@property(nonatomic, copy) NSArray<NSString *> *outputKeyList;
@property(nonatomic, copy) NSDictionary<NSString *, NSRegularExpression *> *outputFilters;

Expand Down Expand Up @@ -589,21 +589,21 @@ - (void)printInfoForFile:(NSString *)path {
// First build up a dictionary containing all the information we want to print out
NSMutableDictionary *outputDict = [NSMutableDictionary dictionary];
if (self.certIndex) {
int index = [self.certIndex intValue];

// --cert-index flag implicitly means that we want only the signing chain. So we find the
// specified certificate in the signing chain, then print out values for all keys in cert.
NSArray *signingChain = self.propertyMap[kSigningChain](self, fileInfo);
if (!signingChain || !signingChain.count) return; // check signing chain isn't empty
int index = 0;
if (*self.certIndex < 0) {
index = (int)signingChain.count - -(*self.certIndex);
if (index < 0) {
index = (int)signingChain.count - -(index);
if (index < 0) {
fprintf(stderr, "Invalid --cert-index: %d\n", *self.certIndex);
fprintf(stderr, "Invalid --cert-index: %d\n", index);
return;
}
} else {
index = *self.certIndex;
if (index >= (int)signingChain.count) {
fprintf(stderr, "Invalid --cert-index: %d\n", *self.certIndex);
fprintf(stderr, "Invalid --cert-index: %d\n", index);
return;
}
}
Expand Down Expand Up @@ -718,7 +718,7 @@ - (NSArray *)parseArguments:(NSArray<NSString *> *)arguments {
[NSString stringWithFormat:@"\n\"%@\" is an invalid argument for --cert-index\n",
arguments[i]]];
}
self.certIndex = &index;
self.certIndex = @(index);
} else if ([arg caseInsensitiveCompare:@"--key"] == NSOrderedSame) {
i += 1; // advance to next argument and grab the key
if (i >= nargs || [arguments[i] hasPrefix:@"--"]) {
Expand Down
4 changes: 2 additions & 2 deletions Source/santactl/Commands/SNTCommandFileInfoTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ @interface SNTCommandFileInfo : NSObject
typedef id (^SNTAttributeBlock)(SNTCommandFileInfo *, SNTFileInfo *);
@property(nonatomic) BOOL recursive;
@property(nonatomic) BOOL jsonOutput;
@property(nonatomic) int *certIndex;
@property(nonatomic) NSNumber *certIndex;
@property(nonatomic, copy) NSArray<NSString *> *outputKeyList;
@property(nonatomic) NSDictionary<NSString *, SNTAttributeBlock> *propertyMap;
+ (NSArray *)fileInfoKeys;
Expand Down Expand Up @@ -71,7 +71,7 @@ - (void)testParseArgumentsKey {

- (void)testParseArgumentsCertIndex {
NSArray *filePaths = [self.cfi parseArguments:@[ @"--cert-index", @"1", @"/usr/bin/yes" ]];
XCTAssertEqual(*self.cfi.certIndex, 1);
XCTAssertEqual([self.cfi.certIndex intValue], 1);
XCTAssertTrue([filePaths containsObject:@"/usr/bin/yes"]);
}

Expand Down

0 comments on commit 9acd503

Please sign in to comment.