| Dimka leon |
05.09.2012 01:06 |
ICQ API генерация хэша пароля в md5
Сделал небольшие классы для авторизации через ICQ API в ICQ. За основу взял имитацию подключения ICQ 7.7 к серверу. Все запросы, отправляемые на https://api.login.icq.net/ расписаны в этой статье http://alexey-m.ru/category/icqapi/ 1 Этап запроса проходит нормально получаю challengeWord и realm. А 2 этап, где надо генерировать пароль не проходит удачно. Приходит ответ:
Код:
HTTP/1.1 200 OK
Date: Tue, 04 Sep 2012 21:12:04 GMT
Set-Cookie: JSESSIONID=990F1E879BF38680CEB577AA73B38A40; Path=/auth; Secure
Pragma: No-cache
Cache-Control: no-cache, must-revalidate
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: text/xml;charset=UTF-8
Content-Language: en-US
P3P: CP="PHY ONL PRE STA CURi OUR IND"
Transfer-Encoding: chunked
<response xmlns="https://api.login.aol.com">
<statusCode>330</statusCode>
<statusText>Password/LoginId Required/Invalid</statusText>
<statusDetailCode>3011</statusDetailCode>
<data>
<challenge>
<info>Enter your password again</info>
<context>UEZuowAAC94aMf51</context>
</challenge>
</data>
</response>
Подскажите, как правильно генерировать хэш пароля в md5?
А вот весь код:
Код:
<?php
class Curl
{
protected $curl;
public $url = null;
public $port = 8080;
public $proxyPort = null;
public $proxyHost = null;
public $post = null;
public $get = null;
public $userAgent = null;
public $referer = false;
public $encoding = false;
public $cookiejar;
public $err = null;
public function conect($url, $port=80)
{
$this->curl = curl_init();
if ($this->curl === false)
{
$this->err('curl_init', curl_errno($this->curl), curl_error($this->curl));
}
$this->url = $url;
$this->setopt(CURLOPT_URL, $this->url);
$this->port = $port;
$this->setopt(CURLOPT_PORT, $this->port);
if (preg_match('/^(http|https):\/\/([^\/]*)(\/|.?)(.*)?/u', $this->url, $preg) === false)
{
$this->err('preg_match($this->url)', '001', $preg[0]);
}
$this->cookiejar = md5($preg[2]);
if ('https' == $preg[1])
{
$this->setopt(CURLOPT_SSL_VERIFYPEER, false);
$this->setopt(CURLOPT_SSL_VERIFYHOST, 1);
$this->setopt(CURLOPT_SSLVERSION, 3);
}
$parh_cookies = H.'/sys/cookies/'.$this->cookiejar.'.cookies';
if (is_file($parh_cookies))
{
$this->setopt(CURLOPT_COOKIEFILE, $parh_cookies);
}
else
{
$this->setopt(CURLOPT_COOKIEJAR, $parh_cookies);
}
}
public function err($type, $code, $mes, $params=null)
{
$this->err["".time().""] = array(
'type' => $type,
'code' => $code,
'message' => $mes,
'params' => $params
);
}
public function setopt($k, $v)
{
if (curl_setopt($this->curl, $k, $v) === false)
{
$this->err('curl_setopt', curl_errno($this->curl), curl_error($this->curl), array($k, $v));
}
}
public function exec()
{
if ($this->referer !== null)
{
$this->setopt(CURLOPT_REFERER, $this->referer);
}
if ($this->encoding !== false)
{
$this->setopt(CURLOPT_ENCODING, $this->encoding);
}
if ($this->userAgent !== null)
{
$this->setopt(CURLOPT_USERAGENT, $this->userAgent);
}
$data = curl_exec($this->curl);
if ($data === false)
{
$this->err('curl_exec', curl_errno($this->curl), curl_error($this->curl));
}
else
{
return $data;
}
}
public function http_proxy($host, $port, $pass=false, $auth=CURLAUTH_BASIC)
{
$this->setopt(CURLOPT_HTTPPROXYTUNNEL, true);
$this->setopt(CURLOPT_PROXY, $host);
$this->setopt(CURLOPT_PROXYPORT, $port);
if ($pass !== false)
{
$this->setopt(CURLOPT_PROXYAUTH, $auth);
$this->setopt(CURLOPT_PROXYUSERPWD, $pass);
}
}
public function httpheader($data)
{
$this->setopt(CURLOPT_HTTPHEADER, $data);
}
public function cookies($data)
{
$this->setopt(CURLOPT_COOKIE, $data);
}
public function get($header=false)
{
$this->get = $this->url;
$this->setopt(CURLOPT_RETURNTRANSFER, true);
if ($header === true)
{
$this->setopt(CURLOPT_HEADER, true);
}
return $this->exec();
}
public function post($data, $header=false)
{
$this->setopt(CURLOPT_POST, true);
$this->post = http_build_query($data);
$this->setopt(CURLOPT_POSTFIELDS, $this->post);
$this->setopt(CURLOPT_RETURNTRANSFER, true);
if ($header === true)
{
$this->setopt(CURLOPT_HEADER, true);
}
return $this->exec();
}
public function close()
{
curl_close($this->curl);
}
}
class AutorizationICQ
{
protected $pass;
protected $uin;
protected $curl;
public $devId = 'gu19PNBblQjCdbMU';
public $tid = null;
public $realm = null;
public $challengeword = null;
public $tokenType = 86400;
public $a = null;
public $buildNumber = 6547;
public $clientName = 'ICQ Client key=gu19PNBblQjCdbMU';
public $clientVersion = 6547;
public $distId = 30014;
public $k = 'gu19PNBblQjCdbMU';
public $majorVersion = 7;
public $minorVersion = 7;
public $pointVersion = 0;
public $port = 443;
public $Ts = null;
public $UrlSig_sha256 = null;
public $CryptUrlSring = null;
public function __construct($uin, $pass)
{
$this->pass = $pass;
$this->uin = $uin;
$this->curl = new Curl();
}
public function conect()
{
$this->curl->conect('https://api.login.icq.net/auth/getChallenge', 443);
$this->userAgent = $this->clientName;
$arrpost = array(
'devId' => $this->devId,
'f' => 'xml',
's' => $this->uin
);
/*
<response xmlns="https://api.login.aol.com">
<statusCode>200</statusCode>
<statusText>OK</statusText>
<data>
<tid>UDquVwAAC9wQxTW5</tid>
<normalize>false</normalize>
<truncate>true</truncate>
<realm>AOL Instant Messenger (SM)</realm>
<challengeWord>3551757255</challengeWord>
</data>
</response>
*/
//$xml = $this->curl->post($arrpost, true);
$xml = new SimpleXMLElement($this->curl->post($arrpost));
if ($xml->statusCode == 200 && $xml->statusText == 'OK')
{
if ($xml->data->normalize == 'false' && $xml->data->truncate == 'true')
{
$this->tid = (string)$xml->data->tid;
$this->realm = (string)$xml->data->realm;
$this->challengeWord = (string)$xml->data->challengeWord;
}
}
print_r($xml);
print_r($this->curl->err);
$this->curl->close();
$this->curl->conect('https://api.login.icq.net/auth/clientLogin', 443);
/*
Не знаю наверно не правильно хэширую пароль
*/
$pwd = md5($this->pass);
$pwd = md5($this->challengeWord.$pwd.$this->realm);
print_r($pwd);
$arrpost = array(
'clientName' => $this->clientName,
'clientVersion' => $this->clientVersion,
'f' => 'xml',
'k' => $this->k,
'pwd' => $pwd,
's' => $this->uin,
'tid' => $this->tid,
'tokenType' => $this->tokenType,
'idType' => 'ICQ',
'digest' => 1
);
print_r($this->curl->post($arrpost, true));
print_r($this->curl->err);
$this->curl->close();
}
}
$icq = new AutorizationICQ(624513802, '12d34d');
$icq->conect();
?>
|