1.1 --- a/MYIdentity.m Sun Jun 07 21:53:56 2009 -0700
1.2 +++ b/MYIdentity.m Tue Jul 21 10:13:08 2009 -0700
1.3 @@ -8,6 +8,7 @@
1.4
1.5 #import "MYIdentity.h"
1.6 #import "MYCrypto_Private.h"
1.7 +#import "MYDigest.h"
1.8
1.9
1.10 @implementation MYIdentity
1.11 @@ -45,7 +46,28 @@
1.12 return nil;
1.13 }
1.14 #else
1.15 - Assert(NO,@"-[MYIdentity initWithCertificateRef] isn't implemented for iPhone yet!");//FIX
1.16 + MYSHA1Digest *keyDigest = self.publicKey.publicKeyDigest;
1.17 + if (!keyDigest) {
1.18 + Warn(@"MYIdentity: Couldn't get key digest of cert %@",certificateRef);
1.19 + [self release];
1.20 + return nil;
1.21 + }
1.22 + _identityRef = [self.keychain identityWithDigest: keyDigest].identityRef;
1.23 + if (!_identityRef) {
1.24 + Warn(@"MYIdentity: Couldn't look up identity for cert %@ with %@",certificateRef, keyDigest);
1.25 + [self release];
1.26 + return nil;
1.27 + }
1.28 +
1.29 + // Debugging: Make sure the cert is correct
1.30 + SecCertificateRef identitysCert = NULL;
1.31 + SecIdentityCopyCertificate(_identityRef, &identitysCert);
1.32 + CFDataRef identitysData = SecCertificateCopyData(identitysCert);
1.33 + AssertEqual(self.certificateData, (NSData*)identitysData);
1.34 + CFRelease(identitysData);
1.35 + CFRelease(identitysCert);
1.36 +
1.37 + CFRetain(_identityRef);
1.38 #endif
1.39 }
1.40 return self;
1.41 @@ -77,6 +99,11 @@
1.42 }
1.43
1.44
1.45 +- (BOOL) removeFromKeychain {
1.46 + return [self.privateKey removeFromKeychain] && [super removeFromKeychain];
1.47 +}
1.48 +
1.49 +
1.50 #if !TARGET_OS_IPHONE
1.51
1.52 + (MYIdentity*) preferredIdentityForName: (NSString*)name