MYCertificateInfo.h
author Jens Alfke <jens@mooseyard.com>
Sat Jun 06 15:01:28 2009 -0700 (2009-06-06)
changeset 21 2c300b15b381
parent 20 MYParsedCertificate.h@df9da0f6b358
child 22 058394513f33
permissions -rw-r--r--
* Created class MYCertificateRequest, factored out of MYCertificateInfo.
* Added method to create a MYIdentity directly from a MYCertificateRequest.
* Added raw modulus+exponent accessor and initializer for MYPublicKey.
* Removed obsolete MYCertGen code, and the MYPrivateKey identity-creation method that used it.
jens@17
     1
//
jens@21
     2
//  MYCertificateInfo.h
jens@17
     3
//  MYCrypto
jens@17
     4
//
jens@17
     5
//  Created by Jens Alfke on 6/2/09.
jens@17
     6
//  Copyright 2009 Jens Alfke. All rights reserved.
jens@17
     7
//
jens@17
     8
jens@17
     9
#import <Foundation/Foundation.h>
jens@21
    10
@class MYCertificateName, MYCertificate, MYIdentity, MYPublicKey, MYPrivateKey, MYOID;
jens@17
    11
jens@21
    12
/** A parsed X.509 certificate; provides access to the names and metadata. */
jens@21
    13
@interface MYCertificateInfo : NSObject 
jens@17
    14
{
jens@19
    15
    @private
jens@19
    16
    NSArray *_root;
jens@17
    17
}
jens@17
    18
jens@21
    19
/** Initialize by parsing X.509 certificate data.
jens@21
    20
    (More commonly you'll get an instance via MYCertificate's 'info' property.) */
jens@17
    21
- (id) initWithCertificateData: (NSData*)data error: (NSError**)outError;
jens@17
    22
jens@19
    23
/** The date/time at which the certificate first becomes valid. */
jens@21
    24
@property (retain, readonly) NSDate *validFrom;
jens@19
    25
jens@19
    26
/** The date/time at which the certificate expires. */
jens@21
    27
@property (retain, readonly) NSDate *validTo;
jens@19
    28
jens@20
    29
/** Information about the identity of the owner of this certificate. */
jens@20
    30
@property (readonly) MYCertificateName *subject;
jens@19
    31
jens@20
    32
/** Information about the identity that signed/authorized this certificate. */
jens@20
    33
@property (readonly) MYCertificateName *issuer;
jens@19
    34
jens@20
    35
/** Returns YES if the issuer is the same as the subject. (Aka a "self-signed" certificate.) */
jens@20
    36
@property (readonly) BOOL isRoot;
jens@19
    37
jens@21
    38
@end
jens@19
    39
jens@17
    40
jens@19
    41
jens@21
    42
@interface MYCertificateRequest : MYCertificateInfo
jens@21
    43
{
jens@21
    44
    @private
jens@21
    45
    MYPublicKey *_publicKey;
jens@21
    46
}
jens@19
    47
jens@19
    48
/** Initializes a blank instance which can be used to create a new certificate.
jens@19
    49
    The certificate will not contain anything yet other than the public key.
jens@19
    50
    The desired attributes should be set, and then the -selfSignWithPrivateKey:error method called. */
jens@19
    51
- (id) initWithPublicKey: (MYPublicKey*)pubKey;
jens@19
    52
jens@21
    53
/** The date/time at which the certificate first becomes valid. Settable. */
jens@21
    54
@property (retain) NSDate *validFrom;
jens@21
    55
jens@21
    56
/** The date/time at which the certificate expires. Settable */
jens@21
    57
@property (retain) NSDate *validTo;
jens@21
    58
jens@21
    59
/** Encodes the certificate request in X.509 format -- this is NOT a certificate!
jens@21
    60
    It has to be sent to a Certificate Authority to be signed.
jens@21
    61
    If you want to generate a self-signed certificate, use one of the self-signing methods instead. */
jens@21
    62
- (NSData*) requestData: (NSError**)outError;
jens@19
    63
jens@19
    64
/** Signs the certificate using the given private key, which must be the counterpart of the
jens@21
    65
    public key stored in the certificate, and returns the encoded certificate data.
jens@19
    66
    The subject attributes will be copied to the issuer attributes.
jens@19
    67
    If no valid date range has been set yet, it will be set to a range of one year starting from
jens@19
    68
    the current time.
jens@21
    69
    A unique serial number based on the current time will be set. */
jens@21
    70
- (NSData*) selfSignWithPrivateKey: (MYPrivateKey*)privateKey error: (NSError**)outError;
jens@19
    71
jens@21
    72
/** Signs the certificate using the given private key, which must be the counterpart of the
jens@21
    73
    public key stored in the certificate; adds the certificate to the keychain;
jens@21
    74
    and returns a MYIdentity representing the paired certificate and private key. */
jens@21
    75
- (MYIdentity*) createSelfSignedIdentityWithPrivateKey: (MYPrivateKey*)privateKey
jens@21
    76
                                                 error: (NSError**)outError;
jens@17
    77
@end
jens@20
    78
jens@20
    79
jens@20
    80
jens@20
    81
/** An X.509 Name structure, describing the subject or issuer of a certificate.
jens@21
    82
    The properties are settable only if this instance belongs to a MYCertificateRequest;
jens@21
    83
    otherwise trying to set them will raise an exception. */
jens@20
    84
@interface MYCertificateName : NSObject
jens@20
    85
{
jens@20
    86
    @private
jens@20
    87
    NSArray *_components;
jens@20
    88
}
jens@20
    89
jens@20
    90
/** The "common name" (nickname, whatever). */
jens@20
    91
@property (copy) NSString *commonName;
jens@20
    92
jens@20
    93
/** The given/first name. */
jens@20
    94
@property (copy) NSString *givenName;
jens@20
    95
jens@20
    96
/** The surname / last name / family name. */
jens@20
    97
@property (copy) NSString *surname;
jens@20
    98
jens@20
    99
/** A description. */
jens@20
   100
@property (copy) NSString *nameDescription;
jens@20
   101
jens@20
   102
/** The raw email address. */
jens@20
   103
@property (copy) NSString *emailAddress;
jens@20
   104
jens@20
   105
/** Lower-level accessor that returns the value associated with the given OID. */
jens@20
   106
- (NSString*) stringForOID: (MYOID*)oid;
jens@20
   107
jens@20
   108
/** Lower-level accessor that sets the value associated with the given OID. */
jens@20
   109
- (void) setString: (NSString*)value forOID: (MYOID*)oid;
jens@20
   110
jens@20
   111
@end