MYParsedCertificate.h
author Jens Alfke <jens@mooseyard.com>
Thu Jun 04 18:36:30 2009 -0700 (2009-06-04)
changeset 19 f6c91b9da05b
parent 17 90a70925562b
child 20 df9da0f6b358
permissions -rw-r--r--
Whew! MYParsedCertificate can now generate certs from scratch. Also added improvements and fixes to the BER/DER codecs.
     1 //
     2 //  MYParsedCertificate.h
     3 //  MYCrypto
     4 //
     5 //  Created by Jens Alfke on 6/2/09.
     6 //  Copyright 2009 Jens Alfke. All rights reserved.
     7 //
     8 
     9 #import <Foundation/Foundation.h>
    10 @class MYCertificate, MYPublicKey, MYPrivateKey, MYOID;
    11 
    12 /** A parsed X.509 certificate. Can be used to get more info about an existing cert,
    13     or to modify a self-signed cert and regenerate it. */
    14 @interface MYParsedCertificate : NSObject 
    15 {
    16     @private
    17     NSData *_data;
    18     NSArray *_root;
    19     MYCertificate *_issuer;
    20 }
    21 
    22 /** Initializes an instance by parsing an existing X.509 certificate's data. */
    23 - (id) initWithCertificateData: (NSData*)data error: (NSError**)outError;
    24 
    25 /** The raw data of the certificate. */
    26 @property (readonly) NSData* certificateData;
    27 
    28 /** The date/time at which the certificate first becomes valid. */
    29 @property (retain) NSDate *validFrom;
    30 
    31 /** The date/time at which the certificate expires. */
    32 @property (retain) NSDate *validTo;
    33 
    34 /** The "common name" (nickname, whatever) of the subject/owner of the certificate. */
    35 @property (copy) NSString *commonName;
    36 
    37 /** The given/first name of the subject/owner of the certificate. */
    38 @property (copy) NSString *givenName;
    39 
    40 /** The surname / last name / family name of the subject/owner of the certificate. */
    41 @property (copy) NSString *surname;
    42 
    43 /** A description of the subject/owner of the certificate. */
    44 @property (copy) NSString *description;
    45 
    46 /** The raw email address of the subject of the certificate. */
    47 @property (copy) NSString *emailAddress;
    48 
    49 /** The public key of the subject of the certificate. */
    50 @property (readonly) MYPublicKey *subjectPublicKey;
    51 
    52 /** Returns YES if the issuer is the same as the subject. (Aka a "self-signed" certificate.) */
    53 @property (readonly) BOOL isRoot;
    54 
    55 /** Associates the certificate to its issuer.
    56     If the cert is not self-signed, you must manually set this property before validating. */
    57 @property (retain) MYCertificate* issuer;
    58 
    59 /** Checks that the issuer's signature is valid and hasn't been tampered with.
    60     If the certificate is root/self-signed, the subjectPublicKey is used to check the signature;
    61     otherwise, the issuer property needs to have been set and its publicKey will be used. */
    62 - (BOOL) validateSignature;
    63 
    64 
    65 // Generating certificates:
    66 
    67 /** Initializes a blank instance which can be used to create a new certificate.
    68     The certificate will not contain anything yet other than the public key.
    69     The desired attributes should be set, and then the -selfSignWithPrivateKey:error method called. */
    70 - (id) initWithPublicKey: (MYPublicKey*)pubKey;
    71 
    72 /** Has the certificate been signed yet? */
    73 @property (readonly) BOOL isSigned;
    74 
    75 /** Signs the certificate using the given private key, which must be the counterpart of the
    76     public key stored in the certificate.
    77     The subject attributes will be copied to the issuer attributes.
    78     If no valid date range has been set yet, it will be set to a range of one year starting from
    79     the current time.
    80     A unique serial number based on the current time will be set.
    81     After this method returns successfully, access the certificateData property to get the
    82     encoded certificate. */
    83 - (BOOL) selfSignWithPrivateKey: (MYPrivateKey*)privateKey error: (NSError**)outError;
    84 
    85 @end