Mercurial > pidgin
comparison libgaim/plugins/ciphertest.c @ 14192:60b1bc8dbf37
[gaim-migrate @ 16863]
Renamed 'core' to 'libgaim'
committer: Tailor Script <tailor@pidgin.im>
| author | Evan Schoenberg <evan.s@dreskin.net> |
|---|---|
| date | Sat, 19 Aug 2006 01:50:10 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 14191:009db0b357b5 | 14192:60b1bc8dbf37 |
|---|---|
| 1 /* | |
| 2 * A plugin to test the ciphers that ship with gaim | |
| 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 | |
| 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
| 19 * 02111-1307, USA. | |
| 20 */ | |
| 21 | |
| 22 #ifdef HAVE_CONFIG_H | |
| 23 #include <config.h> | |
| 24 #endif | |
| 25 | |
| 26 #ifndef GAIM_PLUGINS | |
| 27 #define GAIM_PLUGINS | |
| 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 { | |
| 41 const gchar *question; | |
| 42 const gchar *answer; | |
| 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 | |
| 64 cipher_test_md5() { | |
| 65 GaimCipher *cipher; | |
| 66 GaimCipherContext *context; | |
| 67 gchar digest[33]; | |
| 68 gboolean ret; | |
| 69 gint i = 0; | |
| 70 | |
| 71 cipher = gaim_ciphers_find_cipher("md5"); | |
| 72 if(!cipher) { | |
| 73 gaim_debug_info("cipher-test", | |
| 74 "could not find md5 cipher, not testing\n"); | |
| 75 return; | |
| 76 } | |
| 77 | |
| 78 gaim_debug_info("cipher-test", "Running md5 tests\n"); | |
| 79 | |
| 80 context = gaim_cipher_context_new(cipher, NULL); | |
| 81 | |
| 82 while(md5_tests[i].answer) { | |
| 83 gaim_debug_info("cipher-test", "Test %02d:\n", i); | |
| 84 gaim_debug_info("cipher-test", "Testing '%s'\n", md5_tests[i].question); | |
| 85 | |
| 86 gaim_cipher_context_append(context, (guchar *)md5_tests[i].question, | |
| 87 strlen(md5_tests[i].question)); | |
| 88 | |
| 89 ret = gaim_cipher_context_digest_to_str(context, sizeof(digest), | |
| 90 digest, NULL); | |
| 91 | |
| 92 if(!ret) { | |
| 93 gaim_debug_info("cipher-test", "failed\n"); | |
| 94 } else { | |
| 95 gaim_debug_info("cipher-test", "\tGot: %s\n", digest); | |
| 96 gaim_debug_info("cipher-test", "\tWanted: %s\n", | |
| 97 md5_tests[i].answer); | |
| 98 } | |
| 99 | |
| 100 gaim_cipher_context_reset(context, NULL); | |
| 101 i++; | |
| 102 } | |
| 103 | |
| 104 gaim_cipher_context_destroy(context); | |
| 105 | |
| 106 gaim_debug_info("cipher-test", "md5 tests completed\n\n"); | |
| 107 } | |
| 108 | |
| 109 /************************************************************************** | |
| 110 * SHA-1 stuff | |
| 111 **************************************************************************/ | |
| 112 struct test sha1_tests[5] = { | |
| 113 {"a", "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8"}, | |
| 114 {"abc", "a9993e364706816aba3e25717850c26c9cd0d89d"} , | |
| 115 {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "84983e441c3bd26ebaae4aa1f95129e5e54670f1"} , | |
| 116 {NULL, "34aa973cd4c4daa4f61eeb2bdbad27316534016f"}, | |
| 117 {NULL, NULL} | |
| 118 }; | |
| 119 | |
| 120 static void | |
| 121 cipher_test_sha1() { | |
| 122 GaimCipher *cipher; | |
| 123 GaimCipherContext *context; | |
| 124 gchar digest[41]; | |
| 125 gint i = 0; | |
| 126 gboolean ret; | |
| 127 | |
| 128 cipher = gaim_ciphers_find_cipher("sha1"); | |
| 129 if(!cipher) { | |
| 130 gaim_debug_info("cipher-test", | |
| 131 "could not find sha1 cipher, not testing\n"); | |
| 132 return; | |
| 133 } | |
| 134 | |
| 135 gaim_debug_info("cipher-test", "Running sha1 tests\n"); | |
| 136 | |
| 137 context = gaim_cipher_context_new(cipher, NULL); | |
| 138 | |
| 139 while(sha1_tests[i].answer) { | |
| 140 gaim_debug_info("cipher-test", "Test %02d:\n", i); | |
| 141 gaim_debug_info("cipher-test", "Testing '%s'\n", | |
| 142 (sha1_tests[i].question != NULL) ? | |
| 143 sha1_tests[i].question : "'a'x1000, 1000 times"); | |
| 144 | |
| 145 if(sha1_tests[i].question) { | |
| 146 gaim_cipher_context_append(context, (guchar *)sha1_tests[i].question, | |
| 147 strlen(sha1_tests[i].question)); | |
| 148 } else { | |
| 149 gint j; | |
| 150 guchar buff[1000]; | |
| 151 | |
| 152 memset(buff, 'a', 1000); | |
| 153 | |
| 154 for(j = 0; j < 1000; j++) | |
| 155 gaim_cipher_context_append(context, buff, 1000); | |
| 156 } | |
| 157 | |
| 158 ret = gaim_cipher_context_digest_to_str(context, sizeof(digest), | |
| 159 digest, NULL); | |
| 160 | |
| 161 if(!ret) { | |
| 162 gaim_debug_info("cipher-test", "failed\n"); | |
| 163 } else { | |
| 164 gaim_debug_info("cipher-test", "\tGot: %s\n", digest); | |
| 165 gaim_debug_info("cipher-test", "\tWanted: %s\n", | |
| 166 sha1_tests[i].answer); | |
| 167 } | |
| 168 | |
| 169 gaim_cipher_context_reset(context, NULL); | |
| 170 i++; | |
| 171 } | |
| 172 | |
| 173 gaim_cipher_context_destroy(context); | |
| 174 | |
| 175 gaim_debug_info("cipher-test", "sha1 tests completed\n\n"); | |
| 176 } | |
| 177 | |
| 178 static void | |
| 179 cipher_test_digest() | |
| 180 { | |
| 181 const gchar *nonce = "dcd98b7102dd2f0e8b11d0f600bfb0c093"; | |
| 182 const gchar *client_nonce = "0a4f113b"; | |
| 183 const gchar *username = "Mufasa"; | |
| 184 const gchar *realm = "testrealm@host.com"; | |
| 185 const gchar *password = "Circle Of Life"; | |
| 186 const gchar *algorithm = "md5"; | |
| 187 const gchar *nonce_count = "00000001"; | |
| 188 const gchar *method = "GET"; | |
| 189 const gchar *qop = "auth"; | |
| 190 const gchar *digest_uri = "/dir/index.html"; | |
| 191 const gchar *entity = NULL; | |
| 192 | |
| 193 gchar *session_key; | |
| 194 | |
| 195 gaim_debug_info("cipher-test", "Running HTTP Digest tests\n"); | |
| 196 | |
| 197 session_key = gaim_cipher_http_digest_calculate_session_key( | |
| 198 algorithm, username, realm, password, | |
| 199 nonce, client_nonce); | |
| 200 | |
| 201 if (session_key == NULL) | |
| 202 { | |
| 203 gaim_debug_info("cipher-test", | |
| 204 "gaim_cipher_http_digest_calculate_session_key failed.\n"); | |
| 205 } | |
| 206 else | |
| 207 { | |
| 208 gchar *response; | |
| 209 | |
| 210 gaim_debug_info("cipher-test", "\tsession_key: Got: %s\n", session_key); | |
| 211 gaim_debug_info("cipher-test", "\tsession_key: Wanted: %s\n", "939e7578ed9e3c518a452acee763bce9"); | |
| 212 | |
| 213 response = gaim_cipher_http_digest_calculate_response( | |
| 214 algorithm, method, digest_uri, qop, entity, | |
| 215 nonce, nonce_count, client_nonce, session_key); | |
| 216 | |
| 217 g_free(session_key); | |
| 218 | |
| 219 if (response == NULL) | |
| 220 { | |
| 221 gaim_debug_info("cipher-test", | |
| 222 "gaim_cipher_http_digest_calculate_session_key failed.\n"); | |
| 223 } | |
| 224 else | |
| 225 { | |
| 226 gaim_debug_info("cipher-test", "\tresponse: Got: %s\n", response); | |
| 227 gaim_debug_info("cipher-test", "\tresponse: Wanted: %s\n", "6629fae49393a05397450978507c4ef1"); | |
| 228 g_free(response); | |
| 229 } | |
| 230 } | |
| 231 | |
| 232 gaim_debug_info("cipher-test", "HTTP Digest tests completed\n\n"); | |
| 233 } | |
| 234 | |
| 235 /************************************************************************** | |
| 236 * Plugin stuff | |
| 237 **************************************************************************/ | |
| 238 static gboolean | |
| 239 plugin_load(GaimPlugin *plugin) { | |
| 240 cipher_test_md5(); | |
| 241 cipher_test_sha1(); | |
| 242 cipher_test_digest(); | |
| 243 | |
| 244 return TRUE; | |
| 245 } | |
| 246 | |
| 247 static gboolean | |
| 248 plugin_unload(GaimPlugin *plugin) { | |
| 249 return TRUE; | |
| 250 } | |
| 251 | |
| 252 static GaimPluginInfo info = | |
| 253 { | |
| 254 GAIM_PLUGIN_MAGIC, | |
| 255 GAIM_MAJOR_VERSION, | |
| 256 GAIM_MINOR_VERSION, | |
| 257 GAIM_PLUGIN_STANDARD, /**< type */ | |
| 258 NULL, /**< ui_requirement */ | |
| 259 0, /**< flags */ | |
| 260 NULL, /**< dependencies */ | |
| 261 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 262 | |
| 263 "core-cipher-test", /**< id */ | |
| 264 N_("Cipher Test"), /**< name */ | |
| 265 VERSION, /**< version */ | |
| 266 /** summary */ | |
| 267 N_("Tests the ciphers that ship with gaim."), | |
| 268 /** description */ | |
| 269 N_("Tests the ciphers that ship with gaim."), | |
| 270 "Gary Kramlich <amc_grim@users.sf.net>", /**< author */ | |
| 271 GAIM_WEBSITE, /**< homepage */ | |
| 272 | |
| 273 plugin_load, /**< load */ | |
| 274 plugin_unload, /**< unload */ | |
| 275 NULL, /**< destroy */ | |
| 276 | |
| 277 NULL, /**< ui_info */ | |
| 278 NULL, /**< extra_info */ | |
| 279 NULL, | |
| 280 NULL | |
| 281 }; | |
| 282 | |
| 283 static void | |
| 284 init_plugin(GaimPlugin *plugin) { | |
| 285 } | |
| 286 | |
| 287 GAIM_INIT_PLUGIN(cipher_test, init_plugin, info) |
