author | Jens Alfke <jens@mooseyard.com> |
Tue Jul 21 10:13:08 2009 -0700 (2009-07-21) | |
changeset 27 | d0aadddb9c64 |
parent 24 | 6856e071d25a |
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 |
|
jens@26 | 15 |
@class MYPublicKey, MYIdentity, MYCertificateInfo, MYSHA1Digest; |
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; |
jens@21 | 22 |
MYCertificateInfo *_info; |
snej@0 | 23 |
} |
snej@0 | 24 |
|
snej@0 | 25 |
/** Creates a MYCertificate object for an existing Keychain certificate reference. */ |
snej@8 | 26 |
+ (MYCertificate*) certificateWithCertificateRef: (SecCertificateRef)certificateRef; |
snej@8 | 27 |
|
snej@8 | 28 |
/** Initializes a MYCertificate object for an existing Keychain certificate reference. */ |
snej@0 | 29 |
- (id) initWithCertificateRef: (SecCertificateRef)certificateRef; |
snej@0 | 30 |
|
snej@0 | 31 |
/** Creates a MYCertificate object from exported key data, but does not add it to any keychain. */ |
snej@0 | 32 |
- (id) initWithCertificateData: (NSData*)data; |
snej@0 | 33 |
|
snej@8 | 34 |
/** Checks whether two MYCertificate objects have bit-for-bit identical certificate data. */ |
snej@8 | 35 |
- (BOOL)isEqualToCertificate:(MYCertificate*)cert; |
snej@8 | 36 |
|
snej@1 | 37 |
/** The Keychain object reference for this certificate. */ |
snej@0 | 38 |
@property (readonly) SecCertificateRef certificateRef; |
snej@0 | 39 |
|
snej@0 | 40 |
/** The certificate's data. */ |
snej@0 | 41 |
@property (readonly) NSData *certificateData; |
snej@0 | 42 |
|
snej@0 | 43 |
/** The certificate's public key. */ |
snej@0 | 44 |
@property (readonly) MYPublicKey *publicKey; |
snej@0 | 45 |
|
jens@26 | 46 |
/** The certificate's public key's SHA-1 digest. */ |
jens@26 | 47 |
@property (readonly) MYSHA1Digest *publicKeyDigest; |
jens@26 | 48 |
|
jens@21 | 49 |
/** The Identity (if any) that this Certificate is part of. */ |
jens@21 | 50 |
@property (readonly) MYIdentity *identity; |
jens@21 | 51 |
|
jens@21 | 52 |
/** The metadata of the certificate, like the subject name and expiration date. */ |
jens@21 | 53 |
@property (readonly) MYCertificateInfo *info; |
jens@21 | 54 |
|
jens@21 | 55 |
/** The common name of the subject (owner) of the certificate. */ |
snej@0 | 56 |
@property (readonly) NSString *commonName; |
snej@1 | 57 |
|
jens@23 | 58 |
/** The list (if any) of the subject's email addresses. */ |
jens@23 | 59 |
@property (readonly) NSArray *emailAddresses; |
jens@23 | 60 |
|
jens@24 | 61 |
- (SecTrustResultType) evaluateTrustWithPolicy: (SecPolicyRef)policy; |
jens@24 | 62 |
- (SecTrustResultType) evaluateTrust; |
jens@24 | 63 |
|
snej@2 | 64 |
|
snej@2 | 65 |
/** @name Mac-Only |
snej@2 | 66 |
* Functionality not available on iPhone. |
snej@2 | 67 |
*/ |
snej@2 | 68 |
//@{ |
snej@1 | 69 |
#if !TARGET_OS_IPHONE |
snej@2 | 70 |
|
snej@2 | 71 |
/** Creates a MYCertificate object from exported key data, but does not add it to any keychain. */ |
snej@2 | 72 |
- (id) initWithCertificateData: (NSData*)data |
snej@2 | 73 |
type: (CSSM_CERT_TYPE) type |
snej@2 | 74 |
encoding: (CSSM_CERT_ENCODING) encoding; |
snej@2 | 75 |
|
snej@0 | 76 |
/** Finds the current 'preferred' certificate for the given name string. */ |
snej@0 | 77 |
+ (MYCertificate*) preferredCertificateForName: (NSString*)name; |
snej@0 | 78 |
|
snej@0 | 79 |
/** Associates the receiver as the preferred certificate for the given name string. */ |
snej@0 | 80 |
- (BOOL) setPreferredCertificateForName: (NSString*)name; |
snej@2 | 81 |
|
snej@0 | 82 |
#endif |
snej@2 | 83 |
//@} |
snej@0 | 84 |
|
snej@8 | 85 |
|
snej@8 | 86 |
/** @name Expert |
snej@8 | 87 |
*/ |
snej@8 | 88 |
//@{ |
snej@8 | 89 |
|
snej@8 | 90 |
+ (SecPolicyRef) X509Policy; |
snej@8 | 91 |
+ (SecPolicyRef) SSLPolicy; |
jens@24 | 92 |
|
jens@24 | 93 |
#if !TARGET_OS_IPHONE |
snej@8 | 94 |
+ (SecPolicyRef) SMIMEPolicy; |
snej@8 | 95 |
- (CSSM_CERT_TYPE) certificateType; |
snej@8 | 96 |
- (NSArray*) trustSettings; |
snej@8 | 97 |
- (BOOL) setUserTrust: (SecTrustUserSetting)trustSetting; |
jens@24 | 98 |
#endif |
snej@8 | 99 |
|
snej@8 | 100 |
//@} |
snej@8 | 101 |
|
snej@0 | 102 |
@end |
snej@8 | 103 |
|
snej@8 | 104 |
|
jens@24 | 105 |
NSString* MYTrustResultDescribe( SecTrustResultType result ); |
jens@24 | 106 |
#if !TARGET_OS_IPHONE |
snej@8 | 107 |
NSString* MYPolicyGetName( SecPolicyRef policy ); |
snej@8 | 108 |
NSString* MYTrustDescribe( SecTrustRef trust ); |
jens@24 | 109 |
#endif |