* Some cleanup. Got the test cases to pass again. v0.3
authorsnej@snej.local
Sun Apr 19 21:19:35 2009 -0700 (2009-04-19)
changeset 143af1d1c0ceb5
parent 13 6fd9177eb6da
child 15 2ac5704e229f
* Some cleanup. Got the test cases to pass again.
* Added some missing copyright notices.
MYCertificate.m
MYCrypto+Cocoa.m
MYCryptoTest.m
MYCrypto_Private.h
MYCryptor.m
MYDecoder.m
MYDigest.m
MYEncoder.m
MYIdentity.m
MYKey.m
MYKeychainItem.m
MYPrivateKey.m
MYPublicKey.h
MYPublicKey.m
MYSymmetricKey-iPhone.m
MYSymmetricKey.h
MYSymmetricKey.m
     1.1 --- a/MYCertificate.m	Sun Apr 19 00:01:41 2009 -0700
     1.2 +++ b/MYCertificate.m	Sun Apr 19 21:19:35 2009 -0700
     1.3 @@ -267,3 +267,27 @@
     1.4  
     1.5  
     1.6  #endif !MYCRYPTO_USE_IPHONE_API
     1.7 +
     1.8 +
     1.9 +
    1.10 +/*
    1.11 + Copyright (c) 2009, Jens Alfke <jens@mooseyard.com>. All rights reserved.
    1.12 + 
    1.13 + Redistribution and use in source and binary forms, with or without modification, are permitted
    1.14 + provided that the following conditions are met:
    1.15 + 
    1.16 + * Redistributions of source code must retain the above copyright notice, this list of conditions
    1.17 + and the following disclaimer.
    1.18 + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
    1.19 + and the following disclaimer in the documentation and/or other materials provided with the
    1.20 + distribution.
    1.21 + 
    1.22 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
    1.23 + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
    1.24 + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
    1.25 + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    1.26 + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
    1.27 +  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
    1.28 + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
    1.29 + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.30 + */
     2.1 --- a/MYCrypto+Cocoa.m	Sun Apr 19 00:01:41 2009 -0700
     2.2 +++ b/MYCrypto+Cocoa.m	Sun Apr 19 21:19:35 2009 -0700
     2.3 @@ -46,3 +46,27 @@
     2.4  }
     2.5  
     2.6  @end
     2.7 +
     2.8 +
     2.9 +
    2.10 +/*
    2.11 + Copyright (c) 2009, Jens Alfke <jens@mooseyard.com>. All rights reserved.
    2.12 + 
    2.13 + Redistribution and use in source and binary forms, with or without modification, are permitted
    2.14 + provided that the following conditions are met:
    2.15 + 
    2.16 + * Redistributions of source code must retain the above copyright notice, this list of conditions
    2.17 + and the following disclaimer.
    2.18 + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
    2.19 + and the following disclaimer in the documentation and/or other materials provided with the
    2.20 + distribution.
    2.21 + 
    2.22 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
    2.23 + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
    2.24 + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
    2.25 + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    2.26 + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
    2.27 +  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
    2.28 + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
    2.29 + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2.30 + */
     3.1 --- a/MYCryptoTest.m	Sun Apr 19 00:01:41 2009 -0700
     3.2 +++ b/MYCryptoTest.m	Sun Apr 19 21:19:35 2009 -0700
     3.3 @@ -207,6 +207,7 @@
     3.4  }
     3.5  
     3.6  
     3.7 +#if !TARGET_OS_IPHONE
     3.8  TestCase(MYSymmetricKeyPassphrase) {
     3.9      Log(@"Prompting for raw passphrase --");
    3.10      NSString *rawPassphrase = [MYSymmetricKey promptForPassphraseWithAlertTitle: @"Raw Passphrase Test" 
    3.11 @@ -243,6 +244,7 @@
    3.12      decrypted = [key2 decryptData: encrypted];
    3.13      CAssertEqual(decrypted, cleartext);
    3.14  }
    3.15 +#endif
    3.16  
    3.17  
    3.18  #pragma mark -
    3.19 @@ -265,6 +267,7 @@
    3.20      CAssertEqual(pair.publicKeyDigest, pubKeyDigest);
    3.21      
    3.22      Log(@"SHA1 of pub key = %@", pubKeyData.my_SHA1Digest.asData);
    3.23 +    CAssertEqual(pubKeyData.my_SHA1Digest,pubKeyDigest);
    3.24      
    3.25      // Let's sign data:
    3.26      NSData *data = [@"This is a test. This is only a test!" dataUsingEncoding: NSUTF8StringEncoding];
    3.27 @@ -296,9 +299,13 @@
    3.28  }
    3.29  
    3.30  
    3.31 -static void testWrapSessionKey( MYPrivateKey *privateKey ) {
    3.32 +static void TestWrapSessionKey( MYPrivateKey *privateKey ) {
    3.33 +#if !TARGET_OS_IPHONE
    3.34      MYSymmetricKey *sessionKey = [MYSymmetricKey generateSymmetricKeyOfSize: 128 algorithm:kCCAlgorithmAES128];
    3.35      CAssert(sessionKey);
    3.36 +    NSData *cleartext = [@"This is a test. This is only a test." dataUsingEncoding: NSUTF8StringEncoding];
    3.37 +    NSData *encrypted = [sessionKey encryptData: cleartext];
    3.38 +
    3.39      Log(@"Wrapping session key %@, %@", sessionKey, sessionKey.keyData);
    3.40      NSData *wrapped = [privateKey.publicKey wrapSessionKey: sessionKey];
    3.41      Log(@"Wrapped session key = %u bytes: %@", wrapped.length,wrapped);
    3.42 @@ -309,7 +316,14 @@
    3.43                                                       sizeInBits: 128];
    3.44      Log(@"Unwrapped session key = %@, %@", unwrappedKey, unwrappedKey.keyData);
    3.45      CAssert(unwrappedKey);
    3.46 +    CAssertEq(unwrappedKey.algorithm, sessionKey.algorithm);
    3.47 +    CAssertEq(unwrappedKey.keySizeInBits, sessionKey.keySizeInBits);
    3.48      CAssertEqual(unwrappedKey.keyData, sessionKey.keyData);
    3.49 +
    3.50 +    Log(@"Verifying that unwrapped key works");
    3.51 +    NSData *decrypted = [unwrappedKey decryptData: encrypted];
    3.52 +    CAssertEqual(decrypted, cleartext);
    3.53 +#endif
    3.54  }
    3.55  
    3.56  
    3.57 @@ -323,7 +337,7 @@
    3.58      
    3.59      @try{
    3.60          TestUseKeyPair(pair);
    3.61 -        testWrapSessionKey(pair);
    3.62 +        TestWrapSessionKey(pair);
    3.63          
    3.64          [pair setName: @"Test KeyPair Label"];
    3.65          CAssertEqual(pair.name, @"Test KeyPair Label");
     4.1 --- a/MYCrypto_Private.h	Sun Apr 19 00:01:41 2009 -0700
     4.2 +++ b/MYCrypto_Private.h	Sun Apr 19 21:19:35 2009 -0700
     4.3 @@ -130,4 +130,9 @@
     4.4  NSString* OIDAsString(CSSM_OID OID);
     4.5  CSSM_ALGORITHMS CSSMFromCCAlgorithm( CCAlgorithm ccAlgorithm );
     4.6  
     4.7 +typedef struct {
     4.8 +    CSSM_ALGORITHMS algorithm;
     4.9 +    uint32 sizeInBits;
    4.10 +} MYCryptoWrappedKeyDesc;
    4.11 +
    4.12  #endif
     5.1 --- a/MYCryptor.m	Sun Apr 19 00:01:41 2009 -0700
     5.2 +++ b/MYCryptor.m	Sun Apr 19 21:19:35 2009 -0700
     5.3 @@ -339,3 +339,27 @@
     5.4      [encrypted release];
     5.5      [decrypted release];
     5.6  }
     5.7 +
     5.8 +
     5.9 +
    5.10 +/*
    5.11 + Copyright (c) 2009, Jens Alfke <jens@mooseyard.com>. All rights reserved.
    5.12 + 
    5.13 + Redistribution and use in source and binary forms, with or without modification, are permitted
    5.14 + provided that the following conditions are met:
    5.15 + 
    5.16 + * Redistributions of source code must retain the above copyright notice, this list of conditions
    5.17 + and the following disclaimer.
    5.18 + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
    5.19 + and the following disclaimer in the documentation and/or other materials provided with the
    5.20 + distribution.
    5.21 + 
    5.22 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
    5.23 + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
    5.24 + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
    5.25 + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    5.26 + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
    5.27 +  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
    5.28 + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
    5.29 + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    5.30 + */
     6.1 --- a/MYDecoder.m	Sun Apr 19 00:01:41 2009 -0700
     6.2 +++ b/MYDecoder.m	Sun Apr 19 21:19:35 2009 -0700
     6.3 @@ -370,3 +370,27 @@
     6.4  }
     6.5  
     6.6  #endif DEBUG
     6.7 +
     6.8 +
     6.9 +
    6.10 +/*
    6.11 + Copyright (c) 2009, Jens Alfke <jens@mooseyard.com>. All rights reserved.
    6.12 + 
    6.13 + Redistribution and use in source and binary forms, with or without modification, are permitted
    6.14 + provided that the following conditions are met:
    6.15 + 
    6.16 + * Redistributions of source code must retain the above copyright notice, this list of conditions
    6.17 + and the following disclaimer.
    6.18 + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
    6.19 + and the following disclaimer in the documentation and/or other materials provided with the
    6.20 + distribution.
    6.21 + 
    6.22 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
    6.23 + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
    6.24 + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
    6.25 + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    6.26 + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
    6.27 +  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
    6.28 + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
    6.29 + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    6.30 + */
     7.1 --- a/MYDigest.m	Sun Apr 19 00:01:41 2009 -0700
     7.2 +++ b/MYDigest.m	Sun Apr 19 21:19:35 2009 -0700
     7.3 @@ -282,3 +282,27 @@
     7.4                   @"62A17839B3B86D3543EB2E34D2718A0FE044FA31",
     7.5                   @"FBD25FA6CEE794049973DE3BDF752345617FCA81018C8FC65350BCDD901142DB");
     7.6  }
     7.7 +
     7.8 +
     7.9 +
    7.10 +/*
    7.11 + Copyright (c) 2009, Jens Alfke <jens@mooseyard.com>. All rights reserved.
    7.12 + 
    7.13 + Redistribution and use in source and binary forms, with or without modification, are permitted
    7.14 + provided that the following conditions are met:
    7.15 + 
    7.16 + * Redistributions of source code must retain the above copyright notice, this list of conditions
    7.17 + and the following disclaimer.
    7.18 + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
    7.19 + and the following disclaimer in the documentation and/or other materials provided with the
    7.20 + distribution.
    7.21 + 
    7.22 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
    7.23 + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
    7.24 + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
    7.25 + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    7.26 + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
    7.27 +  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
    7.28 + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
    7.29 + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    7.30 + */
     8.1 --- a/MYEncoder.m	Sun Apr 19 00:01:41 2009 -0700
     8.2 +++ b/MYEncoder.m	Sun Apr 19 21:19:35 2009 -0700
     8.3 @@ -199,3 +199,27 @@
     8.4      Log(@"MYEncoder signed/encrypted %u bytes into %u bytes", source.length,encoded.length);
     8.5  }
     8.6  #endif
     8.7 +
     8.8 +
     8.9 +
    8.10 +/*
    8.11 + Copyright (c) 2009, Jens Alfke <jens@mooseyard.com>. All rights reserved.
    8.12 + 
    8.13 + Redistribution and use in source and binary forms, with or without modification, are permitted
    8.14 + provided that the following conditions are met:
    8.15 + 
    8.16 + * Redistributions of source code must retain the above copyright notice, this list of conditions
    8.17 + and the following disclaimer.
    8.18 + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
    8.19 + and the following disclaimer in the documentation and/or other materials provided with the
    8.20 + distribution.
    8.21 + 
    8.22 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
    8.23 + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
    8.24 + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
    8.25 + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    8.26 + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
    8.27 +  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
    8.28 + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
    8.29 + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    8.30 + */
     9.1 --- a/MYIdentity.m	Sun Apr 19 00:01:41 2009 -0700
     9.2 +++ b/MYIdentity.m	Sun Apr 19 21:19:35 2009 -0700
     9.3 @@ -96,3 +96,27 @@
     9.4  #endif !TARGET_OS_IPHONE
     9.5  
     9.6  @end
     9.7 +
     9.8 +
     9.9 +
    9.10 +/*
    9.11 + Copyright (c) 2009, Jens Alfke <jens@mooseyard.com>. All rights reserved.
    9.12 + 
    9.13 + Redistribution and use in source and binary forms, with or without modification, are permitted
    9.14 + provided that the following conditions are met:
    9.15 + 
    9.16 + * Redistributions of source code must retain the above copyright notice, this list of conditions
    9.17 + and the following disclaimer.
    9.18 + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
    9.19 + and the following disclaimer in the documentation and/or other materials provided with the
    9.20 + distribution.
    9.21 + 
    9.22 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
    9.23 + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
    9.24 + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
    9.25 + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    9.26 + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
    9.27 +  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
    9.28 + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
    9.29 + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    9.30 + */
    10.1 --- a/MYKey.m	Sun Apr 19 00:01:41 2009 -0700
    10.2 +++ b/MYKey.m	Sun Apr 19 21:19:35 2009 -0700
    10.3 @@ -131,7 +131,7 @@
    10.4                      SecExternalItemType type,
    10.5                      SecKeychainRef keychain,
    10.6                      SecKeyImportExportParameters *params) {
    10.7 -    SecExternalFormat inputFormat = (type==kSecItemTypeSessionKey) ?kSecFormatRawKey :kSecFormatOpenSSL;
    10.8 +    SecExternalFormat inputFormat = (type==kSecItemTypeSessionKey) ?kSecFormatRawKey :kSecFormatUnknown;
    10.9      CFArrayRef items = NULL;
   10.10      
   10.11      params->version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION;
   10.12 @@ -142,7 +142,7 @@
   10.13          if (type==kSecItemTypeSessionKey)
   10.14              params->keyUsage = CSSM_KEYUSE_ENCRYPT | CSSM_KEYUSE_DECRYPT;
   10.15          else if (type==kSecItemTypePublicKey)
   10.16 -            params->keyUsage = CSSM_KEYUSE_ENCRYPT | CSSM_KEYUSE_VERIFY;
   10.17 +            params->keyUsage = CSSM_KEYUSE_ENCRYPT | CSSM_KEYUSE_VERIFY | CSSM_KEYUSE_WRAP;
   10.18          else if (type==kSecItemTypePrivateKey)
   10.19              params->keyUsage = CSSM_KEYUSE_DECRYPT | CSSM_KEYUSE_SIGN;
   10.20      }
    11.1 --- a/MYKeychainItem.m	Sun Apr 19 00:01:41 2009 -0700
    11.2 +++ b/MYKeychainItem.m	Sun Apr 19 21:19:35 2009 -0700
    11.3 @@ -97,8 +97,10 @@
    11.4      err = SecItemDelete(self.asQuery);
    11.5  #else
    11.6      err = SecKeychainItemDelete((SecKeychainItemRef)_itemRef);
    11.7 +    if (err==errSecInvalidItemRef)
    11.8 +        return YES;     // result for an item that's not in a keychain
    11.9  #endif
   11.10 -    return err==errSecItemNotFound || err==errSecInvalidItemRef || check(err, @"SecKeychainItemDelete");
   11.11 +    return err==errSecItemNotFound || check(err, @"SecKeychainItemDelete");
   11.12  }
   11.13  
   11.14  
   11.15 @@ -225,3 +227,27 @@
   11.16          return YES;
   11.17  }
   11.18  #endif
   11.19 +
   11.20 +
   11.21 +
   11.22 +/*
   11.23 + Copyright (c) 2009, Jens Alfke <jens@mooseyard.com>. All rights reserved.
   11.24 + 
   11.25 + Redistribution and use in source and binary forms, with or without modification, are permitted
   11.26 + provided that the following conditions are met:
   11.27 + 
   11.28 + * Redistributions of source code must retain the above copyright notice, this list of conditions
   11.29 + and the following disclaimer.
   11.30 + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
   11.31 + and the following disclaimer in the documentation and/or other materials provided with the
   11.32 + distribution.
   11.33 + 
   11.34 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
   11.35 + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
   11.36 + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
   11.37 + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   11.38 + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
   11.39 +  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
   11.40 + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
   11.41 + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   11.42 + */
    12.1 --- a/MYPrivateKey.m	Sun Apr 19 00:01:41 2009 -0700
    12.2 +++ b/MYPrivateKey.m	Sun Apr 19 21:19:35 2009 -0700
    12.3 @@ -340,19 +340,23 @@
    12.4      // Now unwrap the key:
    12.5      MYSymmetricKey *result = nil;
    12.6      CSSM_KEY *unwrappedKey = calloc(1,sizeof(CSSM_KEY));
    12.7 -    CSSM_DATA desc = {};
    12.8 +    CSSM_DATA label = {.Data=(void*)"Imported key", .Length=strlen("Imported key")};
    12.9 +    CSSM_DATA descriptiveData = {};
   12.10      if (checkcssm(CSSM_UnwrapKey(ctx, 
   12.11                                   self.cssmKey,
   12.12                                   &wrappedKey,
   12.13                                   wrappedKey.KeyHeader.KeyUsage,
   12.14                                   wrappedKey.KeyHeader.KeyAttr,
   12.15 -                                 NULL, NULL,
   12.16 +                                 &label,
   12.17 +                                 NULL,
   12.18                                   unwrappedKey,
   12.19 -                                 &desc),
   12.20 +                                 &descriptiveData),
   12.21                    @"CSSM_UnwrapKey")) {
   12.22          result = [[[MYSymmetricKey alloc] _initWithCSSMKey: unwrappedKey] autorelease];
   12.23      }
   12.24      // Finally, delete the context
   12.25 +    if (!result)
   12.26 +        free(unwrappedKey);
   12.27      CSSM_DeleteContext(ctx);
   12.28      return result;
   12.29  }
   12.30 @@ -361,3 +365,27 @@
   12.31  #endif !TARGET_OS_IPHONE
   12.32  
   12.33  @end
   12.34 +
   12.35 +
   12.36 +
   12.37 +/*
   12.38 + Copyright (c) 2009, Jens Alfke <jens@mooseyard.com>. All rights reserved.
   12.39 + 
   12.40 + Redistribution and use in source and binary forms, with or without modification, are permitted
   12.41 + provided that the following conditions are met:
   12.42 + 
   12.43 + * Redistributions of source code must retain the above copyright notice, this list of conditions
   12.44 + and the following disclaimer.
   12.45 + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
   12.46 + and the following disclaimer in the documentation and/or other materials provided with the
   12.47 + distribution.
   12.48 + 
   12.49 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
   12.50 + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
   12.51 + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
   12.52 + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   12.53 + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
   12.54 +  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
   12.55 + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
   12.56 + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   12.57 + */
    13.1 --- a/MYPublicKey.h	Sun Apr 19 00:01:41 2009 -0700
    13.2 +++ b/MYPublicKey.h	Sun Apr 19 21:19:35 2009 -0700
    13.3 @@ -43,10 +43,20 @@
    13.4      (What's actually verified using RSA is the SHA-256 digest of the data.) */
    13.5  - (BOOL) verifySignature: (NSData*)signature ofData: (NSData*)data;
    13.6  
    13.7 +
    13.8 +/** @name Expert
    13.9 + *  Advanced methods. 
   13.10 + */
   13.11 +//@{
   13.12 +#if !TARGET_OS_IPHONE
   13.13 +
   13.14  /** Encrypts a session key using this public key. 
   13.15      The holder of the private key can then unwrap the session key from this data.
   13.16      @param sessionKey  The symmetric session key to wrap/encrypt
   13.17      @return  The encrypted data representing the session key */
   13.18  - (NSData*) wrapSessionKey: (MYSymmetricKey*)sessionKey;
   13.19  
   13.20 +#endif
   13.21 +//@}
   13.22 +
   13.23  @end
    14.1 --- a/MYPublicKey.m	Sun Apr 19 00:01:41 2009 -0700
    14.2 +++ b/MYPublicKey.m	Sun Apr 19 21:19:35 2009 -0700
    14.3 @@ -47,7 +47,7 @@
    14.4  
    14.5  #if !MYCRYPTO_USE_IPHONE_API
    14.6  - (SecExternalFormat) _externalFormat {
    14.7 -    return kSecFormatOpenSSL;
    14.8 +    return kSecFormatBSAFE;
    14.9  }
   14.10  #endif
   14.11  
   14.12 @@ -134,11 +134,12 @@
   14.13                                                      &ctx), 
   14.14                     @"CSSM_CSP_CreateAsymmetricContext"))
   14.15          return nil;
   14.16 -    
   14.17 +        
   14.18      // Now wrap the key:
   14.19      NSData *result = nil;
   14.20      CSSM_WRAP_KEY wrappedKey = {};
   14.21 -    if (checkcssm(CSSM_WrapKey(ctx, credentials, sessionKey.cssmKey, NULL, &wrappedKey),
   14.22 +    CSSM_DATA descriptiveData = {};
   14.23 +    if (checkcssm(CSSM_WrapKey(ctx, credentials, sessionKey.cssmKey, &descriptiveData, &wrappedKey),
   14.24                    @"CSSM_WrapKey")) {
   14.25          // ...and copy the wrapped key data to the result NSData:
   14.26          result = [NSData dataWithBytes: wrappedKey.KeyData.Data length: wrappedKey.KeyData.Length];
    15.1 --- a/MYSymmetricKey-iPhone.m	Sun Apr 19 00:01:41 2009 -0700
    15.2 +++ b/MYSymmetricKey-iPhone.m	Sun Apr 19 21:19:35 2009 -0700
    15.3 @@ -171,3 +171,27 @@
    15.4  
    15.5  
    15.6  #endif MYCRYPTO_USE_IPHONE_API
    15.7 +
    15.8 +
    15.9 +
   15.10 +/*
   15.11 + Copyright (c) 2009, Jens Alfke <jens@mooseyard.com>. All rights reserved.
   15.12 + 
   15.13 + Redistribution and use in source and binary forms, with or without modification, are permitted
   15.14 + provided that the following conditions are met:
   15.15 + 
   15.16 + * Redistributions of source code must retain the above copyright notice, this list of conditions
   15.17 + and the following disclaimer.
   15.18 + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
   15.19 + and the following disclaimer in the documentation and/or other materials provided with the
   15.20 + distribution.
   15.21 + 
   15.22 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
   15.23 + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
   15.24 + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
   15.25 + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   15.26 + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
   15.27 +  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
   15.28 + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
   15.29 + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   15.30 + */
    16.1 --- a/MYSymmetricKey.h	Sun Apr 19 00:01:41 2009 -0700
    16.2 +++ b/MYSymmetricKey.h	Sun Apr 19 21:19:35 2009 -0700
    16.3 @@ -27,6 +27,17 @@
    16.4  + (MYSymmetricKey*) generateSymmetricKeyOfSize: (unsigned)keySizeInBits
    16.5                                       algorithm: (CCAlgorithm)algorithm;
    16.6  
    16.7 +/** The key's algorithm. */
    16.8 +@property (readonly) CCAlgorithm algorithm;
    16.9 +
   16.10 +/** The key's size/length, in bits. */
   16.11 +@property (readonly) unsigned keySizeInBits;
   16.12 +
   16.13 +
   16.14 +#if !TARGET_OS_IPHONE
   16.15 +
   16.16 +- (NSData*) exportWrappedKeyWithPassphrasePrompt: (NSString*)prompt;
   16.17 +
   16.18  /** Converts a passphrase into a symmetric key.
   16.19      The same passphrase (and salt) will always return the same key, so you can use this method
   16.20      to encrypt and decrypt data using a user-entered passphrase, without having to store the key
   16.21 @@ -47,15 +58,6 @@
   16.22                                                      creating: (BOOL)creating
   16.23                                                          salt: (id)saltObj;
   16.24  
   16.25 -/** The key's algorithm. */
   16.26 -@property (readonly) CCAlgorithm algorithm;
   16.27 -
   16.28 -/** The key's size/length, in bits. */
   16.29 -@property (readonly) unsigned keySizeInBits;
   16.30 -
   16.31 -- (NSData*) exportWrappedKeyWithPassphrasePrompt: (NSString*)prompt;
   16.32 -
   16.33 -
   16.34  /** A utility that prompts for a passphrase, using the Security agent's nice modal panel,
   16.35      and returns the raw passphrase as a string.
   16.36      @param alertTitle  A title for the alert (this seems to be ignored by the OS).
   16.37 @@ -65,5 +67,6 @@
   16.38  + (NSString*) promptForPassphraseWithAlertTitle: (NSString*)alertTitle
   16.39                                      alertPrompt: (NSString*)prompt
   16.40                                         creating: (BOOL)creating;
   16.41 +#endif TARGET_OS_IPHONE
   16.42  
   16.43  @end
    17.1 --- a/MYSymmetricKey.m	Sun Apr 19 00:01:41 2009 -0700
    17.2 +++ b/MYSymmetricKey.m	Sun Apr 19 21:19:35 2009 -0700
    17.3 @@ -609,3 +609,27 @@
    17.4  	
    17.5  
    17.6  #endif !MYCRYPTO_USE_IPHONE_API
    17.7 +
    17.8 +
    17.9 +
   17.10 +/*
   17.11 + Copyright (c) 2009, Jens Alfke <jens@mooseyard.com>. All rights reserved.
   17.12 + 
   17.13 + Redistribution and use in source and binary forms, with or without modification, are permitted
   17.14 + provided that the following conditions are met:
   17.15 + 
   17.16 + * Redistributions of source code must retain the above copyright notice, this list of conditions
   17.17 + and the following disclaimer.
   17.18 + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
   17.19 + and the following disclaimer in the documentation and/or other materials provided with the
   17.20 + distribution.
   17.21 + 
   17.22 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
   17.23 + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
   17.24 + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
   17.25 + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   17.26 + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
   17.27 +  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
   17.28 + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
   17.29 + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   17.30 + */