aboutsummaryrefslogtreecommitdiff
path: root/pkcs11.c
diff options
context:
space:
mode:
Diffstat (limited to 'pkcs11.c')
-rw-r--r--pkcs11.c85
1 files changed, 34 insertions, 51 deletions
diff --git a/pkcs11.c b/pkcs11.c
index 3e47c67..4fde44f 100644
--- a/pkcs11.c
+++ b/pkcs11.c
@@ -317,11 +317,11 @@ static inline hal_error_t _hal_whine(const hal_error_t err,
int ok = 0;
hal_error_t code;
- va_start(ap, line)
- do {
- code = va_arg(ap, hal_error_t);
- ok |= (err == code);
- } while (code != HAL_OK);
+ va_start(ap, line);
+ do {
+ code = va_arg(ap, hal_error_t);
+ ok |= (err == code);
+ } while (code != HAL_OK);
va_end(ap);
if (!ok)
@@ -368,6 +368,9 @@ static CK_RV _p11_error_from_hal(const hal_error_t err, const char * const file,
* More here later, first see if this compiles.
*/
+ case HAL_OK:
+ return CKR_OK;
+
default:
#if DEBUG_PKCS11 || DEBUG_HAL
fprintf(stderr, "\n%s:%u: Mapping unhandled HAL error to CKR_FUNCTION_FAILED\n", file, line);
@@ -1630,39 +1633,25 @@ static int p11_object_get_pkey_handle(const p11_session_t * const session,
!sql_check_row(sqlite3_step(q)))
goto fail;
- switch (sqlite3_column_type(q, 0)) {
+ const int column_0_type = sqlite3_column_type(q, 0);
+ const int column_1_type = sqlite3_column_type(q, 1);
- case SQLITE_INTEGER:
+ if (column_0_type == SQLITE_INTEGER)
pkey_type = (hal_key_type_t) sqlite3_column_int64(q, 0);
- break;
-
- case SQLITE_NULL:
- if (!p11_object_pkey_type(object_handle, &pkey_type))
- goto fail;
- break;
- default:
+ else if (column_0_type != SQLITE_NULL || !p11_object_pkey_type(object_handle, &pkey_type))
goto fail;
- }
- switch (sqlite3_column_type(q, 1)) {
-
- case SQLITE_BLOB:
- err = hal_whine_allow(hal_rpc_pkey_find(p11_session_hal_client(session),
- p11_session_hal_session(session), pkey_handle,
- pkey_type, sqlite3_column_blob(q, 1),
- sqlite3_column_bytes(q, 1),
- flags),
+ if (column_1_type == SQLITE_BLOB)
+ err = hal_whine_allow(hal_rpc_pkey_find(p11_session_hal_client(session), p11_session_hal_session(session), pkey_handle,
+ pkey_type, sqlite3_column_blob(q, 1), sqlite3_column_bytes(q, 1), flags),
HAL_ERROR_KEY_NOT_FOUND);
- break;
- case SQLITE_NULL:
- err = HAL_ERROR_KEY_NOT_FOUND;
- break;
+ else if (column_1_type == SQLITE_NULL)
+ err = hal_whine(HAL_ERROR_KEY_NOT_FOUND);
- default:
+ else
goto fail;
- }
if (err == HAL_OK)
ok = 1;
@@ -2285,26 +2274,28 @@ static CK_RV generate_keypair_ec(p11_session_t *session,
static CK_RV generate_keypair(p11_session_t *session,
const CK_MECHANISM_PTR pMechanism,
- const CK_ATTRIBUTE_PTR pPublicKeyTemplate,
- const CK_ULONG ulPublicKeyAttributeCount,
- const CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
- const CK_ULONG ulPrivateKeyAttributeCount,
- CK_OBJECT_HANDLE_PTR phPublicKey,
- CK_OBJECT_HANDLE_PTR phPrivateKey,
CK_RV (*mechanism_handler)(p11_session_t *session,
+
const CK_ATTRIBUTE_PTR pPublicKeyTemplate,
const CK_ULONG ulPublicKeyAttributeCount,
const CK_OBJECT_HANDLE public_handle,
const hal_key_flags_t public_flags,
+
const CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
const CK_ULONG ulPrivateKeyAttributeCount,
const CK_OBJECT_HANDLE private_handle,
const hal_key_flags_t private_flags),
+ const CK_ATTRIBUTE_PTR pPublicKeyTemplate,
+ const CK_ULONG ulPublicKeyAttributeCount,
const p11_descriptor_t * const public_descriptor,
- const p11_descriptor_t * const private_descriptor)
+ CK_OBJECT_HANDLE_PTR phPublicKey,
+ const CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
+ const CK_ULONG ulPrivateKeyAttributeCount,
+ const p11_descriptor_t * const private_descriptor,
+ CK_OBJECT_HANDLE_PTR phPrivateKey)
{
- CK_OBJECT_HANDLE private_handle = CK_INVALID_HANDLE;
CK_OBJECT_HANDLE public_handle = CK_INVALID_HANDLE;
+ CK_OBJECT_HANDLE private_handle = CK_INVALID_HANDLE;
handle_flavor_t public_handle_flavor = handle_flavor_session_object;
handle_flavor_t private_handle_flavor = handle_flavor_session_object;
hal_key_flags_t public_flags = 0;
@@ -4295,23 +4286,15 @@ CK_RV C_GenerateKeyPair(CK_SESSION_HANDLE hSession,
switch (pMechanism->mechanism) {
case CKM_RSA_PKCS_KEY_PAIR_GEN:
- rv = generate_keypair(session, pMechanism,
- pPublicKeyTemplate, ulPublicKeyAttributeCount,
- pPrivateKeyTemplate, ulPrivateKeyAttributeCount,
- phPublicKey, phPrivateKey,
- generate_keypair_rsa_pkcs,
- &p11_descriptor_rsa_public_key,
- &p11_descriptor_rsa_private_key);
+ rv = generate_keypair(session, pMechanism, generate_keypair_rsa_pkcs,
+ pPublicKeyTemplate, ulPublicKeyAttributeCount, &p11_descriptor_rsa_public_key, phPublicKey,
+ pPrivateKeyTemplate, ulPrivateKeyAttributeCount, &p11_descriptor_rsa_private_key, phPrivateKey);
break;
case CKM_EC_KEY_PAIR_GEN:
- rv = generate_keypair(session, pMechanism,
- pPublicKeyTemplate, ulPublicKeyAttributeCount,
- pPrivateKeyTemplate, ulPrivateKeyAttributeCount,
- phPublicKey, phPrivateKey,
- generate_keypair_ec,
- &p11_descriptor_ec_public_key,
- &p11_descriptor_ec_private_key);
+ rv = generate_keypair(session, pMechanism, generate_keypair_ec,
+ pPublicKeyTemplate, ulPublicKeyAttributeCount, &p11_descriptor_ec_public_key, phPublicKey,
+ pPrivateKeyTemplate, ulPrivateKeyAttributeCount, &p11_descriptor_ec_private_key, phPrivateKey);
break;
default: