]> git.saurik.com Git - apple/security.git/blob - certificates/ota_cert_tool/ios_ota_cert_tool/PSCerts.m
Security-57031.30.12.tar.gz
[apple/security.git] / certificates / ota_cert_tool / ios_ota_cert_tool / PSCerts.m
1 //
2 // PSCerts.m
3 // ios_ota_cert_tool
4 //
5 // Created by James Murphy on 12/11/12.
6 // Copyright (c) 2012 James Murphy. All rights reserved.
7 //
8
9 #import "PSCerts.h"
10 #import "PSCertKey.h"
11 #import "PSCert.h"
12
13 @interface PSCerts (PrivateMethods)
14
15 - (void)get_certs:(BOOL)forBadCerts;
16
17 @end
18
19 @implementation PSCerts
20
21 @synthesize certs = _certs;
22
23 - (void)get_certs:(BOOL)forBad
24 {
25 if (nil != _cert_dir_path)
26 {
27 @autoreleasepool
28 {
29 NSFileManager* fileManager = [NSFileManager defaultManager];
30 BOOL isDir = NO;
31 if (![fileManager fileExistsAtPath:_cert_dir_path isDirectory:&isDir] || !isDir)
32 {
33 return;
34 }
35
36 NSDirectoryEnumerator* enumer = [fileManager enumeratorAtPath:_cert_dir_path];
37 if (nil == enumer)
38 {
39 return;
40 }
41
42 for(NSString* cert_path_str in enumer)
43 {
44 if ([cert_path_str hasPrefix:@"."])
45 {
46 continue;
47 }
48
49 NSLog(@"Processing file %@", cert_path_str);
50
51 NSString* full_path = [_cert_dir_path stringByAppendingPathComponent:cert_path_str];
52
53 if (forBad)
54 {
55 PSCertKey* aCertKey = [[PSCertKey alloc] initWithCertFilePath:full_path];
56 if (nil != aCertKey)
57 {
58 [_certs addObject:aCertKey.key_hash];
59 }
60 }
61 else
62 {
63 PSCert* aCert = [[PSCert alloc] initWithCertFilePath:full_path];
64 if (nil != aCert)
65 {
66 [_certs addObject:aCert.cert_hash];
67 }
68
69 }
70 }
71 }
72 }
73 }
74
75 - (id)initWithCertFilePath:(NSString *)filePath forBadCerts:(BOOL)forBad
76 {
77 if (self = [super init])
78 {
79 _cert_dir_path = filePath;
80 _certs = [NSMutableArray array];
81 [self get_certs:forBad];
82 }
83 return self;
84 }
85
86 @end