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

server/2024/12/22 19:08:58/

一、选项页安全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/server/126442.html

相关文章

华为云技术深度解析:以系统性创新加速智能化升级

华为云技术深度解析&#xff1a;以系统性创新加速智能化升级 在当今数字化转型的浪潮中&#xff0c;云计算作为关键的基础设施&#xff0c;正以前所未有的速度推动着各行各业的智能化升级。作为全球领先的云服务提供商&#xff0c;华为云凭借其深厚的技术积累和创新实力&#…

springboot儿童物品共享平台的设计与实现

目录 毕设制作流程功能和技术介绍系统实现截图开发核心技术介绍&#xff1a;使用说明开发步骤编译运行代码执行流程核心代码部分展示可行性分析软件测试详细视频演示源码获取 毕设制作流程 &#xff08;1&#xff09;与指导老师确定系统主要功能&#xff1b; &#xff08;2&am…

互联网前后端分离的开发场景,一般会员和数据权限的判断是放在前端还是后端?

推荐学习文档 golang应用级os框架&#xff0c;欢迎stargolang应用级os框架使用案例&#xff0c;欢迎star案例&#xff1a;基于golang开发的一款超有个性的旅游计划app经历golang实战大纲golang优秀开发常用开源库汇总想学习更多golang知识&#xff0c;这里有免费的golang学习笔…

UE5 项目缓存文件删除、版本控制说明(工程目录结构)

文章目录 前言一、项目文件示例二、缓存文件删除、版本控制说明前言 我们在拷贝项目或者使用 Git 进行版本控制,如果不对文件选择性的控制,大量缓存文件会导致传输速度变慢;或者我们的项目报错了,想要删除缓存文件又不知如何下手,哪些是可删除的,哪些又是不可删除的,本…

自定义 Git

我们可以对 Git 做一些配置。 ‍ 配置别名 有没有经常敲错命令&#xff1f;比如 git status​&#xff1f;status ​这个单词真心不好记。 如果敲 git st ​就表示 git status ​那就简单多了&#xff0c;当然这种偷懒的办法我们是极力赞成的。 我们只需要敲一行命令&…

FOC电机驱动开发踩坑记录

关键技术 SVPWM电机磁场控制电流采样park变换和Clark变换滑膜观测器&#xff08;无感FOC&#xff09; SVPWM电机磁场控制 SVPWM主要思想是通过精确的对UVW三相电流的分时控制&#xff0c;来控制转子的合成力矩&#xff0c;达到目标方向&#xff0c;常用的是6分区的设计&…

行为设计模式 -策略设计模式- JAVA

策略设计模式 一 .简介二. 案例2.1 抽象策略&#xff08;Strategy&#xff09;类2.2 具体策略&#xff08;Concrete Strategy&#xff09;类2.3 环境&#xff08;Context&#xff09;类2.4 测试 三. 结论3.1 优缺点3.2 使用场景 前言 这是我在这个网站整理的笔记,有错误的地方请…

关于鸿蒙next 调用系统权限麦克风

使用app的时候都清楚&#xff0c;想使用麦克风、摄像头&#xff0c;存储照片等&#xff0c;都需要调用系统的权限&#xff0c;没有手机操作系统权限你也使用不了app所提供的功能&#xff0c;虽然app可以正常打开&#xff0c;但是你需要的功能是没办法使用的。今天把自己在鸿蒙学…