blob: 6aadd551709472fe53c0361b0698f03c06c31348 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qwebengineglobalsettings.h"
#include "qwebengineglobalsettings_p.h"
#include <QDebug>
#ifdef signals
#undef signals
#endif
namespace QtWebEngineCore {
extern void configureStubHostResolver(QWebEngineGlobalSettings::SecureDnsMode dnsMode,
std::string dnsOverHttpsTemplates, bool insecureDnsClientEnabled,
bool additionalInsecureDnsTypesEnabled);
extern bool isValidTemplates(std::string templates);
} // namespace QtWebEngineCore
QT_BEGIN_NAMESPACE
/*!
\namespace QWebEngineGlobalSettings
\brief The QWebEngineGlobalSettings namespace holds global settings of the web engine.
\since 6.6
\inmodule QtWebEngineCore
The QWebEngineGlobalSettings namespace holds global properties of the web engine.
Invoke setDnsMode() to configure DNS-over-HTTPS.
\sa QWebEngineGlobalSettings::setDnsMode()
*/
/*!
\enum QWebEngineGlobalSettings::SecureDnsMode
This enum sets the DNS-over-HTTPS mode used by the DnsMode structure:
\value SystemOnly This is the default. Use the system DNS host resolution.
\value SecureWithFallback Enable DNS-over-HTTPS (DoH). DoH servers have to be
provided through \l {QWebEngineGlobalSettings::DnsMode::serverTemplates}{serverTemplates} in
the DnsMode structure. If a host cannot be resolved via the provided servers,
the system DNS host resolution is used.
\value SecureOnly Enable DNS-over-HTTPS and only allow hosts to be resolved
this way. DoH servers have to be provided through
\l {QWebEngineGlobalSettings::DnsMode::serverTemplates}{serverTemplates} in the DnsMode
structure. If the DNS-over-HTTPS resolution fails, there is no fallback and the DNS host
resolution fails completely.
*/
/*!
\class QWebEngineGlobalSettings::DnsMode
\brief The DnsMode struct provides means to specify the DNS host resolution mode.
\since 6.6
\inmodule QtWebEngineCore
The QWebEngineGlobalSettings::DnsMode structure describes the DNS mode and
the associated DNS server template used for the DNS host resolution.
*/
/*!
\variable QWebEngineGlobalSettings::DnsMode::secureMode
\brief The DNS mode used for the host resolution.
Set \a secureMode to SecureDnsMode::SecureOnly to only allow DNS-over-HTTPS host resolution
using servers from \a serverTemplates.
Set \a secureMode to SecureDnsMode::SecureWithFallback to enable DNS-over-HTTPS host resolution
using servers from \a serverTemplates, with a fallback to the system DNS.
\sa QWebEngineGlobalSettings::SecureDnsMode
*/
/*!
\variable QWebEngineGlobalSettings::DnsMode::serverTemplates
\brief A list of server URI templates used for secure DNS-over-HTTPS host resolution.
The \c serverTemplates structure member lists
\l{https://datatracker.ietf.org/d7oc/html/rfc6570}{URI templates}.
An example of a URI template is https://dns.google/dns-query{?dns}.
*/
/*!
\fn void QWebEngineGlobalSettings::setDnsMode(DnsMode dnsMode)
Sets \a dnsMode for DNS-over-HTTPS host resolution.
This function returns \c false if the \l {QWebEngineGlobalSettings::DnsMode::serverTemplates}
{serverTemplates} list in the \l {QWebEngineGlobalSettings::DnsMode}{DnsMode} structure is empty
or contains URI templates that cannot be parsed for SecureDnsMode::SecureOnly or
SecureDnsMode::SecureWithFallback. Otherwise, it returns \c true meaning that the DNS mode
change is triggered.
*/
bool QWebEngineGlobalSettings::setDnsMode(DnsMode dnsMode)
{
QWebEngineGlobalSettingsPrivate *d = QWebEngineGlobalSettingsPrivate::instance();
if (dnsMode.secureMode != SecureDnsMode::SystemOnly) {
const QString servers = dnsMode.serverTemplates.join(QChar::Space);
const std::string templates = servers.toStdString();
if (!QtWebEngineCore::isValidTemplates(templates))
return false;
d->dnsOverHttpsTemplates = templates;
}
d->dnsMode = dnsMode.secureMode;
d->configureStubHostResolver();
return true;
}
/*!
\internal
*/
QWebEngineGlobalSettingsPrivate *QWebEngineGlobalSettingsPrivate::instance()
{
static QWebEngineGlobalSettingsPrivate settings;
return &settings;
}
void QWebEngineGlobalSettingsPrivate::configureStubHostResolver()
{
QtWebEngineCore::configureStubHostResolver(dnsMode, dnsOverHttpsTemplates, insecureDnsClientEnabled, additionalInsecureDnsTypesEnabled);
}
QT_END_NAMESPACE
|