~noskcaj/ubuntu/vivid/gnome-keyring/3.15.90

« back to all changes in this revision

Viewing changes to pkcs11/roots-store/gkm-roots-module.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach
  • Date: 2012-05-14 22:13:02 UTC
  • mfrom: (1.3.1)
  • mto: (80.2.8 experimental) (1.1.77)
  • mto: This revision was merged to the branch mainline in revision 148.
  • Revision ID: package-import@ubuntu.com-20120514221302-0l3gjmqpe6xopond
ImportĀ upstreamĀ versionĀ 3.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "gkm/gkm-file-tracker.h"
29
29
#include "gkm/gkm-serializable.h"
30
30
 
 
31
#include "egg/egg-armor.h"
31
32
#include "egg/egg-error.h"
32
33
#include "egg/egg-openssl.h"
33
34
 
35
36
 
36
37
struct _GkmRootsModule {
37
38
        GkmModule parent;
 
39
        GHashTable *certificates;
38
40
        GkmFileTracker *tracker;
39
 
        GHashTable *certificates;
40
 
        gchar *directory;
 
41
        gboolean is_directory;
 
42
        gchar *path;
41
43
};
42
44
 
43
45
static const CK_SLOT_INFO gkm_roots_module_slot_info = {
136
138
}
137
139
 
138
140
static void
139
 
parsed_pem_block (GQuark type, const guchar *data, gsize n_data,
140
 
                  GHashTable *headers, gpointer user_data)
 
141
parsed_pem_block (GQuark type,
 
142
                  const guchar *data,
 
143
                  gsize n_data,
 
144
                  const gchar *outer,
 
145
                  gsize n_outer,
 
146
                  GHashTable *headers,
 
147
                  gpointer user_data)
141
148
{
142
149
        static GQuark PEM_CERTIFICATE;
143
150
        static volatile gsize quarks_inited = 0;
181
188
        GList *objects, *l;
182
189
        GError *error = NULL;
183
190
        gsize n_data;
184
 
        guint num;
185
191
 
186
192
        manager = gkm_module_get_manager (GKM_MODULE (self));
187
193
        g_return_if_fail (manager);
206
212
        g_list_free (objects);
207
213
 
208
214
        /* Try and parse the PEM */
209
 
        num = egg_openssl_pem_parse (data, n_data, parsed_pem_block, &ctx);
 
215
        egg_armor_parse (data, n_data, parsed_pem_block, &ctx);
210
216
 
211
217
        /* If no PEM data, try to parse directly as DER  */
212
218
        if (ctx.count == 0) {
261
267
{
262
268
        GkmRootsModule *self = GKM_ROOTS_MODULE (base);
263
269
        if (g_str_equal (name, "directory")) {
264
 
                g_free (self->directory);
265
 
                self->directory = g_strdup (value);
 
270
                g_free (self->path);
 
271
                self->path = g_strdup (value);
 
272
                self->is_directory = TRUE;
 
273
 
 
274
        } else if (g_str_equal (name, "file")) {
 
275
                g_free (self->path);
 
276
                self->path = g_strdup (value);
 
277
                self->is_directory = FALSE;
266
278
        }
267
279
}
268
280
 
275
287
        return CKR_OK;
276
288
}
277
289
 
278
 
static GObject*
279
 
gkm_roots_module_constructor (GType type, guint n_props, GObjectConstructParam *props)
 
290
static void
 
291
gkm_roots_module_constructed (GObject *obj)
280
292
{
281
 
        GkmRootsModule *self = GKM_ROOTS_MODULE (G_OBJECT_CLASS (gkm_roots_module_parent_class)->constructor(type, n_props, props));
 
293
        GkmRootsModule *self;
 
294
        const gchar *exclude;
282
295
        GkmManager *manager;
283
 
 
284
 
        g_return_val_if_fail (self, NULL);
285
 
 
286
 
#ifdef ROOT_CERTIFICATES
287
 
        if (!self->directory)
288
 
                self->directory = g_strdup (ROOT_CERTIFICATES);
289
 
#endif
290
 
        if (self->directory) {
291
 
                self->tracker = gkm_file_tracker_new (self->directory, "*", "*.0");
 
296
        gchar *directory;
 
297
        gchar *basename;
 
298
 
 
299
        G_OBJECT_CLASS (gkm_roots_module_parent_class)->constructed (obj);
 
300
 
 
301
        self = GKM_ROOTS_MODULE (obj);
 
302
 
 
303
#ifdef ROOT_CA_FILE
 
304
        if (!self->path) {
 
305
                self->path = g_strdup (ROOT_CA_FILE);
 
306
                self->is_directory = FALSE;
 
307
        }
 
308
#endif
 
309
#ifdef ROOT_CA_DIRECTORY
 
310
        if (!self->path) {
 
311
                self->path = g_strdup (ROOT_CA_DIRECTORY);
 
312
                self->is_directory = TRUE;
 
313
        }
 
314
#endif
 
315
 
 
316
        if (self->path) {
 
317
                if (self->is_directory) {
 
318
                        directory = g_strdup (self->path);
 
319
                        basename = g_strdup ("*");
 
320
                        exclude = "*.0";
 
321
                } else {
 
322
                        directory = g_path_get_dirname (self->path);
 
323
                        basename = g_path_get_basename (self->path);
 
324
                        exclude = NULL;
 
325
                }
 
326
 
 
327
                self->tracker = gkm_file_tracker_new (directory, basename, exclude);
292
328
                g_signal_connect (self->tracker, "file-added", G_CALLBACK (file_load), self);
293
329
                g_signal_connect (self->tracker, "file-changed", G_CALLBACK (file_load), self);
294
330
                g_signal_connect (self->tracker, "file-removed", G_CALLBACK (file_remove), self);
 
331
 
 
332
                g_free (directory);
 
333
                g_free (basename);
295
334
        }
296
335
 
297
336
        manager = gkm_module_get_manager (GKM_MODULE (self));
298
337
        gkm_manager_add_property_index (manager, "unique", TRUE);
299
338
        gkm_manager_add_property_index (manager, "path", FALSE);
300
 
 
301
 
        return G_OBJECT (self);
302
339
}
303
340
 
304
341
static void
305
342
gkm_roots_module_init (GkmRootsModule *self)
306
343
{
307
344
        self->certificates = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL);
308
 
 
309
345
}
310
346
 
311
347
static void
332
368
        g_hash_table_destroy (self->certificates);
333
369
        self->certificates = NULL;
334
370
 
335
 
        g_free (self->directory);
336
 
        self->directory = NULL;
 
371
        g_free (self->path);
 
372
        self->path = NULL;
337
373
 
338
374
        G_OBJECT_CLASS (gkm_roots_module_parent_class)->finalize (obj);
339
375
}
344
380
        GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
345
381
        GkmModuleClass *module_class = GKM_MODULE_CLASS (klass);
346
382
 
347
 
        gobject_class->constructor = gkm_roots_module_constructor;
 
383
        gobject_class->constructed = gkm_roots_module_constructed;
348
384
        gobject_class->dispose = gkm_roots_module_dispose;
349
385
        gobject_class->finalize = gkm_roots_module_finalize;
350
386