13234
|
1 /*
|
|
2 * Gaim's oscar protocol plugin
|
|
3 * This file is the legal property of its developers.
|
|
4 * Please see the AUTHORS file distributed alongside this file.
|
|
5 *
|
|
6 * This library is free software; you can redistribute it and/or
|
|
7 * modify it under the terms of the GNU Lesser General Public
|
|
8 * License as published by the Free Software Foundation; either
|
|
9 * version 2 of the License, or (at your option) any later version.
|
|
10 *
|
|
11 * This library is distributed in the hope that it will be useful,
|
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14 * Lesser General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU Lesser General Public
|
|
17 * License along with this library; if not, write to the Free Software
|
|
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
19 */
|
|
20
|
|
21 /*
|
|
22 * Family 0x0017 - Authentication.
|
|
23 *
|
|
24 * Deals with the authorizer for SNAC-based login, and also old-style
|
|
25 * non-SNAC login.
|
|
26 *
|
|
27 */
|
|
28
|
|
29 #include "oscar.h"
|
|
30
|
|
31 #include "cipher.h"
|
|
32
|
|
33 #include <ctype.h>
|
|
34
|
|
35 #define USE_XOR_FOR_ICQ
|
|
36
|
|
37 #ifdef USE_XOR_FOR_ICQ
|
|
38 /**
|
|
39 * Encode a password using old XOR method
|
|
40 *
|
|
41 * This takes a const pointer to a (null terminated) string
|
|
42 * containing the unencoded password. It also gets passed
|
|
43 * an already allocated buffer to store the encoded password.
|
|
44 * This buffer should be the exact length of the password without
|
|
45 * the null. The encoded password buffer /is not %NULL terminated/.
|
|
46 *
|
|
47 * The encoding_table seems to be a fixed set of values. We'll
|
|
48 * hope it doesn't change over time!
|
|
49 *
|
|
50 * This is only used for the XOR method, not the better MD5 method.
|
|
51 *
|
|
52 * @param password Incoming password.
|
|
53 * @param encoded Buffer to put encoded password.
|
|
54 */
|
|
55 static int aim_encode_password(const char *password, guint8 *encoded)
|
|
56 {
|
|
57 guint8 encoding_table[] = {
|
|
58 #if 0 /* old v1 table */
|
|
59 0xf3, 0xb3, 0x6c, 0x99,
|
|
60 0x95, 0x3f, 0xac, 0xb6,
|
|
61 0xc5, 0xfa, 0x6b, 0x63,
|
|
62 0x69, 0x6c, 0xc3, 0x9f
|
|
63 #else /* v2.1 table, also works for ICQ */
|
|
64 0xf3, 0x26, 0x81, 0xc4,
|
|
65 0x39, 0x86, 0xdb, 0x92,
|
|
66 0x71, 0xa3, 0xb9, 0xe6,
|
|
67 0x53, 0x7a, 0x95, 0x7c
|
|
68 #endif
|
|
69 };
|
|
70 unsigned int i;
|
|
71
|
|
72 for (i = 0; i < strlen(password); i++)
|
|
73 encoded[i] = (password[i] ^ encoding_table[i]);
|
|
74
|
|
75 return 0;
|
|
76 }
|
|
77 #endif
|
|
78
|
|
79 #ifdef USE_OLD_MD5
|
|
80 static int aim_encode_password_md5(const char *password, const char *key, guint8 *digest)
|
|
81 {
|
|
82 GaimCipher *cipher;
|
|
83 GaimCipherContext *context;
|
|
84
|
|
85 cipher = gaim_ciphers_find_cipher("md5");
|
|
86
|
|
87 context = gaim_cipher_context_new(cipher, NULL);
|
|
88 gaim_cipher_context_append(context, (const guchar *)key, strlen(key));
|
|
89 gaim_cipher_context_append(context, (const guchar *)password, strlen(password));
|
|
90 gaim_cipher_context_append(context, (const guchar *)AIM_MD5_STRING, strlen(AIM_MD5_STRING));
|
|
91 gaim_cipher_context_digest(context, 16, digest, NULL);
|
|
92 gaim_cipher_context_destroy(context);
|
|
93
|
|
94 return 0;
|
|
95 }
|
|
96 #else
|
|
97 static int aim_encode_password_md5(const char *password, const char *key, guint8 *digest)
|
|
98 {
|
|
99 GaimCipher *cipher;
|
|
100 GaimCipherContext *context;
|
|
101 guchar passdigest[16];
|
|
102
|
|
103 cipher = gaim_ciphers_find_cipher("md5");
|
|
104
|
|
105 context = gaim_cipher_context_new(cipher, NULL);
|
|
106 gaim_cipher_context_append(context, (const guchar *)password, strlen(password));
|
|
107 gaim_cipher_context_digest(context, 16, passdigest, NULL);
|
|
108 gaim_cipher_context_destroy(context);
|
|
109
|
|
110 context = gaim_cipher_context_new(cipher, NULL);
|
|
111 gaim_cipher_context_append(context, (const guchar *)key, strlen(key));
|
|
112 gaim_cipher_context_append(context, passdigest, 16);
|
|
113 gaim_cipher_context_append(context, (const guchar *)AIM_MD5_STRING, strlen(AIM_MD5_STRING));
|
|
114 gaim_cipher_context_digest(context, 16, digest, NULL);
|
|
115 gaim_cipher_context_destroy(context);
|
|
116
|
|
117 return 0;
|
|
118 }
|
|
119 #endif
|
|
120
|
|
121 /*
|
|
122 * The FLAP version is sent by itself at the beginning of authorization
|
|
123 * connections. The FLAP version is also sent before the cookie when connecting
|
|
124 * for other services (BOS, chatnav, chat, etc.).
|
|
125 */
|
13239
|
126 faim_export int aim_sendflapver(OscarSession *sess, OscarConnection *conn)
|
13234
|
127 {
|
13239
|
128 FlapFrame *fr;
|
13234
|
129
|
13253
|
130 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 4)))
|
13234
|
131 return -ENOMEM;
|
|
132
|
|
133 aimbs_put32(&fr->data, 0x00000001);
|
|
134
|
|
135 aim_tx_enqueue(sess, fr);
|
|
136
|
|
137 return 0;
|
|
138 }
|
|
139
|
|
140 /*
|
|
141 * This just pushes the passed cookie onto the passed connection, without
|
|
142 * the SNAC header or any of that.
|
|
143 *
|
|
144 * Very commonly used, as every connection except auth will require this to
|
|
145 * be the first thing you send.
|
|
146 *
|
|
147 */
|
13239
|
148 faim_export int aim_sendcookie(OscarSession *sess, OscarConnection *conn, const guint16 length, const guint8 *chipsahoy)
|
13234
|
149 {
|
13239
|
150 FlapFrame *fr;
|
13234
|
151 aim_tlvlist_t *tl = NULL;
|
|
152
|
13253
|
153 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 4+2+2+length)))
|
13234
|
154 return -ENOMEM;
|
|
155
|
|
156 aimbs_put32(&fr->data, 0x00000001);
|
|
157 aim_tlvlist_add_raw(&tl, 0x0006, length, chipsahoy);
|
|
158 aim_tlvlist_write(&fr->data, &tl);
|
|
159 aim_tlvlist_free(&tl);
|
|
160
|
|
161 aim_tx_enqueue(sess, fr);
|
|
162
|
|
163 return 0;
|
|
164 }
|
|
165
|
|
166 #ifdef USE_XOR_FOR_ICQ
|
|
167 /*
|
|
168 * Part two of the ICQ hack. Note the ignoring of the key.
|
|
169 */
|
13239
|
170 static int goddamnicq2(OscarSession *sess, OscarConnection *conn, const char *sn, const char *password, ClientInfo *ci)
|
13234
|
171 {
|
13239
|
172 FlapFrame *fr;
|
13234
|
173 aim_tlvlist_t *tl = NULL;
|
|
174 int passwdlen;
|
|
175 guint8 *password_encoded;
|
|
176
|
|
177 passwdlen = strlen(password);
|
|
178 if (!(password_encoded = (guint8 *)malloc(passwdlen+1)))
|
|
179 return -ENOMEM;
|
|
180 if (passwdlen > MAXICQPASSLEN)
|
|
181 passwdlen = MAXICQPASSLEN;
|
|
182
|
13253
|
183 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 1152))) {
|
13234
|
184 free(password_encoded);
|
|
185 return -ENOMEM;
|
|
186 }
|
|
187
|
|
188 aim_encode_password(password, password_encoded);
|
|
189
|
|
190 aimbs_put32(&fr->data, 0x00000001); /* FLAP Version */
|
|
191 aim_tlvlist_add_str(&tl, 0x0001, sn);
|
|
192 aim_tlvlist_add_raw(&tl, 0x0002, passwdlen, password_encoded);
|
|
193
|
|
194 if (ci->clientstring)
|
|
195 aim_tlvlist_add_str(&tl, 0x0003, ci->clientstring);
|
|
196 aim_tlvlist_add_16(&tl, 0x0016, (guint16)ci->clientid);
|
|
197 aim_tlvlist_add_16(&tl, 0x0017, (guint16)ci->major);
|
|
198 aim_tlvlist_add_16(&tl, 0x0018, (guint16)ci->minor);
|
|
199 aim_tlvlist_add_16(&tl, 0x0019, (guint16)ci->point);
|
|
200 aim_tlvlist_add_16(&tl, 0x001a, (guint16)ci->build);
|
|
201 aim_tlvlist_add_32(&tl, 0x0014, (guint32)ci->distrib); /* distribution chan */
|
|
202 aim_tlvlist_add_str(&tl, 0x000f, ci->lang);
|
|
203 aim_tlvlist_add_str(&tl, 0x000e, ci->country);
|
|
204
|
|
205 aim_tlvlist_write(&fr->data, &tl);
|
|
206
|
|
207 free(password_encoded);
|
|
208 aim_tlvlist_free(&tl);
|
|
209
|
|
210 aim_tx_enqueue(sess, fr);
|
|
211
|
|
212 return 0;
|
|
213 }
|
|
214 #endif
|
|
215
|
|
216 /*
|
|
217 * Subtype 0x0002
|
|
218 *
|
|
219 * This is the initial login request packet.
|
|
220 *
|
|
221 * NOTE!! If you want/need to make use of the aim_sendmemblock() function,
|
|
222 * then the client information you send here must exactly match the
|
|
223 * executable that you're pulling the data from.
|
|
224 *
|
|
225 * Java AIM 1.1.19:
|
|
226 * clientstring = "AOL Instant Messenger (TM) version 1.1.19 for Java built 03/24/98, freeMem 215871 totalMem 1048567, i686, Linus, #2 SMP Sun Feb 11 03:41:17 UTC 2001 2.4.1-ac9, IBM Corporation, 1.1.8, 45.3, Tue Mar 27 12:09:17 PST 2001"
|
|
227 * clientid = 0x0001
|
|
228 * major = 0x0001
|
|
229 * minor = 0x0001
|
|
230 * point = (not sent)
|
|
231 * build = 0x0013
|
|
232 * unknown= (not sent)
|
13239
|
233 *
|
13234
|
234 * AIM for Linux 1.1.112:
|
|
235 * clientstring = "AOL Instant Messenger (SM)"
|
|
236 * clientid = 0x1d09
|
|
237 * major = 0x0001
|
|
238 * minor = 0x0001
|
|
239 * point = 0x0001
|
|
240 * build = 0x0070
|
|
241 * unknown= 0x0000008b
|
|
242 * serverstore = 0x01
|
|
243 *
|
|
244 */
|
13239
|
245 faim_export int aim_send_login(OscarSession *sess, OscarConnection *conn, const char *sn, const char *password, ClientInfo *ci, const char *key)
|
13234
|
246 {
|
13239
|
247 FlapFrame *fr;
|
13234
|
248 aim_tlvlist_t *tl = NULL;
|
|
249 guint8 digest[16];
|
|
250 aim_snacid_t snacid;
|
|
251
|
|
252 if (!ci || !sn || !password)
|
|
253 return -EINVAL;
|
|
254
|
|
255 #ifdef USE_XOR_FOR_ICQ
|
|
256 /* If we're signing on an ICQ account then use the older, XOR login method */
|
|
257 if (isdigit(sn[0]))
|
|
258 return goddamnicq2(sess, conn, sn, password, ci);
|
|
259 #endif
|
|
260
|
13253
|
261 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
|
13234
|
262 return -ENOMEM;
|
|
263
|
|
264 snacid = aim_cachesnac(sess, 0x0017, 0x0002, 0x0000, NULL, 0);
|
|
265 aim_putsnac(&fr->data, 0x0017, 0x0002, 0x0000, snacid);
|
|
266
|
|
267 aim_tlvlist_add_str(&tl, 0x0001, sn);
|
|
268
|
|
269 /* Truncate ICQ passwords, if necessary */
|
|
270 if (isdigit(sn[0]) && (strlen(password) > MAXICQPASSLEN))
|
|
271 {
|
|
272 char truncated[MAXICQPASSLEN + 1];
|
|
273 strncpy(truncated, password, MAXICQPASSLEN);
|
|
274 truncated[MAXICQPASSLEN] = 0;
|
|
275 aim_encode_password_md5(truncated, key, digest);
|
|
276 }
|
|
277 else
|
|
278 {
|
|
279 aim_encode_password_md5(password, key, digest);
|
|
280 }
|
|
281
|
|
282 aim_tlvlist_add_raw(&tl, 0x0025, 16, digest);
|
|
283
|
|
284 #ifndef USE_OLD_MD5
|
|
285 aim_tlvlist_add_noval(&tl, 0x004c);
|
|
286 #endif
|
|
287
|
|
288 if (ci->clientstring)
|
|
289 aim_tlvlist_add_str(&tl, 0x0003, ci->clientstring);
|
|
290 aim_tlvlist_add_16(&tl, 0x0016, (guint16)ci->clientid);
|
|
291 aim_tlvlist_add_16(&tl, 0x0017, (guint16)ci->major);
|
|
292 aim_tlvlist_add_16(&tl, 0x0018, (guint16)ci->minor);
|
|
293 aim_tlvlist_add_16(&tl, 0x0019, (guint16)ci->point);
|
|
294 aim_tlvlist_add_16(&tl, 0x001a, (guint16)ci->build);
|
|
295 aim_tlvlist_add_32(&tl, 0x0014, (guint32)ci->distrib);
|
|
296 aim_tlvlist_add_str(&tl, 0x000f, ci->lang);
|
|
297 aim_tlvlist_add_str(&tl, 0x000e, ci->country);
|
|
298
|
|
299 /*
|
|
300 * If set, old-fashioned buddy lists will not work. You will need
|
|
301 * to use SSI.
|
|
302 */
|
|
303 aim_tlvlist_add_8(&tl, 0x004a, 0x01);
|
|
304
|
|
305 aim_tlvlist_write(&fr->data, &tl);
|
|
306
|
|
307 aim_tlvlist_free(&tl);
|
|
308
|
|
309 aim_tx_enqueue(sess, fr);
|
|
310
|
|
311 return 0;
|
|
312 }
|
|
313
|
|
314 /*
|
|
315 * This is sent back as a general response to the login command.
|
|
316 * It can be either an error or a success, depending on the
|
|
317 * presence of certain TLVs.
|
|
318 *
|
|
319 * The client should check the value passed as errorcode. If
|
|
320 * its nonzero, there was an error.
|
|
321 */
|
13239
|
322 static int parse(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
323 {
|
|
324 aim_tlvlist_t *tlvlist;
|
|
325 aim_rxcallback_t userfunc;
|
|
326 struct aim_authresp_info *info;
|
|
327 int ret = 0;
|
|
328
|
|
329 info = (struct aim_authresp_info *)malloc(sizeof(struct aim_authresp_info));
|
|
330 memset(info, 0, sizeof(struct aim_authresp_info));
|
|
331
|
|
332 /*
|
|
333 * Read block of TLVs. All further data is derived
|
|
334 * from what is parsed here.
|
|
335 */
|
|
336 tlvlist = aim_tlvlist_read(bs);
|
|
337
|
|
338 /*
|
|
339 * No matter what, we should have a screen name.
|
|
340 */
|
|
341 memset(sess->sn, 0, sizeof(sess->sn));
|
|
342 if (aim_tlv_gettlv(tlvlist, 0x0001, 1)) {
|
|
343 info->sn = aim_tlv_getstr(tlvlist, 0x0001, 1);
|
|
344 strncpy(sess->sn, info->sn, sizeof(sess->sn));
|
|
345 }
|
|
346
|
|
347 /*
|
|
348 * Check for an error code. If so, we should also
|
|
349 * have an error url.
|
|
350 */
|
|
351 if (aim_tlv_gettlv(tlvlist, 0x0008, 1))
|
|
352 info->errorcode = aim_tlv_get16(tlvlist, 0x0008, 1);
|
|
353 if (aim_tlv_gettlv(tlvlist, 0x0004, 1))
|
|
354 info->errorurl = aim_tlv_getstr(tlvlist, 0x0004, 1);
|
|
355
|
|
356 /*
|
|
357 * BOS server address.
|
|
358 */
|
|
359 if (aim_tlv_gettlv(tlvlist, 0x0005, 1))
|
|
360 info->bosip = aim_tlv_getstr(tlvlist, 0x0005, 1);
|
|
361
|
|
362 /*
|
|
363 * Authorization cookie.
|
|
364 */
|
|
365 if (aim_tlv_gettlv(tlvlist, 0x0006, 1)) {
|
|
366 aim_tlv_t *tmptlv;
|
|
367
|
|
368 tmptlv = aim_tlv_gettlv(tlvlist, 0x0006, 1);
|
|
369
|
|
370 info->cookielen = tmptlv->length;
|
|
371 info->cookie = tmptlv->value;
|
|
372 }
|
|
373
|
|
374 /*
|
|
375 * The email address attached to this account
|
|
376 * Not available for ICQ or @mac.com logins.
|
|
377 * If you receive this TLV, then you are allowed to use
|
|
378 * family 0x0018 to check the status of your email.
|
|
379 * XXX - Not really true!
|
|
380 */
|
|
381 if (aim_tlv_gettlv(tlvlist, 0x0011, 1))
|
|
382 info->email = aim_tlv_getstr(tlvlist, 0x0011, 1);
|
|
383
|
|
384 /*
|
|
385 * The registration status. (Not real sure what it means.)
|
|
386 * Not available for ICQ or @mac.com logins.
|
|
387 *
|
|
388 * 1 = No disclosure
|
|
389 * 2 = Limited disclosure
|
|
390 * 3 = Full disclosure
|
|
391 *
|
|
392 * This has to do with whether your email address is available
|
|
393 * to other users or not. AFAIK, this feature is no longer used.
|
|
394 *
|
|
395 * Means you can use the admin family? (0x0007)
|
|
396 *
|
|
397 */
|
|
398 if (aim_tlv_gettlv(tlvlist, 0x0013, 1))
|
|
399 info->regstatus = aim_tlv_get16(tlvlist, 0x0013, 1);
|
|
400
|
|
401 if (aim_tlv_gettlv(tlvlist, 0x0040, 1))
|
|
402 info->latestbeta.build = aim_tlv_get32(tlvlist, 0x0040, 1);
|
|
403 if (aim_tlv_gettlv(tlvlist, 0x0041, 1))
|
|
404 info->latestbeta.url = aim_tlv_getstr(tlvlist, 0x0041, 1);
|
|
405 if (aim_tlv_gettlv(tlvlist, 0x0042, 1))
|
|
406 info->latestbeta.info = aim_tlv_getstr(tlvlist, 0x0042, 1);
|
|
407 if (aim_tlv_gettlv(tlvlist, 0x0043, 1))
|
|
408 info->latestbeta.name = aim_tlv_getstr(tlvlist, 0x0043, 1);
|
|
409
|
|
410 #if 0
|
|
411 if (aim_tlv_gettlv(tlvlist, 0x0048, 1)) {
|
|
412 /* beta serial */
|
|
413 }
|
|
414 #endif
|
|
415
|
|
416 if (aim_tlv_gettlv(tlvlist, 0x0044, 1))
|
|
417 info->latestrelease.build = aim_tlv_get32(tlvlist, 0x0044, 1);
|
|
418 if (aim_tlv_gettlv(tlvlist, 0x0045, 1))
|
|
419 info->latestrelease.url = aim_tlv_getstr(tlvlist, 0x0045, 1);
|
|
420 if (aim_tlv_gettlv(tlvlist, 0x0046, 1))
|
|
421 info->latestrelease.info = aim_tlv_getstr(tlvlist, 0x0046, 1);
|
|
422 if (aim_tlv_gettlv(tlvlist, 0x0047, 1))
|
|
423 info->latestrelease.name = aim_tlv_getstr(tlvlist, 0x0047, 1);
|
|
424
|
|
425 #if 0
|
|
426 if (aim_tlv_gettlv(tlvlist, 0x0049, 1)) {
|
|
427 /* lastest release serial */
|
|
428 }
|
|
429 #endif
|
|
430
|
|
431 /*
|
|
432 * URL to change password.
|
|
433 */
|
|
434 if (aim_tlv_gettlv(tlvlist, 0x0054, 1))
|
|
435 info->chpassurl = aim_tlv_getstr(tlvlist, 0x0054, 1);
|
|
436
|
|
437 #if 0
|
|
438 /*
|
|
439 * Unknown. Seen on an @mac.com screen name with value of 0x003f
|
|
440 */
|
|
441 if (aim_tlv_gettlv(tlvlist, 0x0055, 1)) {
|
|
442 /* Unhandled */
|
|
443 }
|
|
444 #endif
|
|
445
|
|
446 sess->authinfo = info;
|
|
447
|
|
448 if ((userfunc = aim_callhandler(sess, rx->conn, snac ? snac->family : 0x0017, snac ? snac->subtype : 0x0003)))
|
|
449 ret = userfunc(sess, rx, info);
|
|
450
|
|
451 aim_tlvlist_free(&tlvlist);
|
|
452
|
|
453 return ret;
|
|
454 }
|
|
455
|
|
456 #ifdef USE_XOR_FOR_ICQ
|
|
457 /*
|
|
458 * Subtype 0x0007 (kind of) - Send a fake type 0x0007 SNAC to the client
|
|
459 *
|
|
460 * This is a bit confusing.
|
|
461 *
|
|
462 * Normal SNAC login goes like this:
|
|
463 * - connect
|
|
464 * - server sends flap version
|
|
465 * - client sends flap version
|
|
466 * - client sends screen name (17/6)
|
|
467 * - server sends hash key (17/7)
|
|
468 * - client sends auth request (17/2 -- aim_send_login)
|
|
469 * - server yells
|
|
470 *
|
|
471 * XOR login (for ICQ) goes like this:
|
|
472 * - connect
|
|
473 * - server sends flap version
|
|
474 * - client sends auth request which contains flap version (aim_send_login)
|
|
475 * - server yells
|
|
476 *
|
|
477 * For the client API, we make them implement the most complicated version,
|
|
478 * and for the simpler version, we fake it and make it look like the more
|
|
479 * complicated process.
|
|
480 *
|
|
481 * This is done by giving the client a faked key, just so we can convince
|
|
482 * them to call aim_send_login right away, which will detect the session
|
|
483 * flag that says this is XOR login and ignore the key, sending an ICQ
|
|
484 * login request instead of the normal SNAC one.
|
|
485 *
|
|
486 * As soon as AOL makes ICQ log in the same way as AIM, this is /gone/.
|
|
487 *
|
|
488 * XXX This may cause problems if the client relies on callbacks only
|
|
489 * being called from the context of aim_rxdispatch()...
|
|
490 *
|
|
491 */
|
13239
|
492 static int goddamnicq(OscarSession *sess, OscarConnection *conn, const char *sn)
|
13234
|
493 {
|
13239
|
494 FlapFrame fr;
|
13234
|
495 aim_rxcallback_t userfunc;
|
|
496
|
|
497 fr.conn = conn;
|
|
498
|
|
499 if ((userfunc = aim_callhandler(sess, conn, 0x0017, 0x0007)))
|
|
500 userfunc(sess, &fr, "");
|
|
501
|
|
502 return 0;
|
|
503 }
|
|
504 #endif
|
|
505
|
|
506 /*
|
|
507 * Subtype 0x0006
|
|
508 *
|
|
509 * In AIM 3.5 protocol, the first stage of login is to request login from the
|
|
510 * Authorizer, passing it the screen name for verification. If the name is
|
|
511 * invalid, a 0017/0003 is spit back, with the standard error contents. If
|
|
512 * valid, a 0017/0007 comes back, which is the signal to send it the main
|
|
513 * login command (0017/0002).
|
|
514 *
|
|
515 */
|
13239
|
516 faim_export int aim_request_login(OscarSession *sess, OscarConnection *conn, const char *sn)
|
13234
|
517 {
|
13239
|
518 FlapFrame *fr;
|
13234
|
519 aim_snacid_t snacid;
|
|
520 aim_tlvlist_t *tl = NULL;
|
|
521
|
|
522 if (!sess || !conn || !sn)
|
|
523 return -EINVAL;
|
|
524
|
|
525 #ifdef USE_XOR_FOR_ICQ
|
|
526 if (isdigit(sn[0]))
|
|
527 return goddamnicq(sess, conn, sn);
|
|
528 #endif
|
|
529
|
|
530 aim_sendflapver(sess, conn);
|
|
531
|
13253
|
532 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(sn)+8 )))
|
13234
|
533 return -ENOMEM;
|
|
534
|
|
535 snacid = aim_cachesnac(sess, 0x0017, 0x0006, 0x0000, NULL, 0);
|
|
536 aim_putsnac(&fr->data, 0x0017, 0x0006, 0x0000, snacid);
|
|
537
|
|
538 aim_tlvlist_add_str(&tl, 0x0001, sn);
|
|
539
|
|
540 /* Tell the server we support SecurID logins. */
|
|
541 aim_tlvlist_add_noval(&tl, 0x004b);
|
|
542
|
|
543 /* Unknown. Sent in recent WinAIM clients.*/
|
|
544 aim_tlvlist_add_noval(&tl, 0x005a);
|
|
545
|
|
546 aim_tlvlist_write(&fr->data, &tl);
|
|
547 aim_tlvlist_free(&tl);
|
|
548
|
|
549 aim_tx_enqueue(sess, fr);
|
|
550
|
|
551 return 0;
|
|
552 }
|
|
553
|
|
554 /*
|
|
555 * Subtype 0x0007
|
|
556 *
|
|
557 * Middle handler for 0017/0007 SNACs. Contains the auth key prefixed
|
|
558 * by only its length in a two byte word.
|
|
559 *
|
|
560 * Calls the client, which should then use the value to call aim_send_login.
|
|
561 *
|
|
562 */
|
13239
|
563 static int keyparse(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
564 {
|
|
565 int keylen, ret = 1;
|
|
566 aim_rxcallback_t userfunc;
|
|
567 char *keystr;
|
|
568
|
|
569 keylen = aimbs_get16(bs);
|
|
570 keystr = aimbs_getstr(bs, keylen);
|
|
571
|
|
572 /* XXX - When GiantGrayPanda signed on AIM I got a thing asking me to register
|
|
573 * for the netscape network. This SNAC had a type 0x0058 TLV with length 10.
|
|
574 * Data is 0x0007 0004 3e19 ae1e 0006 0004 0000 0005 */
|
|
575
|
|
576 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
577 ret = userfunc(sess, rx, keystr);
|
|
578
|
|
579 free(keystr);
|
|
580
|
|
581 return ret;
|
|
582 }
|
|
583
|
|
584 /**
|
|
585 * Subtype 0x000a
|
|
586 *
|
|
587 * Receive SecurID request.
|
|
588 */
|
13239
|
589 static int got_securid_request(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
590 {
|
|
591 int ret = 0;
|
|
592 aim_rxcallback_t userfunc;
|
|
593
|
|
594 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
595 ret = userfunc(sess, rx);
|
|
596
|
|
597 return ret;
|
|
598 }
|
|
599
|
|
600 /**
|
|
601 * Subtype 0x000b
|
|
602 *
|
|
603 * Send SecurID response.
|
|
604 */
|
13239
|
605 faim_export int aim_auth_securid_send(OscarSession *sess, const char *securid)
|
13234
|
606 {
|
13239
|
607 OscarConnection *conn;
|
|
608 FlapFrame *fr;
|
13234
|
609 aim_snacid_t snacid;
|
|
610 int len;
|
|
611
|
|
612 if (!sess || !(conn = aim_getconn_type_all(sess, AIM_CONN_TYPE_AUTH)) || !securid)
|
|
613 return -EINVAL;
|
|
614
|
|
615 len = strlen(securid);
|
|
616
|
13253
|
617 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+len)))
|
13234
|
618 return -ENOMEM;
|
|
619
|
|
620 snacid = aim_cachesnac(sess, OSCAR_FAMILY_AUTH, OSCAR_SUBTYPE_AUTH_SECURID_RESPONSE, 0x0000, NULL, 0);
|
|
621 aim_putsnac(&fr->data, OSCAR_FAMILY_AUTH, OSCAR_SUBTYPE_AUTH_SECURID_RESPONSE, 0x0000, 0);
|
|
622
|
|
623 aimbs_put16(&fr->data, len);
|
|
624 aimbs_putstr(&fr->data, securid);
|
|
625
|
|
626 aim_tx_enqueue(sess, fr);
|
|
627
|
|
628 return 0;
|
|
629 }
|
|
630
|
13239
|
631 static void auth_shutdown(OscarSession *sess, aim_module_t *mod)
|
13234
|
632 {
|
|
633 if (sess->authinfo) {
|
|
634 free(sess->authinfo->sn);
|
|
635 free(sess->authinfo->bosip);
|
|
636 free(sess->authinfo->errorurl);
|
|
637 free(sess->authinfo->email);
|
|
638 free(sess->authinfo->chpassurl);
|
|
639 free(sess->authinfo->latestrelease.name);
|
|
640 free(sess->authinfo->latestrelease.url);
|
|
641 free(sess->authinfo->latestrelease.info);
|
|
642 free(sess->authinfo->latestbeta.name);
|
|
643 free(sess->authinfo->latestbeta.url);
|
|
644 free(sess->authinfo->latestbeta.info);
|
|
645 free(sess->authinfo);
|
|
646 }
|
|
647 }
|
|
648
|
13239
|
649 static int snachandler(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
650 {
|
|
651
|
|
652 if (snac->subtype == 0x0003)
|
|
653 return parse(sess, mod, rx, snac, bs);
|
|
654 else if (snac->subtype == 0x0007)
|
|
655 return keyparse(sess, mod, rx, snac, bs);
|
|
656 else if (snac->subtype == 0x000a)
|
|
657 return got_securid_request(sess, mod, rx, snac, bs);
|
|
658
|
|
659 return 0;
|
|
660 }
|
|
661
|
13239
|
662 faim_internal int auth_modfirst(OscarSession *sess, aim_module_t *mod)
|
13234
|
663 {
|
|
664
|
|
665 mod->family = 0x0017;
|
|
666 mod->version = 0x0000;
|
|
667 mod->flags = 0;
|
|
668 strncpy(mod->name, "auth", sizeof(mod->name));
|
|
669 mod->snachandler = snachandler;
|
|
670 mod->shutdown = auth_shutdown;
|
|
671
|
|
672 return 0;
|
|
673 }
|