Mercurial > pidgin
comparison libpurple/protocols/silc/pk.c @ 15822:32c366eeeb99
sed -ie 's/gaim/purple/g'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 19 Mar 2007 07:01:17 +0000 |
parents | 5fe8042783c1 |
children | a5176db228b7 |
comparison
equal
deleted
inserted
replaced
15821:84b0f9b23ede | 15822:32c366eeeb99 |
---|---|
1 /* | 1 /* |
2 | 2 |
3 silcgaim_pk.c | 3 silcpurple_pk.c |
4 | 4 |
5 Author: Pekka Riikonen <priikone@silcnet.org> | 5 Author: Pekka Riikonen <priikone@silcnet.org> |
6 | 6 |
7 Copyright (C) 2004 Pekka Riikonen | 7 Copyright (C) 2004 Pekka Riikonen |
8 | 8 |
17 | 17 |
18 */ | 18 */ |
19 | 19 |
20 #include "silcincludes.h" | 20 #include "silcincludes.h" |
21 #include "silcclient.h" | 21 #include "silcclient.h" |
22 #include "silcgaim.h" | 22 #include "silcpurple.h" |
23 | 23 |
24 /************************* Public Key Verification ***************************/ | 24 /************************* Public Key Verification ***************************/ |
25 | 25 |
26 typedef struct { | 26 typedef struct { |
27 SilcClient client; | 27 SilcClient client; |
37 SilcVerifyPublicKey completion; | 37 SilcVerifyPublicKey completion; |
38 void *context; | 38 void *context; |
39 gboolean changed; | 39 gboolean changed; |
40 } *PublicKeyVerify; | 40 } *PublicKeyVerify; |
41 | 41 |
42 static void silcgaim_verify_ask(const char *entity, | 42 static void silcpurple_verify_ask(const char *entity, |
43 const char *fingerprint, | 43 const char *fingerprint, |
44 const char *babbleprint, | 44 const char *babbleprint, |
45 PublicKeyVerify verify); | 45 PublicKeyVerify verify); |
46 | 46 |
47 static void silcgaim_verify_cb(PublicKeyVerify verify, gint id) | 47 static void silcpurple_verify_cb(PublicKeyVerify verify, gint id) |
48 { | 48 { |
49 if (id != 2) { | 49 if (id != 2) { |
50 if (verify->completion) | 50 if (verify->completion) |
51 verify->completion(FALSE, verify->context); | 51 verify->completion(FALSE, verify->context); |
52 } else { | 52 } else { |
65 silc_free(verify->babbleprint); | 65 silc_free(verify->babbleprint); |
66 silc_free(verify->pk); | 66 silc_free(verify->pk); |
67 silc_free(verify); | 67 silc_free(verify); |
68 } | 68 } |
69 | 69 |
70 static void silcgaim_verify_details_cb(PublicKeyVerify verify) | 70 static void silcpurple_verify_details_cb(PublicKeyVerify verify) |
71 { | 71 { |
72 /* What a hack. We have to display the accept dialog _again_ | 72 /* What a hack. We have to display the accept dialog _again_ |
73 because Gaim closes the dialog after you press the button. Gaim | 73 because Purple closes the dialog after you press the button. Purple |
74 should have option for the dialogs whether the buttons close them | 74 should have option for the dialogs whether the buttons close them |
75 or not. */ | 75 or not. */ |
76 silcgaim_verify_ask(verify->entity, verify->fingerprint, | 76 silcpurple_verify_ask(verify->entity, verify->fingerprint, |
77 verify->babbleprint, verify); | 77 verify->babbleprint, verify); |
78 } | 78 } |
79 | 79 |
80 static void silcgaim_verify_details(PublicKeyVerify verify, gint id) | 80 static void silcpurple_verify_details(PublicKeyVerify verify, gint id) |
81 { | 81 { |
82 SilcPublicKey public_key; | 82 SilcPublicKey public_key; |
83 GaimConnection *gc = verify->client->application; | 83 PurpleConnection *gc = verify->client->application; |
84 SilcGaim sg = gc->proto_data; | 84 SilcPurple sg = gc->proto_data; |
85 | 85 |
86 silc_pkcs_public_key_decode(verify->pk, verify->pk_len, | 86 silc_pkcs_public_key_decode(verify->pk, verify->pk_len, |
87 &public_key); | 87 &public_key); |
88 silcgaim_show_public_key(sg, verify->entity_name, public_key, | 88 silcpurple_show_public_key(sg, verify->entity_name, public_key, |
89 G_CALLBACK(silcgaim_verify_details_cb), | 89 G_CALLBACK(silcpurple_verify_details_cb), |
90 verify); | 90 verify); |
91 silc_pkcs_public_key_free(public_key); | 91 silc_pkcs_public_key_free(public_key); |
92 } | 92 } |
93 | 93 |
94 static void silcgaim_verify_ask(const char *entity, | 94 static void silcpurple_verify_ask(const char *entity, |
95 const char *fingerprint, | 95 const char *fingerprint, |
96 const char *babbleprint, | 96 const char *babbleprint, |
97 PublicKeyVerify verify) | 97 PublicKeyVerify verify) |
98 { | 98 { |
99 char tmp[256], tmp2[256]; | 99 char tmp[256], tmp2[256]; |
110 } | 110 } |
111 g_snprintf(tmp2, sizeof(tmp2), | 111 g_snprintf(tmp2, sizeof(tmp2), |
112 _("Fingerprint and babbleprint for the %s key are:\n\n" | 112 _("Fingerprint and babbleprint for the %s key are:\n\n" |
113 "%s\n%s\n"), entity, fingerprint, babbleprint); | 113 "%s\n%s\n"), entity, fingerprint, babbleprint); |
114 | 114 |
115 gaim_request_action(verify->client->application, _("Verify Public Key"), tmp, tmp2, | 115 purple_request_action(verify->client->application, _("Verify Public Key"), tmp, tmp2, |
116 GAIM_DEFAULT_ACTION_NONE, verify, 3, | 116 PURPLE_DEFAULT_ACTION_NONE, verify, 3, |
117 _("Yes"), G_CALLBACK(silcgaim_verify_cb), | 117 _("Yes"), G_CALLBACK(silcpurple_verify_cb), |
118 _("No"), G_CALLBACK(silcgaim_verify_cb), | 118 _("No"), G_CALLBACK(silcpurple_verify_cb), |
119 _("_View..."), G_CALLBACK(silcgaim_verify_details)); | 119 _("_View..."), G_CALLBACK(silcpurple_verify_details)); |
120 } | 120 } |
121 | 121 |
122 void silcgaim_verify_public_key(SilcClient client, SilcClientConnection conn, | 122 void silcpurple_verify_public_key(SilcClient client, SilcClientConnection conn, |
123 const char *name, SilcSocketType conn_type, | 123 const char *name, SilcSocketType conn_type, |
124 unsigned char *pk, SilcUInt32 pk_len, | 124 unsigned char *pk, SilcUInt32 pk_len, |
125 SilcSKEPKType pk_type, | 125 SilcSKEPKType pk_type, |
126 SilcVerifyPublicKey completion, void *context) | 126 SilcVerifyPublicKey completion, void *context) |
127 { | 127 { |
128 GaimConnection *gc = client->application; | 128 PurpleConnection *gc = client->application; |
129 int i; | 129 int i; |
130 char file[256], filename[256], filename2[256], *ipf, *hostf = NULL; | 130 char file[256], filename[256], filename2[256], *ipf, *hostf = NULL; |
131 char *fingerprint, *babbleprint; | 131 char *fingerprint, *babbleprint; |
132 struct passwd *pw; | 132 struct passwd *pw; |
133 struct stat st; | 133 struct stat st; |
135 conn_type == SILC_SOCKET_TYPE_ROUTER) ? | 135 conn_type == SILC_SOCKET_TYPE_ROUTER) ? |
136 "server" : "client"); | 136 "server" : "client"); |
137 PublicKeyVerify verify; | 137 PublicKeyVerify verify; |
138 | 138 |
139 if (pk_type != SILC_SKE_PK_TYPE_SILC) { | 139 if (pk_type != SILC_SKE_PK_TYPE_SILC) { |
140 gaim_notify_error(gc, _("Verify Public Key"), | 140 purple_notify_error(gc, _("Verify Public Key"), |
141 _("Unsupported public key type"), NULL); | 141 _("Unsupported public key type"), NULL); |
142 if (completion) | 142 if (completion) |
143 completion(FALSE, context); | 143 completion(FALSE, context); |
144 return; | 144 return; |
145 } | 145 } |
160 if (!name) { | 160 if (!name) { |
161 g_snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity, | 161 g_snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity, |
162 conn->sock->ip, conn->sock->port); | 162 conn->sock->ip, conn->sock->port); |
163 g_snprintf(filename, sizeof(filename) - 1, | 163 g_snprintf(filename, sizeof(filename) - 1, |
164 "%s" G_DIR_SEPARATOR_S "%skeys" G_DIR_SEPARATOR_S "%s", | 164 "%s" G_DIR_SEPARATOR_S "%skeys" G_DIR_SEPARATOR_S "%s", |
165 silcgaim_silcdir(), entity, file); | 165 silcpurple_silcdir(), entity, file); |
166 | 166 |
167 g_snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity, | 167 g_snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity, |
168 conn->sock->hostname, conn->sock->port); | 168 conn->sock->hostname, conn->sock->port); |
169 g_snprintf(filename2, sizeof(filename2) - 1, | 169 g_snprintf(filename2, sizeof(filename2) - 1, |
170 "%s" G_DIR_SEPARATOR_S "%skeys" G_DIR_SEPARATOR_S "%s", | 170 "%s" G_DIR_SEPARATOR_S "%skeys" G_DIR_SEPARATOR_S "%s", |
171 silcgaim_silcdir(), entity, file); | 171 silcpurple_silcdir(), entity, file); |
172 | 172 |
173 ipf = filename; | 173 ipf = filename; |
174 hostf = filename2; | 174 hostf = filename2; |
175 } else { | 175 } else { |
176 g_snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity, | 176 g_snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity, |
177 name, conn->sock->port); | 177 name, conn->sock->port); |
178 g_snprintf(filename, sizeof(filename) - 1, | 178 g_snprintf(filename, sizeof(filename) - 1, |
179 "%s" G_DIR_SEPARATOR_S "%skeys" G_DIR_SEPARATOR_S "%s", | 179 "%s" G_DIR_SEPARATOR_S "%skeys" G_DIR_SEPARATOR_S "%s", |
180 silcgaim_silcdir(), entity, file); | 180 silcpurple_silcdir(), entity, file); |
181 | 181 |
182 ipf = filename; | 182 ipf = filename; |
183 } | 183 } |
184 } else { | 184 } else { |
185 /* Replace all whitespaces with `_'. */ | 185 /* Replace all whitespaces with `_'. */ |
189 fingerprint[i] = '_'; | 189 fingerprint[i] = '_'; |
190 | 190 |
191 g_snprintf(file, sizeof(file) - 1, "%skey_%s.pub", entity, fingerprint); | 191 g_snprintf(file, sizeof(file) - 1, "%skey_%s.pub", entity, fingerprint); |
192 g_snprintf(filename, sizeof(filename) - 1, | 192 g_snprintf(filename, sizeof(filename) - 1, |
193 "%s" G_DIR_SEPARATOR_S "%skeys" G_DIR_SEPARATOR_S "%s", | 193 "%s" G_DIR_SEPARATOR_S "%skeys" G_DIR_SEPARATOR_S "%s", |
194 silcgaim_silcdir(), entity, file); | 194 silcpurple_silcdir(), entity, file); |
195 silc_free(fingerprint); | 195 silc_free(fingerprint); |
196 | 196 |
197 ipf = filename; | 197 ipf = filename; |
198 } | 198 } |
199 | 199 |
216 babbleprint = verify->babbleprint = silc_hash_babbleprint(NULL, pk, pk_len); | 216 babbleprint = verify->babbleprint = silc_hash_babbleprint(NULL, pk, pk_len); |
217 | 217 |
218 /* Check whether this key already exists */ | 218 /* Check whether this key already exists */ |
219 if (g_stat(ipf, &st) < 0 && (!hostf || g_stat(hostf, &st) < 0)) { | 219 if (g_stat(ipf, &st) < 0 && (!hostf || g_stat(hostf, &st) < 0)) { |
220 /* Key does not exist, ask user to verify the key and save it */ | 220 /* Key does not exist, ask user to verify the key and save it */ |
221 silcgaim_verify_ask(name ? name : entity, | 221 silcpurple_verify_ask(name ? name : entity, |
222 fingerprint, babbleprint, verify); | 222 fingerprint, babbleprint, verify); |
223 return; | 223 return; |
224 } else { | 224 } else { |
225 /* The key already exists, verify it. */ | 225 /* The key already exists, verify it. */ |
226 SilcPublicKey public_key; | 226 SilcPublicKey public_key; |
234 SILC_PKCS_FILE_BIN) && | 234 SILC_PKCS_FILE_BIN) && |
235 (!hostf || (!silc_pkcs_load_public_key(hostf, &public_key, | 235 (!hostf || (!silc_pkcs_load_public_key(hostf, &public_key, |
236 SILC_PKCS_FILE_PEM) && | 236 SILC_PKCS_FILE_PEM) && |
237 !silc_pkcs_load_public_key(hostf, &public_key, | 237 !silc_pkcs_load_public_key(hostf, &public_key, |
238 SILC_PKCS_FILE_BIN)))) { | 238 SILC_PKCS_FILE_BIN)))) { |
239 silcgaim_verify_ask(name ? name : entity, | 239 silcpurple_verify_ask(name ? name : entity, |
240 fingerprint, babbleprint, verify); | 240 fingerprint, babbleprint, verify); |
241 return; | 241 return; |
242 } | 242 } |
243 | 243 |
244 /* Encode the key data */ | 244 /* Encode the key data */ |
245 encpk = silc_pkcs_public_key_encode(public_key, &encpk_len); | 245 encpk = silc_pkcs_public_key_encode(public_key, &encpk_len); |
246 if (!encpk) { | 246 if (!encpk) { |
247 silcgaim_verify_ask(name ? name : entity, | 247 silcpurple_verify_ask(name ? name : entity, |
248 fingerprint, babbleprint, verify); | 248 fingerprint, babbleprint, verify); |
249 return; | 249 return; |
250 } | 250 } |
251 | 251 |
252 /* Compare the keys */ | 252 /* Compare the keys */ |
253 if (memcmp(encpk, pk, encpk_len)) { | 253 if (memcmp(encpk, pk, encpk_len)) { |
254 /* Ask user to verify the key and save it */ | 254 /* Ask user to verify the key and save it */ |
255 verify->changed = TRUE; | 255 verify->changed = TRUE; |
256 silcgaim_verify_ask(name ? name : entity, | 256 silcpurple_verify_ask(name ? name : entity, |
257 fingerprint, babbleprint, verify); | 257 fingerprint, babbleprint, verify); |
258 return; | 258 return; |
259 } | 259 } |
260 | 260 |
261 /* Local copy matched */ | 261 /* Local copy matched */ |