1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 05:58:58 +01:00

Implemented tcp full, tcp intermediate and tcp abridged connections

This commit is contained in:
Daniil Gentili 2016-08-15 15:43:58 +02:00
parent 1f858ac162
commit 7a1f7c1145
4 changed files with 8 additions and 9 deletions

View File

@ -14,7 +14,7 @@ You can (and you are also encouraged to) contribute by completing any of the fol
The importance of each item will range from 1 to 5. It's better to start from the most important items.
* In Session.php and TL, manage rpc errors, notifications, error codes and basically everything that isn't a normal response (4).
* In Connection.php and Session.php, add support for http, https and (maybe) udp connections and fix tcp intermediate connections (3).
* In Connection.php and Session.php, add support for http, https and (maybe) udp connections (3).
* In API.php, complete a decent authorization flow that supports both bots and normal users (2).
* In PrimeModule.php, fix the mess in it, choose one of (the fastest) native php prime factorization function and implement it without biginteger (1.5).

View File

@ -12,7 +12,7 @@ If not, see <http://www.gnu.org/licenses/>.
namespace danog\MadelineProto;
class API extends Exception
class API
{
public $session;

View File

@ -37,10 +37,10 @@ class Crypt
public static function _ige($message, $key, $iv, $operation = 'decrypt')
{
if (strlen($key) != 32) {
throw new Exception('key must be 32 bytes long (was '.len($key).' bytes)');
throw new Exception('key must be 32 bytes long (was '.strlen($key).' bytes)');
}
if (strlen($iv) != 32) {
throw new Exception('iv must be 32 bytes long (was '.len($iv).' bytes)');
throw new Exception('iv must be 32 bytes long (was '.strlen($iv).' bytes)');
}
$cipher = new \phpseclib\Crypt\AES(\phpseclib\Crypt\AES::MODE_ECB);
$cipher->setKey($key);

View File

@ -28,7 +28,7 @@ class Session extends Tools
'server_salt' => null,
'ip_address' => '149.154.167.50',
'port' => '443',
'protocol' => 'tcp_abridged',
'protocol' => 'tcp_full',
'api_id' => 25628,
'api_hash' => '1fe17cda7d355166cdaa71f04122873c',
'tl_schema' => [
@ -109,7 +109,6 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
$this->server_salt.$this->session_id.$message_id.$this->struct->pack('<II', $this->number, strlen($message_data)).$message_data;
$message_key = substr(sha1($encrypted_data, true), -16);
$padding = \phpseclib\Crypt\Random::string(Tools::posmod(-strlen($encrypted_data), 16));
$this->log->log(strlen($encrypted_data.$padding));
list($aes_key, $aes_iv) = $this->aes_calculate($message_key);
$message = $this->auth_key_id.$message_key.Crypt::ige_encrypt($encrypted_data.$padding, $aes_key, $aes_iv);
}
@ -121,7 +120,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
$this->number += 1;
break;
case 'tcp_intermediate':
$step1 = $this->struct->pack('<I', strlen($message) + 4).$message;
$step1 = $this->struct->pack('<I', strlen($message)).$message;
$this->sock->write($step1);
break;
case 'tcp_abridged':
@ -155,7 +154,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
throw new Exception('CRC32 was not correct!');
}
$x = $this->struct->unpack('<I', substr($packet, 0, 4));
$payload = Tools::fopen_and_write('php://memory', 'rw+b', substr($packet, 4, $packet_length - 8));
$payload = Tools::fopen_and_write('php://memory', 'rw+b', substr($packet, 4, $packet_length - 12));
break;
case 'tcp_intermediate':
$packet_length_data = $this->sock->read(4);
@ -163,7 +162,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
throw new Exception('Nothing in the socket!');
}
$packet_length = $this->struct->unpack('<I', $packet_length_data)[0];
$packet = $this->sock->read($packet_length - 4);
$packet = $this->sock->read($packet_length);
$payload = Tools::fopen_and_write('php://memory', 'rw+b', $packet);
break;
case 'tcp_abridged':