author | snej@snej.local |
Thu Apr 09 22:46:48 2009 -0700 (2009-04-09) | |
changeset 6 | 2d7692f9b6b4 |
parent 3 | 1dfe820d7ebe |
child 8 | 4c0eafa7b233 |
permissions | -rw-r--r-- |
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 |
|
snej@2 | 28 |
#if TARGET_OS_IPHONE && !MYCRYPTO_USE_IPHONE_API |
snej@1 | 29 |
@interface MYKeychain (Private) |
snej@1 | 30 |
- (id) initWithKeychainRef: (SecKeychainRef)keychainRef; |
snej@1 | 31 |
@property (readonly) SecKeychainRef keychainRef, keychainRefOrDefault; |
snej@1 | 32 |
@property (readonly) CSSM_CSP_HANDLE CSPHandle; |
snej@1 | 33 |
@property (readonly) NSString* path; |
snej@1 | 34 |
@end |
snej@1 | 35 |
#endif |
snej@1 | 36 |
|
snej@1 | 37 |
|
snej@0 | 38 |
@interface MYKeychainItem (Private); |
snej@1 | 39 |
- (id) initWithKeychainItemRef: (MYKeychainItemRef)itemRef; |
snej@0 | 40 |
- (NSData*) _getContents: (OSStatus*)outError; |
snej@0 | 41 |
- (NSString*) stringValueOfAttribute: (SecKeychainAttrType)attr; |
snej@0 | 42 |
- (BOOL) setValue: (NSString*)valueStr ofAttribute: (SecKeychainAttrType)attr; |
snej@0 | 43 |
+ (NSData*) _getAttribute: (SecKeychainAttrType)attr ofItem: (MYKeychainItemRef)item; |
snej@0 | 44 |
- (id) _attribute: (SecKeychainAttrType)attribute; |
snej@0 | 45 |
+ (NSString*) _getStringAttribute: (SecKeychainAttrType)attr ofItem: (MYKeychainItemRef)item; |
snej@0 | 46 |
+ (BOOL) _setAttribute: (SecKeychainAttrType)attr ofItem: (MYKeychainItemRef)item |
snej@0 | 47 |
stringValue: (NSString*)stringValue; |
snej@0 | 48 |
@end |
snej@0 | 49 |
|
snej@0 | 50 |
|
snej@0 | 51 |
@interface MYKey (Private) |
snej@1 | 52 |
- (id) initWithKeyData: (NSData*)data; |
snej@0 | 53 |
- (id) _initWithKeyData: (NSData*)data |
snej@0 | 54 |
forKeychain: (SecKeychainRef)keychain; |
snej@1 | 55 |
@property (readonly) SecExternalItemType keyType; |
snej@3 | 56 |
@property (readonly) MYSHA1Digest* _keyDigest; |
snej@3 | 57 |
- (NSData*) _crypt: (NSData *)data operation: (BOOL) op; // YES to encrypt, NO to decrypt |
snej@2 | 58 |
#if !MYCRYPTO_USE_IPHONE_API |
snej@0 | 59 |
@property (readonly) const CSSM_KEY* cssmKey; |
snej@0 | 60 |
- (NSData*) exportKeyInFormat: (SecExternalFormat)format withPEM: (BOOL)withPEM; |
snej@3 | 61 |
- (CSSM_CC_HANDLE) _createSignatureContext: (CSSM_ALGORITHMS)algorithm; |
snej@3 | 62 |
- (CSSM_CC_HANDLE) _createPassThroughContext; |
snej@0 | 63 |
#endif |
snej@0 | 64 |
@property (readonly) NSArray* _itemList; |
snej@0 | 65 |
@end |
snej@0 | 66 |
|
snej@0 | 67 |
|
snej@0 | 68 |
@interface MYSymmetricKey (Private) |
snej@0 | 69 |
+ (MYSymmetricKey*) _generateSymmetricKeyOfSize: (unsigned)keySizeInBits |
snej@0 | 70 |
algorithm: (CCAlgorithm)algorithm |
snej@0 | 71 |
inKeychain: (MYKeychain*)keychain; |
snej@0 | 72 |
@end |
snej@0 | 73 |
|
snej@0 | 74 |
|
snej@0 | 75 |
@interface MYPublicKey (Private) |
snej@0 | 76 |
- (BOOL) setValue: (NSString*)valueStr ofAttribute: (SecKeychainAttrType)attr; |
snej@4 | 77 |
#if !TARGET_OS_IPHONE |
snej@4 | 78 |
- (CSSM_WRAP_KEY*) _unwrappedCSSMKey; |
snej@4 | 79 |
#endif |
snej@0 | 80 |
@end |
snej@0 | 81 |
|
snej@0 | 82 |
|
snej@3 | 83 |
@interface MYPrivateKey (Private) |
snej@3 | 84 |
+ (MYPrivateKey*) _generateRSAKeyPairOfSize: (unsigned)keySize |
snej@3 | 85 |
inKeychain: (MYKeychain*)keychain; |
snej@4 | 86 |
- (id) _initWithKeyRef: (SecKeyRef)privateKey |
snej@4 | 87 |
publicKey: (MYPublicKey*)publicKey; |
snej@3 | 88 |
- (id) _initWithKeyData: (NSData*)privKeyData |
snej@3 | 89 |
publicKeyData: (NSData*)pubKeyData |
snej@3 | 90 |
forKeychain: (SecKeychainRef)keychain |
snej@3 | 91 |
alertTitle: (NSString*)title |
snej@3 | 92 |
alertPrompt: (NSString*)prompt; |
snej@3 | 93 |
- (id) _initWithKeyData: (NSData*)privKeyData |
snej@3 | 94 |
publicKeyData: (NSData*)pubKeyData |
snej@3 | 95 |
forKeychain: (SecKeychainRef)keychain |
snej@3 | 96 |
passphrase: (NSString*)passphrase; |
snej@0 | 97 |
#if !TARGET_OS_IPHONE |
snej@3 | 98 |
- (NSData*) _exportKeyInFormat: (SecExternalFormat)format |
snej@3 | 99 |
withPEM: (BOOL)withPEM |
snej@3 | 100 |
passphrase: (NSString*)passphrase; |
snej@0 | 101 |
#endif |
snej@0 | 102 |
@end |
snej@0 | 103 |
|
snej@0 | 104 |
|
snej@2 | 105 |
#if TARGET_OS_IPHONE && !MYCRYPTO_USE_IPHONE_API |
snej@0 | 106 |
@interface MYCertificate (Private) |
snej@0 | 107 |
- (id) initWithCertificateData: (NSData*)data |
snej@0 | 108 |
type: (CSSM_CERT_TYPE) type |
snej@0 | 109 |
encoding: (CSSM_CERT_ENCODING) encoding; |
snej@0 | 110 |
@end |
snej@0 | 111 |
#endif |
snej@0 | 112 |
|
snej@0 | 113 |
|
snej@0 | 114 |
#undef check |
snej@0 | 115 |
BOOL check(OSStatus err, NSString *what); |
snej@0 | 116 |
|
snej@2 | 117 |
#if !MYCRYPTO_USE_IPHONE_API |
snej@0 | 118 |
BOOL checkcssm(CSSM_RETURN err, NSString *what); |
snej@0 | 119 |
|
snej@0 | 120 |
SecKeyRef importKey(NSData *data, |
snej@0 | 121 |
SecExternalItemType type, |
snej@0 | 122 |
SecKeychainRef keychain, |
snej@0 | 123 |
SecKeyImportExportParameters *params /*non-null*/); |
snej@0 | 124 |
#endif |