gnome-keyring r1528 - in trunk: . pkcs11/gck pkcs11/user-store
- From: nnielsen svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-keyring r1528 - in trunk: . pkcs11/gck pkcs11/user-store
- Date: Sun, 8 Feb 2009 04:56:36 +0000 (UTC)
Author: nnielsen
Date: Sun Feb 8 04:56:36 2009
New Revision: 1528
URL: http://svn.gnome.org/viewvc/gnome-keyring?rev=1528&view=rev
Log:
Create proper factories for storable objects and certificate.
Modified:
trunk/ChangeLog
trunk/pkcs11/gck/gck-certificate.c
trunk/pkcs11/gck/gck-certificate.h
trunk/pkcs11/gck/gck-module.c
trunk/pkcs11/gck/gck-private-key.c
trunk/pkcs11/gck/gck-private-key.h
trunk/pkcs11/gck/gck-public-key.c
trunk/pkcs11/gck/gck-public-key.h
trunk/pkcs11/user-store/gck-user-module.c
trunk/pkcs11/user-store/gck-user-private-key.c
trunk/pkcs11/user-store/gck-user-private-key.h
trunk/pkcs11/user-store/gck-user-public-key.c
trunk/pkcs11/user-store/gck-user-public-key.h
Modified: trunk/pkcs11/gck/gck-certificate.c
==============================================================================
--- trunk/pkcs11/gck/gck-certificate.c (original)
+++ trunk/pkcs11/gck/gck-certificate.c Sun Feb 8 04:56:36 2009
@@ -27,10 +27,12 @@
#include "gck-crypto.h"
#include "gck-data-asn1.h"
#include "gck-data-der.h"
+#include "gck-factory.h"
#include "gck-key.h"
#include "gck-manager.h"
#include "gck-sexp.h"
#include "gck-serializable.h"
+#include "gck-transaction.h"
#include "gck-util.h"
#include "pkcs11/pkcs11.h"
@@ -240,6 +242,39 @@
return 0;
}
+static void
+factory_create_certificate (GckSession *session, GckTransaction *transaction,
+ CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs, GckObject **object)
+{
+ CK_ATTRIBUTE_PTR attr;
+ GckCertificate *cert;
+
+ g_return_if_fail (GCK_IS_TRANSACTION (transaction));
+ g_return_if_fail (attrs || !n_attrs);
+ g_return_if_fail (object);
+
+ /* Dig out the value */
+ attr = gck_attributes_find (attrs, n_attrs, CKA_VALUE);
+ if (attr == NULL) {
+ gck_transaction_fail (transaction, CKR_TEMPLATE_INCOMPLETE);
+ return;
+ }
+
+ cert = g_object_new (GCK_TYPE_CERTIFICATE, NULL);
+
+ /* Load the certificate from the data specified */
+ if (!gck_serializable_load (GCK_SERIALIZABLE (cert), NULL, attr->pValue, attr->ulValueLen)) {
+ gck_transaction_fail (transaction, CKR_ATTRIBUTE_VALUE_INVALID);
+ g_object_unref (cert);
+ return;
+ }
+
+ /* Note that we ignore the subject */
+ gck_attributes_consume (attrs, n_attrs, CKA_VALUE, CKA_SUBJECT, G_MAXULONG);
+
+ *object = GCK_OBJECT (cert);
+}
+
/* -----------------------------------------------------------------------------
* KEY
*/
@@ -707,3 +742,23 @@
return hash;
}
+
+GckFactoryInfo*
+gck_certificate_get_factory (void)
+{
+ static CK_OBJECT_CLASS klass = CKO_CERTIFICATE;
+ static CK_CERTIFICATE_TYPE type = CKC_X_509;
+
+ static CK_ATTRIBUTE attributes[] = {
+ { CKA_CLASS, &klass, sizeof (klass) },
+ { CKA_CERTIFICATE_TYPE, &type, sizeof (type) },
+ };
+
+ static GckFactoryInfo factory = {
+ attributes,
+ G_N_ELEMENTS (attributes),
+ factory_create_certificate
+ };
+
+ return &factory;
+}
Modified: trunk/pkcs11/gck/gck-certificate.h
==============================================================================
--- trunk/pkcs11/gck/gck-certificate.h (original)
+++ trunk/pkcs11/gck/gck-certificate.h Sun Feb 8 04:56:36 2009
@@ -27,6 +27,8 @@
#include "gck-object.h"
#include "gck-types.h"
+#define GCK_FACTORY_CERTIFICATE (gck_certificate_get_factory ())
+
#define GCK_TYPE_CERTIFICATE (gck_certificate_get_type ())
#define GCK_CERTIFICATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCK_TYPE_CERTIFICATE, GckCertificate))
#define GCK_CERTIFICATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCK_TYPE_CERTIFICATE, GckCertificateClass))
@@ -48,6 +50,8 @@
GType gck_certificate_get_type (void);
+GckFactoryInfo* gck_certificate_get_factory (void);
+
gboolean gck_certificate_calc_category (GckCertificate *self,
CK_ULONG* category);
@@ -67,4 +71,5 @@
int hash_algo,
gsize *n_hash);
+
#endif /* __GCK_CERTIFICATE_H__ */
Modified: trunk/pkcs11/gck/gck-module.c
==============================================================================
--- trunk/pkcs11/gck/gck-module.c (original)
+++ trunk/pkcs11/gck/gck-module.c Sun Feb 8 04:56:36 2009
@@ -25,6 +25,7 @@
#include "pkcs11/pkcs11g.h"
#include "gck-attributes.h"
+#include "gck-certificate.h"
#include "gck-factory.h"
#include "gck-manager.h"
#include "gck-module.h"
@@ -418,6 +419,7 @@
/* Register session object factories */
gck_module_register_factory (self, GCK_FACTORY_PRIVATE_KEY);
+ gck_module_register_factory (self, GCK_FACTORY_CERTIFICATE);
gck_module_register_factory (self, GCK_FACTORY_PUBLIC_KEY);
}
Modified: trunk/pkcs11/gck/gck-private-key.c
==============================================================================
--- trunk/pkcs11/gck/gck-private-key.c (original)
+++ trunk/pkcs11/gck/gck-private-key.c Sun Feb 8 04:56:36 2009
@@ -142,6 +142,25 @@
return ret;
}
+static void
+factory_create_private_key (GckSession *session, GckTransaction *transaction,
+ CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs, GckObject **object)
+{
+ GckSexp *sexp;
+
+ g_return_if_fail (GCK_IS_TRANSACTION (transaction));
+ g_return_if_fail (attrs || !n_attrs);
+ g_return_if_fail (object);
+
+ sexp = gck_private_key_create_sexp (session, transaction, attrs, n_attrs);
+ if (sexp == NULL)
+ return;
+
+ *object = g_object_new (GCK_TYPE_PRIVATE_KEY, "base-sexp", sexp, NULL);
+ gck_private_key_store_private (GCK_PRIVATE_KEY (*object), sexp, G_MAXUINT);
+ gck_sexp_unref (sexp);
+}
+
/* -----------------------------------------------------------------------------
* PRIVATE_KEY
*/
@@ -349,24 +368,20 @@
}
-void
-gck_private_key_create (GckSession *session, GckTransaction *transaction,
- CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs, GckObject **object)
+GckSexp*
+gck_private_key_create_sexp (GckSession *session, GckTransaction *transaction,
+ CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs)
{
CK_KEY_TYPE type;
- GckSexp *wrapper;
gcry_sexp_t sexp;
CK_RV ret;
- g_return_if_fail (GCK_IS_TRANSACTION (transaction));
- g_return_if_fail (attrs || !n_attrs);
- g_return_if_fail (object);
-
- *object = NULL;
+ g_return_val_if_fail (GCK_IS_TRANSACTION (transaction), NULL);
+ g_return_val_if_fail (attrs || !n_attrs, NULL);
if (!gck_attributes_find_ulong (attrs, n_attrs, CKA_KEY_TYPE, &type)) {
gck_transaction_fail (transaction, CKR_TEMPLATE_INCOMPLETE);
- return;
+ return NULL;
}
gck_attributes_consume (attrs, n_attrs, CKA_KEY_TYPE, CKA_CLASS, G_MAXULONG);
@@ -386,31 +401,26 @@
if (ret != CKR_OK) {
gck_transaction_fail (transaction, ret);
- return;
+ return NULL;
}
- g_return_if_fail (sexp);
- wrapper = gck_sexp_new (sexp);
- *object = g_object_new (GCK_TYPE_PRIVATE_KEY, "base-sexp", wrapper, NULL);
- gck_private_key_store_private (GCK_PRIVATE_KEY (*object), wrapper, G_MAXUINT);
- gck_sexp_unref (wrapper);
+ g_return_val_if_fail (sexp, NULL);
+ return gck_sexp_new (sexp);
}
GckFactoryInfo*
gck_private_key_get_factory (void)
{
static CK_OBJECT_CLASS klass = CKO_PRIVATE_KEY;
- static CK_BBOOL token = CK_FALSE;
static CK_ATTRIBUTE attributes[] = {
- { CKA_CLASS, &klass, sizeof (klass) },
- { CKA_TOKEN, &token, sizeof (token) },
+ { CKA_CLASS, &klass, sizeof (klass) }
};
static GckFactoryInfo factory = {
attributes,
G_N_ELEMENTS (attributes),
- gck_private_key_create
+ factory_create_private_key
};
return &factory;
Modified: trunk/pkcs11/gck/gck-private-key.h
==============================================================================
--- trunk/pkcs11/gck/gck-private-key.h (original)
+++ trunk/pkcs11/gck/gck-private-key.h Sun Feb 8 04:56:36 2009
@@ -56,10 +56,9 @@
GckFactoryInfo* gck_private_key_get_factory (void);
-void gck_private_key_create (GckSession *session,
+GckSexp* gck_private_key_create_sexp (GckSession *session,
GckTransaction *transaction,
CK_ATTRIBUTE_PTR attrs,
- CK_ULONG n_attrs,
- GckObject **object);
+ CK_ULONG n_attrs);
#endif /* __GCK_PRIVATE_KEY_H__ */
Modified: trunk/pkcs11/gck/gck-public-key.c
==============================================================================
--- trunk/pkcs11/gck/gck-public-key.c (original)
+++ trunk/pkcs11/gck/gck-public-key.c Sun Feb 8 04:56:36 2009
@@ -137,6 +137,23 @@
return ret;
}
+static void
+factory_create_public_key (GckSession *session, GckTransaction *transaction,
+ CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs, GckObject **object)
+{
+ GckSexp *sexp;
+
+ g_return_if_fail (GCK_IS_TRANSACTION (transaction));
+ g_return_if_fail (attrs || !n_attrs);
+ g_return_if_fail (object);
+
+ sexp = gck_public_key_create_sexp (session, transaction, attrs, n_attrs);
+ if (sexp != NULL) {
+ *object = g_object_new (GCK_TYPE_PUBLIC_KEY, "base-sexp", sexp, NULL);
+ gck_sexp_unref (sexp);
+ }
+}
+
/* -----------------------------------------------------------------------------
* PUBLIC_KEY
*/
@@ -281,24 +298,20 @@
* PUBLIC
*/
-void
-gck_public_key_create (GckSession *session, GckTransaction *transaction,
- CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs, GckObject **object)
+GckSexp*
+gck_public_key_create_sexp (GckSession *session, GckTransaction *transaction,
+ CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs)
{
CK_KEY_TYPE type;
- GckSexp *wrapper;
gcry_sexp_t sexp;
CK_RV ret;
- g_return_if_fail (GCK_IS_TRANSACTION (transaction));
- g_return_if_fail (attrs || !n_attrs);
- g_return_if_fail (object);
-
- *object = NULL;
-
+ g_return_val_if_fail (GCK_IS_TRANSACTION (transaction), NULL);
+ g_return_val_if_fail (attrs || !n_attrs, NULL);
+
if (!gck_attributes_find_ulong (attrs, n_attrs, CKA_KEY_TYPE, &type)) {
gck_transaction_fail (transaction, CKR_TEMPLATE_INCOMPLETE);
- return;
+ return NULL;
}
gck_attributes_consume (attrs, n_attrs, CKA_KEY_TYPE, CKA_CLASS, G_MAXULONG);
@@ -317,30 +330,26 @@
if (ret != CKR_OK) {
gck_transaction_fail (transaction, ret);
- return;
+ return NULL;
}
- g_return_if_fail (sexp);
- wrapper = gck_sexp_new (sexp);
- *object = g_object_new (GCK_TYPE_PUBLIC_KEY, "base-sexp", wrapper, NULL);
- gck_sexp_unref (wrapper);
+ g_return_val_if_fail (sexp, NULL);
+ return gck_sexp_new (sexp);
}
GckFactoryInfo*
gck_public_key_get_factory (void)
{
static CK_OBJECT_CLASS klass = CKO_PUBLIC_KEY;
- static CK_BBOOL token = CK_FALSE;
static CK_ATTRIBUTE attributes[] = {
- { CKA_CLASS, &klass, sizeof (klass) },
- { CKA_TOKEN, &token, sizeof (token) },
+ { CKA_CLASS, &klass, sizeof (klass) }
};
static GckFactoryInfo factory = {
attributes,
G_N_ELEMENTS (attributes),
- gck_public_key_create
+ factory_create_public_key
};
return &factory;
Modified: trunk/pkcs11/gck/gck-public-key.h
==============================================================================
--- trunk/pkcs11/gck/gck-public-key.h (original)
+++ trunk/pkcs11/gck/gck-public-key.h Sun Feb 8 04:56:36 2009
@@ -52,9 +52,8 @@
GckFactoryInfo* gck_public_key_get_factory (void);
-void gck_public_key_create (GckSession *session,
+GckSexp* gck_public_key_create_sexp (GckSession *session,
GckTransaction *transaction,
CK_ATTRIBUTE_PTR attrs,
- CK_ULONG n_attrs,
- GckObject **object);
+ CK_ULONG n_attrs);
#endif /* __GCK_PUBLIC_KEY_H__ */
Modified: trunk/pkcs11/user-store/gck-user-module.c
==============================================================================
--- trunk/pkcs11/user-store/gck-user-module.c (original)
+++ trunk/pkcs11/user-store/gck-user-module.c Sun Feb 8 04:56:36 2009
@@ -22,6 +22,8 @@
#include "config.h"
#include "gck-user-module.h"
+#include "gck-user-private-key.h"
+#include "gck-user-public-key.h"
#include "gck-user-storage.h"
#include "gck-user-store.h"
@@ -233,6 +235,10 @@
gck_user_module_init (GckUserModule *self)
{
self->logged_in_apps = g_hash_table_new_full (gck_util_ulong_hash, gck_util_ulong_equal, gck_util_ulong_free, NULL);
+
+ /* For creating stored keys */
+ gck_module_register_factory (GCK_MODULE (self), GCK_FACTORY_USER_PRIVATE_KEY);
+ gck_module_register_factory (GCK_MODULE (self), GCK_FACTORY_USER_PUBLIC_KEY);
}
static void
Modified: trunk/pkcs11/user-store/gck-user-private-key.c
==============================================================================
--- trunk/pkcs11/user-store/gck-user-private-key.c (original)
+++ trunk/pkcs11/user-store/gck-user-private-key.c Sun Feb 8 04:56:36 2009
@@ -26,6 +26,7 @@
#include "gck/gck-attributes.h"
#include "gck/gck-crypto.h"
#include "gck/gck-data-der.h"
+#include "gck/gck-factory.h"
#include "gck/gck-login.h"
#include "gck/gck-manager.h"
#include "gck/gck-object.h"
@@ -59,6 +60,24 @@
* INTERNAL
*/
+static void
+factory_create_private_key (GckSession *session, GckTransaction *transaction,
+ CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs, GckObject **object)
+{
+ GckSexp *sexp;
+
+ g_return_if_fail (attrs || !n_attrs);
+ g_return_if_fail (object);
+
+ sexp = gck_private_key_create_sexp (session, transaction, attrs, n_attrs);
+ if (sexp == NULL)
+ return;
+
+ *object = g_object_new (GCK_TYPE_USER_PRIVATE_KEY, "base-sexp", sexp, NULL);
+ gck_private_key_store_private (GCK_PRIVATE_KEY (*object), sexp, G_MAXUINT);
+ gck_sexp_unref (sexp);
+}
+
/* -----------------------------------------------------------------------------
* OBJECT
*/
@@ -287,3 +306,23 @@
/* -----------------------------------------------------------------------------
* PUBLIC
*/
+
+GckFactoryInfo*
+gck_user_private_key_get_factory (void)
+{
+ static CK_OBJECT_CLASS klass = CKO_PRIVATE_KEY;
+ static CK_BBOOL token = CK_TRUE;
+
+ static CK_ATTRIBUTE attributes[] = {
+ { CKA_CLASS, &klass, sizeof (klass) },
+ { CKA_TOKEN, &token, sizeof (token) },
+ };
+
+ static GckFactoryInfo factory = {
+ attributes,
+ G_N_ELEMENTS (attributes),
+ factory_create_private_key
+ };
+
+ return &factory;
+}
Modified: trunk/pkcs11/user-store/gck-user-private-key.h
==============================================================================
--- trunk/pkcs11/user-store/gck-user-private-key.h (original)
+++ trunk/pkcs11/user-store/gck-user-private-key.h Sun Feb 8 04:56:36 2009
@@ -29,6 +29,8 @@
#include "gck/gck-login.h"
#include "gck/gck-private-key.h"
+#define GCK_FACTORY_USER_PRIVATE_KEY (gck_user_private_key_get_factory ())
+
#define GCK_TYPE_USER_PRIVATE_KEY (gck_user_private_key_get_type ())
#define GCK_USER_PRIVATE_KEY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCK_TYPE_USER_PRIVATE_KEY, GckUserPrivateKey))
#define GCK_USER_PRIVATE_KEY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCK_TYPE_USER_PRIVATE_KEY, GckUserPrivateKeyClass))
@@ -45,4 +47,6 @@
GType gck_user_private_key_get_type (void);
+GckFactoryInfo* gck_user_private_key_get_factory (void);
+
#endif /* __GCK_USER_PRIVATE_KEY_H__ */
Modified: trunk/pkcs11/user-store/gck-user-public-key.c
==============================================================================
--- trunk/pkcs11/user-store/gck-user-public-key.c (original)
+++ trunk/pkcs11/user-store/gck-user-public-key.c Sun Feb 8 04:56:36 2009
@@ -25,6 +25,7 @@
#include "gck/gck-attributes.h"
#include "gck/gck-data-der.h"
+#include "gck/gck-factory.h"
#include "gck/gck-serializable.h"
#include "gck/gck-object.h"
#include "gck/gck-util.h"
@@ -41,6 +42,26 @@
G_IMPLEMENT_INTERFACE (GCK_TYPE_SERIALIZABLE, gck_user_public_key_serializable));
/* -----------------------------------------------------------------------------
+ * INTERNAL
+ */
+
+static void
+factory_create_public_key (GckSession *session, GckTransaction *transaction,
+ CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs, GckObject **object)
+{
+ GckSexp *sexp;
+
+ g_return_if_fail (attrs || !n_attrs);
+ g_return_if_fail (object);
+
+ sexp = gck_public_key_create_sexp (session, transaction, attrs, n_attrs);
+ if (sexp != NULL) {
+ *object = g_object_new (GCK_TYPE_USER_PUBLIC_KEY, "base-sexp", sexp, NULL);
+ gck_sexp_unref (sexp);
+ }
+}
+
+/* -----------------------------------------------------------------------------
* OBJECT
*/
@@ -155,3 +176,22 @@
* PUBLIC
*/
+GckFactoryInfo*
+gck_user_public_key_get_factory (void)
+{
+ static CK_OBJECT_CLASS klass = CKO_PUBLIC_KEY;
+ static CK_BBOOL token = CK_TRUE;
+
+ static CK_ATTRIBUTE attributes[] = {
+ { CKA_CLASS, &klass, sizeof (klass) },
+ { CKA_TOKEN, &token, sizeof (token) },
+ };
+
+ static GckFactoryInfo factory = {
+ attributes,
+ G_N_ELEMENTS (attributes),
+ factory_create_public_key
+ };
+
+ return &factory;
+}
Modified: trunk/pkcs11/user-store/gck-user-public-key.h
==============================================================================
--- trunk/pkcs11/user-store/gck-user-public-key.h (original)
+++ trunk/pkcs11/user-store/gck-user-public-key.h Sun Feb 8 04:56:36 2009
@@ -26,6 +26,8 @@
#include "gck/gck-public-key.h"
+#define GCK_FACTORY_USER_PUBLIC_KEY (gck_user_public_key_get_factory ())
+
#define GCK_TYPE_USER_PUBLIC_KEY (gck_user_public_key_get_type ())
#define GCK_USER_PUBLIC_KEY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCK_TYPE_USER_PUBLIC_KEY, GckUserPublicKey))
#define GCK_USER_PUBLIC_KEY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCK_TYPE_USER_PUBLIC_KEY, GckUserPublicKeyClass))
@@ -42,6 +44,8 @@
GType gck_user_public_key_get_type (void);
+GckFactoryInfo* gck_user_public_key_get_factory (void);
+
GckUserPublicKey* gck_user_public_key_new (const gchar *unique);
#endif /* __GCK_USER_PUBLIC_KEY_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]