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