Mon, 06 Sep 2010 19:36:31 +0000
ChangeLog the Google relay stuff
| 10684 | 1 | /* |
| 15884 | 2 | * A plugin to test the ciphers that ship with purple |
| 10684 | 3 | * |
| 4 | * Copyright (C) 2004, Gary Kramlich <amc_grim@users.sf.net> | |
| 5 | * | |
| 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 | |
| 8 | * published by the Free Software Foundation; either version 2 of the | |
| 9 | * License, or (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, but | |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 | * General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
16786
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
16786
diff
changeset
|
19 | * 02111-1301, USA. |
| 10684 | 20 | */ |
| 21 | ||
| 22 | #ifdef HAVE_CONFIG_H | |
| 23 | #include <config.h> | |
| 24 | #endif | |
| 25 | ||
| 15884 | 26 | #ifndef PURPLE_PLUGINS |
| 27 | #define PURPLE_PLUGINS | |
| 10684 | 28 | #endif |
| 29 | ||
| 30 | #include "internal.h" | |
| 31 | ||
| 32 | #include <glib.h> | |
| 33 | #include <string.h> | |
| 34 | ||
| 35 | #include "cipher.h" | |
| 36 | #include "debug.h" | |
| 37 | #include "plugin.h" | |
| 38 | #include "version.h" | |
| 39 | ||
| 40 | struct test { | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
41 | const gchar *question; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
42 | const gchar *answer; |
| 10684 | 43 | }; |
| 44 | ||
| 45 | /************************************************************************** | |
| 46 | * MD5 Stuff | |
| 47 | **************************************************************************/ | |
| 48 | struct test md5_tests[8] = { | |
| 49 | { "", "d41d8cd98f00b204e9800998ecf8427e"}, | |
| 50 | { "a", "0cc175b9c0f1b6a831c399e269772661"}, | |
| 51 | { "abc", "900150983cd24fb0d6963f7d28e17f72"}, | |
| 52 | { "message digest", "f96b697d7cb7938d525a2f31aaf161d0"}, | |
| 53 | { "abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b"}, | |
| 54 | { "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
| 55 | "abcdefghijklmnopqrstuvwxyz" | |
| 56 | "0123456789", "d174ab98d277d9f5a5611c2c9f419d9f"}, | |
| 57 | {"123456789012345678901234567" | |
| 58 | "890123456789012345678901234" | |
| 59 | "56789012345678901234567890", "57edf4a22be3c955ac49da2e2107b67a"}, | |
| 60 | { NULL, NULL } | |
| 61 | }; | |
| 62 | ||
| 63 | static void | |
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
20288
diff
changeset
|
64 | cipher_test_md5(void) { |
| 15884 | 65 | PurpleCipher *cipher; |
| 66 | PurpleCipherContext *context; | |
|
12388
3a25d96abdaf
[gaim-migrate @ 14694]
Richard Laager <rlaager@pidgin.im>
parents:
12387
diff
changeset
|
67 | gchar digest[33]; |
| 10687 | 68 | gboolean ret; |
| 10684 | 69 | gint i = 0; |
| 70 | ||
| 15884 | 71 | cipher = purple_ciphers_find_cipher("md5"); |
| 10684 | 72 | if(!cipher) { |
| 15884 | 73 | purple_debug_info("cipher-test", |
| 10684 | 74 | "could not find md5 cipher, not testing\n"); |
| 75 | return; | |
| 76 | } | |
| 77 | ||
| 15884 | 78 | purple_debug_info("cipher-test", "Running md5 tests\n"); |
| 10684 | 79 | |
| 15884 | 80 | context = purple_cipher_context_new(cipher, NULL); |
| 10684 | 81 | |
| 82 | while(md5_tests[i].answer) { | |
| 15884 | 83 | purple_debug_info("cipher-test", "Test %02d:\n", i); |
| 84 | purple_debug_info("cipher-test", "Testing '%s'\n", md5_tests[i].question); | |
| 10684 | 85 | |
| 15884 | 86 | purple_cipher_context_append(context, (guchar *)md5_tests[i].question, |
| 10684 | 87 | strlen(md5_tests[i].question)); |
| 88 | ||
| 15884 | 89 | ret = purple_cipher_context_digest_to_str(context, sizeof(digest), |
| 10687 | 90 | digest, NULL); |
| 10684 | 91 | |
| 10687 | 92 | if(!ret) { |
| 15884 | 93 | purple_debug_info("cipher-test", "failed\n"); |
| 10687 | 94 | } else { |
| 15884 | 95 | purple_debug_info("cipher-test", "\tGot: %s\n", digest); |
| 96 | purple_debug_info("cipher-test", "\tWanted: %s\n", | |
| 10687 | 97 | md5_tests[i].answer); |
| 98 | } | |
| 10684 | 99 | |
| 15884 | 100 | purple_cipher_context_reset(context, NULL); |
| 10684 | 101 | i++; |
| 102 | } | |
| 103 | ||
| 15884 | 104 | purple_cipher_context_destroy(context); |
| 10684 | 105 | |
| 15884 | 106 | purple_debug_info("cipher-test", "md5 tests completed\n\n"); |
| 10684 | 107 | } |
| 108 | ||
| 109 | /************************************************************************** | |
| 110 | * SHA-1 stuff | |
| 111 | **************************************************************************/ | |
| 112 | struct test sha1_tests[5] = { | |
| 113 | {"a", "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8"}, | |
| 114 | {"abc", "a9993e364706816aba3e25717850c26c9cd0d89d"} , | |
| 115 | {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "84983e441c3bd26ebaae4aa1f95129e5e54670f1"} , | |
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
20288
diff
changeset
|
116 | {NULL, "34aa973cd4c4daa4f61eeb2bdbad27316534016f"}, |
| 10684 | 117 | {NULL, NULL} |
| 118 | }; | |
| 119 | ||
| 120 | static void | |
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
20288
diff
changeset
|
121 | cipher_test_sha1(void) { |
| 15884 | 122 | PurpleCipher *cipher; |
| 123 | PurpleCipherContext *context; | |
|
12388
3a25d96abdaf
[gaim-migrate @ 14694]
Richard Laager <rlaager@pidgin.im>
parents:
12387
diff
changeset
|
124 | gchar digest[41]; |
| 10684 | 125 | gint i = 0; |
| 10687 | 126 | gboolean ret; |
| 10684 | 127 | |
| 15884 | 128 | cipher = purple_ciphers_find_cipher("sha1"); |
| 10684 | 129 | if(!cipher) { |
| 15884 | 130 | purple_debug_info("cipher-test", |
| 10684 | 131 | "could not find sha1 cipher, not testing\n"); |
| 132 | return; | |
| 133 | } | |
| 134 | ||
| 15884 | 135 | purple_debug_info("cipher-test", "Running sha1 tests\n"); |
| 10684 | 136 | |
| 15884 | 137 | context = purple_cipher_context_new(cipher, NULL); |
| 10684 | 138 | |
| 139 | while(sha1_tests[i].answer) { | |
| 15884 | 140 | purple_debug_info("cipher-test", "Test %02d:\n", i); |
| 141 | purple_debug_info("cipher-test", "Testing '%s'\n", | |
| 10684 | 142 | (sha1_tests[i].question != NULL) ? |
| 143 | sha1_tests[i].question : "'a'x1000, 1000 times"); | |
| 144 | ||
| 145 | if(sha1_tests[i].question) { | |
| 15884 | 146 | purple_cipher_context_append(context, (guchar *)sha1_tests[i].question, |
| 10684 | 147 | strlen(sha1_tests[i].question)); |
| 148 | } else { | |
| 149 | gint j; | |
|
11183
be87fe695c93
[gaim-migrate @ 13295]
Mark Doliner <markdoliner@pidgin.im>
parents:
11033
diff
changeset
|
150 | guchar buff[1000]; |
| 10684 | 151 | |
| 152 | memset(buff, 'a', 1000); | |
| 153 | ||
| 154 | for(j = 0; j < 1000; j++) | |
| 15884 | 155 | purple_cipher_context_append(context, buff, 1000); |
| 10684 | 156 | } |
| 157 | ||
| 15884 | 158 | ret = purple_cipher_context_digest_to_str(context, sizeof(digest), |
| 10687 | 159 | digest, NULL); |
| 10684 | 160 | |
| 10687 | 161 | if(!ret) { |
| 15884 | 162 | purple_debug_info("cipher-test", "failed\n"); |
| 10687 | 163 | } else { |
| 15884 | 164 | purple_debug_info("cipher-test", "\tGot: %s\n", digest); |
| 165 | purple_debug_info("cipher-test", "\tWanted: %s\n", | |
| 10687 | 166 | sha1_tests[i].answer); |
| 167 | } | |
| 10684 | 168 | |
| 15884 | 169 | purple_cipher_context_reset(context, NULL); |
| 10684 | 170 | i++; |
| 171 | } | |
| 172 | ||
| 15884 | 173 | purple_cipher_context_destroy(context); |
| 10684 | 174 | |
| 15884 | 175 | purple_debug_info("cipher-test", "sha1 tests completed\n\n"); |
| 10684 | 176 | } |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
177 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
178 | static void |
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
20288
diff
changeset
|
179 | cipher_test_digest(void) |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
180 | { |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
181 | const gchar *nonce = "dcd98b7102dd2f0e8b11d0f600bfb0c093"; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
182 | const gchar *client_nonce = "0a4f113b"; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
183 | const gchar *username = "Mufasa"; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
184 | const gchar *realm = "testrealm@host.com"; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
185 | const gchar *password = "Circle Of Life"; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
186 | const gchar *algorithm = "md5"; |
|
12389
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
187 | const gchar *nonce_count = "00000001"; |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
188 | const gchar *method = "GET"; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
189 | const gchar *qop = "auth"; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
190 | const gchar *digest_uri = "/dir/index.html"; |
|
12389
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
191 | const gchar *entity = NULL; |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
192 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
193 | gchar *session_key; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
194 | |
| 15884 | 195 | purple_debug_info("cipher-test", "Running HTTP Digest tests\n"); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
196 | |
| 15884 | 197 | session_key = purple_cipher_http_digest_calculate_session_key( |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
198 | algorithm, username, realm, password, |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
199 | nonce, client_nonce); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
200 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
201 | if (session_key == NULL) |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
202 | { |
| 15884 | 203 | purple_debug_info("cipher-test", |
| 204 | "purple_cipher_http_digest_calculate_session_key failed.\n"); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
205 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
206 | else |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
207 | { |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
208 | gchar *response; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
209 | |
| 15884 | 210 | purple_debug_info("cipher-test", "\tsession_key: Got: %s\n", session_key); |
| 211 | purple_debug_info("cipher-test", "\tsession_key: Wanted: %s\n", "939e7578ed9e3c518a452acee763bce9"); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
212 | |
| 15884 | 213 | response = purple_cipher_http_digest_calculate_response( |
|
12389
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
214 | algorithm, method, digest_uri, qop, entity, |
|
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
215 | nonce, nonce_count, client_nonce, session_key); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
216 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
217 | g_free(session_key); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
218 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
219 | if (response == NULL) |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
220 | { |
| 15884 | 221 | purple_debug_info("cipher-test", |
| 222 | "purple_cipher_http_digest_calculate_session_key failed.\n"); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
223 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
224 | else |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
225 | { |
| 15884 | 226 | purple_debug_info("cipher-test", "\tresponse: Got: %s\n", response); |
| 227 | purple_debug_info("cipher-test", "\tresponse: Wanted: %s\n", "6629fae49393a05397450978507c4ef1"); | |
|
12387
913d216b13b2
[gaim-migrate @ 14693]
Richard Laager <rlaager@pidgin.im>
parents:
12382
diff
changeset
|
228 | g_free(response); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
229 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
230 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
231 | |
| 15884 | 232 | purple_debug_info("cipher-test", "HTTP Digest tests completed\n\n"); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
233 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
234 | |
| 10684 | 235 | /************************************************************************** |
| 236 | * Plugin stuff | |
| 237 | **************************************************************************/ | |
| 238 | static gboolean | |
| 15884 | 239 | plugin_load(PurplePlugin *plugin) { |
| 10684 | 240 | cipher_test_md5(); |
| 241 | cipher_test_sha1(); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
242 | cipher_test_digest(); |
| 10684 | 243 | |
| 244 | return TRUE; | |
| 245 | } | |
| 246 | ||
| 11033 | 247 | static gboolean |
| 15884 | 248 | plugin_unload(PurplePlugin *plugin) { |
| 11033 | 249 | return TRUE; |
| 250 | } | |
| 251 | ||
| 15884 | 252 | static PurplePluginInfo info = |
| 10684 | 253 | { |
| 15884 | 254 | PURPLE_PLUGIN_MAGIC, |
| 255 | PURPLE_MAJOR_VERSION, | |
| 256 | PURPLE_MINOR_VERSION, | |
| 257 | PURPLE_PLUGIN_STANDARD, /**< type */ | |
| 10684 | 258 | NULL, /**< ui_requirement */ |
| 259 | 0, /**< flags */ | |
| 260 | NULL, /**< dependencies */ | |
| 15884 | 261 | PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 10684 | 262 | |
| 263 | "core-cipher-test", /**< id */ | |
| 264 | N_("Cipher Test"), /**< name */ | |
|
20288
5ca925a094e2
applied changes from 03b709ec2a153e7e82719df0ba4635108bb1d3c6
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
265 | DISPLAY_VERSION, /**< version */ |
| 10684 | 266 | /** summary */ |
|
15498
2ee3112b6f24
This should be the last of the string changes
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
267 | N_("Tests the ciphers that ship with libpurple."), |
| 10684 | 268 | /** description */ |
|
15498
2ee3112b6f24
This should be the last of the string changes
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
269 | N_("Tests the ciphers that ship with libpurple."), |
| 10684 | 270 | "Gary Kramlich <amc_grim@users.sf.net>", /**< author */ |
| 15884 | 271 | PURPLE_WEBSITE, /**< homepage */ |
| 10684 | 272 | |
| 273 | plugin_load, /**< load */ | |
| 11033 | 274 | plugin_unload, /**< unload */ |
| 10684 | 275 | NULL, /**< destroy */ |
| 276 | ||
| 277 | NULL, /**< ui_info */ | |
| 278 | NULL, /**< extra_info */ | |
| 279 | NULL, | |
|
16786
65c04c7e5c8a
Add padding to structs as necessary to silence compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
280 | NULL, |
|
65c04c7e5c8a
Add padding to structs as necessary to silence compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
281 | /* padding */ |
|
65c04c7e5c8a
Add padding to structs as necessary to silence compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
282 | NULL, |
|
65c04c7e5c8a
Add padding to structs as necessary to silence compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
283 | NULL, |
|
65c04c7e5c8a
Add padding to structs as necessary to silence compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
284 | NULL, |
| 10684 | 285 | NULL |
| 286 | }; | |
| 287 | ||
| 288 | static void | |
| 15884 | 289 | init_plugin(PurplePlugin *plugin) { |
| 10684 | 290 | } |
| 291 | ||
| 15884 | 292 | PURPLE_INIT_PLUGIN(cipher_test, init_plugin, info) |