From f84cec479d41fb143487af7e78a6b3056f6b8823 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Mon, 8 Dec 2008 21:38:18 +0000 Subject: Implement concept of logins (no-op). Do RSA testing, and fix problems discovered in RSA code. --- ckcapi-token.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 4 deletions(-) (limited to 'ckcapi-token.c') diff --git a/ckcapi-token.c b/ckcapi-token.c index a2beb74..4f0a7a3 100644 --- a/ckcapi-token.c +++ b/ckcapi-token.c @@ -23,6 +23,7 @@ static CkCapiArray* object_array = NULL; static CkCapiHash* object_hash = NULL; +static CkCapiArray* logged_in_slots = NULL; typedef struct _SlotInfo { @@ -34,11 +35,11 @@ SlotInfo; #define SLOT_OFFSET 0x00001000 -static const SlotInfo slot_info[] = { +static SlotInfo slot_info[] = { { "My", "Personal Certificates", CKCAPI_SLOT_TRUSTED | CKCAPI_SLOT_CERTS }, { "AddressBook", "Address Book Certificates", CKCAPI_SLOT_CERTS }, - { "CA", "Certificate Authorities", CKCAPI_SLOT_CA | CKCAPI_SLOT_CERTS}, - { "Root", "Root Authorities", CKCAPI_SLOT_TRUSTED | CKCAPI_SLOT_CA | CKCAPI_SLOT_CERTS}, + { "CA", "Certificate Authorities", CKCAPI_SLOT_CA | CKCAPI_SLOT_CERTS }, + { "Root", "Root Authorities", CKCAPI_SLOT_TRUSTED | CKCAPI_SLOT_CA | CKCAPI_SLOT_CERTS }, { "Trust", "Trust", CKCAPI_SLOT_CERTS }, { "TrustedPeople", "Trusted People", CKCAPI_SLOT_TRUSTED | CKCAPI_SLOT_CERTS }, { "AuthRoot", "Auth Root", CKCAPI_SLOT_CERTS }, @@ -130,6 +131,12 @@ ckcapi_token_cleanup_all(void) object_array = NULL; } + if(logged_in_slots) + { + ckcapi_array_free(logged_in_slots, TRUE); + logged_in_slots = NULL; + } + ckcapi_unlock_global(); } @@ -213,7 +220,7 @@ ckcapi_token_register_object(CK_SLOT_ID slot, CkCapiObject* obj) /* Sanity check, in case calcs went wrong somewhere */ ASSERT(klen < 0xFFFFFF); -/* xxxxx hash function xxxxx */ + /* Look in the hash and find a previous object */ prev = ckcapi_hash_get(object_hash, key, klen); if(prev) @@ -267,3 +274,73 @@ ckcapi_token_register_object(CK_SLOT_ID slot, CkCapiObject* obj) return ret; } + +CK_BBOOL +ckcapi_token_is_logged_in(CK_SLOT_ID slot) +{ + unsigned int count, offset; + + ASSERT(ckcapi_token_is_valid(slot)); + + if(!logged_in_slots) + return CK_FALSE; + + offset = SLOT_TO_OFFSET(slot); + count = ckcapi_token_get_count(); + + ASSERT(logged_in_slots->len == count && offset < count); + return ckcapi_array_index(logged_in_slots, CK_BBOOL, offset); +} + +CK_RV +ckcapi_token_login(CK_SLOT_ID slot) +{ + unsigned int i, count; + unsigned int offset; + CK_BBOOL value; + + ASSERT(ckcapi_token_is_valid(slot)); + + offset = SLOT_TO_OFFSET(slot); + count = ckcapi_token_get_count(); + + if(!logged_in_slots) + { + logged_in_slots = ckcapi_array_sized_new(0, 1, sizeof(CK_BBOOL), count); + if(!logged_in_slots) + return CKR_HOST_MEMORY; + + value = CK_FALSE; + for(i = 0; i < count; ++i) + ckcapi_array_append(logged_in_slots, value); + + } + + ASSERT(logged_in_slots->len == count && offset < count); + if(ckcapi_array_index(logged_in_slots, CK_BBOOL, offset)) + return CKR_USER_ALREADY_LOGGED_IN; + + ckcapi_array_index(logged_in_slots, CK_BBOOL, offset) = CK_TRUE; + return CKR_OK; +} + +CK_RV +ckcapi_token_logout(CK_SLOT_ID slot) +{ + unsigned int count, offset; + + ASSERT(ckcapi_token_is_valid(slot)); + + if(!logged_in_slots) + return CKR_USER_NOT_LOGGED_IN; + + offset = SLOT_TO_OFFSET(slot); + count = ckcapi_token_get_count(); + + ASSERT(logged_in_slots->len == count && offset < count); + if(!ckcapi_array_index(logged_in_slots, CK_BBOOL, offset)) + return CKR_USER_NOT_LOGGED_IN; + + ckcapi_array_index(logged_in_slots, CK_BBOOL, offset) = CK_FALSE; + return CKR_OK; +} -- cgit v1.2.3