Thu, 03 Apr 2014 04:58:04 +0200
Silc: ignore Wcast-align in silc.h
| 8849 | 1 | /* |
| 2 | ||
| 15884 | 3 | silcpurple_pk.c |
| 8849 | 4 | |
| 5 | Author: Pekka Riikonen <priikone@silcnet.org> | |
| 6 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
7 | Copyright (C) 2004 - 2007 Pekka Riikonen |
| 8849 | 8 | |
| 9 | This program is free software; you can redistribute it and/or modify | |
| 10 | it under the terms of the GNU General Public License as published by | |
| 11 | the Free Software Foundation; version 2 of the License. | |
| 12 | ||
| 13 | This program 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. | |
| 17 | ||
| 18 | */ | |
| 19 | ||
|
28981
4e3922ab4844
Include 'internal.h' before all other headers to make some non-gcc compilers happy.
Paul Aurich <darkrain42@pidgin.im>
parents:
22972
diff
changeset
|
20 | #include "internal.h" |
|
35190
5986ee34c476
libpurple: Fix build and warnings with glib 2.24
Ankit Vani <a@nevitus.org>
parents:
34449
diff
changeset
|
21 | #include "glibcompat.h" |
|
35681
54694ef14d46
Silc: ignore Wcast-align in silc.h
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35190
diff
changeset
|
22 | PURPLE_BEGIN_IGNORE_CAST_ALIGN |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
23 | #include "silc.h" |
|
35681
54694ef14d46
Silc: ignore Wcast-align in silc.h
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35190
diff
changeset
|
24 | PURPLE_END_IGNORE_CAST_ALIGN |
| 8849 | 25 | #include "silcclient.h" |
| 15884 | 26 | #include "silcpurple.h" |
| 8849 | 27 | |
| 28 | /************************* Public Key Verification ***************************/ | |
| 29 | ||
| 30 | typedef struct { | |
| 31 | SilcClient client; | |
| 32 | SilcClientConnection conn; | |
| 33 | char *filename; | |
| 34 | char *entity; | |
| 35 | char *entity_name; | |
| 36 | char *fingerprint; | |
| 37 | char *babbleprint; | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
38 | SilcPublicKey public_key; |
| 8849 | 39 | SilcVerifyPublicKey completion; |
| 40 | void *context; | |
| 41 | gboolean changed; | |
| 42 | } *PublicKeyVerify; | |
| 43 | ||
| 15884 | 44 | static void silcpurple_verify_ask(const char *entity, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
45 | const char *fingerprint, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
46 | const char *babbleprint, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
47 | PublicKeyVerify verify); |
| 8849 | 48 | |
| 15884 | 49 | static void silcpurple_verify_cb(PublicKeyVerify verify, gint id) |
| 8849 | 50 | { |
| 51 | if (id != 2) { | |
| 52 | if (verify->completion) | |
| 53 | verify->completion(FALSE, verify->context); | |
| 54 | } else { | |
| 55 | if (verify->completion) | |
| 56 | verify->completion(TRUE, verify->context); | |
| 57 | ||
| 58 | /* Save the key for future checking */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
59 | silc_pkcs_save_public_key(verify->filename, verify->public_key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
60 | SILC_PKCS_FILE_BASE64); |
| 8849 | 61 | } |
| 62 | ||
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
21630
diff
changeset
|
63 | g_free(verify->filename); |
|
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
21630
diff
changeset
|
64 | g_free(verify->entity); |
|
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
21630
diff
changeset
|
65 | g_free(verify->entity_name); |
| 8849 | 66 | silc_free(verify->fingerprint); |
| 67 | silc_free(verify->babbleprint); | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
68 | silc_pkcs_public_key_free(verify->public_key); |
| 8849 | 69 | silc_free(verify); |
| 70 | } | |
| 71 | ||
| 15884 | 72 | static void silcpurple_verify_details_cb(PublicKeyVerify verify) |
| 8849 | 73 | { |
| 74 | /* What a hack. We have to display the accept dialog _again_ | |
| 15884 | 75 | because Purple closes the dialog after you press the button. Purple |
| 8849 | 76 | should have option for the dialogs whether the buttons close them |
| 77 | or not. */ | |
| 15884 | 78 | silcpurple_verify_ask(verify->entity, verify->fingerprint, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
79 | verify->babbleprint, verify); |
| 8849 | 80 | } |
| 81 | ||
| 15884 | 82 | static void silcpurple_verify_details(PublicKeyVerify verify, gint id) |
| 8849 | 83 | { |
| 15884 | 84 | PurpleConnection *gc = verify->client->application; |
|
32281
0ef1a6d8ca53
Convert silc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
28981
diff
changeset
|
85 | SilcPurple sg = purple_connection_get_protocol_data(gc); |
| 8849 | 86 | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
87 | silcpurple_show_public_key(sg, verify->entity_name, verify->public_key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
88 | G_CALLBACK(silcpurple_verify_details_cb), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
89 | verify); |
| 8849 | 90 | } |
| 91 | ||
| 15884 | 92 | static void silcpurple_verify_ask(const char *entity, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
93 | const char *fingerprint, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
94 | const char *babbleprint, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
95 | PublicKeyVerify verify) |
| 8849 | 96 | { |
|
16492
4f0dc2d16e55
Update SILC to match resent request API changes
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
97 | PurpleConnection *gc = verify->client->application; |
| 8849 | 98 | char tmp[256], tmp2[256]; |
| 99 | ||
| 100 | if (verify->changed) { | |
| 101 | g_snprintf(tmp, sizeof(tmp), | |
| 102 | _("Received %s's public key. Your local copy does not match this " | |
| 103 | "key. Would you still like to accept this public key?"), | |
| 104 | entity); | |
| 105 | } else { | |
| 106 | g_snprintf(tmp, sizeof(tmp), | |
| 107 | _("Received %s's public key. Would you like to accept this " | |
| 108 | "public key?"), entity); | |
| 109 | } | |
| 110 | g_snprintf(tmp2, sizeof(tmp2), | |
| 111 | _("Fingerprint and babbleprint for the %s key are:\n\n" | |
| 112 | "%s\n%s\n"), entity, fingerprint, babbleprint); | |
| 113 | ||
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
114 | purple_request_action(gc, _("Verify Public Key"), tmp, tmp2, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
115 | PURPLE_DEFAULT_ACTION_NONE, |
|
34331
c8486462bb63
Request API refactoring: switch purple_request_action to PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34304
diff
changeset
|
116 | purple_request_cpar_from_connection(gc), verify, 3, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
117 | _("Yes"), G_CALLBACK(silcpurple_verify_cb), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
118 | _("No"), G_CALLBACK(silcpurple_verify_cb), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
119 | _("_View..."), G_CALLBACK(silcpurple_verify_details)); |
| 8849 | 120 | } |
| 121 | ||
| 15884 | 122 | void silcpurple_verify_public_key(SilcClient client, SilcClientConnection conn, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
123 | const char *name, SilcConnectionType conn_type, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
124 | SilcPublicKey public_key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
125 | SilcVerifyPublicKey completion, void *context) |
| 8849 | 126 | { |
| 15884 | 127 | PurpleConnection *gc = client->application; |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33940
diff
changeset
|
128 | gsize i; |
| 8849 | 129 | char file[256], filename[256], filename2[256], *ipf, *hostf = NULL; |
| 130 | char *fingerprint, *babbleprint; | |
| 131 | struct passwd *pw; | |
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32281
diff
changeset
|
132 | GStatBuf st; |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
133 | char *entity = ((conn_type == SILC_CONN_SERVER || |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
134 | conn_type == SILC_CONN_ROUTER) ? |
| 8849 | 135 | "server" : "client"); |
| 136 | PublicKeyVerify verify; | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
137 | const char *ip, *hostname; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
138 | SilcUInt16 port; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
139 | unsigned char *pk; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
140 | SilcUInt32 pk_len; |
| 8849 | 141 | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
142 | if (silc_pkcs_get_type(public_key) != SILC_PKCS_SILC) { |
| 15884 | 143 | purple_notify_error(gc, _("Verify Public Key"), |
|
34449
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34331
diff
changeset
|
144 | _("Unsupported public key type"), NULL, |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34331
diff
changeset
|
145 | purple_request_cpar_from_connection(gc)); |
| 8849 | 146 | if (completion) |
| 147 | completion(FALSE, context); | |
| 148 | return; | |
| 149 | } | |
| 150 | ||
| 151 | pw = getpwuid(getuid()); | |
| 152 | if (!pw) { | |
| 153 | if (completion) | |
| 154 | completion(FALSE, context); | |
| 155 | return; | |
| 156 | } | |
| 157 | ||
| 158 | memset(filename, 0, sizeof(filename)); | |
| 159 | memset(filename2, 0, sizeof(filename2)); | |
| 160 | memset(file, 0, sizeof(file)); | |
| 161 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
162 | silc_socket_stream_get_info(silc_packet_stream_get_stream(conn->stream), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
163 | NULL, &hostname, &ip, &port); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
164 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
165 | pk = silc_pkcs_public_key_encode(public_key, &pk_len); |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
166 | if (!pk) { |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
167 | if (completion) |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
168 | completion(FALSE, context); |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
169 | return; |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
170 | } |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
171 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
172 | if (conn_type == SILC_CONN_SERVER || |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
173 | conn_type == SILC_CONN_ROUTER) { |
| 8849 | 174 | if (!name) { |
| 175 | g_snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity, | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
176 | ip, port); |
| 8849 | 177 | g_snprintf(filename, sizeof(filename) - 1, |
| 178 | "%s" G_DIR_SEPARATOR_S "%skeys" G_DIR_SEPARATOR_S "%s", | |
| 15884 | 179 | silcpurple_silcdir(), entity, file); |
| 8849 | 180 | |
| 181 | g_snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity, | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
182 | hostname, port); |
| 8849 | 183 | g_snprintf(filename2, sizeof(filename2) - 1, |
| 184 | "%s" G_DIR_SEPARATOR_S "%skeys" G_DIR_SEPARATOR_S "%s", | |
| 15884 | 185 | silcpurple_silcdir(), entity, file); |
| 8849 | 186 | |
| 187 | ipf = filename; | |
| 188 | hostf = filename2; | |
| 189 | } else { | |
| 190 | g_snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity, | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
191 | name, port); |
| 8849 | 192 | g_snprintf(filename, sizeof(filename) - 1, |
| 193 | "%s" G_DIR_SEPARATOR_S "%skeys" G_DIR_SEPARATOR_S "%s", | |
| 15884 | 194 | silcpurple_silcdir(), entity, file); |
| 8849 | 195 | |
| 196 | ipf = filename; | |
| 197 | } | |
| 198 | } else { | |
| 199 | /* Replace all whitespaces with `_'. */ | |
| 200 | fingerprint = silc_hash_fingerprint(NULL, pk, pk_len); | |
| 201 | for (i = 0; i < strlen(fingerprint); i++) | |
| 202 | if (fingerprint[i] == ' ') | |
| 203 | fingerprint[i] = '_'; | |
| 204 | ||
| 205 | g_snprintf(file, sizeof(file) - 1, "%skey_%s.pub", entity, fingerprint); | |
| 206 | g_snprintf(filename, sizeof(filename) - 1, | |
| 207 | "%s" G_DIR_SEPARATOR_S "%skeys" G_DIR_SEPARATOR_S "%s", | |
| 15884 | 208 | silcpurple_silcdir(), entity, file); |
| 8849 | 209 | silc_free(fingerprint); |
| 210 | ||
| 211 | ipf = filename; | |
| 212 | } | |
| 213 | ||
| 214 | verify = silc_calloc(1, sizeof(*verify)); | |
| 215 | if (!verify) | |
| 216 | return; | |
| 217 | verify->client = client; | |
| 218 | verify->conn = conn; | |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
21630
diff
changeset
|
219 | verify->filename = g_strdup(ipf); |
|
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
21630
diff
changeset
|
220 | verify->entity = g_strdup(entity); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
221 | verify->entity_name = (conn_type != SILC_CONN_CLIENT ? |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
21630
diff
changeset
|
222 | (name ? g_strdup(name) : g_strdup(hostname)) |
| 8849 | 223 | : NULL); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
224 | verify->public_key = silc_pkcs_public_key_copy(public_key); |
| 8849 | 225 | verify->completion = completion; |
| 226 | verify->context = context; | |
| 227 | fingerprint = verify->fingerprint = silc_hash_fingerprint(NULL, pk, pk_len); | |
| 228 | babbleprint = verify->babbleprint = silc_hash_babbleprint(NULL, pk, pk_len); | |
| 229 | ||
| 230 | /* Check whether this key already exists */ | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10116
diff
changeset
|
231 | if (g_stat(ipf, &st) < 0 && (!hostf || g_stat(hostf, &st) < 0)) { |
| 8849 | 232 | /* Key does not exist, ask user to verify the key and save it */ |
| 15884 | 233 | silcpurple_verify_ask(name ? name : entity, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
234 | fingerprint, babbleprint, verify); |
| 8849 | 235 | return; |
| 236 | } else { | |
| 237 | /* The key already exists, verify it. */ | |
| 238 | SilcPublicKey public_key; | |
| 239 | unsigned char *encpk; | |
| 240 | SilcUInt32 encpk_len; | |
| 241 | ||
| 242 | /* Load the key file, try for both IP filename and hostname filename */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
243 | if (!silc_pkcs_load_public_key(ipf, &public_key) && |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
244 | (!hostf || (!silc_pkcs_load_public_key(hostf, &public_key)))) { |
| 15884 | 245 | silcpurple_verify_ask(name ? name : entity, |
| 8849 | 246 | fingerprint, babbleprint, verify); |
| 247 | return; | |
| 248 | } | |
| 249 | ||
| 250 | /* Encode the key data */ | |
| 251 | encpk = silc_pkcs_public_key_encode(public_key, &encpk_len); | |
| 252 | if (!encpk) { | |
| 15884 | 253 | silcpurple_verify_ask(name ? name : entity, |
| 8849 | 254 | fingerprint, babbleprint, verify); |
| 255 | return; | |
| 256 | } | |
| 257 | ||
| 258 | /* Compare the keys */ | |
| 259 | if (memcmp(encpk, pk, encpk_len)) { | |
| 260 | /* Ask user to verify the key and save it */ | |
| 261 | verify->changed = TRUE; | |
| 15884 | 262 | silcpurple_verify_ask(name ? name : entity, |
| 8849 | 263 | fingerprint, babbleprint, verify); |
| 264 | return; | |
| 265 | } | |
| 266 | ||
| 267 | /* Local copy matched */ | |
| 268 | if (completion) | |
| 269 | completion(TRUE, context); | |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
21630
diff
changeset
|
270 | g_free(verify->filename); |
|
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
21630
diff
changeset
|
271 | g_free(verify->entity); |
|
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
21630
diff
changeset
|
272 | g_free(verify->entity_name); |
| 8849 | 273 | silc_free(verify->fingerprint); |
| 274 | silc_free(verify->babbleprint); | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
275 | silc_pkcs_public_key_free(verify->public_key); |
| 8849 | 276 | silc_free(verify); |
| 277 | } | |
| 278 | } |