247
247
factory_create_certificate (GckSession *session, GckTransaction *transaction,
248
CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs, GckObject **object)
248
CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs)
250
250
CK_ATTRIBUTE_PTR attr;
251
251
GckCertificate *cert;
253
g_return_if_fail (GCK_IS_TRANSACTION (transaction));
254
g_return_if_fail (attrs || !n_attrs);
255
g_return_if_fail (object);
253
g_return_val_if_fail (GCK_IS_TRANSACTION (transaction), NULL);
254
g_return_val_if_fail (attrs || !n_attrs, NULL);
257
256
/* Dig out the value */
258
257
attr = gck_attributes_find (attrs, n_attrs, CKA_VALUE);
259
258
if (attr == NULL) {
260
259
gck_transaction_fail (transaction, CKR_TEMPLATE_INCOMPLETE);
264
cert = g_object_new (GCK_TYPE_CERTIFICATE, "module", gck_session_get_module (session), NULL);
263
cert = g_object_new (GCK_TYPE_CERTIFICATE,
264
"module", gck_session_get_module (session),
265
"manager", gck_manager_for_template (attrs, n_attrs, session),
266
268
/* Load the certificate from the data specified */
267
269
if (!gck_serializable_load (GCK_SERIALIZABLE (cert), NULL, attr->pValue, attr->ulValueLen)) {
268
270
gck_transaction_fail (transaction, CKR_ATTRIBUTE_VALUE_INVALID);
269
271
g_object_unref (cert);
273
275
/* Note that we ignore the subject */
274
276
gck_attributes_consume (attrs, n_attrs, CKA_VALUE, CKA_SUBJECT, G_MAXULONG);
276
*object = GCK_OBJECT (cert);
278
gck_session_complete_object_creation (session, transaction, GCK_OBJECT (cert),
279
TRUE, attrs, n_attrs);
280
return GCK_OBJECT (cert);
279
283
/* -----------------------------------------------------------------------------
521
gck_certificate_real_load (GckSerializable *base, GckLogin *login, const guchar *data, gsize n_data)
525
gck_certificate_real_load (GckSerializable *base, GckSecret *login, const guchar *data, gsize n_data)
523
527
GckCertificate *self = GCK_CERTIFICATE (base);
524
528
ASN1_TYPE asn1 = ASN1_TYPE_EMPTY;
556
560
case GCK_DATA_SUCCESS:
557
561
wrapper = gck_sexp_new (sexp);
558
562
if (!self->pv->key)
559
self->pv->key = gck_certificate_key_new (gck_object_get_module (GCK_OBJECT (self)), self);
560
gck_key_set_base_sexp (GCK_KEY (self->pv->key), wrapper);
563
self->pv->key = gck_certificate_key_new (gck_object_get_module (GCK_OBJECT (self)),
564
gck_object_get_manager (GCK_OBJECT (self)),
566
gck_sexp_key_set_base (GCK_SEXP_KEY (self->pv->key), wrapper);
561
567
gck_sexp_unref (wrapper);
595
gck_certificate_real_save (GckSerializable *base, GckLogin *login, guchar **data, gsize *n_data)
601
gck_certificate_real_save (GckSerializable *base, GckSecret *login, guchar **data, gsize *n_data)
597
603
GckCertificate *self = GCK_CERTIFICATE (base);
778
784
{ CKA_CERTIFICATE_TYPE, &type, sizeof (type) },
781
static GckFactoryInfo factory = {
787
static GckFactory factory = {
783
789
G_N_ELEMENTS (attributes),
784
790
factory_create_certificate