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