]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_keychain/regressions/kc-15-key-update-valueref.c
Security-58286.260.20.tar.gz
[apple/security.git] / OSX / libsecurity_keychain / regressions / kc-15-key-update-valueref.c
index 5d8f4682af59992a107e2ff49b8ef6d4d8d0df20..6895404003aa79e3267ac246e85b4da79863c25a 100644 (file)
@@ -35,6 +35,7 @@
 #include <CoreFoundation/CoreFoundation.h>
 #include <CoreServices/CoreServices.h>
 #include <Security/Security.h>
+#include <utilities/SecCFRelease.h>
 
 #include <stdlib.h>
 #include <string.h>
@@ -43,7 +44,6 @@
 #include <time.h>
 #include <sys/param.h>
 
-static int quiet = 0;
 static int debug = 1;
 static int verbose = 1;
 
@@ -78,9 +78,9 @@ static void PrintCFStringWithFormat(const char *formatStr, CFStringRef inStr)
     }
 }
 
-const CFStringRef gPrefix = CFSTR("Test Key");
-const CFStringRef gLabel = CFSTR("Test AES Encryption Key");
-const CFStringRef gUUID = CFSTR("550e8400-e29b-41d4-a716-446655441234");
+const CFStringRef g15Prefix = CFSTR("Test Key");
+const CFStringRef g15Label = CFSTR("Test AES Encryption Key");
+const CFStringRef g15UUID = CFSTR("550e8400-e29b-41d4-a716-446655441234");
 
 // CreateSymmetricKey will create a new AES-128 symmetric encryption key
 // with the provided label, application label, and application tag.
@@ -115,7 +115,7 @@ static int CreateSymmetricKey(
        // note: the access descriptor should be the same string as will be used for the item's label,
        // since it's the string that is displayed by the access confirmation dialog to describe the item.
        SecAccessRef access = NULL;
-       status = SecAccessCreate(gLabel, NULL, &access);
+       status = SecAccessCreate(g15Label, NULL, &access);
 
        // create a dictionary of parameters describing the key we want to create
        CFMutableDictionaryRef params = CFDictionaryCreateMutable(NULL, 0,
@@ -127,7 +127,7 @@ static int CreateSymmetricKey(
        CFDictionaryAddValue( params, kSecAttrAccess, access );
        CFDictionaryAddValue( params, kSecAttrKeyClass, kSecAttrKeyClassSymmetric );
        CFDictionaryAddValue( params, kSecAttrKeyType, kSecAttrKeyTypeAES );
-       CFDictionaryAddValue( params, kSecAttrKeySizeInBits, keySize );
+    CFDictionaryAddValue( params, kSecAttrKeySizeInBits, keySize ); CFRelease(keySize);
        CFDictionaryAddValue( params, kSecAttrIsPermanent, kCFBooleanTrue );
        CFDictionaryAddValue( params, kSecAttrCanEncrypt, kCFBooleanTrue );
        CFDictionaryAddValue( params, kSecAttrCanDecrypt, kCFBooleanTrue );
@@ -180,10 +180,11 @@ static int TestUpdateItems(SecKeychainRef keychain)
        // first, create a symmetric key
        CFGregorianDate curGDate = CFAbsoluteTimeGetGregorianDate(CFAbsoluteTimeGetCurrent(), NULL);
        CFStringRef curDateLabel = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%4d-%02d-%02d)"),
-               gPrefix, (int) (curGDate.year), (int) (curGDate.month), (int) (curGDate.day));
+               g15Prefix, (int) (curGDate.year), (int) (curGDate.month), (int) (curGDate.day));
        CFStringRef curAppTag = CFSTR("SecItemUpdate");
 
-       status = CreateSymmetricKey(keychain, curDateLabel, gUUID, curAppTag, noErr);
+       status = CreateSymmetricKey(keychain, curDateLabel, g15UUID, curAppTag, noErr);
+    CFReleaseNull(curDateLabel);
        if (status && status != errSecDuplicateItem)
                ++result;
     
@@ -200,7 +201,7 @@ static int TestUpdateItems(SecKeychainRef keychain)
        CFNumberRef keySize = CFNumberCreate(NULL, kCFNumberIntType, &keySizeValue);
 
        CFDictionaryAddValue( params, kSecAttrKeyType, kSecAttrKeyTypeRSA );
-       CFDictionaryAddValue( params, kSecAttrKeySizeInBits, keySize );
+    CFDictionaryAddValue( params, kSecAttrKeySizeInBits, keySize ); CFReleaseNull(keySize);
        CFDictionaryAddValue( params, kSecAttrLabel, keyLabel );
 //     CFDictionaryAddValue( params, kSecAttrAccess, access );
 // %%% note that SecKeyGeneratePair will create the key pair in the default keychain
@@ -215,8 +216,8 @@ static int TestUpdateItems(SecKeychainRef keychain)
        PrintTestResult("TestUpdateItems: generating key pair", status, noErr);
     
     // Make sure we have the key of interest
-    checkN(testName, makeQueryKeyDictionaryWithLabel(keychain, kSecAttrKeyClassPrivate, keyLabel), 1);
-    checkN(testName, makeQueryKeyDictionaryWithLabel(keychain, kSecAttrKeyClassPrivate, newLabel), 0);
+    checkN(testName, createQueryKeyDictionaryWithLabel(keychain, kSecAttrKeyClassPrivate, keyLabel), 1);
+    checkN(testName, createQueryKeyDictionaryWithLabel(keychain, kSecAttrKeyClassPrivate, newLabel), 0);
 
        // create a query which will match just the private key item (based on its known reference)
        CFMutableDictionaryRef query = CFDictionaryCreateMutable(NULL, 0,
@@ -262,8 +263,8 @@ static int TestUpdateItems(SecKeychainRef keychain)
        PrintTestResult("TestUpdateItems: updating item", status, noErr);
     
     // Make sure label changed
-    checkN(testName, makeQueryKeyDictionaryWithLabel(keychain, kSecAttrKeyClassPrivate, keyLabel), 0);
-    checkN(testName, makeQueryKeyDictionaryWithLabel(keychain, kSecAttrKeyClassPrivate, newLabel), 1);
+    checkN(testName, createQueryKeyDictionaryWithLabel(keychain, kSecAttrKeyClassPrivate, keyLabel), 0);
+    checkN(testName, createQueryKeyDictionaryWithLabel(keychain, kSecAttrKeyClassPrivate, newLabel), 1);
 
        if (publicKey)
                CFRelease(publicKey);