[gnome-keyring] [pkcs11] Propogate errors retrieving value while wrapping secret.
- From: Stefan Walter <stefw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-keyring] [pkcs11] Propogate errors retrieving value while wrapping secret.
- Date: Sun, 3 Jan 2010 20:57:08 +0000 (UTC)
commit 2a00634309d8dc6aa5afcff8dc0bb001da13982e
Author: Stef Walter <stef memberwebs com>
Date: Sun Jan 3 02:16:43 2010 +0000
[pkcs11] Propogate errors retrieving value while wrapping secret.
pkcs11/gck/gck-aes-mechanism.c | 43 ++++++++++++++++++++----------------
pkcs11/gck/gck-null-mechanism.c | 46 +++++++++++++++++++++-----------------
2 files changed, 49 insertions(+), 40 deletions(-)
---
diff --git a/pkcs11/gck/gck-aes-mechanism.c b/pkcs11/gck/gck-aes-mechanism.c
index b8cecff..1389560 100644
--- a/pkcs11/gck/gck-aes-mechanism.c
+++ b/pkcs11/gck/gck-aes-mechanism.c
@@ -31,40 +31,44 @@
#include "egg/egg-padding.h"
#include "egg/egg-secure-memory.h"
-static gboolean
+static CK_RV
retrieve_length (GckSession *session, GckObject *wrapped, gsize *length)
{
CK_ATTRIBUTE attr;
+ CK_RV rv;
attr.type = CKA_VALUE;
attr.pValue = NULL;
attr.ulValueLen = 0;
- if (gck_object_get_attribute (wrapped, session, &attr) != CKR_OK)
- return FALSE;
-
- *length = attr.ulValueLen;
- return TRUE;
+ rv = gck_object_get_attribute (wrapped, session, &attr);
+ if (rv == CKR_OK)
+ *length = attr.ulValueLen;
+ return rv;
}
-static gpointer
-retrieve_value (GckSession *session, GckObject *wrapped, gsize *n_value)
+static CK_RV
+retrieve_value (GckSession *session, GckObject *wrapped,
+ gpointer *value, gsize *n_value)
{
CK_ATTRIBUTE attr;
+ CK_RV rv;
- if (!retrieve_length (session, wrapped, n_value))
- return NULL;
+ rv = retrieve_length (session, wrapped, n_value);
+ if (rv != CKR_OK)
+ return rv;
attr.type = CKA_VALUE;
attr.pValue = egg_secure_alloc (*n_value);
attr.ulValueLen = *n_value;
- if (gck_object_get_attribute (wrapped, session, &attr) != CKR_OK) {
+ rv = gck_object_get_attribute (wrapped, session, &attr);
+ if (rv == CKR_OK)
+ *value = attr.pValue;
+ else
egg_secure_free (attr.pValue);
- return NULL;
- }
- return attr.pValue;
+ return rv;
}
CK_RV
@@ -96,8 +100,9 @@ gck_aes_mechanism_wrap (GckSession *session, CK_MECHANISM_PTR mech,
/* They just want the length */
if (!output) {
- if (!retrieve_length (session, wrapped, &n_value))
- return CKR_KEY_NOT_WRAPPABLE;
+ rv = retrieve_length (session, wrapped, &n_value);
+ if (rv != CKR_OK)
+ return rv;
if (!egg_padding_pkcs7_pad (NULL, block, NULL, n_value, NULL, &n_padded))
return CKR_KEY_SIZE_RANGE;
*n_output = n_padded;
@@ -113,10 +118,10 @@ gck_aes_mechanism_wrap (GckSession *session, CK_MECHANISM_PTR mech,
return CKR_MECHANISM_PARAM_INVALID;
}
- value = retrieve_value (session, wrapped, &n_value);
- if (value == NULL) {
+ rv = retrieve_value (session, wrapped, &value, &n_value);
+ if (rv != CKR_OK) {
gcry_cipher_close (cih);
- return CKR_KEY_NOT_WRAPPABLE;
+ return rv;
}
ret = egg_padding_pkcs7_pad (egg_secure_realloc, block, value, n_value, &padded, &n_padded);
diff --git a/pkcs11/gck/gck-null-mechanism.c b/pkcs11/gck/gck-null-mechanism.c
index 149aea5..03f0862 100644
--- a/pkcs11/gck/gck-null-mechanism.c
+++ b/pkcs11/gck/gck-null-mechanism.c
@@ -30,40 +30,44 @@
#include "egg/egg-libgcrypt.h"
#include "egg/egg-secure-memory.h"
-static gboolean
+static CK_RV
retrieve_length (GckSession *session, GckObject *wrapped, gsize *length)
{
CK_ATTRIBUTE attr;
+ CK_RV rv;
attr.type = CKA_VALUE;
attr.pValue = NULL;
attr.ulValueLen = 0;
- if (gck_object_get_attribute (wrapped, session, &attr) != CKR_OK)
- return FALSE;
-
- *length = attr.ulValueLen;
- return TRUE;
+ rv = gck_object_get_attribute (wrapped, session, &attr);
+ if (rv == CKR_OK)
+ *length = attr.ulValueLen;
+ return rv;
}
-static gpointer
-retrieve_value (GckSession *session, GckObject *wrapped, gsize *n_value)
+static CK_RV
+retrieve_value (GckSession *session, GckObject *wrapped,
+ gpointer *value, gsize *n_value)
{
CK_ATTRIBUTE attr;
+ CK_RV rv;
- if (!retrieve_length (session, wrapped, n_value))
- return NULL;
+ rv = retrieve_length (session, wrapped, n_value);
+ if (rv != CKR_OK)
+ return rv;
attr.type = CKA_VALUE;
attr.pValue = egg_secure_alloc (*n_value);
attr.ulValueLen = *n_value;
- if (gck_object_get_attribute (wrapped, session, &attr) != CKR_OK) {
+ rv = gck_object_get_attribute (wrapped, session, &attr);
+ if (rv == CKR_OK)
+ *value = attr.pValue;
+ else
egg_secure_free (attr.pValue);
- return NULL;
- }
- return attr.pValue;
+ return rv;
}
CK_RV
@@ -88,18 +92,18 @@ gck_null_mechanism_wrap (GckSession *session, CK_MECHANISM_PTR mech,
/* They just want the length */
if (!output) {
- if (!retrieve_length (session, wrapped, &n_value))
- return CKR_KEY_NOT_WRAPPABLE;
- *n_output = n_value;
- return CKR_OK;
+ rv = retrieve_length (session, wrapped, &n_value);
+ if (rv == CKR_OK)
+ *n_output = n_value;
+ return rv;
}
if (mech->ulParameterLen)
return CKR_MECHANISM_PARAM_INVALID;
- value = retrieve_value (session, wrapped, &n_value);
- if (value == NULL)
- return CKR_KEY_NOT_WRAPPABLE;
+ rv = retrieve_value (session, wrapped, &value, &n_value);
+ if (rv != CKR_OK)
+ return rv;
rv = gck_util_return_data (output, n_output, value, n_value);
egg_secure_free (value);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]