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);
29 static int add_keyblock_key(struct ksign_public_key *pk, void *data)
31 printk("- Added public key %X%X\n", pk->keyid[0], pk->keyid[1]);
33 if (pk->expiredate && pk->expiredate < xtime.tv_sec)
34 printk(" - public key has expired\n");
36 if (pk->timestamp > xtime.tv_sec )
37 printk(" - key was been created %lu seconds in future\n",
38 pk->timestamp - xtime.tv_sec);
40 atomic_inc(&pk->count);
42 down_write(&keyring_sem);
43 list_add_tail(&pk->link, &keyring);
44 up_write(&keyring_sem);
49 static int add_keyblock_uid(struct ksign_user_id *uid, void *data)
51 printk("- User ID: %s\n", uid->name);
55 /*****************************************************************************/
59 int ksign_load_keyring_from_buffer(const void *buffer, size_t size)
61 printk("Loading keyring\n");
63 return ksign_parse_packets((const uint8_t *) buffer,
69 } /* end ksign_load_keyring_from_buffer() */
71 /*****************************************************************************/
75 struct ksign_public_key *ksign_get_public_key(const uint32_t *keyid)
77 struct ksign_public_key *pk;
79 down_read(&keyring_sem);
81 list_for_each_entry(pk, &keyring, link) {
82 if (memcmp(pk->keyid, keyid, sizeof(pk->keyid)) == 0) {
83 atomic_inc(&pk->count);
89 up_read(&keyring_sem);
92 } /* end ksign_get_public_key() */
94 /*****************************************************************************/
96 * clear the public key keyring
98 void ksign_clear_keyring(void)
100 struct ksign_public_key *pk;
102 down_write(&keyring_sem);
104 while (!list_empty(&keyring)) {
105 pk = list_entry(keyring.next, struct ksign_public_key, link);
108 ksign_put_public_key(pk);
111 up_write(&keyring_sem);
112 } /* end ksign_clear_keyring() */