noglitchyo / dealdoh
基于PHP构建的简单DNS over HTTPS代理。
Requires
- php: ^7.3
- ext-json: *
- ext-sockets: *
- clue/socket-raw: ^1.4
- nyholm/psr7: ^1.1
- php-http/guzzle6-adapter: ^2.0
- psr/http-client: *
- psr/http-server-middleware: ^1.0
- psr/log: ^1.1
- react/dns: ^1.3.0
Requires (Dev)
- mockery/mockery: ^1.2
- monolog/monolog: ^1.24
- phpstan/phpstan: ^0.11.8
- phpunit/phpunit: ^8.1
- react/datagram: ^1.5
- squizlabs/php_codesniffer: 3.*
- symfony/process: ^5.1
This package is auto-updated.
Last update: 2024-08-29 05:12:37 UTC
README
与DNS over HTTPS和更多内容互动!
Dealdoh是一个DNS-over-HTTPS (DoH)代理,以及一个用PHP编写的DNS消息库。
概述
这个库能够代理DoH请求和/或发送使用标准UDP/TCP以及各种现代和安全的DNS协议(如DNSCrypt、DNS-over-HTTPS (DoH)、GoogleDNS)的DNS查询。
它试图实现以下目标
- 提供对大量DNS协议的高度兼容性。
- 为PHP中的DNS开发提供良好的抽象层。
功能
- DoH代理中间件符合PSR-15/PSR-7规范。
- 创建并发送DNS消息到不同类型的DNS上游解析器。
- 通过多个DNS上游解析器转发DNS查询。
- 兼容DNS协议:RFC-1035(TCP/UDP上的普通DNS)、RFC-8484(DoH)、Google DoH API、DNSCrypt
- 围绕DNS开发的抽象层。
- 解析DNS戳记
客户端
dealdoh-client是一个命令行工具,它提供这个库的即时可用实现来发送和转发DNS查询。
库
要求
- PHP 7.3
- Web服务器
- 可选:启用HTTPS并使用有效的证书(自签名证书也可以工作,但取决于发起查询的DOH客户端)
安装
-
运行
composer require noglitchyo/dealdoh
-
DohResolverMiddleware::forward()
方法消耗PSR-7 ServerRequest。以下是一些兼容的实现- https://github.com/Nyholm/psr7 -
composer require nyholm/psr7
- https://github.com/guzzle/psr7 -
composer require guzzle/psr7
- https://github.com/zendframework/zend-diactoros -
composer require zendframework/zend-diactoros
- https://github.com/Nyholm/psr7 -
-
配置您的应用程序以调用
DohResolverMiddleware::forward()
-
安装测试
如RFC-8484中建议,通常,DoH客户端/服务器将在路径:/dns-query
上发送/接收DNS请求。您的应用程序应该配置为监听此路由。
存在大量可以用于测试安装的DoH客户端。
-
从Web浏览器使用客户端
Mozilla Firefox提供了一个受信任的递归解析器,可以配置为查询DoH服务器。Daniel Stenberg的文章提供了大量关于TRR及其配置的详细信息。请查阅浏览器实现列表。
示例
<?php use GuzzleHttp\Client as GuzzleClient; use Http\Adapter\Guzzle6\Client as GuzzleClientAdapter; use NoGlitchYo\Dealdoh\Dns\Client\DnsCryptClient; use NoGlitchYo\Dealdoh\Dns\Client\DohClient; use NoGlitchYo\Dealdoh\Dns\Client\PlainDnsClient; use NoGlitchYo\Dealdoh\Dns\Resolver\DnsUpstreamPoolResolver; use NoGlitchYo\Dealdoh\Entity\DnsUpstreamPool; use NoGlitchYo\Dealdoh\Mapper\DnsCrypt\AuthenticatedEncryptionMapper; use NoGlitchYo\Dealdoh\Mapper\HttpResponseMapper; use NoGlitchYo\Dealdoh\Mapper\MessageMapper; use NoGlitchYo\Dealdoh\Middleware\DohResolverMiddleware; use NoGlitchYo\Dealdoh\Repository\DnsCrypt\CertificateRepository; use Psr\Http\Message\ResponseInterface; $messageMapper = new MessageMapper(); // Initialize the DNS clients to use with the resolver $dnsClients = [ new DohClient(new GuzzleClientAdapter(new GuzzleClient()), $messageMapper), new PlainDnsClient($messageMapper), new DnsCryptClient(new AuthenticatedEncryptionMapper(), new CertificateRepository(), $messageMapper) ]; // Initialize the list of DNS upstreams to use to resolve the DNS queries $dnsUpstreamPool = new DnsUpstreamPool([ 'dns://8.8.8.8:53', 'https://cloudflare-dns.com/dns-query', 'sdns://AQcAAAAAAAAAFlsyMDAxOmJjODoxODI0OjczODo6MV0gAyfzz5J-mV9G-yOB4Hwcdk7yX12EQs5Iva7kV3oGtlEgMi5kbnNjcnlwdC1jZXJ0LmFjc2Fjc2FyLWFtcy5jb20', ]); // Initialize the DNS resolver with the list of upstreams and the list of clients able to exchange with the upstreams $dnsResolver = new DnsUpstreamPoolResolver($dnsUpstreamPool, $dnsClients); // Create the ResolverMiddleware with the created DnsResolver $dohMiddleware = new DohResolverMiddleware($dnsResolver, $messageMapper, new HttpResponseMapper($messageMapper)); /** @var $response ResponseInterface */ $response = $dohMiddleware->forward(/* Expect a \Psr\Http\Message\RequestInterface object */);
更多示例
查看一些非常简单的集成示例,了解如何完成它
测试
如果您想运行测试,请检查项目并使用以下命令运行测试:
composer test
贡献
从这里开始 CONTRIBUTING.md。
许可证
本项目采用MIT许可证 - 请参阅LICENSE.md文件了解详细信息
致谢
- https://github.com/reactphp/dns
- https://github.com/mageddo/dns-proxy-server
- https://github.com/facebookexperimental/doh-proxy
- https://github.com/DNSCrypt/dnscrypt-proxy