Changeset 5ebff60 for protocols/oscar/auth.c
- Timestamp:
- 2015-02-20T22:50:54Z (10 years ago)
- Branches:
- master
- Children:
- 0b9daac, 3d45471, 7733b8c
- Parents:
- af359b4
- git-author:
- Indent <please@…> (19-02-15 05:47:20)
- git-committer:
- dequis <dx@…> (20-02-15 22:50:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/oscar/auth.c
raf359b4 r5ebff60 4 4 */ 5 5 6 #include <aim.h> 6 #include <aim.h> 7 7 8 8 #include "md5.h" … … 10 10 static int aim_encode_password(const char *password, unsigned char *encoded); 11 11 12 /* 12 /* 13 13 * This just pushes the passed cookie onto the passed connection, without 14 14 * the SNAC header or any of that. … … 23 23 aim_tlvlist_t *tl = NULL; 24 24 25 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x0001, 4 +2+2+AIM_COOKIELEN)))25 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x0001, 4 + 2 + 2 + AIM_COOKIELEN))) { 26 26 return -ENOMEM; 27 } 27 28 28 29 aimbs_put32(&fr->data, 0x00000001); 29 aim_addtlvtochain_raw(&tl, 0x0006, AIM_COOKIELEN, chipsahoy); 30 aim_addtlvtochain_raw(&tl, 0x0006, AIM_COOKIELEN, chipsahoy); 30 31 aim_writetlvchain(&fr->data, &tl); 31 32 aim_freetlvchain(&tl); … … 48 49 aim_frame_t *fr; 49 50 50 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 4))) 51 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 4))) { 51 52 return -ENOMEM; 53 } 52 54 53 55 aimbs_put32(&fr->data, 0x00000001); … … 95 97 aim_frame_t fr; 96 98 aim_rxcallback_t userfunc; 97 99 98 100 sess->flags &= ~AIM_SESS_FLAGS_SNACLOGIN; 99 101 sess->flags |= AIM_SESS_FLAGS_XORLOGIN; 100 102 101 103 fr.conn = conn; 102 103 if ((userfunc = aim_callhandler(sess, conn, 0x0017, 0x0007))) 104 105 if ((userfunc = aim_callhandler(sess, conn, 0x0017, 0x0007))) { 104 106 userfunc(sess, &fr, ""); 105 106 return 0; 107 } 108 109 /* 110 * In AIM 3.5 protocol, the first stage of login is to request login from the 111 * Authorizer, passing it the screen name for verification. If the name is 112 * invalid, a 0017/0003 is spit back, with the standard error contents. If 113 * valid, a 0017/0007 comes back, which is the signal to send it the main 114 * login command (0017/0002). 107 } 108 109 return 0; 110 } 111 112 /* 113 * In AIM 3.5 protocol, the first stage of login is to request login from the 114 * Authorizer, passing it the screen name for verification. If the name is 115 * invalid, a 0017/0003 is spit back, with the standard error contents. If 116 * valid, a 0017/0007 comes back, which is the signal to send it the main 117 * login command (0017/0002). 115 118 * 116 119 */ … … 121 124 aim_tlvlist_t *tl = NULL; 122 125 struct im_connection *ic = sess->aux_data; 123 124 if (!sess || !conn || !sn) 126 127 if (!sess || !conn || !sn) { 125 128 return -EINVAL; 126 127 if (g_ascii_isdigit(sn[0]) && set_getbool(&ic->acc->set, "old_icq_auth")) 129 } 130 131 if (g_ascii_isdigit(sn[0]) && set_getbool(&ic->acc->set, "old_icq_auth")) { 128 132 return goddamnicq(sess, conn, sn); 133 } 129 134 130 135 sess->flags |= AIM_SESS_FLAGS_SNACLOGIN; … … 132 137 aim_sendflapver(sess, conn); 133 138 134 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 +2+2+strlen(sn))))139 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 2 + 2 + strlen(sn)))) { 135 140 return -ENOMEM; 141 } 136 142 137 143 snacid = aim_cachesnac(sess, 0x0017, 0x0006, 0x0000, NULL, 0); 138 144 aim_putsnac(&fr->data, 0x0017, 0x0006, 0x0000, snacid); 139 145 140 aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), (guint8 *) sn);146 aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), (guint8 *) sn); 141 147 aim_writetlvchain(&fr->data, &tl); 142 148 aim_freetlvchain(&tl); … … 152 158 static int goddamnicq2(aim_session_t *sess, aim_conn_t *conn, const char *sn, const char *password) 153 159 { 154 static const char clientstr[] = { "ICQ Inc. - Product of ICQ (TM) 2001b.5.17.1.3642.85"};155 static const char lang[] = { "en"};156 static const char country[] = { "us"};160 static const char clientstr[] = { "ICQ Inc. - Product of ICQ (TM) 2001b.5.17.1.3642.85" }; 161 static const char lang[] = { "en" }; 162 static const char country[] = { "us" }; 157 163 aim_frame_t *fr; 158 164 aim_tlvlist_t *tl = NULL; 159 165 guint8 *password_encoded; 160 166 161 if (!(password_encoded = (guint8 *) g_malloc(strlen(password)))) 167 if (!(password_encoded = (guint8 *) g_malloc(strlen(password)))) { 162 168 return -ENOMEM; 169 } 163 170 164 171 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 1152))) { … … 170 177 171 178 aimbs_put32(&fr->data, 0x00000001); 172 aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), (guint8 *) sn);179 aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), (guint8 *) sn); 173 180 aim_addtlvtochain_raw(&tl, 0x0002, strlen(password), password_encoded); 174 aim_addtlvtochain_raw(&tl, 0x0003, strlen(clientstr), (guint8 *) clientstr);181 aim_addtlvtochain_raw(&tl, 0x0003, strlen(clientstr), (guint8 *) clientstr); 175 182 aim_addtlvtochain16(&tl, 0x0016, 0x010a); /* cliend ID */ 176 183 aim_addtlvtochain16(&tl, 0x0017, 0x0005); /* major version */ … … 179 186 aim_addtlvtochain16(&tl, 0x001a, 0x0e3a); /* build */ 180 187 aim_addtlvtochain32(&tl, 0x0014, 0x00000055); /* distribution chan */ 181 aim_addtlvtochain_raw(&tl, 0x000f, strlen(lang), (guint8 *) lang);182 aim_addtlvtochain_raw(&tl, 0x000e, strlen(country), (guint8 *) country);188 aim_addtlvtochain_raw(&tl, 0x000f, strlen(lang), (guint8 *) lang); 189 aim_addtlvtochain_raw(&tl, 0x000e, strlen(country), (guint8 *) country); 183 190 184 191 aim_writetlvchain(&fr->data, &tl); … … 194 201 /* 195 202 * send_login(int socket, char *sn, char *password) 196 * 203 * 197 204 * This is the initial login request packet. 198 205 * … … 249 256 * build = 0x0013 250 257 * unknown= (not sent) 251 * 258 * 252 259 * AIM for Linux 1.1.112: 253 260 * clientstring = "AOL Instant Messenger (SM)" … … 261 268 * 262 269 */ 263 int aim_send_login(aim_session_t *sess, aim_conn_t *conn, const char *sn, const char *password, struct client_info_s *ci, const char *key) 270 int aim_send_login(aim_session_t *sess, aim_conn_t *conn, const char *sn, const char *password, 271 struct client_info_s *ci, const char *key) 264 272 { 265 273 aim_frame_t *fr; … … 268 276 aim_snacid_t snacid; 269 277 270 if (!ci || !sn || !password) 278 if (!ci || !sn || !password) { 271 279 return -EINVAL; 280 } 272 281 273 282 /* … … 276 285 * 277 286 */ 278 if (sess->flags & AIM_SESS_FLAGS_XORLOGIN) 287 if (sess->flags & AIM_SESS_FLAGS_XORLOGIN) { 279 288 return goddamnicq2(sess, conn, sn, password); 280 281 282 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) 289 } 290 291 292 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) { 283 293 return -ENOMEM; 294 } 284 295 285 296 snacid = aim_cachesnac(sess, 0x0017, 0x0002, 0x0000, NULL, 0); 286 297 aim_putsnac(&fr->data, 0x0017, 0x0002, 0x0000, snacid); 287 298 288 aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), (guint8 *) sn);299 aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), (guint8 *) sn); 289 300 290 301 aim_encode_password_md5(password, key, digest); … … 295 306 */ 296 307 297 if (ci->clientstring) 298 aim_addtlvtochain_raw(&tl, 0x0003, strlen(ci->clientstring), (guint8 *)ci->clientstring); 299 aim_addtlvtochain16(&tl, 0x0016, (guint16)ci->clientid); 300 aim_addtlvtochain16(&tl, 0x0017, (guint16)ci->major); 301 aim_addtlvtochain16(&tl, 0x0018, (guint16)ci->minor); 302 aim_addtlvtochain16(&tl, 0x0019, (guint16)ci->point); 303 aim_addtlvtochain16(&tl, 0x001a, (guint16)ci->build); 304 aim_addtlvtochain_raw(&tl, 0x000e, strlen(ci->country), (guint8 *)ci->country); 305 aim_addtlvtochain_raw(&tl, 0x000f, strlen(ci->lang), (guint8 *)ci->lang); 308 if (ci->clientstring) { 309 aim_addtlvtochain_raw(&tl, 0x0003, strlen(ci->clientstring), (guint8 *) ci->clientstring); 310 } 311 aim_addtlvtochain16(&tl, 0x0016, (guint16) ci->clientid); 312 aim_addtlvtochain16(&tl, 0x0017, (guint16) ci->major); 313 aim_addtlvtochain16(&tl, 0x0018, (guint16) ci->minor); 314 aim_addtlvtochain16(&tl, 0x0019, (guint16) ci->point); 315 aim_addtlvtochain16(&tl, 0x001a, (guint16) ci->build); 316 aim_addtlvtochain_raw(&tl, 0x000e, strlen(ci->country), (guint8 *) ci->country); 317 aim_addtlvtochain_raw(&tl, 0x000f, strlen(ci->lang), (guint8 *) ci->lang); 306 318 307 319 /* … … 314 326 315 327 aim_freetlvchain(&tl); 316 328 317 329 aim_tx_enqueue(sess, fr); 318 330 … … 324 336 md5_state_t state; 325 337 326 md5_init(&state); 327 md5_append(&state, (const md5_byte_t *) key, strlen(key));328 md5_append(&state, (const md5_byte_t *) password, strlen(password));329 md5_append(&state, (const md5_byte_t *) AIM_MD5_STRING, strlen(AIM_MD5_STRING));330 md5_finish(&state, (md5_byte_t *) digest);338 md5_init(&state); 339 md5_append(&state, (const md5_byte_t *) key, strlen(key)); 340 md5_append(&state, (const md5_byte_t *) password, strlen(password)); 341 md5_append(&state, (const md5_byte_t *) AIM_MD5_STRING, strlen(AIM_MD5_STRING)); 342 md5_finish(&state, (md5_byte_t *) digest); 331 343 332 344 return 0; … … 345 357 * 346 358 * The encoding_table seems to be a fixed set of values. We'll 347 * hope it doesn't change over time! 359 * hope it doesn't change over time! 348 360 * 349 361 * This is only used for the XOR method, not the better MD5 method. … … 353 365 { 354 366 guint8 encoding_table[] = { 355 /* v2.1 table, also works for ICQ */367 /* v2.1 table, also works for ICQ */ 356 368 0xf3, 0x26, 0x81, 0xc4, 357 369 0x39, 0x86, 0xdb, 0x92, … … 361 373 int i; 362 374 363 for (i = 0; i < strlen(password); i++) 375 for (i = 0; i < strlen(password); i++) { 364 376 encoded[i] = (password[i] ^ encoding_table[i]); 377 } 365 378 366 379 return 0; … … 370 383 * This is sent back as a general response to the login command. 371 384 * It can be either an error or a success, depending on the 372 * precense of certain TLVs. 385 * precense of certain TLVs. 373 386 * 374 387 * The client should check the value passed as errorcode. If … … 404 417 * have an error url. 405 418 */ 406 if (aim_gettlv(tlvlist, 0x0008, 1)) 419 if (aim_gettlv(tlvlist, 0x0008, 1)) { 407 420 info.errorcode = aim_gettlv16(tlvlist, 0x0008, 1); 408 if (aim_gettlv(tlvlist, 0x0004, 1)) 421 } 422 if (aim_gettlv(tlvlist, 0x0004, 1)) { 409 423 info.errorurl = aim_gettlv_str(tlvlist, 0x0004, 1); 424 } 410 425 411 426 /* 412 427 * BOS server address. 413 428 */ 414 if (aim_gettlv(tlvlist, 0x0005, 1)) 429 if (aim_gettlv(tlvlist, 0x0005, 1)) { 415 430 info.bosip = aim_gettlv_str(tlvlist, 0x0005, 1); 431 } 416 432 417 433 /* … … 430 446 * Not available for ICQ logins. 431 447 */ 432 if (aim_gettlv(tlvlist, 0x0011, 1)) 448 if (aim_gettlv(tlvlist, 0x0011, 1)) { 433 449 info.email = aim_gettlv_str(tlvlist, 0x0011, 1); 450 } 434 451 435 452 /* … … 445 462 * 446 463 */ 447 if (aim_gettlv(tlvlist, 0x0013, 1)) 464 if (aim_gettlv(tlvlist, 0x0013, 1)) { 448 465 info.regstatus = aim_gettlv16(tlvlist, 0x0013, 1); 449 450 if (aim_gettlv(tlvlist, 0x0040, 1)) 466 } 467 468 if (aim_gettlv(tlvlist, 0x0040, 1)) { 451 469 info.latestbeta.build = aim_gettlv32(tlvlist, 0x0040, 1); 452 if (aim_gettlv(tlvlist, 0x0041, 1)) 470 } 471 if (aim_gettlv(tlvlist, 0x0041, 1)) { 453 472 info.latestbeta.url = aim_gettlv_str(tlvlist, 0x0041, 1); 454 if (aim_gettlv(tlvlist, 0x0042, 1)) 473 } 474 if (aim_gettlv(tlvlist, 0x0042, 1)) { 455 475 info.latestbeta.info = aim_gettlv_str(tlvlist, 0x0042, 1); 456 if (aim_gettlv(tlvlist, 0x0043, 1)) 476 } 477 if (aim_gettlv(tlvlist, 0x0043, 1)) { 457 478 info.latestbeta.name = aim_gettlv_str(tlvlist, 0x0043, 1); 458 if (aim_gettlv(tlvlist, 0x0048, 1)) 479 } 480 if (aim_gettlv(tlvlist, 0x0048, 1)) { 459 481 ; /* no idea what this is */ 460 482 461 if (aim_gettlv(tlvlist, 0x0044, 1)) 483 } 484 if (aim_gettlv(tlvlist, 0x0044, 1)) { 462 485 info.latestrelease.build = aim_gettlv32(tlvlist, 0x0044, 1); 463 if (aim_gettlv(tlvlist, 0x0045, 1)) 486 } 487 if (aim_gettlv(tlvlist, 0x0045, 1)) { 464 488 info.latestrelease.url = aim_gettlv_str(tlvlist, 0x0045, 1); 465 if (aim_gettlv(tlvlist, 0x0046, 1)) 489 } 490 if (aim_gettlv(tlvlist, 0x0046, 1)) { 466 491 info.latestrelease.info = aim_gettlv_str(tlvlist, 0x0046, 1); 467 if (aim_gettlv(tlvlist, 0x0047, 1)) 492 } 493 if (aim_gettlv(tlvlist, 0x0047, 1)) { 468 494 info.latestrelease.name = aim_gettlv_str(tlvlist, 0x0047, 1); 469 if (aim_gettlv(tlvlist, 0x0049, 1)) 495 } 496 if (aim_gettlv(tlvlist, 0x0049, 1)) { 470 497 ; /* no idea what this is */ 471 498 472 499 473 if ((userfunc = aim_callhandler(sess, rx->conn, snac ? snac->family : 0x0017, snac ? snac->subtype : 0x0003))) 500 } 501 if ((userfunc = aim_callhandler(sess, rx->conn, snac ? snac->family : 0x0017, snac ? snac->subtype : 0x0003))) { 474 502 ret = userfunc(sess, rx, &info); 503 } 475 504 476 505 g_free(info.sn); … … 506 535 keystr = aimbs_getstr(bs, keylen); 507 536 508 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) 537 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { 509 538 ret = userfunc(sess, rx, keystr); 510 511 g_free(keystr); 539 } 540 541 g_free(keystr); 512 542 513 543 return ret; … … 517 547 { 518 548 519 if (snac->subtype == 0x0003) 549 if (snac->subtype == 0x0003) { 520 550 return parse(sess, mod, rx, snac, bs); 521 else if (snac->subtype == 0x0007)551 } else if (snac->subtype == 0x0007) { 522 552 return keyparse(sess, mod, rx, snac, bs); 553 } 523 554 524 555 return 0;
Note: See TracChangeset
for help on using the changeset viewer.