Finally fixed req_DH_params method

This commit is contained in:
danogentili 2016-08-14 20:00:30 +02:00
parent 127a698265
commit e284fb8ef6
4 changed files with 18 additions and 13 deletions

10
composer.lock generated
View File

@ -9,16 +9,16 @@
"packages": [ "packages": [
{ {
"name": "danog/phpstruct", "name": "danog/phpstruct",
"version": "1.1", "version": "1.1.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/danog/PHPStruct.git", "url": "https://github.com/danog/PHPStruct.git",
"reference": "ac1d7a0b1eb54d5b10dca553be816c8fb0881e47" "reference": "635b6a57a903b976c56c1283d00ee26b8a1b175d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/danog/PHPStruct/zipball/ac1d7a0b1eb54d5b10dca553be816c8fb0881e47", "url": "https://api.github.com/repos/danog/PHPStruct/zipball/635b6a57a903b976c56c1283d00ee26b8a1b175d",
"reference": "ac1d7a0b1eb54d5b10dca553be816c8fb0881e47", "reference": "635b6a57a903b976c56c1283d00ee26b8a1b175d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -53,7 +53,7 @@
"struct", "struct",
"unpack" "unpack"
], ],
"time": "2016-07-29 15:13:54" "time": "2016-08-14 17:51:55"
}, },
{ {
"name": "paragonie/constant_time_encoding", "name": "paragonie/constant_time_encoding",

View File

@ -18,7 +18,7 @@ class RSA extends TL\TL
public $n; // phpseclib\Math\BigInteger class public $n; // phpseclib\Math\BigInteger class
public $e; // phpseclib\Math\BigInteger class public $e; // phpseclib\Math\BigInteger class
public $fp; // phpseclib\Math\BigInteger class public $fp; // phpseclib\Math\BigInteger class
public $fp_float; // float public $fp_bytes; // bytes
public function __construct($key) public function __construct($key)
{ {
@ -27,8 +27,8 @@ class RSA extends TL\TL
$this->n = $this->key->modulus; $this->n = $this->key->modulus;
$this->e = $this->key->exponent; $this->e = $this->key->exponent;
$this->fp = new \phpseclib\Math\BigInteger(strrev(substr(sha1($this->serialize_param('bytes', $this->n->toBytes()).$this->serialize_param('bytes', $this->e->toBytes()), true), -8)), -256); $this->fp_bytes = substr(sha1($this->serialize_param('bytes', $this->n->toBytes()).$this->serialize_param('bytes', $this->e->toBytes()), true), -8);
$this->fp_float = (float) $this->fp->toString(); $this->fp = new \phpseclib\Math\BigInteger(strrev($this->fp_bytes), -256);
} }
public function encrypt($data) public function encrypt($data)

View File

@ -245,7 +245,8 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
throw new Exception('Handshake: wrong nonce'); throw new Exception('Handshake: wrong nonce');
} }
foreach ($ResPQ['server_public_key_fingerprints'] as $curfp) { foreach ($ResPQ['server_public_key_fingerprints'] as $curfp) {
if ($curfp === $this->key->fp_float) { $curfp_biginteger = new \phpseclib\Math\BigInteger($curfp);
if ($this->key->fp->equals($curfp_biginteger)) {
$public_key_fingerprint = $curfp; $public_key_fingerprint = $curfp;
break; break;
} }
@ -284,7 +285,6 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
// req_DH_params // req_DH_params
$this->log->log('Starting Diffie Hellman key exchange'); $this->log->log('Starting Diffie Hellman key exchange');
$server_dh_params = $this->method_call('req_DH_params', $server_dh_params = $this->method_call('req_DH_params',
[ [
'nonce' => $nonce, 'nonce' => $nonce,

View File

@ -98,7 +98,6 @@ class TL
if (!is_numeric($value)) { if (!is_numeric($value)) {
throw new Exception("serialize_param: given value isn't numeric"); throw new Exception("serialize_param: given value isn't numeric");
} }
return \danog\PHP\Struct::pack('<q', $value); return \danog\PHP\Struct::pack('<q', $value);
break; break;
case 'int128': case 'int128':
@ -167,10 +166,16 @@ class TL
if ($l == 254) { if ($l == 254) {
$long_len = \danog\PHP\Struct::unpack('<I', fread($bytes_io, 3).\danog\MadelineProto\Tools::string2bin('\x00')) [0]; $long_len = \danog\PHP\Struct::unpack('<I', fread($bytes_io, 3).\danog\MadelineProto\Tools::string2bin('\x00')) [0];
$x = fread($bytes_io, $long_len); $x = fread($bytes_io, $long_len);
fread($bytes_io, \danog\MadelineProto\Tools::posmod(-$long_len, 4)); $resto = \danog\MadelineProto\Tools::posmod(-$long_len, 4);
if ($resto > 0) {
fread($bytes_io, $resto);
}
} else { } else {
$x = fread($bytes_io, $l); $x = fread($bytes_io, $l);
fread($bytes_io, \danog\MadelineProto\Tools::posmod(-($l + 1), 4)); $resto = \danog\MadelineProto\Tools::posmod(-($l + 1), 4);
if ($resto > 0) {
fread($bytes_io, $resto);
}
} }
if (!is_string($x)) { if (!is_string($x)) {
throw new Exception("deserialize: generated value isn't a string"); throw new Exception("deserialize: generated value isn't a string");