# HG changeset patch # User snej@snej.local # Date 1240201175 25200 # Node ID 3af1d1c0ceb5f20e2f58e05ecadfd46e881d0636 # Parent 6fd9177eb6dad7cab1b6aaf865d6e0e9ad9b669d * Some cleanup. Got the test cases to pass again. * Added some missing copyright notices. diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYCertificate.m --- a/MYCertificate.m Sun Apr 19 00:01:41 2009 -0700 +++ b/MYCertificate.m Sun Apr 19 21:19:35 2009 -0700 @@ -267,3 +267,27 @@ #endif !MYCRYPTO_USE_IPHONE_API + + + +/* + Copyright (c) 2009, Jens Alfke . All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + and the following disclaimer in the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI- + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYCrypto+Cocoa.m --- a/MYCrypto+Cocoa.m Sun Apr 19 00:01:41 2009 -0700 +++ b/MYCrypto+Cocoa.m Sun Apr 19 21:19:35 2009 -0700 @@ -46,3 +46,27 @@ } @end + + + +/* + Copyright (c) 2009, Jens Alfke . All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + and the following disclaimer in the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI- + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYCryptoTest.m --- a/MYCryptoTest.m Sun Apr 19 00:01:41 2009 -0700 +++ b/MYCryptoTest.m Sun Apr 19 21:19:35 2009 -0700 @@ -207,6 +207,7 @@ } +#if !TARGET_OS_IPHONE TestCase(MYSymmetricKeyPassphrase) { Log(@"Prompting for raw passphrase --"); NSString *rawPassphrase = [MYSymmetricKey promptForPassphraseWithAlertTitle: @"Raw Passphrase Test" @@ -243,6 +244,7 @@ decrypted = [key2 decryptData: encrypted]; CAssertEqual(decrypted, cleartext); } +#endif #pragma mark - @@ -265,6 +267,7 @@ CAssertEqual(pair.publicKeyDigest, pubKeyDigest); Log(@"SHA1 of pub key = %@", pubKeyData.my_SHA1Digest.asData); + CAssertEqual(pubKeyData.my_SHA1Digest,pubKeyDigest); // Let's sign data: NSData *data = [@"This is a test. This is only a test!" dataUsingEncoding: NSUTF8StringEncoding]; @@ -296,9 +299,13 @@ } -static void testWrapSessionKey( MYPrivateKey *privateKey ) { +static void TestWrapSessionKey( MYPrivateKey *privateKey ) { +#if !TARGET_OS_IPHONE MYSymmetricKey *sessionKey = [MYSymmetricKey generateSymmetricKeyOfSize: 128 algorithm:kCCAlgorithmAES128]; CAssert(sessionKey); + NSData *cleartext = [@"This is a test. This is only a test." dataUsingEncoding: NSUTF8StringEncoding]; + NSData *encrypted = [sessionKey encryptData: cleartext]; + Log(@"Wrapping session key %@, %@", sessionKey, sessionKey.keyData); NSData *wrapped = [privateKey.publicKey wrapSessionKey: sessionKey]; Log(@"Wrapped session key = %u bytes: %@", wrapped.length,wrapped); @@ -309,7 +316,14 @@ sizeInBits: 128]; Log(@"Unwrapped session key = %@, %@", unwrappedKey, unwrappedKey.keyData); CAssert(unwrappedKey); + CAssertEq(unwrappedKey.algorithm, sessionKey.algorithm); + CAssertEq(unwrappedKey.keySizeInBits, sessionKey.keySizeInBits); CAssertEqual(unwrappedKey.keyData, sessionKey.keyData); + + Log(@"Verifying that unwrapped key works"); + NSData *decrypted = [unwrappedKey decryptData: encrypted]; + CAssertEqual(decrypted, cleartext); +#endif } @@ -323,7 +337,7 @@ @try{ TestUseKeyPair(pair); - testWrapSessionKey(pair); + TestWrapSessionKey(pair); [pair setName: @"Test KeyPair Label"]; CAssertEqual(pair.name, @"Test KeyPair Label"); diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYCrypto_Private.h --- a/MYCrypto_Private.h Sun Apr 19 00:01:41 2009 -0700 +++ b/MYCrypto_Private.h Sun Apr 19 21:19:35 2009 -0700 @@ -130,4 +130,9 @@ NSString* OIDAsString(CSSM_OID OID); CSSM_ALGORITHMS CSSMFromCCAlgorithm( CCAlgorithm ccAlgorithm ); +typedef struct { + CSSM_ALGORITHMS algorithm; + uint32 sizeInBits; +} MYCryptoWrappedKeyDesc; + #endif diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYCryptor.m --- a/MYCryptor.m Sun Apr 19 00:01:41 2009 -0700 +++ b/MYCryptor.m Sun Apr 19 21:19:35 2009 -0700 @@ -339,3 +339,27 @@ [encrypted release]; [decrypted release]; } + + + +/* + Copyright (c) 2009, Jens Alfke . All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + and the following disclaimer in the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI- + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYDecoder.m --- a/MYDecoder.m Sun Apr 19 00:01:41 2009 -0700 +++ b/MYDecoder.m Sun Apr 19 21:19:35 2009 -0700 @@ -370,3 +370,27 @@ } #endif DEBUG + + + +/* + Copyright (c) 2009, Jens Alfke . All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + and the following disclaimer in the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI- + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYDigest.m --- a/MYDigest.m Sun Apr 19 00:01:41 2009 -0700 +++ b/MYDigest.m Sun Apr 19 21:19:35 2009 -0700 @@ -282,3 +282,27 @@ @"62A17839B3B86D3543EB2E34D2718A0FE044FA31", @"FBD25FA6CEE794049973DE3BDF752345617FCA81018C8FC65350BCDD901142DB"); } + + + +/* + Copyright (c) 2009, Jens Alfke . All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + and the following disclaimer in the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI- + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYEncoder.m --- a/MYEncoder.m Sun Apr 19 00:01:41 2009 -0700 +++ b/MYEncoder.m Sun Apr 19 21:19:35 2009 -0700 @@ -199,3 +199,27 @@ Log(@"MYEncoder signed/encrypted %u bytes into %u bytes", source.length,encoded.length); } #endif + + + +/* + Copyright (c) 2009, Jens Alfke . All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + and the following disclaimer in the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI- + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYIdentity.m --- a/MYIdentity.m Sun Apr 19 00:01:41 2009 -0700 +++ b/MYIdentity.m Sun Apr 19 21:19:35 2009 -0700 @@ -96,3 +96,27 @@ #endif !TARGET_OS_IPHONE @end + + + +/* + Copyright (c) 2009, Jens Alfke . All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + and the following disclaimer in the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI- + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYKey.m --- a/MYKey.m Sun Apr 19 00:01:41 2009 -0700 +++ b/MYKey.m Sun Apr 19 21:19:35 2009 -0700 @@ -131,7 +131,7 @@ SecExternalItemType type, SecKeychainRef keychain, SecKeyImportExportParameters *params) { - SecExternalFormat inputFormat = (type==kSecItemTypeSessionKey) ?kSecFormatRawKey :kSecFormatOpenSSL; + SecExternalFormat inputFormat = (type==kSecItemTypeSessionKey) ?kSecFormatRawKey :kSecFormatUnknown; CFArrayRef items = NULL; params->version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION; @@ -142,7 +142,7 @@ if (type==kSecItemTypeSessionKey) params->keyUsage = CSSM_KEYUSE_ENCRYPT | CSSM_KEYUSE_DECRYPT; else if (type==kSecItemTypePublicKey) - params->keyUsage = CSSM_KEYUSE_ENCRYPT | CSSM_KEYUSE_VERIFY; + params->keyUsage = CSSM_KEYUSE_ENCRYPT | CSSM_KEYUSE_VERIFY | CSSM_KEYUSE_WRAP; else if (type==kSecItemTypePrivateKey) params->keyUsage = CSSM_KEYUSE_DECRYPT | CSSM_KEYUSE_SIGN; } diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYKeychainItem.m --- a/MYKeychainItem.m Sun Apr 19 00:01:41 2009 -0700 +++ b/MYKeychainItem.m Sun Apr 19 21:19:35 2009 -0700 @@ -97,8 +97,10 @@ err = SecItemDelete(self.asQuery); #else err = SecKeychainItemDelete((SecKeychainItemRef)_itemRef); + if (err==errSecInvalidItemRef) + return YES; // result for an item that's not in a keychain #endif - return err==errSecItemNotFound || err==errSecInvalidItemRef || check(err, @"SecKeychainItemDelete"); + return err==errSecItemNotFound || check(err, @"SecKeychainItemDelete"); } @@ -225,3 +227,27 @@ return YES; } #endif + + + +/* + Copyright (c) 2009, Jens Alfke . All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + and the following disclaimer in the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI- + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYPrivateKey.m --- a/MYPrivateKey.m Sun Apr 19 00:01:41 2009 -0700 +++ b/MYPrivateKey.m Sun Apr 19 21:19:35 2009 -0700 @@ -340,19 +340,23 @@ // Now unwrap the key: MYSymmetricKey *result = nil; CSSM_KEY *unwrappedKey = calloc(1,sizeof(CSSM_KEY)); - CSSM_DATA desc = {}; + CSSM_DATA label = {.Data=(void*)"Imported key", .Length=strlen("Imported key")}; + CSSM_DATA descriptiveData = {}; if (checkcssm(CSSM_UnwrapKey(ctx, self.cssmKey, &wrappedKey, wrappedKey.KeyHeader.KeyUsage, wrappedKey.KeyHeader.KeyAttr, - NULL, NULL, + &label, + NULL, unwrappedKey, - &desc), + &descriptiveData), @"CSSM_UnwrapKey")) { result = [[[MYSymmetricKey alloc] _initWithCSSMKey: unwrappedKey] autorelease]; } // Finally, delete the context + if (!result) + free(unwrappedKey); CSSM_DeleteContext(ctx); return result; } @@ -361,3 +365,27 @@ #endif !TARGET_OS_IPHONE @end + + + +/* + Copyright (c) 2009, Jens Alfke . All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + and the following disclaimer in the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI- + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYPublicKey.h --- a/MYPublicKey.h Sun Apr 19 00:01:41 2009 -0700 +++ b/MYPublicKey.h Sun Apr 19 21:19:35 2009 -0700 @@ -43,10 +43,20 @@ (What's actually verified using RSA is the SHA-256 digest of the data.) */ - (BOOL) verifySignature: (NSData*)signature ofData: (NSData*)data; + +/** @name Expert + * Advanced methods. + */ +//@{ +#if !TARGET_OS_IPHONE + /** Encrypts a session key using this public key. The holder of the private key can then unwrap the session key from this data. @param sessionKey The symmetric session key to wrap/encrypt @return The encrypted data representing the session key */ - (NSData*) wrapSessionKey: (MYSymmetricKey*)sessionKey; +#endif +//@} + @end diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYPublicKey.m --- a/MYPublicKey.m Sun Apr 19 00:01:41 2009 -0700 +++ b/MYPublicKey.m Sun Apr 19 21:19:35 2009 -0700 @@ -47,7 +47,7 @@ #if !MYCRYPTO_USE_IPHONE_API - (SecExternalFormat) _externalFormat { - return kSecFormatOpenSSL; + return kSecFormatBSAFE; } #endif @@ -134,11 +134,12 @@ &ctx), @"CSSM_CSP_CreateAsymmetricContext")) return nil; - + // Now wrap the key: NSData *result = nil; CSSM_WRAP_KEY wrappedKey = {}; - if (checkcssm(CSSM_WrapKey(ctx, credentials, sessionKey.cssmKey, NULL, &wrappedKey), + CSSM_DATA descriptiveData = {}; + if (checkcssm(CSSM_WrapKey(ctx, credentials, sessionKey.cssmKey, &descriptiveData, &wrappedKey), @"CSSM_WrapKey")) { // ...and copy the wrapped key data to the result NSData: result = [NSData dataWithBytes: wrappedKey.KeyData.Data length: wrappedKey.KeyData.Length]; diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYSymmetricKey-iPhone.m --- a/MYSymmetricKey-iPhone.m Sun Apr 19 00:01:41 2009 -0700 +++ b/MYSymmetricKey-iPhone.m Sun Apr 19 21:19:35 2009 -0700 @@ -171,3 +171,27 @@ #endif MYCRYPTO_USE_IPHONE_API + + + +/* + Copyright (c) 2009, Jens Alfke . All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + and the following disclaimer in the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI- + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYSymmetricKey.h --- a/MYSymmetricKey.h Sun Apr 19 00:01:41 2009 -0700 +++ b/MYSymmetricKey.h Sun Apr 19 21:19:35 2009 -0700 @@ -27,6 +27,17 @@ + (MYSymmetricKey*) generateSymmetricKeyOfSize: (unsigned)keySizeInBits algorithm: (CCAlgorithm)algorithm; +/** The key's algorithm. */ +@property (readonly) CCAlgorithm algorithm; + +/** The key's size/length, in bits. */ +@property (readonly) unsigned keySizeInBits; + + +#if !TARGET_OS_IPHONE + +- (NSData*) exportWrappedKeyWithPassphrasePrompt: (NSString*)prompt; + /** Converts a passphrase into a symmetric key. The same passphrase (and salt) will always return the same key, so you can use this method to encrypt and decrypt data using a user-entered passphrase, without having to store the key @@ -47,15 +58,6 @@ creating: (BOOL)creating salt: (id)saltObj; -/** The key's algorithm. */ -@property (readonly) CCAlgorithm algorithm; - -/** The key's size/length, in bits. */ -@property (readonly) unsigned keySizeInBits; - -- (NSData*) exportWrappedKeyWithPassphrasePrompt: (NSString*)prompt; - - /** A utility that prompts for a passphrase, using the Security agent's nice modal panel, and returns the raw passphrase as a string. @param alertTitle A title for the alert (this seems to be ignored by the OS). @@ -65,5 +67,6 @@ + (NSString*) promptForPassphraseWithAlertTitle: (NSString*)alertTitle alertPrompt: (NSString*)prompt creating: (BOOL)creating; +#endif TARGET_OS_IPHONE @end diff -r 6fd9177eb6da -r 3af1d1c0ceb5 MYSymmetricKey.m --- a/MYSymmetricKey.m Sun Apr 19 00:01:41 2009 -0700 +++ b/MYSymmetricKey.m Sun Apr 19 21:19:35 2009 -0700 @@ -609,3 +609,27 @@ #endif !MYCRYPTO_USE_IPHONE_API + + + +/* + Copyright (c) 2009, Jens Alfke . All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + and the following disclaimer in the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI- + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */