author | snej@snej.local |
Sun Apr 12 22:16:14 2009 -0700 (2009-04-12) | |
changeset 9 | aa5eb3fd6ebf |
parent 2 | 8982b8fada63 |
child 16 | c409dbc4f068 |
permissions | -rw-r--r-- |
snej@0 | 1 |
// |
snej@0 | 2 |
// MYCertificate.h |
snej@0 | 3 |
// MYCrypto |
snej@0 | 4 |
// |
snej@0 | 5 |
// Created by Jens Alfke on 3/26/09. |
snej@0 | 6 |
// Copyright 2009 Jens Alfke. All rights reserved. |
snej@0 | 7 |
// |
snej@0 | 8 |
|
snej@0 | 9 |
#import "MYKeychainItem.h" |
snej@0 | 10 |
|
snej@0 | 11 |
#if !TARGET_OS_IPHONE |
snej@0 | 12 |
#import <Security/cssmtype.h> |
snej@0 | 13 |
#endif |
snej@0 | 14 |
|
snej@0 | 15 |
@class MYPublicKey; |
snej@0 | 16 |
|
snej@0 | 17 |
|
snej@0 | 18 |
/** An X.509 certificate. */ |
snej@0 | 19 |
@interface MYCertificate : MYKeychainItem { |
snej@1 | 20 |
@private |
snej@0 | 21 |
SecCertificateRef _certificateRef; |
snej@0 | 22 |
} |
snej@0 | 23 |
|
snej@0 | 24 |
/** Creates a MYCertificate object for an existing Keychain certificate reference. */ |
snej@8 | 25 |
+ (MYCertificate*) certificateWithCertificateRef: (SecCertificateRef)certificateRef; |
snej@8 | 26 |
|
snej@8 | 27 |
/** Initializes a MYCertificate object for an existing Keychain certificate reference. */ |
snej@0 | 28 |
- (id) initWithCertificateRef: (SecCertificateRef)certificateRef; |
snej@0 | 29 |
|
snej@0 | 30 |
/** Creates a MYCertificate object from exported key data, but does not add it to any keychain. */ |
snej@0 | 31 |
- (id) initWithCertificateData: (NSData*)data; |
snej@0 | 32 |
|
snej@8 | 33 |
/** Checks whether two MYCertificate objects have bit-for-bit identical certificate data. */ |
snej@8 | 34 |
- (BOOL)isEqualToCertificate:(MYCertificate*)cert; |
snej@8 | 35 |
|
snej@1 | 36 |
/** The Keychain object reference for this certificate. */ |
snej@0 | 37 |
@property (readonly) SecCertificateRef certificateRef; |
snej@0 | 38 |
|
snej@0 | 39 |
/** The certificate's data. */ |
snej@0 | 40 |
@property (readonly) NSData *certificateData; |
snej@0 | 41 |
|
snej@0 | 42 |
/** The certificate's public key. */ |
snej@0 | 43 |
@property (readonly) MYPublicKey *publicKey; |
snej@0 | 44 |
|
snej@1 | 45 |
/** The name of the subject (owner) of the certificate. */ |
snej@0 | 46 |
@property (readonly) NSString *commonName; |
snej@1 | 47 |
|
snej@2 | 48 |
|
snej@2 | 49 |
/** @name Mac-Only |
snej@2 | 50 |
* Functionality not available on iPhone. |
snej@2 | 51 |
*/ |
snej@2 | 52 |
//@{ |
snej@1 | 53 |
#if !TARGET_OS_IPHONE |
snej@2 | 54 |
|
snej@2 | 55 |
/** Creates a MYCertificate object from exported key data, but does not add it to any keychain. */ |
snej@2 | 56 |
- (id) initWithCertificateData: (NSData*)data |
snej@2 | 57 |
type: (CSSM_CERT_TYPE) type |
snej@2 | 58 |
encoding: (CSSM_CERT_ENCODING) encoding; |
snej@2 | 59 |
|
snej@1 | 60 |
/** The list (if any) of the subject's email addresses. */ |
snej@0 | 61 |
@property (readonly) NSArray *emailAddresses; |
snej@0 | 62 |
|
snej@0 | 63 |
/** Finds the current 'preferred' certificate for the given name string. */ |
snej@0 | 64 |
+ (MYCertificate*) preferredCertificateForName: (NSString*)name; |
snej@0 | 65 |
|
snej@0 | 66 |
/** Associates the receiver as the preferred certificate for the given name string. */ |
snej@0 | 67 |
- (BOOL) setPreferredCertificateForName: (NSString*)name; |
snej@2 | 68 |
|
snej@0 | 69 |
#endif |
snej@2 | 70 |
//@} |
snej@0 | 71 |
|
snej@8 | 72 |
|
snej@8 | 73 |
/** @name Expert |
snej@8 | 74 |
*/ |
snej@8 | 75 |
//@{ |
snej@8 | 76 |
#if !TARGET_OS_IPHONE |
snej@8 | 77 |
|
snej@8 | 78 |
+ (SecPolicyRef) X509Policy; |
snej@8 | 79 |
+ (SecPolicyRef) SSLPolicy; |
snej@8 | 80 |
+ (SecPolicyRef) SMIMEPolicy; |
snej@8 | 81 |
- (CSSM_CERT_TYPE) certificateType; |
snej@8 | 82 |
- (NSArray*) trustSettings; |
snej@8 | 83 |
- (BOOL) setUserTrust: (SecTrustUserSetting)trustSetting; |
snej@8 | 84 |
|
snej@8 | 85 |
#endif |
snej@8 | 86 |
//@} |
snej@8 | 87 |
|
snej@0 | 88 |
@end |
snej@8 | 89 |
|
snej@8 | 90 |
|
snej@8 | 91 |
NSString* MYPolicyGetName( SecPolicyRef policy ); |
snej@8 | 92 |
NSString* MYTrustDescribe( SecTrustRef trust ); |
snej@8 | 93 |
NSString* MYTrustResultDescribe( SecTrustResultType result ); |