aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Bottomley <James.Bottomley@HansenPartnership.com>2019-02-18 14:22:51 -0800
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2019-02-18 14:22:51 -0800
commit3bc25b1bd130900bf5bdcf453317b2c459c442e6 (patch)
tree692099aab0f825593d873c2d145f228d9bd34c68
parent92713e054b365c7dfd4d8597e9257fcd90fa02ce (diff)
downloadopenssl-pkcs11-export-3bc25b1bd130900bf5bdcf453317b2c459c442e6.tar.gz
Make sessions dynamic
Remove the fixed session limit and now make every session have an entry in the cache. Keep to one allowable session per slot. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
-rw-r--r--pkcs11.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/pkcs11.c b/pkcs11.c
index 5141a81..99e9fb5 100644
--- a/pkcs11.c
+++ b/pkcs11.c
@@ -153,7 +153,10 @@ C_GetSlotInfo(CK_SLOT_ID slot, CK_SLOT_INFO_PTR info)
return CKR_OK;
}
-static int session_count = 0;
+static int session_init(CK_SESSION_HANDLE handle)
+{
+ return (int)(unsigned long)cache_get_by_secnum(handle, "session_init", NULL);
+}
static int logged_in(CK_SESSION_HANDLE handle)
{
@@ -169,12 +172,10 @@ CK_RV C_OpenSession(CK_SLOT_ID slot, CK_FLAGS flags, CK_VOID_PTR app,
return CKR_ARGUMENTS_BAD;
if (slot > cache_get_sections() - 1)
return CKR_ARGUMENTS_BAD;
- if (session_count > 2) {
- fprintf(stderr, "token is out of sessions, total=%d\n",
- session_count);
+ if (session_init(slot))
return CKR_SESSION_COUNT;
- }
- session_count++;
+
+ cache_add_by_secnum(slot, "session_init", (const char *)1, CACHE_INT);
*handle = slot;
return CKR_OK;
@@ -183,14 +184,22 @@ CK_RV C_OpenSession(CK_SLOT_ID slot, CK_FLAGS flags, CK_VOID_PTR app,
CK_RV
C_CloseSession(CK_SESSION_HANDLE handle)
{
- session_count--;
+ if (!session_init(handle))
+ return CKR_SESSION_HANDLE_INVALID;
+ cache_add_by_secnum(handle, "session_init", (const char *)0, CACHE_INT);
+
return CKR_OK;
}
CK_RV
C_CloseAllSessions(CK_SLOT_ID slot)
{
- session_count = 0;
+ int i;
+ const int count = cache_get_sections() - 1;
+
+ for (i = 1; i < count; i++)
+ cache_add_by_secnum(slot, "session_init", 0, CACHE_INT);
+
return CKR_OK;
}
@@ -405,6 +414,8 @@ C_GetSessionInfo(CK_SESSION_HANDLE handle, CK_SESSION_INFO_PTR info)
{
if (!info)
return CKR_ARGUMENTS_BAD;
+ if (!session_init(handle))
+ return CKR_SESSION_HANDLE_INVALID;
memset(info, 0, sizeof(*info));
info->state = logged_in(handle) ?
CKS_RO_USER_FUNCTIONS : CKS_RO_PUBLIC_SESSION;