5 * Copyright (c) 2008-2010,2012-2014 Apple Inc. All Rights Reserved.
10 Test code for SOSCircle keys
13 #include <CoreFoundation/CoreFoundation.h>
14 #include <Security/SecBase.h>
15 #include <Security/SecItem.h>
16 #include <Security/SecKey.h>
17 #if TARGET_OS_EMBEDDED
18 #include <Security/SecInternal.h>
20 #include <Security/SecItemPriv.h>
23 #include <utilities/SecCFWrappers.h>
24 #include <utilities/iOSforOSX.h>
26 #include "SOSCircle_regressions.h"
28 static SecKeyRef
GeneratePermanentFullECKey(int keySize
, CFStringRef name
)
30 SecKeyRef public_key
= NULL
;
31 SecKeyRef full_key
= NULL
;
33 CFNumberRef key_size_num
= CFNumberCreate(kCFAllocatorDefault
, kCFNumberIntType
, &keySize
);
35 CFDictionaryRef keygen_parameters
= CFDictionaryCreateForCFTypes(kCFAllocatorDefault
,
36 kSecAttrKeyType
, kSecAttrKeyTypeEC
,
37 kSecAttrKeySizeInBits
, key_size_num
,
38 kSecAttrIsPermanent
, kCFBooleanTrue
,
39 kSecAttrAccessible
, kSecAttrAccessibleAlwaysThisDeviceOnly
,
43 CFReleaseNull(key_size_num
);
44 ok_status(SecKeyGeneratePair(keygen_parameters
, &public_key
, &full_key
), "generate EC Key Pair");
45 CFReleaseNull(keygen_parameters
);
46 CFReleaseNull(public_key
);
51 static void tests(void)
53 CFStringRef ourAccountName
= CFSTR("LjzZ2JteIrnHoHWf5hYb1WGqjI");
54 CFStringRef circleName
= kSecAttrAccessibleWhenUnlocked
;
55 CFStringRef keyName
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("ID for %@-%@"), ourAccountName
, circleName
);
56 const int keySize
= 256;
59 SecKeyRef full_key
= GeneratePermanentFullECKey(keySize
, keyName
);
60 ok(full_key
, "EC Key generated");
63 CFNumberRef key_size_num
= CFNumberCreate(kCFAllocatorDefault
, kCFNumberIntType
, &keySize
);
65 CFDictionaryRef keysearch_parameters
= CFDictionaryCreateForCFTypes(kCFAllocatorDefault
,
66 kSecClass
, kSecClassKey
,
67 kSecReturnRef
, kCFBooleanTrue
,
68 kSecAttrKeySizeInBits
, key_size_num
,
69 kSecAttrLabel
, keyName
,
72 CFReleaseNull(key_size_num
);
73 CFReleaseNull(keyName
);
75 CFTypeRef results
= NULL
;
76 ok_status(SecItemCopyMatching(keysearch_parameters
, &results
), "find EC key by attr");
77 ok(results
&& (CFGetTypeID(results
) == SecKeyGetTypeID()), "Got a SecKeyRef");
78 CFReleaseNull(results
);
80 ok_status(SecItemDelete(keysearch_parameters
), "delete EC Key Pair");
82 CFRelease(keysearch_parameters
);
85 int sc_51_persistentEC(int argc
, char *const *argv
)