![]() |
|
|||||||
| Web-программирование PHP, Perl, JavaScript, HTML, CGI, ASP, MySQL, etc. |
|
|
Опции темы | Оценить тему |
|
|
#1 |
|
Участник
Регистрация: 05.09.2012
Сообщений: 3
Репутация: 1
|
Сделал небольшие классы для авторизации через 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> А вот весь код: Код:
<?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();
?>
|
|
|
|
|
#3 |
|
Участник
|
md5($key + md5($password) + AIM_COSCAR_STRING)
AIM_COSCAR_STRING = "AOL Instant Messenger (SM)" Добавлено через 31 минуту
__________________
Хочешь знать как работает ICQ? Читай документацию по протоколу в OSCAR. Последний раз редактировалось .fry; 05.09.2012 в 13:53. Причина: Добавлено сообщение |
|
|
|
|
#4 | |
|
Участник
Регистрация: 05.09.2012
Сообщений: 3
Репутация: 1
|
Код:
SimpleXMLElement Object
(
[statusCode] => 200
[statusText] => OK
[data] => SimpleXMLElement Object
(
[tid] => UEdagwAAC+MazgJS
[normalize] => false
[truncate] => true
[realm] => AOL Instant Messenger (SM)
[challengeWord] => 2224445243
)
)
// realm
AOL Instant Messenger (SM)
//challengeWord
2224445243
/// генерированный пароль
5df1fa27f3136d91eb3a0589e438e809
HTTP/1.1 200 OK
Date: Wed, 05 Sep 2012 13:58:28 GMT
Set-Cookie: JSESSIONID=73040C13A37A4012B42F3282BA1A7E8B; 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>UEdagwAAC+MazgJS</context>
</challenge>
</data>
</response>
Цитата:
Добавлено через 8 минут Не знаю может кодировка строк не та, всё делаю в UTF-8. Всю голову сломал, буду очень рад если подскажите как делать правильно... В долгу не останусь)) Последний раз редактировалось Dimka leon; 05.09.2012 в 17:12. Причина: Добавлено сообщение |
|
|
|
|
|
#5 |
|
Участник
|
Dimka leon, PHP старый? http://www.php.net/manual/ru/function.hex2bin.php
Попробуй в win1251, реалм тоже конвертируй в 1251. Вообще судя по документации AIM, там используется другой метод хэширования пароля. Точнее, пароль идёт plain-text (потому, что используется ssl). Добавлено через 1 минуту Если всё это не поможет, попробуй послать plain-text password, если нет, попробуй не запрашивать ключ.
__________________
Хочешь знать как работает ICQ? Читай документацию по протоколу в OSCAR. Последний раз редактировалось .fry; 06.09.2012 в 15:34. Причина: Добавлено сообщение |
|
|
|
|
#6 |
|
Участник
Регистрация: 11.06.2009
Сообщений: 7
Репутация: 6
|
Dimka leon, не мучай себе мозг с md5 логином, дальше проблемы будут с подписанием запросов, а ты с получением токена разобраться еще не можешь...
Получай токен "обычным" логином, меньше гемора, один фиг он только по https возможен |
|
|
|
|
#7 |
|
Участник
|
alexey-m, на PHP очень легко сгенерить подпись.
__________________
Хочешь знать как работает ICQ? Читай документацию по протоколу в OSCAR. |
|
|
|
|
#8 |
|
Участник
Регистрация: 11.06.2009
Сообщений: 7
Репутация: 6
|
.fry, ее и на c++/delphi/java генерить не проблема, я не о сложностях реализации hmac-sha256 имел ввиду, а о генерации самого ключа подписи, если при обычном логине все просто и прозаично, то при md5 не все так очевидно.
|
|
|
|
|
#9 |
|
Участник
Регистрация: 05.09.2012
Сообщений: 3
Репутация: 1
|
как всегда холивар, буду копаться сам)) как всё сделаю... Выложу ответ... А для генерация подписи есть отличное pecl решение hash_hmac()
Добавлено через 2 минуты .fry походу самый понимающий, сразу видно в теме.... А остальные так просто забежали)) Последний раз редактировалось Dimka leon; 08.09.2012 в 16:16. Причина: Добавлено сообщение |
|
|