1 /* Protocol-independent Key structures */ 2 /* Copyright (C) 2001-2003 William Tompkins */ 3 4 /* This plugin is free software, distributed under the GNU General Public */ 5 /* License. */ 6 /* Please see the file "COPYING" distributed with this source code */ 7 /* for more details */ 8 /* */ 9 /* */ 10 /* This software is distributed in the hope that it will be useful, */ 11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ 13 /* General Public License for more details. */ 14 15 /* To compile and use: */ 16 /* See INSTALL file. */ 17 18 #ifndef KEYS_H 19 #define KEYS_H 20 21 #include "cryptproto.h" 22 23 #include "debug.h" 24 #include "conversation.h" 25 26 27 #define KEY_DIGEST_LENGTH 10 28 #define KEY_FINGERPRINT_LENGTH 59 29 30 #define MAX_KEY_STORLEN 8000 /* The maximum length of a key stored in a file (in chars) */ 31 32 struct crypt_key { 33 crypt_proto* proto; 34 proto_union store; /* Protocol dependent key data */ 35 /* enum {Public, Private} type; */ 36 char length[6]; /* string: Size of key (for ui display) */ 37 char digest[KEY_DIGEST_LENGTH]; /* Top 10 hex digits of modulus */ 38 char fingerprint[KEY_FINGERPRINT_LENGTH]; /* SHA-1 hash of modulus, as 12:34:56...*/ 39 /* Why have both digest and fingerprint? Well a) historical b) practicality */ 40 /* digest is insecure as a means of verifying that keys are actually the same */ 41 /* fingerprint is too long to include with every message */ 42 }; 43 typedef struct crypt_key crypt_key; 44 45 struct key_ring_data { 46 char name[64]; 47 PurpleAccount* account; 48 crypt_key* key; 49 }; 50 typedef struct key_ring_data key_ring_data; 51 typedef GSList key_ring; 52 53 /* List of all the keys we know about */ 54 extern key_ring *PE_buddy_ring, *PE_saved_buddy_ring, *PE_my_priv_ring, *PE_my_pub_ring; 55 static const char Private_key_file[] = "id.priv"; 56 static const char Public_key_file[] = "id"; 57 static const char Buddy_key_file[] = "known_keys"; 58 59 /*The key routines: */ 60 crypt_key * PE_find_key_by_name(key_ring *, const char *name, PurpleAccount* acct); 61 crypt_key * PE_find_own_key_by_name(key_ring **, char *name, PurpleAccount *acct, PurpleConversation *conv); 62 void PE_debug_dump_keyring(key_ring *); 63 key_ring * PE_find_key_node_by_name(key_ring *, const char *name, PurpleAccount* acct); 64 void PE_received_key(char *keystr, char *name, PurpleAccount* acct, PurpleConversation *conv, char** orig_msg); 65 key_ring * PE_load_keys(const char *); 66 void PE_save_keys(key_ring *, char *, char *); 67 void PE_key_rings_init(void); 68 key_ring* PE_add_key_to_ring(key_ring*, key_ring_data*); 69 void PE_add_key_to_file(const char *filename, key_ring_data* key); 70 key_ring* PE_del_key_from_ring(key_ring* ring, const char* name, PurpleAccount* acct); 71 void PE_del_key_from_file(const char *filename, const char *name, PurpleAccount *acct); 72 void PE_del_one_key_from_file(const char *filename, int key_num, const char *name); 73 key_ring* PE_clear_ring(key_ring*); 74 void PE_make_private_pair(crypt_proto* proto, const char* name, PurpleAccount* acct, int keylength); 75 gboolean PE_check_base_key_path(); 76 #endif 77