1 /* ksign-keyring.c: public key cache
3 * Copyright (C) 2001 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This file is derived from part of GnuPG.
8 * GnuPG is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * GnuPG is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
23 #include <linux/rwsem.h>
26 static LIST_HEAD(keyring);
27 static DECLARE_RWSEM(keyring_sem);
30 * handle a public key element parsed from the keyring blob
32 static int add_keyblock_key(struct ksign_public_key *pk, void *data)
34 printk("- Added public key %X%X\n", pk->keyid[0], pk->keyid[1]);
36 if (pk->expiredate && pk->expiredate < xtime.tv_sec)
37 printk(" - public key has expired\n");
39 if (pk->timestamp > xtime.tv_sec )
40 printk(" - key was been created %lu seconds in future\n",
41 pk->timestamp - xtime.tv_sec);
43 atomic_inc(&pk->count);
45 down_write(&keyring_sem);
46 list_add_tail(&pk->link, &keyring);
47 up_write(&keyring_sem);
53 * handle a user ID element parsed from the keyring blob
55 static int add_keyblock_uid(struct ksign_user_id *uid, void *data)
57 printk("- User ID: %s\n", uid->name);
62 * add the keys from a ASN.1 encoded blob into the keyring
64 int ksign_load_keyring_from_buffer(const void *buffer, size_t size)
66 printk("Loading keyring\n");
68 return ksign_parse_packets((const uint8_t *) buffer,
77 * find a public key by ID
79 struct ksign_public_key *ksign_get_public_key(const uint32_t *keyid)
81 struct ksign_public_key *pk;
83 down_read(&keyring_sem);
85 list_for_each_entry(pk, &keyring, link) {
86 if (memcmp(pk->keyid, keyid, sizeof(pk->keyid)) == 0) {
87 atomic_inc(&pk->count);
95 up_read(&keyring_sem);
100 * clear the public-key keyring
102 void ksign_clear_keyring(void)
104 struct ksign_public_key *pk;
106 down_write(&keyring_sem);
108 while (!list_empty(&keyring)) {
109 pk = list_entry(keyring.next, struct ksign_public_key, link);
112 ksign_put_public_key(pk);
115 up_write(&keyring_sem);