MYCertificate.h
author Jens Alfke <jens@mooseyard.com>
Tue Jun 02 13:16:28 2009 -0700 (2009-06-02)
changeset 16 c409dbc4f068
parent 8 4c0eafa7b233
child 21 2c300b15b381
permissions -rw-r--r--
* Added ASN.1 / BER / DER utilities, to be used in generating and parsing X.509 certs.
* Added Keychain user-interaction-allowed setter. Added doc comments to MYSymmetricKey.
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@16
    15
@class MYPublicKey, MYIdentity;
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
jens@16
    60
/** The Identity (if any) that this Certificate is part of. */
jens@16
    61
@property (readonly) MYIdentity *identity;
jens@16
    62
snej@1
    63
/** The list (if any) of the subject's email addresses. */
snej@0
    64
@property (readonly) NSArray *emailAddresses;
snej@0
    65
snej@0
    66
/** Finds the current 'preferred' certificate for the given name string. */
snej@0
    67
+ (MYCertificate*) preferredCertificateForName: (NSString*)name;
snej@0
    68
snej@0
    69
/** Associates the receiver as the preferred certificate for the given name string. */
snej@0
    70
- (BOOL) setPreferredCertificateForName: (NSString*)name;
snej@2
    71
snej@0
    72
#endif
snej@2
    73
//@}
snej@0
    74
snej@8
    75
snej@8
    76
/** @name Expert
snej@8
    77
 */
snej@8
    78
//@{
snej@8
    79
#if !TARGET_OS_IPHONE
snej@8
    80
snej@8
    81
+ (SecPolicyRef) X509Policy;
snej@8
    82
+ (SecPolicyRef) SSLPolicy;
snej@8
    83
+ (SecPolicyRef) SMIMEPolicy;
snej@8
    84
- (CSSM_CERT_TYPE) certificateType;
snej@8
    85
- (NSArray*) trustSettings;
snej@8
    86
- (BOOL) setUserTrust: (SecTrustUserSetting)trustSetting;
snej@8
    87
    
snej@8
    88
#endif
snej@8
    89
//@}
snej@8
    90
    
snej@0
    91
@end
snej@8
    92
snej@8
    93
snej@8
    94
NSString* MYPolicyGetName( SecPolicyRef policy );
snej@8
    95
NSString* MYTrustDescribe( SecTrustRef trust );
snej@8
    96
NSString* MYTrustResultDescribe( SecTrustResultType result );