diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/mock.c | 113 | ||||
-rw-r--r-- | common/mock.h | 37 |
2 files changed, 142 insertions, 8 deletions
diff --git a/common/mock.c b/common/mock.c index 14fd3ec..411c6eb 100644 --- a/common/mock.c +++ b/common/mock.c @@ -34,6 +34,7 @@ #include "config.h" +#include "debug.h" #include "library.h" #define CRYPTOKI_EXPORTS #include "pkcs11.h" @@ -220,7 +221,7 @@ mock_module_reset_objects (CK_SLOT_ID slot_id) { CKA_LABEL, label, strlen (label) }, { CKA_INVALID, NULL, 0 }, }; - p11_dict_set (the_objects, handle_to_pointer (2), p11_attrs_dup (attrs)); + p11_dict_set (the_objects, handle_to_pointer (MOCK_DATA_OBJECT), p11_attrs_dup (attrs)); } /* Private capitalize key */ @@ -353,8 +354,6 @@ mock_C_Initialize (CK_VOID_PTR init_args) CK_RV ret = CKR_OK; pid_t pid; - p11_debug ("C_Initialize: enter"); - p11_mutex_lock (&init_mutex); if (init_args != NULL) { @@ -369,7 +368,7 @@ mock_C_Initialize (CK_VOID_PTR init_args) (args->CreateMutex != NULL && args->DestroyMutex != NULL && args->LockMutex != NULL && args->UnlockMutex != NULL); if (!supplied_ok) { - p11_debug_precond ("p11-kit: invalid set of mutex calls supplied"); + p11_debug_precond ("invalid set of mutex calls supplied\n"); ret = CKR_ARGUMENTS_BAD; goto done; } @@ -379,7 +378,7 @@ mock_C_Initialize (CK_VOID_PTR init_args) * We must be able to use our pthread functionality. */ if (!(args->flags & CKF_OS_LOCKING_OK)) { - p11_debug_precond ("p11-kit: can't do without os locking"); + p11_debug_precond ("can't do without os locking\n"); ret = CKR_CANT_LOCK; goto done; } @@ -390,7 +389,7 @@ mock_C_Initialize (CK_VOID_PTR init_args) /* This process has called C_Initialize already */ if (pid == pkcs11_initialized_pid) { - p11_debug_precond ("p11-kit: C_Initialize called twice for same process"); + p11_debug_precond ("p11-kit: C_Initialize called twice for same process\n"); ret = CKR_CRYPTOKI_ALREADY_INITIALIZED; goto done; } @@ -560,7 +559,25 @@ mock_C_GetSlotInfo (CK_SLOT_ID slot_id, } CK_RV -mock_C_GetSlotInfo__invalid_slotid (CK_SLOT_ID slot_id, +mock_C_GetSlotList__fail_first (CK_BBOOL token_present, + CK_SLOT_ID_PTR slot_list, + CK_ULONG_PTR count) +{ + return CKR_VENDOR_DEFINED; +} + +CK_RV +mock_C_GetSlotList__fail_late (CK_BBOOL token_present, + CK_SLOT_ID_PTR slot_list, + CK_ULONG_PTR count) +{ + if (!slot_list) + return mock_C_GetSlotList (token_present, slot_list, count); + return CKR_VENDOR_DEFINED; +} + +CK_RV +mock_C_GetSlotInfo__invalid_slotid (CK_SLOT_ID id, CK_SLOT_INFO_PTR info) { return_val_if_fail (info, CKR_ARGUMENTS_BAD); @@ -650,7 +667,26 @@ mock_C_GetMechanismList (CK_SLOT_ID slot_id, } CK_RV -mock_C_GetMechanismList__invalid_slotid (CK_SLOT_ID slot_id, +mock_C_GetTokenInfo_not_initialized (CK_SLOT_ID slot_id, + CK_TOKEN_INFO_PTR info) +{ + CK_RV rv; + + rv = mock_C_GetTokenInfo (slot_id, info); + if (rv == CKR_OK) + info->flags &= ~ CKF_TOKEN_INITIALIZED; + + return rv; +} + +/* + * TWO mechanisms: + * CKM_MOCK_CAPITALIZE + * CKM_MOCK_PREFIX + */ + +CK_RV +mock_C_GetMechanismList__invalid_slotid (CK_SLOT_ID id, CK_MECHANISM_TYPE_PTR mechanism_list, CK_ULONG_PTR count) { @@ -808,6 +844,18 @@ mock_C_OpenSession__invalid_slotid (CK_SLOT_ID slot_id, } CK_RV +mock_C_OpenSession__fails (CK_SLOT_ID slot_id, + CK_FLAGS flags, + CK_VOID_PTR user_data, + CK_NOTIFY callback, + CK_SESSION_HANDLE_PTR session) +{ + return_val_if_fail (session, CKR_ARGUMENTS_BAD); + + return CKR_DEVICE_ERROR; +} + +CK_RV mock_C_CloseSession (CK_SESSION_HANDLE session) { Session *sess; @@ -1339,6 +1387,30 @@ mock_C_GetAttributeValue__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_C_GetAttributeValue__fail_first (CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE object, + CK_ATTRIBUTE_PTR template, + CK_ULONG count) +{ + return CKR_FUNCTION_REJECTED; +} + +CK_RV +mock_C_GetAttributeValue__fail_late (CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE object, + CK_ATTRIBUTE_PTR template, + CK_ULONG count) +{ + CK_ULONG i; + + for (i = 0; i < count; i++) { + if (template[i].pValue) + return CKR_FUNCTION_FAILED; + } + return mock_C_GetAttributeValue (session, object, template, count); +} + +CK_RV mock_C_SetAttributeValue (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object, CK_ATTRIBUTE_PTR template, @@ -1386,8 +1458,14 @@ enumerate_and_find_objects (CK_OBJECT_HANDLE object, FindObjects *ctx = user_data; CK_ATTRIBUTE *match; CK_ATTRIBUTE *attr; + CK_BBOOL private; CK_ULONG i; + if (!logged_in) { + if (p11_attrs_find_bool (attrs, CKA_PRIVATE, &private) && private) + return 1; /* Continue */ + } + for (i = 0; i < ctx->count; ++i) { match = ctx->template + i; attr = p11_attrs_find (attrs, match->type); @@ -1450,6 +1528,14 @@ mock_C_FindObjectsInit__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_C_FindObjectsInit__fails (CK_SESSION_HANDLE session, + CK_ATTRIBUTE_PTR template, + CK_ULONG count) +{ + return CKR_DEVICE_MEMORY; +} + +CK_RV mock_C_FindObjects (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE_PTR objects, CK_ULONG max_object_count, @@ -1493,6 +1579,17 @@ mock_C_FindObjects__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_C_FindObjects__fails (CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE_PTR objects, + CK_ULONG max_count, + CK_ULONG_PTR count) +{ + return_val_if_fail (count, CKR_ARGUMENTS_BAD); + + return CKR_DEVICE_REMOVED; +} + +CK_RV mock_C_FindObjectsFinal (CK_SESSION_HANDLE session) { diff --git a/common/mock.h b/common/mock.h index 5beebe6..daac1c8 100644 --- a/common/mock.h +++ b/common/mock.h @@ -67,6 +67,7 @@ enum { MOCK_SLOT_ONE_ID = 52, MOCK_SLOT_TWO_ID = 134, + MOCK_DATA_OBJECT = 2, MOCK_PRIVATE_KEY_CAPITALIZE = 3, MOCK_PUBLIC_KEY_CAPITALIZE = 4, MOCK_PRIVATE_KEY_PREFIX = 5, @@ -109,6 +110,14 @@ CK_RV mock_C_GetSlotList__no_tokens (CK_BBOOL token_presen CK_SLOT_ID_PTR slot_list, CK_ULONG_PTR count); +CK_RV mock_C_GetSlotList__fail_first (CK_BBOOL token_present, + CK_SLOT_ID_PTR slot_list, + CK_ULONG_PTR count); + +CK_RV mock_C_GetSlotList__fail_late (CK_BBOOL token_present, + CK_SLOT_ID_PTR slot_list, + CK_ULONG_PTR count); + CK_RV mock_C_GetSlotInfo (CK_SLOT_ID slot_id, CK_SLOT_INFO_PTR info); @@ -121,6 +130,9 @@ CK_RV mock_C_GetTokenInfo (CK_SLOT_ID slot_id, CK_RV mock_C_GetTokenInfo__invalid_slotid (CK_SLOT_ID slot_id, CK_TOKEN_INFO_PTR info); +CK_RV mock_C_GetTokenInfo_not_initialized (CK_SLOT_ID slot_id, + CK_TOKEN_INFO_PTR info); + CK_RV mock_C_GetMechanismList (CK_SLOT_ID slot_id, CK_MECHANISM_TYPE_PTR mechanism_list, CK_ULONG_PTR count); @@ -161,6 +173,12 @@ CK_RV mock_C_OpenSession__invalid_slotid (CK_SLOT_ID slot_id, CK_NOTIFY callback, CK_SESSION_HANDLE_PTR session); +CK_RV mock_C_OpenSession__fails (CK_SLOT_ID slot_id, + CK_FLAGS flags, + CK_VOID_PTR user_data, + CK_NOTIFY callback, + CK_SESSION_HANDLE_PTR session); + CK_RV mock_C_OpenSession (CK_SLOT_ID slot_id, CK_FLAGS flags, CK_VOID_PTR user_data, @@ -289,6 +307,16 @@ CK_RV mock_C_GetAttributeValue__invalid_handle (CK_SESSION_HANDLE ses CK_ATTRIBUTE_PTR template, CK_ULONG count); +CK_RV mock_C_GetAttributeValue__fail_first (CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE object, + CK_ATTRIBUTE_PTR template, + CK_ULONG count); + +CK_RV mock_C_GetAttributeValue__fail_late (CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE object, + CK_ATTRIBUTE_PTR template, + CK_ULONG count); + CK_RV mock_C_SetAttributeValue (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object, CK_ATTRIBUTE_PTR template, @@ -307,6 +335,10 @@ CK_RV mock_C_FindObjectsInit__invalid_handle (CK_SESSION_HANDLE ses CK_ATTRIBUTE_PTR template, CK_ULONG count); +CK_RV mock_C_FindObjectsInit__fails (CK_SESSION_HANDLE session, + CK_ATTRIBUTE_PTR template, + CK_ULONG count); + CK_RV mock_C_FindObjects (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE_PTR objects, CK_ULONG max_object_count, @@ -317,6 +349,11 @@ CK_RV mock_C_FindObjects__invalid_handle (CK_SESSION_HANDLE ses CK_ULONG max_count, CK_ULONG_PTR count); +CK_RV mock_C_FindObjects__fails (CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE_PTR objects, + CK_ULONG max_count, + CK_ULONG_PTR count); + CK_RV mock_C_FindObjectsFinal (CK_SESSION_HANDLE session); CK_RV mock_C_FindObjectsFinal__invalid_handle (CK_SESSION_HANDLE session); |