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