snej@0
|
1 |
//
|
snej@0
|
2 |
// MYCrypto_Private.h
|
snej@0
|
3 |
// MYCrypto
|
snej@0
|
4 |
//
|
snej@0
|
5 |
// Created by Jens Alfke on 3/23/09.
|
snej@0
|
6 |
// Copyright 2009 Jens Alfke. All rights reserved.
|
snej@0
|
7 |
//
|
snej@0
|
8 |
|
snej@2
|
9 |
#import "MYCryptoConfig.h"
|
snej@0
|
10 |
#import "MYKeychain.h"
|
snej@0
|
11 |
#import "MYKey.h"
|
snej@0
|
12 |
#import "MYSymmetricKey.h"
|
snej@3
|
13 |
#import "MYPublicKey.h"
|
snej@3
|
14 |
#import "MYPrivateKey.h"
|
snej@0
|
15 |
#import "MYCertificate.h"
|
snej@0
|
16 |
#import "Test.h"
|
snej@0
|
17 |
#import <Security/Security.h>
|
snej@0
|
18 |
|
snej@0
|
19 |
|
snej@2
|
20 |
#if MYCRYPTO_USE_IPHONE_API
|
snej@0
|
21 |
typedef CFTypeRef SecKeychainAttrType;
|
snej@0
|
22 |
typedef CFTypeRef SecKeychainItemRef;
|
snej@0
|
23 |
typedef CFTypeRef SecKeychainRef;
|
snej@1
|
24 |
typedef CFTypeRef SecExternalItemType;
|
snej@0
|
25 |
#endif
|
snej@0
|
26 |
|
snej@1
|
27 |
|
jens@21
|
28 |
@interface MYKeychain (Private)
|
jens@21
|
29 |
- (MYIdentity*) identityWithDigest: (MYSHA1Digest*)pubKeyDigest;
|
snej@2
|
30 |
#if TARGET_OS_IPHONE && !MYCRYPTO_USE_IPHONE_API
|
snej@1
|
31 |
- (id) initWithKeychainRef: (SecKeychainRef)keychainRef;
|
snej@1
|
32 |
@property (readonly) SecKeychainRef keychainRef, keychainRefOrDefault;
|
snej@1
|
33 |
@property (readonly) CSSM_CSP_HANDLE CSPHandle;
|
snej@1
|
34 |
@property (readonly) NSString* path;
|
jens@21
|
35 |
#endif
|
snej@1
|
36 |
@end
|
snej@1
|
37 |
|
snej@1
|
38 |
|
snej@0
|
39 |
@interface MYKeychainItem (Private);
|
snej@1
|
40 |
- (id) initWithKeychainItemRef: (MYKeychainItemRef)itemRef;
|
snej@0
|
41 |
- (NSData*) _getContents: (OSStatus*)outError;
|
snej@0
|
42 |
- (NSString*) stringValueOfAttribute: (SecKeychainAttrType)attr;
|
snej@0
|
43 |
- (BOOL) setValue: (NSString*)valueStr ofAttribute: (SecKeychainAttrType)attr;
|
snej@0
|
44 |
+ (NSData*) _getAttribute: (SecKeychainAttrType)attr ofItem: (MYKeychainItemRef)item;
|
snej@0
|
45 |
- (id) _attribute: (SecKeychainAttrType)attribute;
|
snej@0
|
46 |
+ (NSString*) _getStringAttribute: (SecKeychainAttrType)attr ofItem: (MYKeychainItemRef)item;
|
snej@0
|
47 |
+ (BOOL) _setAttribute: (SecKeychainAttrType)attr ofItem: (MYKeychainItemRef)item
|
snej@0
|
48 |
stringValue: (NSString*)stringValue;
|
snej@0
|
49 |
@end
|
snej@0
|
50 |
|
snej@0
|
51 |
|
snej@0
|
52 |
@interface MYKey (Private)
|
snej@1
|
53 |
- (id) initWithKeyData: (NSData*)data;
|
snej@0
|
54 |
- (id) _initWithKeyData: (NSData*)data
|
snej@0
|
55 |
forKeychain: (SecKeychainRef)keychain;
|
jens@23
|
56 |
@property (readonly) SecExternalItemType keyClass, keyType;
|
snej@3
|
57 |
@property (readonly) MYSHA1Digest* _keyDigest;
|
snej@3
|
58 |
- (NSData*) _crypt: (NSData *)data operation: (BOOL) op; // YES to encrypt, NO to decrypt
|
jens@23
|
59 |
#if MYCRYPTO_USE_IPHONE_API
|
jens@23
|
60 |
+ (SecKeyRef) _addKeyWithInfo: (NSMutableDictionary*)info;
|
jens@23
|
61 |
#else
|
snej@0
|
62 |
@property (readonly) const CSSM_KEY* cssmKey;
|
snej@12
|
63 |
@property (readonly) const CSSM_CSP_HANDLE cssmCSPHandle;
|
snej@3
|
64 |
- (CSSM_CC_HANDLE) _createSignatureContext: (CSSM_ALGORITHMS)algorithm;
|
snej@3
|
65 |
- (CSSM_CC_HANDLE) _createPassThroughContext;
|
snej@0
|
66 |
#endif
|
snej@0
|
67 |
@property (readonly) NSArray* _itemList;
|
snej@0
|
68 |
@end
|
snej@0
|
69 |
|
snej@0
|
70 |
|
snej@0
|
71 |
@interface MYSymmetricKey (Private)
|
snej@13
|
72 |
#if !MYCRYPTO_USE_IPHONE_API
|
snej@13
|
73 |
- (id) _initWithCSSMKey: (CSSM_KEY*)cssmKey;
|
snej@13
|
74 |
#endif
|
snej@0
|
75 |
+ (MYSymmetricKey*) _generateSymmetricKeyOfSize: (unsigned)keySizeInBits
|
snej@0
|
76 |
algorithm: (CCAlgorithm)algorithm
|
snej@0
|
77 |
inKeychain: (MYKeychain*)keychain;
|
snej@0
|
78 |
@end
|
snej@0
|
79 |
|
snej@0
|
80 |
|
snej@0
|
81 |
@interface MYPublicKey (Private)
|
snej@0
|
82 |
- (BOOL) setValue: (NSString*)valueStr ofAttribute: (SecKeychainAttrType)attr;
|
snej@4
|
83 |
#if !TARGET_OS_IPHONE
|
snej@4
|
84 |
- (CSSM_WRAP_KEY*) _unwrappedCSSMKey;
|
snej@4
|
85 |
#endif
|
snej@0
|
86 |
@end
|
snej@0
|
87 |
|
snej@0
|
88 |
|
snej@3
|
89 |
@interface MYPrivateKey (Private)
|
snej@3
|
90 |
+ (MYPrivateKey*) _generateRSAKeyPairOfSize: (unsigned)keySize
|
snej@3
|
91 |
inKeychain: (MYKeychain*)keychain;
|
snej@4
|
92 |
- (id) _initWithKeyRef: (SecKeyRef)privateKey
|
snej@4
|
93 |
publicKey: (MYPublicKey*)publicKey;
|
snej@3
|
94 |
- (id) _initWithKeyData: (NSData*)privKeyData
|
snej@3
|
95 |
publicKeyData: (NSData*)pubKeyData
|
snej@3
|
96 |
forKeychain: (SecKeychainRef)keychain
|
snej@3
|
97 |
alertTitle: (NSString*)title
|
snej@3
|
98 |
alertPrompt: (NSString*)prompt;
|
snej@3
|
99 |
- (id) _initWithKeyData: (NSData*)privKeyData
|
snej@3
|
100 |
publicKeyData: (NSData*)pubKeyData
|
snej@3
|
101 |
forKeychain: (SecKeychainRef)keychain
|
snej@3
|
102 |
passphrase: (NSString*)passphrase;
|
snej@0
|
103 |
#if !TARGET_OS_IPHONE
|
snej@3
|
104 |
- (NSData*) _exportKeyInFormat: (SecExternalFormat)format
|
snej@3
|
105 |
withPEM: (BOOL)withPEM
|
snej@3
|
106 |
passphrase: (NSString*)passphrase;
|
snej@0
|
107 |
#endif
|
snej@0
|
108 |
@end
|
snej@0
|
109 |
|
snej@0
|
110 |
|
snej@2
|
111 |
#if TARGET_OS_IPHONE && !MYCRYPTO_USE_IPHONE_API
|
snej@0
|
112 |
@interface MYCertificate (Private)
|
snej@0
|
113 |
- (id) initWithCertificateData: (NSData*)data
|
snej@0
|
114 |
type: (CSSM_CERT_TYPE) type
|
snej@0
|
115 |
encoding: (CSSM_CERT_ENCODING) encoding;
|
snej@0
|
116 |
@end
|
snej@0
|
117 |
#endif
|
snej@0
|
118 |
|
snej@0
|
119 |
|
snej@0
|
120 |
#undef check
|
snej@0
|
121 |
BOOL check(OSStatus err, NSString *what);
|
snej@0
|
122 |
|
snej@8
|
123 |
#define checksave(CALL) ({OSStatus err=(CALL); check(err,@""#CALL) || (_error=err, NO);})
|
snej@8
|
124 |
|
snej@2
|
125 |
#if !MYCRYPTO_USE_IPHONE_API
|
snej@0
|
126 |
BOOL checkcssm(CSSM_RETURN err, NSString *what);
|
snej@0
|
127 |
|
snej@0
|
128 |
SecKeyRef importKey(NSData *data,
|
snej@0
|
129 |
SecExternalItemType type,
|
snej@0
|
130 |
SecKeychainRef keychain,
|
snej@0
|
131 |
SecKeyImportExportParameters *params /*non-null*/);
|
snej@8
|
132 |
|
snej@8
|
133 |
NSString* OIDAsString(CSSM_OID OID);
|
snej@13
|
134 |
CSSM_ALGORITHMS CSSMFromCCAlgorithm( CCAlgorithm ccAlgorithm );
|
snej@8
|
135 |
|
snej@14
|
136 |
typedef struct {
|
snej@14
|
137 |
CSSM_ALGORITHMS algorithm;
|
snej@14
|
138 |
uint32 sizeInBits;
|
snej@14
|
139 |
} MYCryptoWrappedKeyDesc;
|
snej@14
|
140 |
|
snej@0
|
141 |
#endif
|