Chromium 使用安全 DNS功能源码分析c++

devtools/2024/10/4 19:22:05/

一、选项页安全dns选项如下图:

二、那么如何自定义安全dns功能呢?

1、先看前端部分代码调用

shared.rollup.jsclass PrivacyPageBrowserProxyImpl {.................................................................getSecureDnsResolverList() {return sendWithPromise("getSecureDnsResolverList")  //获取dns列表}getSecureDnsSetting() {return sendWithPromise("getSecureDnsSetting")     }isValidConfig(entry) {return sendWithPromise("isValidConfig", entry)  //检测dns是否正确}probeConfig(entry) {return sendWithPromise("probeConfig", entry)}static getInstance() {return instance$g || (instance$g = new PrivacyPageBrowserProxyImpl)}static setInstance(obj) {instance$g = obj}
}

2、看c++代码对应的注册函数

chrome\browser\ui\webui\settings\settings_secure_dns_handler.cc

void SecureDnsHandler::RegisterMessages() {web_ui()->RegisterMessageCallback("getSecureDnsResolverList",base::BindRepeating(&SecureDnsHandler::HandleGetSecureDnsResolverList,base::Unretained(this)));web_ui()->RegisterMessageCallback("getSecureDnsSetting",base::BindRepeating(&SecureDnsHandler::HandleGetSecureDnsSetting,base::Unretained(this)));web_ui()->RegisterMessageCallback("isValidConfig",base::BindRepeating(&SecureDnsHandler::HandleIsValidConfig,base::Unretained(this)));web_ui()->RegisterMessageCallback("probeConfig", base::BindRepeating(&SecureDnsHandler::HandleProbeConfig,base::Unretained(this)));web_ui()->RegisterMessageCallback("recordUserDropdownInteraction",base::BindRepeating(&SecureDnsHandler::HandleRecordUserDropdownInteraction,base::Unretained(this)));
}1、先看 前端"getSecureDnsResolverList "dns列表对应c+++获取函数
base::Value::List SecureDnsHandler::GetSecureDnsResolverList() {base::Value::List resolvers;// Add a custom option to the front of the listbase::Value::Dict custom;custom.Set("name", l10n_util::GetStringUTF8(IDS_SETTINGS_CUSTOM));custom.Set("value", std::string());  // Empty value means custom.custom.Set("policy", std::string());resolvers.Append(std::move(custom));//providers_ 是dns数据列表来源,定义参考下面介绍for (const auto* entry : providers_) {net::DnsOverHttpsConfig doh_config({entry->doh_server_config});base::Value::Dict dict;dict.Set("name", entry->ui_name);dict.Set("value", doh_config.ToString());dict.Set("policy", entry->privacy_policy);resolvers.Append(std::move(dict));}// Randomize the order of the resolvers, but keep custom in first place.base::RandomShuffle(std::next(resolvers.begin()), resolvers.end());return resolvers;
}2、重点看providers_函数 ,其赋值和定义看代码:chrome\browser\ui\webui\settings\settings_secure_dns_handler.hstatic net::DohProviderEntry::List GetFilteredProviders();net::DohProviderEntry::List providers_ = GetFilteredProviders();std::unique_ptr<chrome_browser_net::DnsProbeRunner> runner_;chrome_browser_net::DnsProbeRunner::NetworkContextGetternetwork_context_getter_ =base::BindRepeating(&SecureDnsHandler::GetNetworkContext,base::Unretained(this));// static
net::DohProviderEntry::List SecureDnsHandler::GetFilteredProviders() {return secure_dns::ProvidersForCountry(secure_dns::SelectEnabledProviders(net::DohProviderEntry::GetList()),country_codes::GetCurrentCountryID());
}providers_ 通过GetFilteredProviders()获取列表3、最后看列表定义net::DohProviderEntry::GetList()
net\dns\public\doh_provider_entry.cc
const DohProviderEntry::List& DohProviderEntry::GetList() {// See /net/docs/adding_doh_providers.md for instructions on modifying this// DoH provider list.//// The provider names in these entries should be kept in sync with the// DohProviderId histogram suffix list in// tools/metrics/histograms/metadata/histogram_suffixes_list.xml.static const base::NoDestructor<DohProviderEntry::List> providers{{new DohProviderEntry("AlekBergNl",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderAlekBergNl, base::FEATURE_ENABLED_BY_DEFAULT),DohProviderIdForHistogram::kAlekBergNl,/*ip_strs=*/{}, /*dns_over_tls_hostnames=*/{},"https://dnsnl.alekberg.net/dns-query{?dns}",/*ui_name=*/"alekberg.net (NL)",/*privacy_policy=*/"https://alekberg.net/privacy",/*display_globally=*/false,/*display_countries=*/{"NL"}, LoggingLevel::kNormal),new DohProviderEntry("CleanBrowsingAdult",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderCleanBrowsingAdult, base::FEATURE_ENABLED_BY_DEFAULT),/*provider_id_for_histogram=*/absl::nullopt,{"185.228.168.10", "185.228.169.11", "2a0d:2a00:1::1","2a0d:2a00:2::1"},/*dns_over_tls_hostnames=*/{"adult-filter-dns.cleanbrowsing.org"},"https://doh.cleanbrowsing.org/doh/adult-filter{?dns}",/*ui_name=*/"", /*privacy_policy=*/"",/*display_globally=*/false, /*display_countries=*/{},LoggingLevel::kNormal),new DohProviderEntry("CleanBrowsingFamily",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderCleanBrowsingFamily, base::FEATURE_ENABLED_BY_DEFAULT),DohProviderIdForHistogram::kCleanBrowsingFamily,{"185.228.168.168", "185.228.169.168","2a0d:2a00:1::", "2a0d:2a00:2::"},/*dns_over_tls_hostnames=*/{"family-filter-dns.cleanbrowsing.org"},"https://doh.cleanbrowsing.org/doh/family-filter{?dns}",/*ui_name=*/"CleanBrowsing (Family Filter)",/*privacy_policy=*/"https://cleanbrowsing.org/privacy",/*display_globally=*/true, /*display_countries=*/{},LoggingLevel::kNormal),new DohProviderEntry("CleanBrowsingSecure",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderCleanBrowsingSecure, base::FEATURE_ENABLED_BY_DEFAULT),/*provider_id_for_histogram=*/absl::nullopt,{"185.228.168.9", "185.228.169.9", "2a0d:2a00:1::2","2a0d:2a00:2::2"},/*dns_over_tls_hostnames=*/{"security-filter-dns.cleanbrowsing.org"},"https://doh.cleanbrowsing.org/doh/security-filter{?dns}",/*ui_name=*/"", /*privacy_policy=*/"", /*display_globally=*/false,/*display_countries=*/{}, LoggingLevel::kNormal),new DohProviderEntry("Cloudflare",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderCloudflare, base::FEATURE_ENABLED_BY_DEFAULT),DohProviderIdForHistogram::kCloudflare,{"1.1.1.1", "1.0.0.1", "2606:4700:4700::1111","2606:4700:4700::1001"},/*dns_over_tls_hostnames=*/{"one.one.one.one", "1dot1dot1dot1.cloudflare-dns.com"},"https://chrome.cloudflare-dns.com/dns-query",/*ui_name=*/"Cloudflare (1.1.1.1)","https://developers.cloudflare.com/1.1.1.1/privacy/"/*privacy_policy=*/"public-dns-resolver/",/*display_globally=*/true, /*display_countries=*/{},LoggingLevel::kExtra),new DohProviderEntry("Comcast",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderComcast, base::FEATURE_ENABLED_BY_DEFAULT),/*provider_id_for_histogram=*/absl::nullopt,{"75.75.75.75", "75.75.76.76", "2001:558:feed::1","2001:558:feed::2"},/*dns_over_tls_hostnames=*/{"dot.xfinity.com"},"https://doh.xfinity.com/dns-query{?dns}", /*ui_name=*/"",/*privacy_policy*/ "", /*display_globally=*/false,/*display_countries=*/{}, LoggingLevel::kExtra),new DohProviderEntry("Cox",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderCox, base::FEATURE_DISABLED_BY_DEFAULT),/*provider_id_for_histogram=*/absl::nullopt,{"68.105.28.11", "68.105.28.12", "2001:578:3f::30"},/*dns_over_tls_hostnames=*/{"dot.cox.net"},"https://doh.cox.net/dns-query",/*ui_name=*/"", /*privacy_policy=*/"",/*display_globally=*/false, /*display_countries=*/{},LoggingLevel::kNormal),new DohProviderEntry("Cznic",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderCznic, base::FEATURE_ENABLED_BY_DEFAULT),DohProviderIdForHistogram::kCznic,{"185.43.135.1", "193.17.47.1", "2001:148f:fffe::1","2001:148f:ffff::1"},/*dns_over_tls_hostnames=*/{"odvr.nic.cz"}, "https://odvr.nic.cz/doh",/*ui_name=*/"CZ.NIC ODVR",/*privacy_policy=*/"https://www.nic.cz/odvr/",/*display_globally=*/false, /*display_countries=*/{"CZ"},LoggingLevel::kNormal),new DohProviderEntry("Dnssb",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderDnssb, base::FEATURE_ENABLED_BY_DEFAULT),DohProviderIdForHistogram::kDnsSb,{"185.222.222.222", "45.11.45.11", "2a09::", "2a11::"},/*dns_over_tls_hostnames=*/{"dns.sb"},"https://doh.dns.sb/dns-query{?dns}", /*ui_name=*/"DNS.SB",/*privacy_policy=*/"https://dns.sb/privacy/",/*display_globally=*/false, /*display_countries=*/{"EE", "DE"},LoggingLevel::kNormal),new DohProviderEntry("Google",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderGoogle, base::FEATURE_ENABLED_BY_DEFAULT),DohProviderIdForHistogram::kGoogle,{"8.8.8.8", "8.8.4.4", "2001:4860:4860::8888","2001:4860:4860::8844"},/*dns_over_tls_hostnames=*/{"dns.google", "dns.google.com", "8888.google"},"https://dns.google/dns-query{?dns}",/*ui_name=*/"Google (Public DNS)","https://developers.google.com/speed/public-dns/"/*privacy_policy=*/"privacy",/*display_globally=*/true, /*display_countries=*/{},LoggingLevel::kExtra),new DohProviderEntry("GoogleDns64",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderGoogleDns64, base::FEATURE_ENABLED_BY_DEFAULT),/*provider_id_for_histogram=*/absl::nullopt,{"2001:4860:4860::64", "2001:4860:4860::6464"},/*dns_over_tls_hostnames=*/{"dns64.dns.google"},"https://dns64.dns.google/dns-query{?dns}",/*ui_name=*/"", /*privacy_policy=*/"",/*display_globally=*/false,/*display_countries=*/{}, LoggingLevel::kNormal),new DohProviderEntry("Iij",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderIij, base::FEATURE_ENABLED_BY_DEFAULT),DohProviderIdForHistogram::kIij, /*ip_strs=*/{},/*dns_over_tls_hostnames=*/{}, "https://public.dns.iij.jp/dns-query",/*ui_name=*/"IIJ (Public DNS)",/*privacy_policy=*/"https://public.dns.iij.jp/",/*display_globally=*/false, /*display_countries=*/{"JP"},LoggingLevel::kNormal),new DohProviderEntry("NextDns",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderNextDns, base::FEATURE_ENABLED_BY_DEFAULT),DohProviderIdForHistogram::kNextDns, /*ip_strs=*/{},/*dns_over_tls_hostnames=*/{}, "https://chromium.dns.nextdns.io",/*ui_name=*/"NextDNS",/*privacy_policy=*/"https://nextdns.io/privacy",/*display_globally=*/false, /*display_countries=*/{"US"},LoggingLevel::kNormal),new DohProviderEntry("OpenDNS",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderOpenDNS, base::FEATURE_ENABLED_BY_DEFAULT),DohProviderIdForHistogram::kOpenDns,{"208.67.222.222", "208.67.220.220", "2620:119:35::35","2620:119:53::53"},/*dns_over_tls_hostnames=*/{},"https://doh.opendns.com/dns-query{?dns}", /*ui_name=*/"OpenDNS","https://www.cisco.com/c/en/us/about/legal/"/*privacy_policy=*/"privacy-full.html",/*display_globally=*/true, /*display_countries=*/{},LoggingLevel::kNormal),new DohProviderEntry("OpenDNSFamily",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderOpenDNSFamily, base::FEATURE_ENABLED_BY_DEFAULT),/*provider_id_for_histogram=*/absl::nullopt,{"208.67.222.123", "208.67.220.123", "2620:119:35::123","2620:119:53::123"},/*dns_over_tls_hostnames=*/{},"https://doh.familyshield.opendns.com/dns-query{?dns}",/*ui_name=*/"", /*privacy_policy=*/"", /*display_globally=*/false,/*display_countries=*/{}, LoggingLevel::kNormal),new DohProviderEntry("Quad9Cdn",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderQuad9Cdn, base::FEATURE_ENABLED_BY_DEFAULT),/*provider_id_for_histogram=*/absl::nullopt,{"9.9.9.11", "149.112.112.11", "2620:fe::11", "2620:fe::fe:11"},/*dns_over_tls_hostnames=*/{"dns11.quad9.net"},"https://dns11.quad9.net/dns-query", /*ui_name=*/"",/*privacy_policy=*/"", /*display_globally=*/false,/*display_countries=*/{}, LoggingLevel::kNormal),new DohProviderEntry("Quad9Insecure",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderQuad9Insecure, base::FEATURE_ENABLED_BY_DEFAULT),/*provider_id_for_histogram=*/absl::nullopt,{"9.9.9.10", "149.112.112.10", "2620:fe::10", "2620:fe::fe:10"},/*dns_over_tls_hostnames=*/{"dns10.quad9.net"},"https://dns10.quad9.net/dns-query", /*ui_name=*/"",/*privacy_policy=*/"", /*display_globally=*/false,/*display_countries=*/{}, LoggingLevel::kNormal),new DohProviderEntry("Quad9Secure",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderQuad9Secure, base::FEATURE_DISABLED_BY_DEFAULT),DohProviderIdForHistogram::kQuad9Secure,{"9.9.9.9", "149.112.112.112", "2620:fe::fe", "2620:fe::9"},/*dns_over_tls_hostnames=*/{"dns.quad9.net", "dns9.quad9.net"},"https://dns.quad9.net/dns-query", /*ui_name=*/"Quad9 (9.9.9.9)",/*privacy_policy=*/"https://www.quad9.net/home/privacy/",/*display_globally=*/true, /*display_countries=*/{},LoggingLevel::kExtra),new DohProviderEntry("Quickline",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderQuickline, base::FEATURE_ENABLED_BY_DEFAULT),/*provider_id_for_histogram=*/absl::nullopt,{"212.60.61.246", "212.60.63.246", "2001:1a88:10:ffff::1","2001:1a88:10:ffff::2"},/*dns_over_tls_hostnames=*/{"dot.quickline.ch"},"https://doh.quickline.ch/dns-query{?dns}",/*ui_name=*/"", /*privacy_policy=*/"",/*display_globally=*/false,/*display_countries=*/{}, LoggingLevel::kNormal),new DohProviderEntry("Spectrum1",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderSpectrum1, base::FEATURE_ENABLED_BY_DEFAULT),/*provider_id_for_histogram=*/absl::nullopt,{"209.18.47.61", "209.18.47.62", "2001:1998:0f00:0001::1","2001:1998:0f00:0002::1"},/*dns_over_tls_hostnames=*/{},"https://doh-01.spectrum.com/dns-query{?dns}",/*ui_name=*/"", /*privacy_policy=*/"",/*display_globally=*/false,/*display_countries=*/{}, LoggingLevel::kNormal),new DohProviderEntry("Spectrum2",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderSpectrum2, base::FEATURE_ENABLED_BY_DEFAULT),/*provider_id_for_histogram=*/absl::nullopt,{"209.18.47.61", "209.18.47.62", "2001:1998:0f00:0001::1","2001:1998:0f00:0002::1"},/*dns_over_tls_hostnames=*/{},"https://doh-02.spectrum.com/dns-query{?dns}",/*ui_name=*/"", /*privacy_policy=*/"",/*display_globally=*/false,/*display_countries=*/{}, LoggingLevel::kNormal),new DohProviderEntry("Switch",MAKE_BASE_FEATURE_WITH_STATIC_STORAGE(DohProviderSwitch, base::FEATURE_DISABLED_BY_DEFAULT),/*provider_id_for_histogram=*/absl::nullopt,{"130.59.31.251", "130.59.31.248", "2001:620:0:ff::2","2001:620:0:ff::3"},/*dns_over_tls_hostnames=*/{"dns.switch.ch"},"https://dns.switch.ch/dns-query", /*ui_name=*/"",/*privacy_policy=*/"", /*display_globally=*/false,/*display_countries=*/{}, LoggingLevel::kNormal),}};return *providers;
}

    
三、至此数据来源分析完毕,如果想要用自己的dns只需要在
net\dns\public\doh_provider_entry.cc
const DohProviderEntry::List& DohProviderEntry::GetList() 函数里面按照此格式追加即可。
不同版本内核的浏览器有所差异。


http://www.ppmy.cn/devtools/119138.html

相关文章

【java数据结构】泛型

【java数据结构】泛型 一、包装类1.1 基本数据类型对应的包装类1.2 装箱和拆箱 二、泛型2.1 引出泛型2.2 什么是泛型2.3 语法2.3.1 泛型类2.3.2 泛型接口2.3.3 泛型方法 2.4 擦除机制2.5 泛型通配符2.5.1 <?>无限定的通配符2.5.2 <? extends T>上界的通配符2.5.3…

DnsDiag:一款针对DNS的故障排除和安全审计工具

关于DnsDiag DnsDiag是一款针对DNS的故障排除和安全审计工具&#xff0c;在该工具的帮助下&#xff0c;广大研究人员可以轻松检测DNS基础设施的安全性。 你是否曾怀疑过你的 ISP 是否劫持了你的 DNS 流量&#xff1f;你是否曾观察到 DNS 响应有任何异常行为&#xff1f;你是否…

Linux操作系统如何定时关机?

在日常使用电脑的过程中&#xff0c;一般都会有软件升级、系统杀毒的工作&#xff0c;可能还需要电脑的定时关机、提醒事项功能。对于Linux操作系统&#xff0c;可以使用几种任务计划工具来指定相应的任务计划&#xff0c;使这些需求自动在后台运行。 一、at命令 at命令的作用…

【Linux】基于驱动框架的程序编写测试

【Linux】基于驱动框架的程序编写测试 字符设备驱动工作原理☆ 驱动程序开发驱动程序开发步骤驱动代码框架驱动框架设计流程 编译与测试编译测试 参考博文&#xff1a; 【Linux】基于框架编写驱动代码、驱动代码编译和测试 Linux驱动&#xff08;驱动程序开发、驱动框架代码编…

Spire.PDF for .NET【页面设置】演示:对PDF 文件进行分页

PDF 分页不仅允许用户在 PDF 文件中添加页码&#xff0c;还可以将 PDF 文档分成几部分&#xff0c;以便添加一些附加信息&#xff0c;例如 PDF 文件封面、简介或参考资料。因此&#xff0c;PDF 分页为管理大型文件或组织书籍提供了极大的便利。本节将向您展示一种通过C#、VB.NE…

Excel 获取某列不为空的值【INDEX函数 | SMALL函数或 LARGE函数 | ROW函数 | ISBLANK 函数】

〇、需求 Excel 获取某列不为空的值(获取某列中第一个非空值 或 获取某列中最后一个非空值)。 一、知识点讲解 INDEX函数 和 SMALL函数 两个函数搭配使用都可以实现上述需求 获取某列中第一个非空值 。 INDEX函数 和 LARGE函数 两个函数搭配使用都可以实现上述需求 获取某…

【CKA】二、节点管理-设置节点不可用

2、节点管理-设置节点不可用 1. 考题内容&#xff1a; 2. 答题思路&#xff1a; 先设置节点不可用&#xff0c;然后驱逐节点上的pod 这道题就两条命令&#xff0c;直接背熟就行。 也可以查看帮助 kubectl cordon -h kubectl drain -h 参数详情&#xff1a; –delete-empty…

关于音频噪音处理【常见问题、解决方案等】

1、降噪 【1】动物叫声处理 问题描述 原视频的人声与动物叫声重合&#xff0c;想清除动物的声音。 解决方案 [1] 声音模型噪音消除 1、将音频文件导入Adobe Audition 2、打开频谱图&#xff0c;找到相应噪音的特征&#xff0c;用画笔工具选择所有噪音区域 3、使用“学习声音模…