[gnome-keyring] Implement testing for context specific login prompt.
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring] Implement testing for context specific login prompt.
- Date: Tue, 8 Jun 2010 20:07:38 +0000 (UTC)
commit f83e2ff053f527a968f77fd0d7b4a6ca76bb07dd
Author: Stef Walter <stef memberwebs com>
Date: Tue Jun 8 20:06:42 2010 +0000
Implement testing for context specific login prompt.
pkcs11/gkm/gkm-attributes.c | 51 +++++++
pkcs11/gkm/gkm-attributes.h | 17 +++
pkcs11/gkm/gkm-test.c | 98 +++++++-------
pkcs11/gkm/gkm-test.h | 6 +
pkcs11/wrap-layer/gkm-wrap-prompt.c | 8 +-
pkcs11/wrap-layer/tests/Makefile.am | 3 +-
pkcs11/wrap-layer/tests/test-login-specific.c | 132 ++++++++++++++++++
.../{test-prompt-login.c => test-login-user.c} | 142 ++++++++------------
8 files changed, 323 insertions(+), 134 deletions(-)
---
diff --git a/pkcs11/gkm/gkm-attributes.c b/pkcs11/gkm/gkm-attributes.c
index 7028bdc..ff0780f 100644
--- a/pkcs11/gkm/gkm-attributes.c
+++ b/pkcs11/gkm/gkm-attributes.c
@@ -588,6 +588,57 @@ gkm_template_set (GArray *template, CK_ATTRIBUTE_PTR attr)
}
void
+gkm_template_set_value (GArray *template, CK_ATTRIBUTE_TYPE type,
+ CK_VOID_PTR value, CK_ULONG length)
+{
+ CK_ATTRIBUTE attr;
+ g_return_if_fail (template);
+
+ attr.type = type;
+ attr.pValue = value;
+ attr.ulValueLen = length;
+ gkm_template_set (template, &attr);
+}
+
+void
+gkm_template_set_string (GArray *template, CK_ATTRIBUTE_TYPE type, const gchar *value)
+{
+ CK_ATTRIBUTE attr;
+ g_return_if_fail (template);
+ g_return_if_fail (value);
+
+ attr.type = type;
+ attr.pValue = (CK_VOID_PTR)value;
+ attr.ulValueLen = strlen (value);
+ gkm_template_set (template, &attr);
+
+}
+void
+gkm_template_set_ulong (GArray *template, CK_ATTRIBUTE_TYPE type, CK_ULONG value)
+{
+ CK_ATTRIBUTE attr;
+ g_return_if_fail (template);
+
+ attr.type = type;
+ attr.pValue = &value;
+ attr.ulValueLen = sizeof (value);
+ gkm_template_set (template, &attr);
+
+}
+
+void
+gkm_template_set_boolean (GArray *template, CK_ATTRIBUTE_TYPE type, CK_BBOOL value)
+{
+ CK_ATTRIBUTE attr;
+ g_return_if_fail (template);
+
+ attr.type = type;
+ attr.pValue = &value;
+ attr.ulValueLen = sizeof (value);
+ gkm_template_set (template, &attr);
+}
+
+void
gkm_template_free (GArray *template)
{
guint i;
diff --git a/pkcs11/gkm/gkm-attributes.h b/pkcs11/gkm/gkm-attributes.h
index bb6a3d0..97088d4 100644
--- a/pkcs11/gkm/gkm-attributes.h
+++ b/pkcs11/gkm/gkm-attributes.h
@@ -121,6 +121,23 @@ GArray* gkm_template_new (CK_ATTRI
void gkm_template_set (GArray *template,
CK_ATTRIBUTE_PTR attr);
+void gkm_template_set_value (GArray *template,
+ CK_ATTRIBUTE_TYPE type,
+ CK_VOID_PTR value,
+ CK_ULONG length);
+
+void gkm_template_set_string (GArray *template,
+ CK_ATTRIBUTE_TYPE type,
+ const gchar *value);
+
+void gkm_template_set_ulong (GArray *template,
+ CK_ATTRIBUTE_TYPE type,
+ CK_ULONG value);
+
+void gkm_template_set_boolean (GArray *template,
+ CK_ATTRIBUTE_TYPE type,
+ CK_BBOOL value);
+
void gkm_template_free (GArray *template);
CK_ATTRIBUTE_PTR gkm_template_find (GArray *template,
diff --git a/pkcs11/gkm/gkm-test.c b/pkcs11/gkm/gkm-test.c
index 37c477b..11a2761 100644
--- a/pkcs11/gkm/gkm-test.c
+++ b/pkcs11/gkm/gkm-test.c
@@ -123,10 +123,8 @@ lookup_object (Session *session, CK_OBJECT_HANDLE hObject)
CK_RV
gkm_test_C_Initialize (CK_VOID_PTR pInitArgs)
{
-#if 0
GArray *attrs;
CK_ULONG value;
-#endif
CK_C_INITIALIZE_ARGS_PTR args;
g_return_val_if_fail (initialized == FALSE, CKR_CRYPTOKI_ALREADY_INITIALIZED);
@@ -149,61 +147,59 @@ gkm_test_C_Initialize (CK_VOID_PTR pInitArgs)
the_sessions = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, free_session);
the_objects = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)gkm_template_free);
-#if 0
/* Our token object */
- attrs = gp11_attributes_newv (CKA_CLASS, GP11_ULONG, CKO_DATA,
- CKA_LABEL, GP11_STRING, "TEST LABEL",
- GP11_INVALID);
+ attrs = gkm_template_new (NULL, 0);
+ gkm_template_set_ulong (attrs, CKA_CLASS, CKO_DATA);
+ gkm_template_set_string (attrs, CKA_LABEL, "TEST LABEL");
g_hash_table_insert (the_objects, GUINT_TO_POINTER (2), attrs);
/* Private capitalize key */
value = CKM_T_CAPITALIZE;
- attrs = gp11_attributes_newv (CKA_CLASS, GP11_ULONG, CKO_PRIVATE_KEY,
- CKA_LABEL, GP11_STRING, "Private Capitalize Key",
- CKA_ALLOWED_MECHANISMS, sizeof (value), &value,
- CKA_DECRYPT, GP11_BOOLEAN, TRUE,
- CKA_PRIVATE, GP11_BOOLEAN, TRUE,
- CKA_WRAP, GP11_BOOLEAN, TRUE,
- CKA_UNWRAP, GP11_BOOLEAN, TRUE,
- CKA_DERIVE, GP11_BOOLEAN, TRUE,
- CKA_VALUE, GP11_STRING, "value",
- GP11_INVALID);
+ attrs = gkm_template_new (NULL, 0);
+ gkm_template_set_ulong (attrs, CKA_CLASS, CKO_PRIVATE_KEY);
+ gkm_template_set_string (attrs, CKA_LABEL, "Private Capitalize Key");
+ gkm_template_set_value (attrs, CKA_ALLOWED_MECHANISMS, &value, sizeof (value));
+ gkm_template_set_boolean (attrs, CKA_DECRYPT, CK_TRUE);
+ gkm_template_set_boolean (attrs, CKA_PRIVATE, CK_TRUE);
+ gkm_template_set_boolean (attrs, CKA_WRAP, CK_TRUE);
+ gkm_template_set_boolean (attrs, CKA_UNWRAP, CK_TRUE);
+ gkm_template_set_boolean (attrs, CKA_DERIVE, CK_TRUE);
+ gkm_template_set_string (attrs, CKA_VALUE, "value");
g_hash_table_insert (the_objects, GUINT_TO_POINTER (PRIVATE_KEY_CAPITALIZE), attrs);
/* Public capitalize key */
value = CKM_T_CAPITALIZE;
- attrs = gp11_attributes_newv (CKA_CLASS, GP11_ULONG, CKO_PUBLIC_KEY,
- CKA_LABEL, GP11_STRING, "Public Capitalize Key",
- CKA_ALLOWED_MECHANISMS, sizeof (value), &value,
- CKA_ENCRYPT, GP11_BOOLEAN, TRUE,
- CKA_PRIVATE, GP11_BOOLEAN, FALSE,
- CKA_VALUE, GP11_STRING, "value",
- GP11_INVALID);
+ attrs = gkm_template_new (NULL, 0);
+ gkm_template_set_ulong (attrs, CKA_CLASS, CKO_PUBLIC_KEY);
+ gkm_template_set_string (attrs, CKA_LABEL, "Public Capitalize Key");
+ gkm_template_set_value (attrs, CKA_ALLOWED_MECHANISMS, &value, sizeof (value));
+ gkm_template_set_boolean (attrs, CKA_ENCRYPT, CK_TRUE);
+ gkm_template_set_boolean (attrs, CKA_PRIVATE, CK_FALSE);
+ gkm_template_set_string (attrs, CKA_VALUE, "value");
g_hash_table_insert (the_objects, GUINT_TO_POINTER (PUBLIC_KEY_CAPITALIZE), attrs);
/* Private prefix key */
value = CKM_T_PREFIX;
- attrs = gp11_attributes_newv (CKA_CLASS, GP11_ULONG, CKO_PRIVATE_KEY,
- CKA_LABEL, GP11_STRING, "Private prefix key",
- CKA_ALLOWED_MECHANISMS, sizeof (value), &value,
- CKA_SIGN, GP11_BOOLEAN, TRUE,
- CKA_PRIVATE, GP11_BOOLEAN, TRUE,
- CKA_ALWAYS_AUTHENTICATE, GP11_BOOLEAN, TRUE,
- CKA_VALUE, GP11_STRING, "value",
- GP11_INVALID);
+ attrs = gkm_template_new (NULL, 0);
+ gkm_template_set_ulong (attrs, CKA_CLASS, CKO_PRIVATE_KEY);
+ gkm_template_set_string (attrs, CKA_LABEL, "Private prefix key");
+ gkm_template_set_value (attrs, CKA_ALLOWED_MECHANISMS, &value, sizeof (value));
+ gkm_template_set_boolean (attrs, CKA_SIGN, CK_TRUE);
+ gkm_template_set_boolean (attrs, CKA_PRIVATE, CK_TRUE);
+ gkm_template_set_boolean (attrs, CKA_ALWAYS_AUTHENTICATE, CK_TRUE);
+ gkm_template_set_string (attrs, CKA_VALUE, "value");
g_hash_table_insert (the_objects, GUINT_TO_POINTER (PRIVATE_KEY_PREFIX), attrs);
/* Private prefix key */
value = CKM_T_PREFIX;
- attrs = gp11_attributes_newv (CKA_CLASS, GP11_ULONG, CKO_PUBLIC_KEY,
- CKA_LABEL, GP11_STRING, "Public prefix key",
- CKA_ALLOWED_MECHANISMS, sizeof (value), &value,
- CKA_VERIFY, GP11_BOOLEAN, TRUE,
- CKA_PRIVATE, GP11_BOOLEAN, FALSE,
- CKA_VALUE, GP11_STRING, "value",
- GP11_INVALID);
+ attrs = gkm_template_new (NULL, 0);
+ gkm_template_set_ulong (attrs, CKA_CLASS, CKO_PUBLIC_KEY);
+ gkm_template_set_string (attrs, CKA_LABEL, "Public prefix key");
+ gkm_template_set_value (attrs, CKA_ALLOWED_MECHANISMS, &value, sizeof (value));
+ gkm_template_set_boolean (attrs, CKA_VERIFY, CK_TRUE);
+ gkm_template_set_boolean (attrs, CKA_PRIVATE, CK_FALSE);
+ gkm_template_set_string (attrs, CKA_VALUE, "value");
g_hash_table_insert (the_objects, GUINT_TO_POINTER (PUBLIC_KEY_PREFIX), attrs);
-#endif
initialized = TRUE;
return CKR_OK;
@@ -343,7 +339,7 @@ static const CK_TOKEN_INFO TEST_TOKEN_ONE = {
CK_RV
gkm_test_C_GetTokenInfo (CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo)
{
- g_assert (pInfo != NULL && "Invalid pInfo");
+ g_return_val_if_fail (pInfo != NULL, CKR_ARGUMENTS_BAD);
if (slotID == GKM_TEST_SLOT_ONE) {
memcpy (pInfo, &TEST_TOKEN_ONE, sizeof (*pInfo));
@@ -351,11 +347,16 @@ gkm_test_C_GetTokenInfo (CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo)
} else if (slotID == GKM_TEST_SLOT_TWO) {
return CKR_TOKEN_NOT_PRESENT;
} else {
- g_assert_not_reached (); /* "Invalid slot id" */
- return CKR_SLOT_ID_INVALID;
+ g_return_val_if_reached (CKR_SLOT_ID_INVALID);
}
}
+CK_RV
+gkm_fail_C_GetTokenInfo (CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo)
+{
+ return CKR_GENERAL_ERROR;
+}
+
/*
* TWO mechanisms:
* CKM_T_CAPITALIZE
@@ -498,7 +499,7 @@ gkm_test_C_GetSessionInfo (CK_SESSION_HANDLE hSession, CK_SESSION_INFO_PTR pInfo
{
Session *session;
- g_assert (pInfo != NULL && "Invalid pInfo");
+ g_return_val_if_fail (pInfo != NULL, CKR_ARGUMENTS_BAD);
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
g_assert (session != NULL && "No such session found");
@@ -510,6 +511,12 @@ gkm_test_C_GetSessionInfo (CK_SESSION_HANDLE hSession, CK_SESSION_INFO_PTR pInfo
}
CK_RV
+gkm_fail_C_GetSessionInfo (CK_SESSION_HANDLE hSession, CK_SESSION_INFO_PTR pInfo)
+{
+ return CKR_GENERAL_ERROR;
+}
+
+CK_RV
gkm_test_C_InitPIN (CK_SESSION_HANDLE hSession, CK_UTF8CHAR_PTR pPin,
CK_ULONG ulPinLen)
{
@@ -587,6 +594,7 @@ gkm_test_C_Login (CK_SESSION_HANDLE hSession, CK_USER_TYPE userType,
return CKR_PIN_INCORRECT;
if (userType == CKU_CONTEXT_SPECIFIC) {
+ g_return_val_if_fail (session->want_context_login == TRUE, CKR_OPERATION_NOT_INITIALIZED);
session->want_context_login = CK_FALSE;
} else {
logged_in = TRUE;
@@ -773,9 +781,7 @@ gkm_test_C_FindObjectsInit (CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTempla
CK_ULONG i;
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
- g_assert (session != NULL && "No such session found");
- if (!session)
- return CKR_SESSION_HANDLE_INVALID;
+ g_return_val_if_fail (session != NULL, CKR_SESSION_HANDLE_INVALID);
/* Starting an operation, cancels any previous one */
if (session->operation != 0)
diff --git a/pkcs11/gkm/gkm-test.h b/pkcs11/gkm/gkm-test.h
index 993d86c..f908056 100644
--- a/pkcs11/gkm/gkm-test.h
+++ b/pkcs11/gkm/gkm-test.h
@@ -60,6 +60,9 @@ CK_RV gkm_test_C_GetSlotInfo (CK_SLOT_ID slotID,
CK_RV gkm_test_C_GetTokenInfo (CK_SLOT_ID slotID,
CK_TOKEN_INFO_PTR pInfo);
+CK_RV gkm_fail_C_GetTokenInfo (CK_SLOT_ID slotID,
+ CK_TOKEN_INFO_PTR pInfo);
+
CK_RV gkm_test_C_GetMechanismList (CK_SLOT_ID slotID,
CK_MECHANISM_TYPE_PTR pMechanismList,
CK_ULONG_PTR pulCount);
@@ -94,6 +97,9 @@ CK_RV gkm_test_C_CancelFunction (CK_SESSION_HANDLE hSession);
CK_RV gkm_test_C_GetSessionInfo (CK_SESSION_HANDLE hSession,
CK_SESSION_INFO_PTR pInfo);
+CK_RV gkm_fail_C_GetSessionInfo (CK_SESSION_HANDLE hSession,
+ CK_SESSION_INFO_PTR pInfo);
+
CK_RV gkm_test_C_InitPIN (CK_SESSION_HANDLE hSession,
CK_UTF8CHAR_PTR pPin,
CK_ULONG ulPinLen);
diff --git a/pkcs11/wrap-layer/gkm-wrap-prompt.c b/pkcs11/wrap-layer/gkm-wrap-prompt.c
index 25f6fe4..db2ffa3 100644
--- a/pkcs11/wrap-layer/gkm-wrap-prompt.c
+++ b/pkcs11/wrap-layer/gkm-wrap-prompt.c
@@ -822,8 +822,12 @@ login_prompt_for_specific (CK_FUNCTION_LIST_PTR module, CK_SESSION_HANDLE sessio
g_assert (module);
- if (object == 0)
- return NULL;
+ /*
+ * Should have an object at this point, if none exists it's an
+ * indication of either a buggy PKCS#11 module, or bugs in this
+ * wrap-layer not stashing away the context specific object.
+ */
+ g_return_val_if_fail (object != 0, NULL);
/* Find out if the object is CKA_ALWAYS_AUTHENTICATE */
always = CK_FALSE;
diff --git a/pkcs11/wrap-layer/tests/Makefile.am b/pkcs11/wrap-layer/tests/Makefile.am
index 79e6cb7..621384a 100644
--- a/pkcs11/wrap-layer/tests/Makefile.am
+++ b/pkcs11/wrap-layer/tests/Makefile.am
@@ -1,6 +1,7 @@
TESTING_FILES = \
- test-prompt-login.c
+ test-login-user.c \
+ test-login-specific.c
UNIT_PROMPT =
diff --git a/pkcs11/wrap-layer/tests/test-login-specific.c b/pkcs11/wrap-layer/tests/test-login-specific.c
new file mode 100644
index 0000000..335f535
--- /dev/null
+++ b/pkcs11/wrap-layer/tests/test-login-specific.c
@@ -0,0 +1,132 @@
+/*
+ * gnome-keyring
+ *
+ * Copyright (C) 2010 Stefan Walter
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "test-framework.h"
+
+#include "gkm/gkm-test.h"
+
+#include "wrap-layer/gkm-wrap-layer.h"
+
+#include "ui/gku-prompt.h"
+
+static CK_FUNCTION_LIST prompt_login_functions;
+static CK_FUNCTION_LIST_PTR module = NULL;
+static CK_SESSION_HANDLE session = 0;
+
+DEFINE_SETUP (login_specific)
+{
+ CK_FUNCTION_LIST_PTR funcs;
+ CK_OBJECT_HANDLE key;
+ CK_SLOT_ID slot_id;
+ CK_ULONG n_slots = 1;
+ CK_ULONG count;
+ CK_RV rv;
+
+ CK_BBOOL always = TRUE;
+ CK_ATTRIBUTE attrs[] = {
+ { CKA_ALWAYS_AUTHENTICATE, &always, sizeof (always) }
+ };
+
+ CK_MECHANISM mech = { CKM_T_PREFIX, NULL, 0 };
+
+ /* Always start off with test functions */
+ rv = gkm_test_C_GetFunctionList (&funcs);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+ memcpy (&prompt_login_functions, funcs, sizeof (prompt_login_functions));
+
+ gkm_wrap_layer_reset_modules ();
+ gkm_wrap_layer_add_module (&prompt_login_functions);
+ module = gkm_wrap_layer_get_functions ();
+
+ gku_prompt_dummy_prepare_response ();
+
+ /* Open a session */
+ rv = (module->C_Initialize) (NULL);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+
+ rv = (module->C_GetSlotList) (CK_TRUE, &slot_id, &n_slots);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+
+ rv = (module->C_OpenSession) (slot_id, CKF_SERIAL_SESSION, NULL, NULL, &session);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+
+ /* Find the always authenticate object */
+ rv = (module->C_FindObjectsInit) (session, attrs, 1);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+
+ rv = (module->C_FindObjects) (session, &key, 1, &count);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+ g_assert (count == 1);
+ g_assert (key != 0);
+
+ rv = (module->C_FindObjectsFinal) (session);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+
+ /* Start a signing operation, that needs to be authenticated */
+ rv = (module->C_SignInit) (session, &mech, key);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+}
+
+DEFINE_TEARDOWN (login_specific)
+{
+ CK_RV rv;
+
+ rv = (module->C_CloseSession) (session);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+ session = 0;
+
+ rv = (module->C_Finalize) (NULL);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+ module = NULL;
+}
+
+DEFINE_TEST (login_specific_ok_password)
+{
+ CK_RV rv;
+
+ gku_prompt_dummy_queue_ok_password ("booo");
+
+ rv = (module->C_Login) (session, CKU_CONTEXT_SPECIFIC, NULL, 0);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+}
+
+DEFINE_TEST (login_specific_bad_password_then_cancel)
+{
+ CK_RV rv;
+
+ gku_prompt_dummy_queue_ok_password ("bad password");
+ gku_prompt_dummy_queue_no ();
+
+ rv = (module->C_Login) (session, CKU_CONTEXT_SPECIFIC, NULL, 0);
+ gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
+}
+
+DEFINE_TEST (login_specific_cancel_immediately)
+{
+ CK_RV rv;
+
+ gku_prompt_dummy_queue_no ();
+
+ rv = (module->C_Login) (session, CKU_CONTEXT_SPECIFIC, NULL, 0);
+ gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
+}
diff --git a/pkcs11/wrap-layer/tests/test-prompt-login.c b/pkcs11/wrap-layer/tests/test-login-user.c
similarity index 50%
rename from pkcs11/wrap-layer/tests/test-prompt-login.c
rename to pkcs11/wrap-layer/tests/test-login-user.c
index 4c9c46b..0002c9e 100644
--- a/pkcs11/wrap-layer/tests/test-prompt-login.c
+++ b/pkcs11/wrap-layer/tests/test-login-user.c
@@ -23,104 +23,34 @@
#include "test-framework.h"
-#include "egg/egg-secure-memory.h"
-
#include "gkm/gkm-test.h"
-#include "gkm/gkm-util.h"
-
-#include "pkcs11/pkcs11.h"
#include "wrap-layer/gkm-wrap-layer.h"
#include "ui/gku-prompt.h"
-#include <glib-object.h>
-
-CK_FUNCTION_LIST prompt_login_functions = {
- { 2, 11 }, /* version */
- gkm_test_C_Initialize,
- gkm_test_C_Finalize,
- gkm_test_C_GetInfo,
- gkm_test_C_GetFunctionList,
- gkm_test_C_GetSlotList,
- gkm_test_C_GetSlotInfo,
- gkm_test_C_GetTokenInfo,
- gkm_test_C_GetMechanismList,
- gkm_test_C_GetMechanismInfo,
- gkm_test_C_InitToken,
- gkm_test_C_InitPIN,
- gkm_test_C_SetPIN,
- gkm_test_C_OpenSession,
- gkm_test_C_CloseSession,
- gkm_test_C_CloseAllSessions,
- gkm_test_C_GetSessionInfo,
- gkm_test_C_GetOperationState,
- gkm_test_C_SetOperationState,
- gkm_test_C_Login,
- gkm_test_C_Logout,
- gkm_test_C_CreateObject,
- gkm_test_C_CopyObject,
- gkm_test_C_DestroyObject,
- gkm_test_C_GetObjectSize,
- gkm_test_C_GetAttributeValue,
- gkm_test_C_SetAttributeValue,
- gkm_test_C_FindObjectsInit,
- gkm_test_C_FindObjects,
- gkm_test_C_FindObjectsFinal,
- gkm_test_C_EncryptInit,
- gkm_test_C_Encrypt,
- gkm_test_C_EncryptUpdate,
- gkm_test_C_EncryptFinal,
- gkm_test_C_DecryptInit,
- gkm_test_C_Decrypt,
- gkm_test_C_DecryptUpdate,
- gkm_test_C_DecryptFinal,
- gkm_test_C_DigestInit,
- gkm_test_C_Digest,
- gkm_test_C_DigestUpdate,
- gkm_test_C_DigestKey,
- gkm_test_C_DigestFinal,
- gkm_test_C_SignInit,
- gkm_test_C_Sign,
- gkm_test_C_SignUpdate,
- gkm_test_C_SignFinal,
- gkm_test_C_SignRecoverInit,
- gkm_test_C_SignRecover,
- gkm_test_C_VerifyInit,
- gkm_test_C_Verify,
- gkm_test_C_VerifyUpdate,
- gkm_test_C_VerifyFinal,
- gkm_test_C_VerifyRecoverInit,
- gkm_test_C_VerifyRecover,
- gkm_test_C_DigestEncryptUpdate,
- gkm_test_C_DecryptDigestUpdate,
- gkm_test_C_SignEncryptUpdate,
- gkm_test_C_DecryptVerifyUpdate,
- gkm_test_C_GenerateKey,
- gkm_test_C_GenerateKeyPair,
- gkm_test_C_WrapKey,
- gkm_test_C_UnwrapKey,
- gkm_test_C_DeriveKey,
- gkm_test_C_SeedRandom,
- gkm_test_C_GenerateRandom,
- gkm_test_C_GetFunctionStatus,
- gkm_test_C_CancelFunction,
- gkm_test_C_WaitForSlotEvent
-};
-
+static CK_FUNCTION_LIST prompt_login_functions;
static CK_FUNCTION_LIST_PTR module = NULL;
static CK_SESSION_HANDLE session = 0;
-DEFINE_SETUP (module)
+DEFINE_SETUP (login_user)
{
+ CK_FUNCTION_LIST_PTR funcs;
CK_SLOT_ID slot_id;
CK_ULONG n_slots = 1;
CK_RV rv;
+ /* Always start off with test functions */
+ rv = gkm_test_C_GetFunctionList (&funcs);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+ memcpy (&prompt_login_functions, funcs, sizeof (prompt_login_functions));
+
gkm_wrap_layer_reset_modules ();
gkm_wrap_layer_add_module (&prompt_login_functions);
module = gkm_wrap_layer_get_functions ();
+ gku_prompt_dummy_prepare_response ();
+
/* Open a session */
rv = (module->C_Initialize) (NULL);
gkm_assert_cmprv (rv, ==, CKR_OK);
@@ -132,7 +62,7 @@ DEFINE_SETUP (module)
gkm_assert_cmprv (rv, ==, CKR_OK);
}
-DEFINE_TEARDOWN (module)
+DEFINE_TEARDOWN (login_user)
{
CK_RV rv;
@@ -145,25 +75,67 @@ DEFINE_TEARDOWN (module)
module = NULL;
}
-DEFINE_TEST (login_prompt_ok)
+DEFINE_TEST (login_fail_unsupported_so)
+{
+ CK_RV rv;
+
+ rv = (module->C_Login) (session, CKU_SO, NULL, 0);
+ gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
+}
+
+DEFINE_TEST (login_skip_prompt_because_pin)
+{
+ CK_RV rv;
+
+ rv = (module->C_Login) (session, CKU_USER, (guchar*)"booo", 4);
+ gkm_assert_cmprv (rv, ==, CKR_OK);
+}
+
+DEFINE_TEST (login_user_ok_password)
{
CK_RV rv;
- gku_prompt_dummy_prepare_response ();
gku_prompt_dummy_queue_ok_password ("booo");
rv = (module->C_Login) (session, CKU_USER, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
-DEFINE_TEST (login_prompt_cancel)
+DEFINE_TEST (login_user_bad_password_then_cancel)
{
CK_RV rv;
- gku_prompt_dummy_prepare_response ();
gku_prompt_dummy_queue_ok_password ("bad password");
gku_prompt_dummy_queue_no ();
rv = (module->C_Login) (session, CKU_USER, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
}
+
+DEFINE_TEST (login_user_cancel_immediately)
+{
+ CK_RV rv;
+
+ gku_prompt_dummy_queue_no ();
+
+ rv = (module->C_Login) (session, CKU_USER, NULL, 0);
+ gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
+}
+
+DEFINE_TEST (login_user_fail_get_session_info)
+{
+ CK_RV rv;
+
+ prompt_login_functions.C_GetSessionInfo = gkm_fail_C_GetSessionInfo;
+ rv = (module->C_Login) (session, CKU_USER, NULL, 0);
+ gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
+}
+
+DEFINE_TEST (login_user_fail_get_token_info)
+{
+ CK_RV rv;
+
+ prompt_login_functions.C_GetTokenInfo = gkm_fail_C_GetTokenInfo;
+ rv = (module->C_Login) (session, CKU_USER, NULL, 0);
+ gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]