mirror of
https://github.com/siemens-mobile-hacks/naticq_server.git
synced 2026-11-25 18:27:17 +00:00
Plain-text auth support for IServerd ICQ-servers (#2)
This commit is contained in:
parent
591001fb6f
commit
799868a096
4 changed files with 88 additions and 21 deletions
4
flap.h
4
flap.h
|
|
@ -23,7 +23,9 @@
|
|||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
#include "common.h"
|
||||
|
||||
using namespace std;
|
||||
|
|
|
|||
75
icqkid2.cpp
75
icqkid2.cpp
|
|
@ -115,7 +115,7 @@ ICQKid2::ICQKid2(void)
|
|||
: sock(-1), flap_seq_number(1), snac_seq_number(1), network_timeout(-1), \
|
||||
network_break_flag(false), connect_phase_percentage(0), \
|
||||
icons_service(NULL), online_status(STATUS_OFFLINE), xStatus(X_STATUS_NONE), \
|
||||
myPrivSrvStatus(PRIV_ALL_CAN_SEE), myPrivSrvStatus_item_id(0)
|
||||
myPrivSrvStatus(PRIV_ALL_CAN_SEE), myPrivSrvStatus_item_id(0), plain_text_auth(false)
|
||||
{
|
||||
snac_cache = new SnacCache;
|
||||
setProxy();
|
||||
|
|
@ -171,21 +171,26 @@ bool ICQKid2::doConnect(uint32_t astat)
|
|||
if (sock<0) return false; //0
|
||||
connect_phase_percentage += 2;
|
||||
|
||||
if (!waitHello()) { CLOSE_SOCK(sock); return false; } //2
|
||||
connect_phase_percentage += 2;
|
||||
|
||||
if (!sendSignOn0()) { CLOSE_SOCK(sock); return false; } //4
|
||||
connect_phase_percentage += 2; //8; //2;
|
||||
|
||||
if (!sendMD5saltrequest(&snac_sync)) { CLOSE_SOCK(sock); return false; } //6
|
||||
connect_phase_percentage += 2;
|
||||
|
||||
if (!getMD5salt(snac_sync, md5_salt)) { CLOSE_SOCK(sock); return false; } //8
|
||||
connect_phase_percentage += 2;
|
||||
|
||||
if (!sendMD5authorize(&snac_sync, md5_salt)) { CLOSE_SOCK(sock); return false; } //10
|
||||
connect_phase_percentage += 2;
|
||||
|
||||
if (plain_text_auth) {
|
||||
if (!waitHello()) { CLOSE_SOCK(sock); return false; } //2
|
||||
connect_phase_percentage += 2;
|
||||
|
||||
if (!sendPlainTextAuth(&snac_sync)) { CLOSE_SOCK(sock); return false; } //6
|
||||
connect_phase_percentage += 2;
|
||||
} else {
|
||||
if (!sendSignOn0()) { CLOSE_SOCK(sock); return false; } //4
|
||||
connect_phase_percentage += 2; //8; //2;
|
||||
|
||||
if (!sendMD5saltrequest(&snac_sync)) { CLOSE_SOCK(sock); return false; } //6
|
||||
connect_phase_percentage += 2;
|
||||
|
||||
if (!getMD5salt(snac_sync, md5_salt)) { CLOSE_SOCK(sock); return false; } //8
|
||||
connect_phase_percentage += 2;
|
||||
|
||||
if (!sendMD5authorize(&snac_sync, md5_salt)) { CLOSE_SOCK(sock); return false; } //10
|
||||
connect_phase_percentage += 2;
|
||||
}
|
||||
|
||||
if (!getBOSSparams(boss_host, boss_port, boss_cookie)) { CLOSE_SOCK(sock); return false; } //12
|
||||
connect_phase_percentage += 2;
|
||||
|
||||
|
|
@ -2827,6 +2832,34 @@ bool ICQKid2::sendSignOn0(void)
|
|||
return fp.send_to(sock);
|
||||
}
|
||||
|
||||
bool ICQKid2::sendPlainTextAuth(uint32_t * snac_sync)
|
||||
{
|
||||
FlapPacket fp;
|
||||
fp.frame_type=FT_SIGNON;
|
||||
fp.seq_number=flap_seq_number++;
|
||||
fp.payload.resize(4);
|
||||
fp.payload[3]=1;
|
||||
|
||||
string enc_password = mypassword;
|
||||
|
||||
static const uint8_t enc_key[] = {0xF3, 0x26, 0x81, 0xC4, 0x39, 0x86, 0xDB, 0x92, 0x71, 0xA3, 0xB9, 0xE6, 0x53, 0x7A, 0x95, 0x7C};
|
||||
for (int i = 0; i < enc_password.size(); i++) {
|
||||
enc_password[i] = enc_password[i] ^ enc_key[i % 16];
|
||||
}
|
||||
|
||||
TLVPack tlv_pack;
|
||||
tlv_pack.data.push_back(TLVField(myuin, TLV_UID));
|
||||
tlv_pack.data.push_back(TLVField(enc_password, TLV_PWD));
|
||||
vector<uint8_t> data_vec;
|
||||
tlv_pack.encode_to(data_vec);
|
||||
|
||||
for (int i = 0; i < data_vec.size(); i++) {
|
||||
fp.payload.push_back(data_vec[i]);
|
||||
}
|
||||
|
||||
return fp.send_to(sock);
|
||||
}
|
||||
|
||||
// ----------------=========ooooOOOOOOOOOoooo=========----------------
|
||||
bool ICQKid2::sendMD5saltrequest(uint32_t * snac_sync)
|
||||
{
|
||||
|
|
@ -2925,11 +2958,15 @@ bool ICQKid2::getBOSSparams(string & boss_host, int & boss_port, vector<uint8_t>
|
|||
}
|
||||
while(--t);
|
||||
if (!t) return false;
|
||||
if (fp.frame_type!=FT_DATA) return false;
|
||||
if (fp.frame_type!=FT_DATA && !plain_text_auth) return false;
|
||||
SNACData snd;
|
||||
if (!snd.decode_from(fp.payload)) return false;
|
||||
TLVPack tlv_pack;
|
||||
if (!tlv_pack.decode_from(snd.data)) return false;
|
||||
if (plain_text_auth) {
|
||||
if (!tlv_pack.decode_from(fp.payload)) return false;
|
||||
} else {
|
||||
if (!snd.decode_from(fp.payload)) return false;
|
||||
if (!tlv_pack.decode_from(snd.data)) return false;
|
||||
}
|
||||
TLVField * err_tlv = tlv_pack.findTLV(0x0008);
|
||||
if (err_tlv!=NULL) // Packet contains error code
|
||||
{
|
||||
|
|
|
|||
|
|
@ -250,6 +250,7 @@ class SNACData;
|
|||
class ICQKid2{
|
||||
public:
|
||||
string mypassword;
|
||||
bool plain_text_auth;
|
||||
virtual void getMD5hash(vector<uint8_t> md5_salt, uint8_t * md5_hash);
|
||||
typedef enum
|
||||
{
|
||||
|
|
@ -265,6 +266,9 @@ class ICQKid2{
|
|||
void setUIN(string auin) { myuin=auin; }
|
||||
void setPassword(string apwd) { mypassword=apwd; }
|
||||
void setLoginHost(string ahost="login.icq.com", int aport=5190) { loginhost=ahost; loginport=aport; }
|
||||
void setPlainTextAuth(bool flag) {
|
||||
plain_text_auth = flag;
|
||||
}
|
||||
void setProxy(string ahost="", int aport=0, string auid="", string apwd="", ProxyType apr_type=NONE)
|
||||
{
|
||||
proxy_host=ahost;
|
||||
|
|
@ -490,6 +494,7 @@ class ICQKid2{
|
|||
|
||||
bool waitHello(void);
|
||||
bool sendSignOn0(void);
|
||||
bool sendPlainTextAuth(uint32_t * snac_sync);
|
||||
bool sendMD5saltrequest(uint32_t * snac_sync);
|
||||
bool getMD5salt(uint32_t snac_sync, vector<uint8_t> & md5_salt);
|
||||
bool sendMD5authorize(uint32_t * snac_sync, vector<uint8_t> & md5_salt);
|
||||
|
|
|
|||
|
|
@ -997,6 +997,19 @@ void *ServerThread(void *tParam)
|
|||
|
||||
time_t naticq_timeout;
|
||||
MyIcqInterface miif;
|
||||
|
||||
bool use_plain_text = false;
|
||||
if (getenv("ICQ_PLAIN_TEXT")) {
|
||||
use_plain_text = strcmp(getenv("ICQ_PLAIN_TEXT"), "1") == 0;
|
||||
}
|
||||
|
||||
if (getenv("ICQ_SERVER")) {
|
||||
const char *server = getenv("ICQ_SERVER");
|
||||
int port = atoi(getenv("ICQ_SERVER_PORT") ?: "5190");
|
||||
DPRINTF("Using server %s:%d\n", server, port);
|
||||
miif.setLoginHost(server, port);
|
||||
}
|
||||
|
||||
miif.naticq_sock=s;
|
||||
miif.subIGId=__SVN_REVISION__;
|
||||
NatICQ_PKT rpkt;
|
||||
|
|
@ -1021,12 +1034,22 @@ void *ServerThread(void *tParam)
|
|||
rpkt.data[rpkt.len]=0;
|
||||
miif.setPassword(rpkt.data);
|
||||
miif.md5auth=false;
|
||||
miif.setPlainTextAuth(use_plain_text);
|
||||
/*
|
||||
strcpy(rpkt.data,"Download new version!");
|
||||
rpkt.len=strlen(rpkt.data);
|
||||
rpkt.type=T_ERROR;
|
||||
miif.NatICQTX(&rpkt);
|
||||
*/
|
||||
}else{
|
||||
miif.md5auth=true;
|
||||
miif.md5auth=true;
|
||||
if (use_plain_text) {
|
||||
strcpy(rpkt.data,"This server only supports plain-text auth! Download the right NatICQ version!");
|
||||
|
||||
rpkt.len=strlen(rpkt.data);
|
||||
rpkt.type=T_ERROR;
|
||||
miif.NatICQTX(&rpkt);
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(rpkt.data,"%u",rpkt.uin);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue