~ubuntu-branches/ubuntu/natty/gnome-keyring/natty

« back to all changes in this revision

Viewing changes to pkcs11/gck/gck-certificate.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-02-16 19:00:06 UTC
  • mfrom: (1.1.58 upstream)
  • Revision ID: james.westby@ubuntu.com-20100216190006-cqpnic4zxlkmmi0o
Tags: 2.29.90git20100218-0ubuntu1
Updated to a git snapshot version

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "gck-data-asn1.h"
29
29
#include "gck-data-der.h"
30
30
#include "gck-factory.h"
31
 
#include "gck-key.h"
 
31
#include "gck-sexp-key.h"
32
32
#include "gck-manager.h"
33
33
#include "gck-session.h"
34
34
#include "gck-sexp.h"
243
243
        return 0;
244
244
}
245
245
 
246
 
static void
 
246
static GckObject*
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)
249
249
{
250
250
        CK_ATTRIBUTE_PTR attr;
251
251
        GckCertificate *cert;
252
 
        
253
 
        g_return_if_fail (GCK_IS_TRANSACTION (transaction));
254
 
        g_return_if_fail (attrs || !n_attrs);
255
 
        g_return_if_fail (object);
256
 
        
 
252
 
 
253
        g_return_val_if_fail (GCK_IS_TRANSACTION (transaction), NULL);
 
254
        g_return_val_if_fail (attrs || !n_attrs, NULL);
 
255
 
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);
261
 
                return;
 
260
                return NULL;
262
261
        }
263
262
        
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
                             NULL);
265
267
        
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);
270
 
                return;
 
272
                return NULL;
271
273
        }
272
274
                
273
275
        /* Note that we ignore the subject */
274
276
        gck_attributes_consume (attrs, n_attrs, CKA_VALUE, CKA_SUBJECT, G_MAXULONG);
275
277
 
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);
277
281
}
278
282
 
279
283
/* -----------------------------------------------------------------------------
518
522
}
519
523
 
520
524
static gboolean 
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)
522
526
{
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)),
 
565
                                                                 self);
 
566
                gck_sexp_key_set_base (GCK_SEXP_KEY (self->pv->key), wrapper);
561
567
                gck_sexp_unref (wrapper);
562
568
                break;
563
569
 
592
598
}
593
599
 
594
600
static gboolean 
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)
596
602
{
597
603
        GckCertificate *self = GCK_CERTIFICATE (base);
598
604
        
767
773
        return hash;
768
774
}
769
775
 
770
 
GckFactoryInfo*
 
776
GckFactory*
771
777
gck_certificate_get_factory (void)
772
778
{
773
779
        static CK_OBJECT_CLASS klass = CKO_CERTIFICATE;
778
784
                { CKA_CERTIFICATE_TYPE, &type, sizeof (type) },
779
785
        };
780
786
 
781
 
        static GckFactoryInfo factory = {
 
787
        static GckFactory factory = {
782
788
                attributes,
783
789
                G_N_ELEMENTS (attributes),
784
790
                factory_create_certificate