Mercurial > pidgin
comparison src/protocols/simple/simple.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 | 4d3119205a33 |
children | e024601d45c7 |
comparison
equal
deleted
inserted
replaced
12381:29e237c4141b | 12382:cfc808463763 |
---|---|
258 return types; | 258 return types; |
259 } | 259 } |
260 | 260 |
261 static gchar *auth_header(struct simple_account_data *sip, struct sip_auth *auth, gchar *method, gchar *target) { | 261 static gchar *auth_header(struct simple_account_data *sip, struct sip_auth *auth, gchar *method, gchar *target) { |
262 gchar noncecount[9]; | 262 gchar noncecount[9]; |
263 HASHHEX HA2; | 263 gchar *response; |
264 HASHHEX response; | |
265 gchar *ret; | 264 gchar *ret; |
266 gchar *tmp; | 265 gchar *tmp; |
267 | 266 |
268 if(auth->type == 1) { /* Digest */ | 267 if(auth->type == 1) { /* Digest */ |
269 sprintf(noncecount, "%08d", auth->nc++); | 268 sprintf(noncecount, "%08d", auth->nc++); |
270 DigestCalcResponse(auth->HA1, auth->nonce, noncecount, "", "", method, target, HA2, response); | 269 response = gaim_cipher_http_digest_calculate_response( |
270 "md5", method, target, NULL, NULL, 0, | |
271 auth->nonce, noncecount, NULL, auth->digest_session_key); | |
271 gaim_debug(GAIM_DEBUG_MISC, "simple", "response %s\n", response); | 272 gaim_debug(GAIM_DEBUG_MISC, "simple", "response %s\n", response); |
272 ret = g_strdup_printf("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=\"%s\", response=\"%s\"\r\n",sip->username, auth->realm, auth->nonce, target, noncecount, response); | 273 |
274 ret = g_strdup_printf("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=\"%s\", response=\"%s\"\r\n", sip->username, auth->realm, auth->nonce, target, noncecount, response); | |
275 g_free(response); | |
273 return ret; | 276 return ret; |
274 } else if(auth->type == 2) { /* NTLM */ | 277 } else if(auth->type == 2) { /* NTLM */ |
275 if(auth->nc == 3) { | 278 if(auth->nc == 3) { |
276 ret = gaim_ntlm_gen_type3(sip->username, sip->password, "gaim", sip->servername, auth->nonce); | 279 ret = gaim_ntlm_gen_type3(sip->username, sip->password, "gaim", sip->servername, auth->nonce); |
277 tmp = g_strdup_printf("NTLM qop=\"auth\" realm=\"%s\" targetname=\"%s\" response=\"%s\"\r\n",auth->realm, auth->target, ret); | 280 tmp = g_strdup_printf("NTLM qop=\"auth\" realm=\"%s\" targetname=\"%s\" response=\"%s\"\r\n", auth->realm, auth->target, ret); |
278 g_free(ret); | 281 g_free(ret); |
279 return tmp; | 282 return tmp; |
280 } | 283 } |
281 ret = gaim_ntlm_gen_type1("gaim", sip->servername); | 284 ret = gaim_ntlm_gen_type1("gaim", sip->servername); |
282 tmp = g_strdup_printf("NTLM qop=\"auth\" realm=\"%s\" targetname=\"%s\" response=\"%s\"\r\n", auth->realm, auth->target, ret); | 285 tmp = g_strdup_printf("NTLM qop=\"auth\" realm=\"%s\" targetname=\"%s\" response=\"%s\"\r\n", auth->realm, auth->target, ret); |
283 g_free(ret); | 286 g_free(ret); |
284 return tmp; | 287 return tmp; |
285 } | 288 } |
286 | 289 |
287 sprintf(noncecount, "%08d", auth->nc++); | 290 sprintf(noncecount, "%08d", auth->nc++); |
288 DigestCalcResponse(auth->HA1, auth->nonce, noncecount, "", "", method, target, HA2, response); | 291 response = gaim_cipher_http_digest_calculate_response( |
292 "md5", method, target, NULL, NULL, 0, | |
293 auth->nonce, noncecount, NULL, auth->digest_session_key); | |
289 gaim_debug(GAIM_DEBUG_MISC, "simple", "response %s\n", response); | 294 gaim_debug(GAIM_DEBUG_MISC, "simple", "response %s\n", response); |
290 ret = g_strdup_printf("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=\"%s\", response=\"%s\"\r\n",sip->username, auth->realm, auth->nonce, target, noncecount, response); | 295 |
296 ret = g_strdup_printf("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=\"%s\", response=\"%s\"\r\n", sip->username, auth->realm, auth->nonce, target, noncecount, response); | |
297 g_free(response); | |
291 return ret; | 298 return ret; |
292 } | 299 } |
293 | 300 |
294 static void fill_auth(struct simple_account_data *sip, gchar *hdr, struct sip_auth *auth) { | 301 static void fill_auth(struct simple_account_data *sip, gchar *hdr, struct sip_auth *auth) { |
295 int i=0; | 302 int i=0; |
344 } | 351 } |
345 g_strfreev(parts); | 352 g_strfreev(parts); |
346 | 353 |
347 gaim_debug(GAIM_DEBUG_MISC, "simple", "nonce: %s realm: %s ", auth->nonce, auth->realm); | 354 gaim_debug(GAIM_DEBUG_MISC, "simple", "nonce: %s realm: %s ", auth->nonce, auth->realm); |
348 | 355 |
349 DigestCalcHA1("md5", sip->username, auth->realm, sip->password, auth->nonce, "", auth->HA1); | 356 auth->digest_session_key = gaim_cipher_http_digest_calculate_session_key( |
357 "md5", sip->username, auth->realm, sip->password, auth->nonce, NULL); | |
350 | 358 |
351 auth->nc=1; | 359 auth->nc=1; |
352 } | 360 } |
353 | 361 |
354 static void simple_input_cb(gpointer data, gint source, GaimInputCondition cond); | 362 static void simple_input_cb(gpointer data, gint source, GaimInputCondition cond); |