MYCertificate now checks validity of self-signed certs loaded from the keychain (because the Security framework doesn't validate self-signed certs.)
5 // Created by Jens Alfke on 3/26/09.
6 // Copyright 2009 Jens Alfke. All rights reserved.
9 #import "MYKeychainItem.h"
12 #import <Security/cssmtype.h>
15 @class MYPublicKey, MYIdentity, MYCertificateInfo, MYSHA1Digest;
18 /** An X.509 certificate. */
19 @interface MYCertificate : MYKeychainItem {
21 SecCertificateRef _certificateRef;
22 MYCertificateInfo *_info;
25 /** Creates a MYCertificate object for an existing Keychain certificate reference. */
26 + (MYCertificate*) certificateWithCertificateRef: (SecCertificateRef)certificateRef;
28 /** Initializes a MYCertificate object for an existing Keychain certificate reference. */
29 - (id) initWithCertificateRef: (SecCertificateRef)certificateRef;
31 /** Creates a MYCertificate object from exported key data, but does not add it to any keychain. */
32 - (id) initWithCertificateData: (NSData*)data;
34 /** Checks whether two MYCertificate objects have bit-for-bit identical certificate data. */
35 - (BOOL)isEqualToCertificate:(MYCertificate*)cert;
37 /** The Keychain object reference for this certificate. */
38 @property (readonly) SecCertificateRef certificateRef;
40 /** The certificate's data. */
41 @property (readonly) NSData *certificateData;
43 /** The certificate's public key. */
44 @property (readonly) MYPublicKey *publicKey;
46 /** The certificate's public key's SHA-1 digest. */
47 @property (readonly) MYSHA1Digest *publicKeyDigest;
49 /** The Identity (if any) that this Certificate is part of. */
50 @property (readonly) MYIdentity *identity;
52 /** The metadata of the certificate, like the subject name and expiration date. */
53 @property (readonly) MYCertificateInfo *info;
55 /** The common name of the subject (owner) of the certificate. */
56 @property (readonly) NSString *commonName;
58 /** The list (if any) of the subject's email addresses. */
59 @property (readonly) NSArray *emailAddresses;
61 - (SecTrustResultType) evaluateTrustWithPolicy: (SecPolicyRef)policy;
62 - (SecTrustResultType) evaluateTrust;
66 * Functionality not available on iPhone.
71 /** Creates a MYCertificate object from exported key data, but does not add it to any keychain. */
72 - (id) initWithCertificateData: (NSData*)data
73 type: (CSSM_CERT_TYPE) type
74 encoding: (CSSM_CERT_ENCODING) encoding;
76 /** Finds the current 'preferred' certificate for the given name string. */
77 + (MYCertificate*) preferredCertificateForName: (NSString*)name;
79 /** Associates the receiver as the preferred certificate for the given name string. */
80 - (BOOL) setPreferredCertificateForName: (NSString*)name;
90 + (SecPolicyRef) X509Policy;
91 + (SecPolicyRef) SSLPolicy;
94 + (SecPolicyRef) SMIMEPolicy;
95 - (CSSM_CERT_TYPE) certificateType;
96 - (NSArray*) trustSettings;
97 - (BOOL) setUserTrust: (SecTrustUserSetting)trustSetting;
105 NSString* MYTrustResultDescribe( SecTrustResultType result );
106 #if !TARGET_OS_IPHONE
107 NSString* MYPolicyGetName( SecPolicyRef policy );
108 NSString* MYTrustDescribe( SecTrustRef trust );