⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 family_auth.c

📁 Linux下的多协议即时通讯程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Purple's oscar protocol plugin * This file is the legal property of its developers. * Please see the AUTHORS file distributed alongside this file. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*//* * Family 0x0017 - Authentication. * * Deals with the authorizer for SNAC-based login, and also old-style * non-SNAC login. * */#include "oscar.h"#include "cipher.h"#include <ctype.h>#define USE_XOR_FOR_ICQ#ifdef USE_XOR_FOR_ICQ/** * Encode a password using old XOR method * * This takes a const pointer to a (null terminated) string * containing the unencoded password.  It also gets passed * an already allocated buffer to store the encoded password. * This buffer should be the exact length of the password without * the null.  The encoded password buffer /is not %NULL terminated/. * * The encoding_table seems to be a fixed set of values.  We'll * hope it doesn't change over time! * * This is only used for the XOR method, not the better MD5 method. * * @param password Incoming password. * @param encoded Buffer to put encoded password. */static intaim_encode_password(const char *password, guint8 *encoded){	guint8 encoding_table[] = {#if 0 /* old v1 table */		0xf3, 0xb3, 0x6c, 0x99,		0x95, 0x3f, 0xac, 0xb6,		0xc5, 0xfa, 0x6b, 0x63,		0x69, 0x6c, 0xc3, 0x9f#else /* v2.1 table, also works for ICQ */		0xf3, 0x26, 0x81, 0xc4,		0x39, 0x86, 0xdb, 0x92,		0x71, 0xa3, 0xb9, 0xe6,		0x53, 0x7a, 0x95, 0x7c#endif	};	unsigned int i;	for (i = 0; i < strlen(password); i++)		encoded[i] = (password[i] ^ encoding_table[i]);	return 0;}#endif#ifdef USE_OLD_MD5static intaim_encode_password_md5(const char *password, size_t password_len, const char *key, guint8 *digest){	PurpleCipher *cipher;	PurpleCipherContext *context;	cipher = purple_ciphers_find_cipher("md5");	context = purple_cipher_context_new(cipher, NULL);	purple_cipher_context_append(context, (const guchar *)key, strlen(key));	purple_cipher_context_append(context, (const guchar *)password, password_len);	purple_cipher_context_append(context, (const guchar *)AIM_MD5_STRING, strlen(AIM_MD5_STRING));	purple_cipher_context_digest(context, 16, digest, NULL);	purple_cipher_context_destroy(context);	return 0;}#elsestatic intaim_encode_password_md5(const char *password, size_t password_len, const char *key, guint8 *digest){	PurpleCipher *cipher;	PurpleCipherContext *context;	guchar passdigest[16];	cipher = purple_ciphers_find_cipher("md5");	context = purple_cipher_context_new(cipher, NULL);	purple_cipher_context_append(context, (const guchar *)password, password_len);	purple_cipher_context_digest(context, 16, passdigest, NULL);	purple_cipher_context_destroy(context);	context = purple_cipher_context_new(cipher, NULL);	purple_cipher_context_append(context, (const guchar *)key, strlen(key));	purple_cipher_context_append(context, passdigest, 16);	purple_cipher_context_append(context, (const guchar *)AIM_MD5_STRING, strlen(AIM_MD5_STRING));	purple_cipher_context_digest(context, 16, digest, NULL);	purple_cipher_context_destroy(context);	return 0;}#endif#ifdef USE_XOR_FOR_ICQ/* * Part two of the ICQ hack.  Note the ignoring of the key. */static intgoddamnicq2(OscarData *od, FlapConnection *conn, const char *sn, const char *password, ClientInfo *ci){	FlapFrame *frame;	GSList *tlvlist = NULL;	int passwdlen;	guint8 *password_encoded;	passwdlen = strlen(password);	password_encoded = (guint8 *)g_malloc(passwdlen+1);	if (passwdlen > MAXICQPASSLEN)		passwdlen = MAXICQPASSLEN;	frame = flap_frame_new(od, 0x01, 1152);	aim_encode_password(password, password_encoded);	byte_stream_put32(&frame->data, 0x00000001); /* FLAP Version */	aim_tlvlist_add_str(&tlvlist, 0x0001, sn);	aim_tlvlist_add_raw(&tlvlist, 0x0002, passwdlen, password_encoded);	if (ci->clientstring)		aim_tlvlist_add_str(&tlvlist, 0x0003, ci->clientstring);	aim_tlvlist_add_16(&tlvlist, 0x0016, (guint16)ci->clientid);	aim_tlvlist_add_16(&tlvlist, 0x0017, (guint16)ci->major);	aim_tlvlist_add_16(&tlvlist, 0x0018, (guint16)ci->minor);	aim_tlvlist_add_16(&tlvlist, 0x0019, (guint16)ci->point);	aim_tlvlist_add_16(&tlvlist, 0x001a, (guint16)ci->build);	aim_tlvlist_add_32(&tlvlist, 0x0014, (guint32)ci->distrib); /* distribution chan */	aim_tlvlist_add_str(&tlvlist, 0x000f, ci->lang);	aim_tlvlist_add_str(&tlvlist, 0x000e, ci->country);	aim_tlvlist_write(&frame->data, &tlvlist);	g_free(password_encoded);	aim_tlvlist_free(tlvlist);	flap_connection_send(conn, frame);	return 0;}#endif/* * Subtype 0x0002 * * This is the initial login request packet. * * NOTE!! If you want/need to make use of the aim_sendmemblock() function, * then the client information you send here must exactly match the * executable that you're pulling the data from. * * Java AIM 1.1.19: *   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" *   clientid = 0x0001 *   major  = 0x0001 *   minor  = 0x0001 *   point = (not sent) *   build  = 0x0013 *   unknown= (not sent) * * AIM for Linux 1.1.112: *   clientstring = "AOL Instant Messenger (SM)" *   clientid = 0x1d09 *   major  = 0x0001 *   minor  = 0x0001 *   point = 0x0001 *   build  = 0x0070 *   unknown= 0x0000008b *   serverstore = 0x01 * */intaim_send_login(OscarData *od, FlapConnection *conn, const char *sn, const char *password, gboolean truncate_pass, ClientInfo *ci, const char *key){	FlapFrame *frame;	GSList *tlvlist = NULL;	guint8 digest[16];	aim_snacid_t snacid;	size_t password_len;	if (!ci || !sn || !password)		return -EINVAL;#ifdef USE_XOR_FOR_ICQ	/* If we're signing on an ICQ account then use the older, XOR login method */	if (isdigit(sn[0]))		return goddamnicq2(od, conn, sn, password, ci);#endif	frame = flap_frame_new(od, 0x02, 1152);	snacid = aim_cachesnac(od, 0x0017, 0x0002, 0x0000, NULL, 0);	aim_putsnac(&frame->data, 0x0017, 0x0002, 0x0000, snacid);	aim_tlvlist_add_str(&tlvlist, 0x0001, sn);	/* Truncate ICQ and AOL passwords, if necessary */	password_len = strlen(password);	if (isdigit(sn[0]) && (password_len > MAXICQPASSLEN))		password_len = MAXICQPASSLEN;	else if (truncate_pass && password_len > 8)		password_len = 8;	aim_encode_password_md5(password, password_len, key, digest);	aim_tlvlist_add_raw(&tlvlist, 0x0025, 16, digest);#ifndef USE_OLD_MD5	aim_tlvlist_add_noval(&tlvlist, 0x004c);#endif	if (ci->clientstring)		aim_tlvlist_add_str(&tlvlist, 0x0003, ci->clientstring);	aim_tlvlist_add_16(&tlvlist, 0x0016, (guint16)ci->clientid);	aim_tlvlist_add_16(&tlvlist, 0x0017, (guint16)ci->major);	aim_tlvlist_add_16(&tlvlist, 0x0018, (guint16)ci->minor);	aim_tlvlist_add_16(&tlvlist, 0x0019, (guint16)ci->point);	aim_tlvlist_add_16(&tlvlist, 0x001a, (guint16)ci->build);	aim_tlvlist_add_32(&tlvlist, 0x0014, (guint32)ci->distrib);	aim_tlvlist_add_str(&tlvlist, 0x000f, ci->lang);	aim_tlvlist_add_str(&tlvlist, 0x000e, ci->country);	/*	 * If set, old-fashioned buddy lists will not work. You will need	 * to use SSI.	 */	aim_tlvlist_add_8(&tlvlist, 0x004a, 0x01);	aim_tlvlist_write(&frame->data, &tlvlist);	aim_tlvlist_free(tlvlist);	flap_connection_send(conn, frame);	return 0;}/* * This is sent back as a general response to the login command. * It can be either an error or a success, depending on the * presence of certain TLVs. * * The client should check the value passed as errorcode. If * its nonzero, there was an error. */static intparse(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs){	GSList *tlvlist;	aim_rxcallback_t userfunc;	struct aim_authresp_info *info;	int ret = 0;	info = g_new0(struct aim_authresp_info, 1);	/*	 * Read block of TLVs.  All further data is derived	 * from what is parsed here.	 */	tlvlist = aim_tlvlist_read(bs);	/*	 * No matter what, we should have a screen name.	 */	memset(od->sn, 0, sizeof(od->sn));	if (aim_tlv_gettlv(tlvlist, 0x0001, 1)) {		info->sn = aim_tlv_getstr(tlvlist, 0x0001, 1);		strncpy(od->sn, info->sn, sizeof(od->sn));	}	/*	 * Check for an error code.  If so, we should also	 * have an error url.	 */	if (aim_tlv_gettlv(tlvlist, 0x0008, 1))		info->errorcode = aim_tlv_get16(tlvlist, 0x0008, 1);	if (aim_tlv_gettlv(tlvlist, 0x0004, 1))		info->errorurl = aim_tlv_getstr(tlvlist, 0x0004, 1);	/*	 * BOS server address.	 */	if (aim_tlv_gettlv(tlvlist, 0x0005, 1))		info->bosip = aim_tlv_getstr(tlvlist, 0x0005, 1);	/*	 * Authorization cookie.	 */	if (aim_tlv_gettlv(tlvlist, 0x0006, 1)) {		aim_tlv_t *tmptlv;		tmptlv = aim_tlv_gettlv(tlvlist, 0x0006, 1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -