]> git.saurik.com Git - apple/security.git/blob - certificates/ota_cert_tool/ios_ota_cert_tool/PSCertKey.m
Security-57031.1.35.tar.gz
[apple/security.git] / certificates / ota_cert_tool / ios_ota_cert_tool / PSCertKey.m
1 //
2 // PSCertKey.m
3 // ios_ota_cert_tool
4 //
5 // Created by James Murphy on 12/12/12.
6 // Copyright (c) 2012 James Murphy. All rights reserved.
7 //
8
9 #import "PSCertKey.h"
10 #import <Security/Security.h>
11 #import "PSUtilities.h"
12
13 @implementation PSCertKey
14
15 @synthesize key_hash = _key_hash;
16
17
18 - (id)initWithCertFilePath:(NSString *)filePath
19 {
20 if ((self = [super init]))
21 {
22 _key_hash = nil;
23
24 CFDataRef temp_cf_data = [PSUtilities readFile:filePath];
25 if (NULL == temp_cf_data)
26 {
27 NSLog(@"PSCertKey: Unable to read data for file %@", filePath);
28 return nil;
29 }
30
31 SecCertificateRef aCert = [PSUtilities getCertificateFromData:temp_cf_data];
32 CFRelease(temp_cf_data);
33 if (NULL != aCert)
34 {
35 CFDataRef temp_key_data = [PSUtilities getKeyDataFromCertificate:aCert];
36 if (NULL != temp_key_data)
37 {
38 _key_hash = [PSUtilities digestAndEncode:temp_key_data useSHA1:YES];
39 CFRelease(temp_key_data);
40 }
41 CFRelease(aCert);
42 }
43 }
44 return self;
45 }
46
47 @end