Mercurial > pidgin
comparison libpurple/plugins/ciphertest.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 | 42961709cb30 |
children | d638845509fd |
comparison
equal
deleted
inserted
replaced
15821:84b0f9b23ede | 15822:32c366eeeb99 |
---|---|
1 /* | 1 /* |
2 * A plugin to test the ciphers that ship with gaim | 2 * A plugin to test the ciphers that ship with purple |
3 * | 3 * |
4 * Copyright (C) 2004, Gary Kramlich <amc_grim@users.sf.net> | 4 * Copyright (C) 2004, Gary Kramlich <amc_grim@users.sf.net> |
5 * | 5 * |
6 * This program is free software; you can redistribute it and/or | 6 * This program is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU General Public License as | 7 * modify it under the terms of the GNU General Public License as |
21 | 21 |
22 #ifdef HAVE_CONFIG_H | 22 #ifdef HAVE_CONFIG_H |
23 #include <config.h> | 23 #include <config.h> |
24 #endif | 24 #endif |
25 | 25 |
26 #ifndef GAIM_PLUGINS | 26 #ifndef PURPLE_PLUGINS |
27 #define GAIM_PLUGINS | 27 #define PURPLE_PLUGINS |
28 #endif | 28 #endif |
29 | 29 |
30 #include "internal.h" | 30 #include "internal.h" |
31 | 31 |
32 #include <glib.h> | 32 #include <glib.h> |
60 { NULL, NULL } | 60 { NULL, NULL } |
61 }; | 61 }; |
62 | 62 |
63 static void | 63 static void |
64 cipher_test_md5() { | 64 cipher_test_md5() { |
65 GaimCipher *cipher; | 65 PurpleCipher *cipher; |
66 GaimCipherContext *context; | 66 PurpleCipherContext *context; |
67 gchar digest[33]; | 67 gchar digest[33]; |
68 gboolean ret; | 68 gboolean ret; |
69 gint i = 0; | 69 gint i = 0; |
70 | 70 |
71 cipher = gaim_ciphers_find_cipher("md5"); | 71 cipher = purple_ciphers_find_cipher("md5"); |
72 if(!cipher) { | 72 if(!cipher) { |
73 gaim_debug_info("cipher-test", | 73 purple_debug_info("cipher-test", |
74 "could not find md5 cipher, not testing\n"); | 74 "could not find md5 cipher, not testing\n"); |
75 return; | 75 return; |
76 } | 76 } |
77 | 77 |
78 gaim_debug_info("cipher-test", "Running md5 tests\n"); | 78 purple_debug_info("cipher-test", "Running md5 tests\n"); |
79 | 79 |
80 context = gaim_cipher_context_new(cipher, NULL); | 80 context = purple_cipher_context_new(cipher, NULL); |
81 | 81 |
82 while(md5_tests[i].answer) { | 82 while(md5_tests[i].answer) { |
83 gaim_debug_info("cipher-test", "Test %02d:\n", i); | 83 purple_debug_info("cipher-test", "Test %02d:\n", i); |
84 gaim_debug_info("cipher-test", "Testing '%s'\n", md5_tests[i].question); | 84 purple_debug_info("cipher-test", "Testing '%s'\n", md5_tests[i].question); |
85 | 85 |
86 gaim_cipher_context_append(context, (guchar *)md5_tests[i].question, | 86 purple_cipher_context_append(context, (guchar *)md5_tests[i].question, |
87 strlen(md5_tests[i].question)); | 87 strlen(md5_tests[i].question)); |
88 | 88 |
89 ret = gaim_cipher_context_digest_to_str(context, sizeof(digest), | 89 ret = purple_cipher_context_digest_to_str(context, sizeof(digest), |
90 digest, NULL); | 90 digest, NULL); |
91 | 91 |
92 if(!ret) { | 92 if(!ret) { |
93 gaim_debug_info("cipher-test", "failed\n"); | 93 purple_debug_info("cipher-test", "failed\n"); |
94 } else { | 94 } else { |
95 gaim_debug_info("cipher-test", "\tGot: %s\n", digest); | 95 purple_debug_info("cipher-test", "\tGot: %s\n", digest); |
96 gaim_debug_info("cipher-test", "\tWanted: %s\n", | 96 purple_debug_info("cipher-test", "\tWanted: %s\n", |
97 md5_tests[i].answer); | 97 md5_tests[i].answer); |
98 } | 98 } |
99 | 99 |
100 gaim_cipher_context_reset(context, NULL); | 100 purple_cipher_context_reset(context, NULL); |
101 i++; | 101 i++; |
102 } | 102 } |
103 | 103 |
104 gaim_cipher_context_destroy(context); | 104 purple_cipher_context_destroy(context); |
105 | 105 |
106 gaim_debug_info("cipher-test", "md5 tests completed\n\n"); | 106 purple_debug_info("cipher-test", "md5 tests completed\n\n"); |
107 } | 107 } |
108 | 108 |
109 /************************************************************************** | 109 /************************************************************************** |
110 * SHA-1 stuff | 110 * SHA-1 stuff |
111 **************************************************************************/ | 111 **************************************************************************/ |
117 {NULL, NULL} | 117 {NULL, NULL} |
118 }; | 118 }; |
119 | 119 |
120 static void | 120 static void |
121 cipher_test_sha1() { | 121 cipher_test_sha1() { |
122 GaimCipher *cipher; | 122 PurpleCipher *cipher; |
123 GaimCipherContext *context; | 123 PurpleCipherContext *context; |
124 gchar digest[41]; | 124 gchar digest[41]; |
125 gint i = 0; | 125 gint i = 0; |
126 gboolean ret; | 126 gboolean ret; |
127 | 127 |
128 cipher = gaim_ciphers_find_cipher("sha1"); | 128 cipher = purple_ciphers_find_cipher("sha1"); |
129 if(!cipher) { | 129 if(!cipher) { |
130 gaim_debug_info("cipher-test", | 130 purple_debug_info("cipher-test", |
131 "could not find sha1 cipher, not testing\n"); | 131 "could not find sha1 cipher, not testing\n"); |
132 return; | 132 return; |
133 } | 133 } |
134 | 134 |
135 gaim_debug_info("cipher-test", "Running sha1 tests\n"); | 135 purple_debug_info("cipher-test", "Running sha1 tests\n"); |
136 | 136 |
137 context = gaim_cipher_context_new(cipher, NULL); | 137 context = purple_cipher_context_new(cipher, NULL); |
138 | 138 |
139 while(sha1_tests[i].answer) { | 139 while(sha1_tests[i].answer) { |
140 gaim_debug_info("cipher-test", "Test %02d:\n", i); | 140 purple_debug_info("cipher-test", "Test %02d:\n", i); |
141 gaim_debug_info("cipher-test", "Testing '%s'\n", | 141 purple_debug_info("cipher-test", "Testing '%s'\n", |
142 (sha1_tests[i].question != NULL) ? | 142 (sha1_tests[i].question != NULL) ? |
143 sha1_tests[i].question : "'a'x1000, 1000 times"); | 143 sha1_tests[i].question : "'a'x1000, 1000 times"); |
144 | 144 |
145 if(sha1_tests[i].question) { | 145 if(sha1_tests[i].question) { |
146 gaim_cipher_context_append(context, (guchar *)sha1_tests[i].question, | 146 purple_cipher_context_append(context, (guchar *)sha1_tests[i].question, |
147 strlen(sha1_tests[i].question)); | 147 strlen(sha1_tests[i].question)); |
148 } else { | 148 } else { |
149 gint j; | 149 gint j; |
150 guchar buff[1000]; | 150 guchar buff[1000]; |
151 | 151 |
152 memset(buff, 'a', 1000); | 152 memset(buff, 'a', 1000); |
153 | 153 |
154 for(j = 0; j < 1000; j++) | 154 for(j = 0; j < 1000; j++) |
155 gaim_cipher_context_append(context, buff, 1000); | 155 purple_cipher_context_append(context, buff, 1000); |
156 } | 156 } |
157 | 157 |
158 ret = gaim_cipher_context_digest_to_str(context, sizeof(digest), | 158 ret = purple_cipher_context_digest_to_str(context, sizeof(digest), |
159 digest, NULL); | 159 digest, NULL); |
160 | 160 |
161 if(!ret) { | 161 if(!ret) { |
162 gaim_debug_info("cipher-test", "failed\n"); | 162 purple_debug_info("cipher-test", "failed\n"); |
163 } else { | 163 } else { |
164 gaim_debug_info("cipher-test", "\tGot: %s\n", digest); | 164 purple_debug_info("cipher-test", "\tGot: %s\n", digest); |
165 gaim_debug_info("cipher-test", "\tWanted: %s\n", | 165 purple_debug_info("cipher-test", "\tWanted: %s\n", |
166 sha1_tests[i].answer); | 166 sha1_tests[i].answer); |
167 } | 167 } |
168 | 168 |
169 gaim_cipher_context_reset(context, NULL); | 169 purple_cipher_context_reset(context, NULL); |
170 i++; | 170 i++; |
171 } | 171 } |
172 | 172 |
173 gaim_cipher_context_destroy(context); | 173 purple_cipher_context_destroy(context); |
174 | 174 |
175 gaim_debug_info("cipher-test", "sha1 tests completed\n\n"); | 175 purple_debug_info("cipher-test", "sha1 tests completed\n\n"); |
176 } | 176 } |
177 | 177 |
178 static void | 178 static void |
179 cipher_test_digest() | 179 cipher_test_digest() |
180 { | 180 { |
190 const gchar *digest_uri = "/dir/index.html"; | 190 const gchar *digest_uri = "/dir/index.html"; |
191 const gchar *entity = NULL; | 191 const gchar *entity = NULL; |
192 | 192 |
193 gchar *session_key; | 193 gchar *session_key; |
194 | 194 |
195 gaim_debug_info("cipher-test", "Running HTTP Digest tests\n"); | 195 purple_debug_info("cipher-test", "Running HTTP Digest tests\n"); |
196 | 196 |
197 session_key = gaim_cipher_http_digest_calculate_session_key( | 197 session_key = purple_cipher_http_digest_calculate_session_key( |
198 algorithm, username, realm, password, | 198 algorithm, username, realm, password, |
199 nonce, client_nonce); | 199 nonce, client_nonce); |
200 | 200 |
201 if (session_key == NULL) | 201 if (session_key == NULL) |
202 { | 202 { |
203 gaim_debug_info("cipher-test", | 203 purple_debug_info("cipher-test", |
204 "gaim_cipher_http_digest_calculate_session_key failed.\n"); | 204 "purple_cipher_http_digest_calculate_session_key failed.\n"); |
205 } | 205 } |
206 else | 206 else |
207 { | 207 { |
208 gchar *response; | 208 gchar *response; |
209 | 209 |
210 gaim_debug_info("cipher-test", "\tsession_key: Got: %s\n", session_key); | 210 purple_debug_info("cipher-test", "\tsession_key: Got: %s\n", session_key); |
211 gaim_debug_info("cipher-test", "\tsession_key: Wanted: %s\n", "939e7578ed9e3c518a452acee763bce9"); | 211 purple_debug_info("cipher-test", "\tsession_key: Wanted: %s\n", "939e7578ed9e3c518a452acee763bce9"); |
212 | 212 |
213 response = gaim_cipher_http_digest_calculate_response( | 213 response = purple_cipher_http_digest_calculate_response( |
214 algorithm, method, digest_uri, qop, entity, | 214 algorithm, method, digest_uri, qop, entity, |
215 nonce, nonce_count, client_nonce, session_key); | 215 nonce, nonce_count, client_nonce, session_key); |
216 | 216 |
217 g_free(session_key); | 217 g_free(session_key); |
218 | 218 |
219 if (response == NULL) | 219 if (response == NULL) |
220 { | 220 { |
221 gaim_debug_info("cipher-test", | 221 purple_debug_info("cipher-test", |
222 "gaim_cipher_http_digest_calculate_session_key failed.\n"); | 222 "purple_cipher_http_digest_calculate_session_key failed.\n"); |
223 } | 223 } |
224 else | 224 else |
225 { | 225 { |
226 gaim_debug_info("cipher-test", "\tresponse: Got: %s\n", response); | 226 purple_debug_info("cipher-test", "\tresponse: Got: %s\n", response); |
227 gaim_debug_info("cipher-test", "\tresponse: Wanted: %s\n", "6629fae49393a05397450978507c4ef1"); | 227 purple_debug_info("cipher-test", "\tresponse: Wanted: %s\n", "6629fae49393a05397450978507c4ef1"); |
228 g_free(response); | 228 g_free(response); |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 gaim_debug_info("cipher-test", "HTTP Digest tests completed\n\n"); | 232 purple_debug_info("cipher-test", "HTTP Digest tests completed\n\n"); |
233 } | 233 } |
234 | 234 |
235 /************************************************************************** | 235 /************************************************************************** |
236 * Plugin stuff | 236 * Plugin stuff |
237 **************************************************************************/ | 237 **************************************************************************/ |
238 static gboolean | 238 static gboolean |
239 plugin_load(GaimPlugin *plugin) { | 239 plugin_load(PurplePlugin *plugin) { |
240 cipher_test_md5(); | 240 cipher_test_md5(); |
241 cipher_test_sha1(); | 241 cipher_test_sha1(); |
242 cipher_test_digest(); | 242 cipher_test_digest(); |
243 | 243 |
244 return TRUE; | 244 return TRUE; |
245 } | 245 } |
246 | 246 |
247 static gboolean | 247 static gboolean |
248 plugin_unload(GaimPlugin *plugin) { | 248 plugin_unload(PurplePlugin *plugin) { |
249 return TRUE; | 249 return TRUE; |
250 } | 250 } |
251 | 251 |
252 static GaimPluginInfo info = | 252 static PurplePluginInfo info = |
253 { | 253 { |
254 GAIM_PLUGIN_MAGIC, | 254 PURPLE_PLUGIN_MAGIC, |
255 GAIM_MAJOR_VERSION, | 255 PURPLE_MAJOR_VERSION, |
256 GAIM_MINOR_VERSION, | 256 PURPLE_MINOR_VERSION, |
257 GAIM_PLUGIN_STANDARD, /**< type */ | 257 PURPLE_PLUGIN_STANDARD, /**< type */ |
258 NULL, /**< ui_requirement */ | 258 NULL, /**< ui_requirement */ |
259 0, /**< flags */ | 259 0, /**< flags */ |
260 NULL, /**< dependencies */ | 260 NULL, /**< dependencies */ |
261 GAIM_PRIORITY_DEFAULT, /**< priority */ | 261 PURPLE_PRIORITY_DEFAULT, /**< priority */ |
262 | 262 |
263 "core-cipher-test", /**< id */ | 263 "core-cipher-test", /**< id */ |
264 N_("Cipher Test"), /**< name */ | 264 N_("Cipher Test"), /**< name */ |
265 VERSION, /**< version */ | 265 VERSION, /**< version */ |
266 /** summary */ | 266 /** summary */ |
267 N_("Tests the ciphers that ship with libpurple."), | 267 N_("Tests the ciphers that ship with libpurple."), |
268 /** description */ | 268 /** description */ |
269 N_("Tests the ciphers that ship with libpurple."), | 269 N_("Tests the ciphers that ship with libpurple."), |
270 "Gary Kramlich <amc_grim@users.sf.net>", /**< author */ | 270 "Gary Kramlich <amc_grim@users.sf.net>", /**< author */ |
271 GAIM_WEBSITE, /**< homepage */ | 271 PURPLE_WEBSITE, /**< homepage */ |
272 | 272 |
273 plugin_load, /**< load */ | 273 plugin_load, /**< load */ |
274 plugin_unload, /**< unload */ | 274 plugin_unload, /**< unload */ |
275 NULL, /**< destroy */ | 275 NULL, /**< destroy */ |
276 | 276 |
279 NULL, | 279 NULL, |
280 NULL | 280 NULL |
281 }; | 281 }; |
282 | 282 |
283 static void | 283 static void |
284 init_plugin(GaimPlugin *plugin) { | 284 init_plugin(PurplePlugin *plugin) { |
285 } | 285 } |
286 | 286 |
287 GAIM_INIT_PLUGIN(cipher_test, init_plugin, info) | 287 PURPLE_INIT_PLUGIN(cipher_test, init_plugin, info) |