MYCrypto_Private.h
changeset 0 0a6527af039b
child 1 60e4cbbb5128
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/MYCrypto_Private.h	Sat Apr 04 20:42:03 2009 -0700
     1.3 @@ -0,0 +1,124 @@
     1.4 +//
     1.5 +//  MYCrypto_Private.h
     1.6 +//  MYCrypto
     1.7 +//
     1.8 +//  Created by Jens Alfke on 3/23/09.
     1.9 +//  Copyright 2009 Jens Alfke. All rights reserved.
    1.10 +//
    1.11 +
    1.12 +#import "MYKeychain.h"
    1.13 +#import "MYKey.h"
    1.14 +#import "MYSymmetricKey.h"
    1.15 +#import "MYKeyPair.h"
    1.16 +#import "MYCertificate.h"
    1.17 +#import "Test.h"
    1.18 +#import <Security/Security.h>
    1.19 +
    1.20 +/*  The iPhone simulator actually has the Mac OS X security API, not the iPhone one.
    1.21 +    So don't use the iPhone API when configured to run in the simulator. */
    1.22 +#if TARGET_OS_IPHONE
    1.23 +#if !TARGET_IPHONE_SIMULATOR
    1.24 +#define USE_IPHONE_API 1
    1.25 +#endif
    1.26 +#endif
    1.27 +
    1.28 +#ifndef USE_IPHONE_API
    1.29 +#define USE_IPHONE_API 0
    1.30 +#endif
    1.31 +
    1.32 +
    1.33 +#if USE_IPHONE_API
    1.34 +typedef CFTypeRef SecKeychainAttrType;
    1.35 +typedef CFTypeRef SecKeychainItemRef;
    1.36 +typedef CFTypeRef SecKeychainRef;
    1.37 +#endif
    1.38 +
    1.39 +@interface MYKeychainItem (Private);
    1.40 +- (NSData*) _getContents: (OSStatus*)outError;
    1.41 +- (NSString*) stringValueOfAttribute: (SecKeychainAttrType)attr;
    1.42 +- (BOOL) setValue: (NSString*)valueStr ofAttribute: (SecKeychainAttrType)attr;
    1.43 ++ (NSData*) _getAttribute: (SecKeychainAttrType)attr ofItem: (MYKeychainItemRef)item;
    1.44 +- (id) _attribute: (SecKeychainAttrType)attribute;
    1.45 ++ (NSString*) _getStringAttribute: (SecKeychainAttrType)attr ofItem: (MYKeychainItemRef)item;
    1.46 ++ (BOOL) _setAttribute: (SecKeychainAttrType)attr ofItem: (MYKeychainItemRef)item
    1.47 +           stringValue: (NSString*)stringValue;
    1.48 +@end      
    1.49 +
    1.50 +
    1.51 +@interface MYKey (Private)
    1.52 +- (id) _initWithKeyData: (NSData*)data
    1.53 +            forKeychain: (SecKeychainRef)keychain;
    1.54 +#if !USE_IPHONE_API
    1.55 +@property (readonly) const CSSM_KEY* cssmKey;
    1.56 +- (NSData*) exportKeyInFormat: (SecExternalFormat)format withPEM: (BOOL)withPEM;
    1.57 +#endif
    1.58 +@property (readonly) NSArray* _itemList;
    1.59 +@end
    1.60 +
    1.61 +
    1.62 +@interface MYSymmetricKey (Private)
    1.63 ++ (MYSymmetricKey*) _generateSymmetricKeyOfSize: (unsigned)keySizeInBits
    1.64 +                                      algorithm: (CCAlgorithm)algorithm
    1.65 +                                     inKeychain: (MYKeychain*)keychain;
    1.66 +@end
    1.67 +
    1.68 +
    1.69 +@interface MYPublicKey (Private)
    1.70 ++ (MYSHA1Digest*) _digestOfKey: (SecKeyRef)key;
    1.71 +- (BOOL) setValue: (NSString*)valueStr ofAttribute: (SecKeychainAttrType)attr;
    1.72 +@end
    1.73 +
    1.74 +
    1.75 +@interface MYKeyPair (Private)
    1.76 ++ (MYKeyPair*) _generateRSAKeyPairOfSize: (unsigned)keySize
    1.77 +                            inKeychain: (SecKeychainRef)keychain;
    1.78 +- (id) _initWithPublicKeyData: (NSData*)pubKeyData 
    1.79 +               privateKeyData: (NSData*)privKeyData
    1.80 +                  forKeychain: (SecKeychainRef)keychain
    1.81 +                   alertTitle: (NSString*)title
    1.82 +                  alertPrompt: (NSString*)prompt;
    1.83 +- (id) _initWithPublicKeyData: (NSData*)pubKeyData 
    1.84 +               privateKeyData: (NSData*)privKeyData
    1.85 +                  forKeychain: (SecKeychainRef)keychain 
    1.86 +                   passphrase: (NSString*)passphrase;
    1.87 +#if !TARGET_OS_IPHONE
    1.88 +- (NSData*) _exportPrivateKeyInFormat: (SecExternalFormat)format
    1.89 +                              withPEM: (BOOL)withPEM
    1.90 +                           passphrase: (NSString*)passphrase;
    1.91 +#endif
    1.92 +@end
    1.93 +
    1.94 +
    1.95 +#if TARGET_OS_IPHONE && !USE_IPHONE_API
    1.96 +@interface MYCertificate (Private)
    1.97 +- (id) initWithCertificateData: (NSData*)data
    1.98 +                          type: (CSSM_CERT_TYPE) type
    1.99 +                      encoding: (CSSM_CERT_ENCODING) encoding;
   1.100 +@end
   1.101 +#endif
   1.102 +
   1.103 +
   1.104 +#if TARGET_OS_IPHONE && !USE_IPHONE_API
   1.105 +@interface MYKeychain (Private)
   1.106 +- (id) initWithKeychainRef: (SecKeychainRef)keychainRef;
   1.107 +@property (readonly) SecKeychainRef keychainRef, keychainRefOrDefault;
   1.108 +@property (readonly) CSSM_CSP_HANDLE CSPHandle;
   1.109 +@property (readonly) NSString* path;
   1.110 +@end
   1.111 +#endif
   1.112 +
   1.113 +
   1.114 +NSData* _crypt(SecKeyRef key, NSData *data, CCOperation op);
   1.115 +
   1.116 +#undef check
   1.117 +BOOL check(OSStatus err, NSString *what);
   1.118 +
   1.119 +#if !USE_IPHONE_API
   1.120 +BOOL checkcssm(CSSM_RETURN err, NSString *what);
   1.121 +
   1.122 +SecKeyRef importKey(NSData *data, 
   1.123 +                    SecExternalItemType type,
   1.124 +                    SecKeychainRef keychain,
   1.125 +                    SecKeyImportExportParameters *params /*non-null*/);
   1.126 +CSSM_CC_HANDLE cssmCreateSignatureContext(SecKeyRef key);
   1.127 +#endif