Whew! MYParsedCertificate can now generate certs from scratch. Also added improvements and fixes to the BER/DER codecs.
5 // Created by Jens Alfke on 3/23/09.
6 // Copyright 2009 Jens Alfke. All rights reserved.
9 #import "MYCryptoConfig.h"
10 #import "MYKeychain.h"
12 #import "MYSymmetricKey.h"
13 #import "MYPublicKey.h"
14 #import "MYPrivateKey.h"
15 #import "MYCertificate.h"
17 #import <Security/Security.h>
20 #if MYCRYPTO_USE_IPHONE_API
21 typedef CFTypeRef SecKeychainAttrType;
22 typedef CFTypeRef SecKeychainItemRef;
23 typedef CFTypeRef SecKeychainRef;
24 typedef CFTypeRef SecExternalItemType;
28 #if TARGET_OS_IPHONE && !MYCRYPTO_USE_IPHONE_API
29 @interface MYKeychain (Private)
30 - (id) initWithKeychainRef: (SecKeychainRef)keychainRef;
31 @property (readonly) SecKeychainRef keychainRef, keychainRefOrDefault;
32 @property (readonly) CSSM_CSP_HANDLE CSPHandle;
33 @property (readonly) NSString* path;
38 @interface MYKeychainItem (Private);
39 - (id) initWithKeychainItemRef: (MYKeychainItemRef)itemRef;
40 - (NSData*) _getContents: (OSStatus*)outError;
41 - (NSString*) stringValueOfAttribute: (SecKeychainAttrType)attr;
42 - (BOOL) setValue: (NSString*)valueStr ofAttribute: (SecKeychainAttrType)attr;
43 + (NSData*) _getAttribute: (SecKeychainAttrType)attr ofItem: (MYKeychainItemRef)item;
44 - (id) _attribute: (SecKeychainAttrType)attribute;
45 + (NSString*) _getStringAttribute: (SecKeychainAttrType)attr ofItem: (MYKeychainItemRef)item;
46 + (BOOL) _setAttribute: (SecKeychainAttrType)attr ofItem: (MYKeychainItemRef)item
47 stringValue: (NSString*)stringValue;
51 @interface MYKey (Private)
52 - (id) initWithKeyData: (NSData*)data;
53 - (id) _initWithKeyData: (NSData*)data
54 forKeychain: (SecKeychainRef)keychain;
55 @property (readonly) SecExternalItemType keyType;
56 @property (readonly) MYSHA1Digest* _keyDigest;
57 - (NSData*) _crypt: (NSData *)data operation: (BOOL) op; // YES to encrypt, NO to decrypt
58 #if !MYCRYPTO_USE_IPHONE_API
59 @property (readonly) const CSSM_KEY* cssmKey;
60 @property (readonly) const CSSM_CSP_HANDLE cssmCSPHandle;
61 - (CSSM_CC_HANDLE) _createSignatureContext: (CSSM_ALGORITHMS)algorithm;
62 - (CSSM_CC_HANDLE) _createPassThroughContext;
64 @property (readonly) NSArray* _itemList;
68 @interface MYSymmetricKey (Private)
69 #if !MYCRYPTO_USE_IPHONE_API
70 - (id) _initWithCSSMKey: (CSSM_KEY*)cssmKey;
72 + (MYSymmetricKey*) _generateSymmetricKeyOfSize: (unsigned)keySizeInBits
73 algorithm: (CCAlgorithm)algorithm
74 inKeychain: (MYKeychain*)keychain;
78 @interface MYPublicKey (Private)
79 - (BOOL) setValue: (NSString*)valueStr ofAttribute: (SecKeychainAttrType)attr;
81 - (CSSM_WRAP_KEY*) _unwrappedCSSMKey;
86 @interface MYPrivateKey (Private)
87 + (MYPrivateKey*) _generateRSAKeyPairOfSize: (unsigned)keySize
88 inKeychain: (MYKeychain*)keychain;
89 - (id) _initWithKeyRef: (SecKeyRef)privateKey
90 publicKey: (MYPublicKey*)publicKey;
91 - (id) _initWithKeyData: (NSData*)privKeyData
92 publicKeyData: (NSData*)pubKeyData
93 forKeychain: (SecKeychainRef)keychain
94 alertTitle: (NSString*)title
95 alertPrompt: (NSString*)prompt;
96 - (id) _initWithKeyData: (NSData*)privKeyData
97 publicKeyData: (NSData*)pubKeyData
98 forKeychain: (SecKeychainRef)keychain
99 passphrase: (NSString*)passphrase;
100 #if !TARGET_OS_IPHONE
101 - (NSData*) _exportKeyInFormat: (SecExternalFormat)format
102 withPEM: (BOOL)withPEM
103 passphrase: (NSString*)passphrase;
108 #if TARGET_OS_IPHONE && !MYCRYPTO_USE_IPHONE_API
109 @interface MYCertificate (Private)
110 - (id) initWithCertificateData: (NSData*)data
111 type: (CSSM_CERT_TYPE) type
112 encoding: (CSSM_CERT_ENCODING) encoding;
118 BOOL check(OSStatus err, NSString *what);
120 #define checksave(CALL) ({OSStatus err=(CALL); check(err,@""#CALL) || (_error=err, NO);})
122 #if !MYCRYPTO_USE_IPHONE_API
123 BOOL checkcssm(CSSM_RETURN err, NSString *what);
125 SecKeyRef importKey(NSData *data,
126 SecExternalItemType type,
127 SecKeychainRef keychain,
128 SecKeyImportExportParameters *params /*non-null*/);
130 NSString* OIDAsString(CSSM_OID OID);
131 CSSM_ALGORITHMS CSSMFromCCAlgorithm( CCAlgorithm ccAlgorithm );
134 CSSM_ALGORITHMS algorithm;
136 } MYCryptoWrappedKeyDesc;