1 #include <Security/SecKeychain.h>
2 #include <Security/SecKeyPriv.h>
3 #include <Security/SecKeychainSearch.h>
7 #include "keychain_regressions.h"
8 #include "kc-helpers.h"
12 SecKeychainRef keychain
= createNewKeychain("test", "test");
14 /* Symmetric key tests. */
16 ok_status(SecKeyGenerate(keychain
, CSSM_ALGID_AES
, 128,
17 0 /* contextHandle */,
18 CSSM_KEYUSE_DECRYPT
| CSSM_KEYUSE_ENCRYPT
,
19 CSSM_KEYATTR_EXTRACTABLE
,
20 NULL
, NULL
), "SecKeyGenerate");
23 SecKeychainAttribute sym_attrs
[] =
25 { kSecKeyEncrypt
, sizeof(btrue
), &btrue
}
27 SecKeychainAttributeList sym_attr_list
=
28 { sizeof(sym_attrs
) / sizeof(*sym_attrs
), sym_attrs
};
29 SecKeychainSearchRef search
= NULL
;
30 ok_status(SecKeychainSearchCreateFromAttributes(keychain
,
31 CSSM_DL_DB_RECORD_SYMMETRIC_KEY
, &sym_attr_list
, &search
),
32 "create symmetric encryption key search");
33 SecKeychainItemRef item
= NULL
;
34 ok_status(SecKeychainSearchCopyNext(search
, &item
), "get first key");
36 if (item
) CFRelease(item
);
37 is_status(SecKeychainSearchCopyNext(search
, &item
),
38 errSecItemNotFound
, "copy next returns no more keys");
41 ok_status(SecKeychainSearchCreateFromAttributes(keychain
,
42 CSSM_DL_DB_RECORD_ANY
, NULL
, &search
),
43 "create any item search");
46 ok_status(SecKeychainSearchCopyNext(search
, &item
), "get first key");
48 if (item
) CFRelease(item
);
50 is_status(SecKeychainSearchCopyNext(search
, &item
),
51 errSecItemNotFound
, "copy next returns no more keys");
54 SecKeyRef aes_key2
= NULL
;
55 ok_status(SecKeyGenerate(keychain
, CSSM_ALGID_AES
, 128,
56 0 /* contextHandle */,
57 CSSM_KEYUSE_DECRYPT
| CSSM_KEYUSE_ENCRYPT
,
58 CSSM_KEYATTR_EXTRACTABLE
,
59 NULL
, &aes_key2
), "SecKeyGenerate and get key");
61 is(CFGetRetainCount(aes_key2
), 1, "retain count is 1");
65 ok_status(SecKeychainDelete(keychain
), "%s: SecKeychainDelete", testName
);
69 int kc_12_key_create_symmetric(int argc
, char *const *argv
)