noglitchyo/dealdoh

基于PHP构建的简单DNS over HTTPS代理。

0.4.0-beta 2020-08-05 15:18 UTC

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消息库。

PHP from Packagist Build Status codecov Scrutinizer code quality (GitHub/Bitbucket) Packagist

概述

这个库能够代理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客户端)

安装

如RFC-8484中建议,通常,DoH客户端/服务器将在路径:/dns-query上发送/接收DNS请求。您的应用程序应该配置为监听此路由。

存在大量可以用于测试安装的DoH客户端。

示例

<?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文件了解详细信息

致谢

参考