MYCertificate.h
author Jens Alfke <jens@mooseyard.com>
Wed Jun 10 09:02:18 2009 -0700 (2009-06-10)
changeset 25 38c3c3923e1f
parent 23 39fec79de6e8
child 26 d9c2a06d4e4e
permissions -rw-r--r--
Changed the X.509 version number in generated certs from 1 to 3, so that SecCertificateCreateFromData on iPhone will accept them. :-/
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@21
    15
@class MYPublicKey, MYIdentity, MYCertificateInfo;
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@21
    46
/** The Identity (if any) that this Certificate is part of. */
jens@21
    47
@property (readonly) MYIdentity *identity;
jens@21
    48
jens@21
    49
/** The metadata of the certificate, like the subject name and expiration date. */
jens@21
    50
@property (readonly) MYCertificateInfo *info;
jens@21
    51
jens@21
    52
/** The common name of the subject (owner) of the certificate. */
snej@0
    53
@property (readonly) NSString *commonName;
snej@1
    54
jens@23
    55
/** The list (if any) of the subject's email addresses. */
jens@23
    56
@property (readonly) NSArray *emailAddresses;
jens@23
    57
jens@24
    58
- (SecTrustResultType) evaluateTrustWithPolicy: (SecPolicyRef)policy;
jens@24
    59
- (SecTrustResultType) evaluateTrust;
jens@24
    60
snej@2
    61
snej@2
    62
/** @name Mac-Only
snej@2
    63
 *  Functionality not available on iPhone. 
snej@2
    64
 */
snej@2
    65
//@{
snej@1
    66
#if !TARGET_OS_IPHONE
snej@2
    67
snej@2
    68
/** Creates a MYCertificate object from exported key data, but does not add it to any keychain. */
snej@2
    69
- (id) initWithCertificateData: (NSData*)data
snej@2
    70
                          type: (CSSM_CERT_TYPE) type
snej@2
    71
                      encoding: (CSSM_CERT_ENCODING) encoding;
snej@2
    72
snej@0
    73
/** Finds the current 'preferred' certificate for the given name string. */
snej@0
    74
+ (MYCertificate*) preferredCertificateForName: (NSString*)name;
snej@0
    75
snej@0
    76
/** Associates the receiver as the preferred certificate for the given name string. */
snej@0
    77
- (BOOL) setPreferredCertificateForName: (NSString*)name;
snej@2
    78
snej@0
    79
#endif
snej@2
    80
//@}
snej@0
    81
snej@8
    82
snej@8
    83
/** @name Expert
snej@8
    84
 */
snej@8
    85
//@{
snej@8
    86
snej@8
    87
+ (SecPolicyRef) X509Policy;
snej@8
    88
+ (SecPolicyRef) SSLPolicy;
jens@24
    89
jens@24
    90
#if !TARGET_OS_IPHONE
snej@8
    91
+ (SecPolicyRef) SMIMEPolicy;
snej@8
    92
- (CSSM_CERT_TYPE) certificateType;
snej@8
    93
- (NSArray*) trustSettings;
snej@8
    94
- (BOOL) setUserTrust: (SecTrustUserSetting)trustSetting;
jens@24
    95
#endif
snej@8
    96
    
snej@8
    97
//@}
snej@8
    98
    
snej@0
    99
@end
snej@8
   100
snej@8
   101
jens@24
   102
NSString* MYTrustResultDescribe( SecTrustResultType result );
jens@24
   103
#if !TARGET_OS_IPHONE
snej@8
   104
NSString* MYPolicyGetName( SecPolicyRef policy );
snej@8
   105
NSString* MYTrustDescribe( SecTrustRef trust );
jens@24
   106
#endif