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@22
|
42 |
/** A mutable, unsigned certificate that can be filled out and then signed by the issuer.
|
jens@22
|
43 |
Used to generate an identity certificate for a key-pair. */
|
jens@21
|
44 |
@interface MYCertificateRequest : MYCertificateInfo
|
jens@21
|
45 |
{
|
jens@21
|
46 |
@private
|
jens@21
|
47 |
MYPublicKey *_publicKey;
|
jens@21
|
48 |
}
|
jens@19
|
49 |
|
jens@19
|
50 |
/** Initializes a blank instance which can be used to create a new certificate.
|
jens@19
|
51 |
The certificate will not contain anything yet other than the public key.
|
jens@19
|
52 |
The desired attributes should be set, and then the -selfSignWithPrivateKey:error method called. */
|
jens@19
|
53 |
- (id) initWithPublicKey: (MYPublicKey*)pubKey;
|
jens@19
|
54 |
|
jens@21
|
55 |
/** The date/time at which the certificate first becomes valid. Settable. */
|
jens@21
|
56 |
@property (retain) NSDate *validFrom;
|
jens@21
|
57 |
|
jens@21
|
58 |
/** The date/time at which the certificate expires. Settable */
|
jens@21
|
59 |
@property (retain) NSDate *validTo;
|
jens@21
|
60 |
|
jens@21
|
61 |
/** Encodes the certificate request in X.509 format -- this is NOT a certificate!
|
jens@21
|
62 |
It has to be sent to a Certificate Authority to be signed.
|
jens@21
|
63 |
If you want to generate a self-signed certificate, use one of the self-signing methods instead. */
|
jens@21
|
64 |
- (NSData*) requestData: (NSError**)outError;
|
jens@19
|
65 |
|
jens@19
|
66 |
/** Signs the certificate using the given private key, which must be the counterpart of the
|
jens@21
|
67 |
public key stored in the certificate, and returns the encoded certificate data.
|
jens@19
|
68 |
The subject attributes will be copied to the issuer attributes.
|
jens@19
|
69 |
If no valid date range has been set yet, it will be set to a range of one year starting from
|
jens@19
|
70 |
the current time.
|
jens@21
|
71 |
A unique serial number based on the current time will be set. */
|
jens@21
|
72 |
- (NSData*) selfSignWithPrivateKey: (MYPrivateKey*)privateKey error: (NSError**)outError;
|
jens@19
|
73 |
|
jens@21
|
74 |
/** Signs the certificate using the given private key, which must be the counterpart of the
|
jens@21
|
75 |
public key stored in the certificate; adds the certificate to the keychain;
|
jens@21
|
76 |
and returns a MYIdentity representing the paired certificate and private key. */
|
jens@21
|
77 |
- (MYIdentity*) createSelfSignedIdentityWithPrivateKey: (MYPrivateKey*)privateKey
|
jens@21
|
78 |
error: (NSError**)outError;
|
jens@17
|
79 |
@end
|
jens@20
|
80 |
|
jens@20
|
81 |
|
jens@20
|
82 |
|
jens@20
|
83 |
/** An X.509 Name structure, describing the subject or issuer of a certificate.
|
jens@21
|
84 |
The properties are settable only if this instance belongs to a MYCertificateRequest;
|
jens@21
|
85 |
otherwise trying to set them will raise an exception. */
|
jens@20
|
86 |
@interface MYCertificateName : NSObject
|
jens@20
|
87 |
{
|
jens@20
|
88 |
@private
|
jens@20
|
89 |
NSArray *_components;
|
jens@20
|
90 |
}
|
jens@20
|
91 |
|
jens@20
|
92 |
/** The "common name" (nickname, whatever). */
|
jens@20
|
93 |
@property (copy) NSString *commonName;
|
jens@20
|
94 |
|
jens@20
|
95 |
/** The given/first name. */
|
jens@20
|
96 |
@property (copy) NSString *givenName;
|
jens@20
|
97 |
|
jens@20
|
98 |
/** The surname / last name / family name. */
|
jens@20
|
99 |
@property (copy) NSString *surname;
|
jens@20
|
100 |
|
jens@20
|
101 |
/** A description. */
|
jens@20
|
102 |
@property (copy) NSString *nameDescription;
|
jens@20
|
103 |
|
jens@20
|
104 |
/** The raw email address. */
|
jens@20
|
105 |
@property (copy) NSString *emailAddress;
|
jens@20
|
106 |
|
jens@20
|
107 |
/** Lower-level accessor that returns the value associated with the given OID. */
|
jens@20
|
108 |
- (NSString*) stringForOID: (MYOID*)oid;
|
jens@20
|
109 |
|
jens@20
|
110 |
/** Lower-level accessor that sets the value associated with the given OID. */
|
jens@20
|
111 |
- (void) setString: (NSString*)value forOID: (MYOID*)oid;
|
jens@20
|
112 |
|
jens@20
|
113 |
@end
|