Mercurial > pidgin
comparison plugins/ciphertest.c @ 12382:cfc808463763
[gaim-migrate @ 14688]
Reimplement HTTP Digest Authentication (RFC 2617) as part of the Cipher API
committer: Tailor Script <tailor@pidgin.im>
| author | Richard Laager <rlaager@wiktel.com> |
|---|---|
| date | Wed, 07 Dec 2005 04:50:36 +0000 |
| parents | bb0d7b719af2 |
| children | 1112a9ef2cc6 |
comparison
equal
deleted
inserted
replaced
| 12381:29e237c4141b | 12382:cfc808463763 |
|---|---|
| 36 #include "debug.h" | 36 #include "debug.h" |
| 37 #include "plugin.h" | 37 #include "plugin.h" |
| 38 #include "version.h" | 38 #include "version.h" |
| 39 | 39 |
| 40 struct test { | 40 struct test { |
| 41 const guchar *question; | 41 const gchar *question; |
| 42 const guchar *answer; | 42 const gchar *answer; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 /************************************************************************** | 45 /************************************************************************** |
| 46 * MD5 Stuff | 46 * MD5 Stuff |
| 47 **************************************************************************/ | 47 **************************************************************************/ |
| 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 gaim_debug_info("cipher-test", "Test %02d:\n", i); |
| 84 gaim_debug_info("cipher-test", "Testing '%s'\n", md5_tests[i].question); | 84 gaim_debug_info("cipher-test", "Testing '%s'\n", md5_tests[i].question); |
| 85 | 85 |
| 86 gaim_cipher_context_append(context, md5_tests[i].question, | 86 gaim_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 = gaim_cipher_context_digest_to_str(context, sizeof(digest), |
| 90 digest, NULL); | 90 digest, NULL); |
| 91 | 91 |
| 141 gaim_debug_info("cipher-test", "Testing '%s'\n", | 141 gaim_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, sha1_tests[i].question, | 146 gaim_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 |
| 172 | 172 |
| 173 gaim_cipher_context_destroy(context); | 173 gaim_cipher_context_destroy(context); |
| 174 | 174 |
| 175 gaim_debug_info("cipher-test", "sha1 tests completed\n\n"); | 175 gaim_debug_info("cipher-test", "sha1 tests completed\n\n"); |
| 176 } | 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 *hashed_entity = ""; | |
| 192 size_t hashed_entity_len = 0; | |
| 193 | |
| 194 gchar *session_key; | |
| 195 | |
| 196 gaim_debug_info("cipher-test", "Running HTTP Digest tests\n"); | |
| 197 | |
| 198 session_key = gaim_cipher_http_digest_calculate_session_key( | |
| 199 algorithm, username, realm, password, | |
| 200 nonce, client_nonce); | |
| 201 | |
| 202 if (session_key == NULL) | |
| 203 { | |
| 204 gaim_debug_info("cipher-test", | |
| 205 "gaim_cipher_http_digest_calculate_session_key failed.\n"); | |
| 206 } | |
| 207 else | |
| 208 { | |
| 209 gchar *response; | |
| 210 | |
| 211 gaim_debug_info("cipher-test", "\tsession_key: Got: %s\n", session_key); | |
| 212 gaim_debug_info("cipher-test", "\tsession_key: Wanted: %s\n", "939e7578ed9e3c518a452acee763bce9"); | |
| 213 | |
| 214 response = gaim_cipher_http_digest_calculate_response( | |
| 215 algorithm, method, digest_uri, qop, | |
| 216 hashed_entity, hashed_entity_len, nonce, | |
| 217 nonce_count, client_nonce, session_key); | |
| 218 | |
| 219 g_free(session_key); | |
| 220 | |
| 221 if (response == NULL) | |
| 222 { | |
| 223 gaim_debug_info("cipher-test", | |
| 224 "gaim_cipher_http_digest_calculate_session_key failed.\n"); | |
| 225 } | |
| 226 else | |
| 227 { | |
| 228 gaim_debug_info("cipher-test", "\tresponse: Got: %s\n", response); | |
| 229 gaim_debug_info("cipher-test", "\tresponse: Wanted: %s\n", "6629fae49393a05397450978507c4ef1"); | |
| 230 } | |
| 231 } | |
| 232 | |
| 233 gaim_debug_info("cipher-test", "HTTP Digest tests completed\n\n"); | |
| 234 } | |
| 235 | |
| 177 /************************************************************************** | 236 /************************************************************************** |
| 178 * Plugin stuff | 237 * Plugin stuff |
| 179 **************************************************************************/ | 238 **************************************************************************/ |
| 180 static gboolean | 239 static gboolean |
| 181 plugin_load(GaimPlugin *plugin) { | 240 plugin_load(GaimPlugin *plugin) { |
| 182 cipher_test_md5(); | 241 cipher_test_md5(); |
| 183 cipher_test_sha1(); | 242 cipher_test_sha1(); |
| 243 cipher_test_digest(); | |
| 184 | 244 |
| 185 return TRUE; | 245 return TRUE; |
| 186 } | 246 } |
| 187 | 247 |
| 188 static gboolean | 248 static gboolean |
