From 8b03c63a9e9a42a49f5f723c095b1c253aa45ccf Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 12 Jun 2019 18:26:55 +0200 Subject: [PATCH] Use DNS over HTTPS by default in all clients --- composer.json | 36 ++++++++++++++++++++----------- src/danog/MadelineProto/Magic.php | 20 +++++++++++++---- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index 1ab5fa03..369606d8 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "krakjoe/pthreads-polyfill": "*" }, "require": { - "php": ">=7.1.0", + "php": ">=7.0.0", "danog/primemodule": "^1.0.3", "danog/magicalserializer": "^1.0", "phpseclib/phpseclib": "dev-master#27370df as 2.0.15", @@ -21,13 +21,15 @@ "ext-xml": "*", "ext-fileinfo": "*", "amphp/amp": "^2.0", - "amphp/socket": "^0.10.11", "amphp/websocket": "dev-master", "amphp/websocket-client": "dev-master", - "amphp/artax": "^3.0", - "amphp/file": "^0.3.5", + "amphp/socket": "^0.10", + "amphp/dns": "dev-master#aa1892bdf13b787d759df6f2523e8027a434d927 as v0.9.x-dev", + "amphp/artax": "dev-master", + "amphp/file": "^0.3", "amphp/uri": "^0.1.4", - "amphp/byte-stream": "1.6.0" + "amphp/byte-stream": "^1.6", + "danog/dns-over-https": "^0.1" }, "require-dev": { "phpdocumentor/reflection-docblock": "^3.1", @@ -37,12 +39,10 @@ "suggest": { "ext-libtgvoip": "Install the php-libtgvoip extension to make phone calls (https://github.com/danog/php-libtgvoip)" }, - "authors": [ - { - "name": "Daniil Gentili", - "email": "daniil@daniil.it" - } - ], + "authors": [{ + "name": "Daniil Gentili", + "email": "daniil@daniil.it" + }], "autoload": { "psr-0": { "danog\\MadelineProto\\": "src/" @@ -51,5 +51,15 @@ "src/BigIntegor.php", "src/YieldReturnValue.php" ] - } -} + }, + "repositories": [ + { + "type": "git", + "url": "https://github.com/danog/phpseclib" + }, + { + "type": "git", + "url": "https://github.com/danog/dns" + } + ] +} \ No newline at end of file diff --git a/src/danog/MadelineProto/Magic.php b/src/danog/MadelineProto/Magic.php index a2c17f62..1b26a051 100644 --- a/src/danog/MadelineProto/Magic.php +++ b/src/danog/MadelineProto/Magic.php @@ -19,8 +19,12 @@ namespace danog\MadelineProto; -use function Amp\Promise\wait; +use Amp\DoH\DoHConfig; +use Amp\DoH\Nameserver; +use Amp\DoH\Rfc8484StubResolver; use Amp\Loop; +use function Amp\Dns\resolver; +use function Amp\Promise\wait; class Magic { @@ -135,10 +139,18 @@ class Magic } // Even an empty handler is enough to catch ctrl+c if (defined('SIGINT')) { - if (function_exists('pcntl_async_signals')) pcntl_async_signals(true); - Loop::onSignal(SIGINT, static function () { Logger::log('Got sigint', Logger::FATAL_ERROR); die(); }); - Loop::onSignal(SIGTERM, static function () { Logger::log('Got sigterm', Logger::FATAL_ERROR); die(); }); + //if (function_exists('pcntl_async_signals')) pcntl_async_signals(true); + Loop::onSignal(SIGINT, static function () {Logger::log('Got sigint', Logger::FATAL_ERROR);die();}); + Loop::onSignal(SIGTERM, static function () {Logger::log('Got sigterm', Logger::FATAL_ERROR);die();}); } + $DohConfig = new DoHConfig( + [ + new Nameserver('https://mozilla.cloudflare-dns.com/dns-query'), + new Nameserver('https://google.com/resolve', Nameserver::GOOGLE_JSON, ["Host" => "dns.google.com"]), + ] + ); + resolver(new Rfc8484StubResolver($DohConfig)); + self::$inited = true; } }