8#include "QtCore/private/qipaddress_p.h"
9#include "QtCore/qlist.h"
11#if QT_CONFIG(settings)
33 IPv6Address ipv6Addr = {};
52 if (parser.
parse(headers)) {
54#if QT_CONFIG(settings)
56 hstsStore->synchronize();
66#if QT_CONFIG(settings)
71 hstsStore->synchronize();
77 bool includeSubDomains)
83#if QT_CONFIG(settings)
85 hstsStore->synchronize();
90 bool includeSubDomains)
98 const HostName hostName(host);
99 const auto pos = knownHosts.find(hostName);
100 QHstsPolicy::PolicyFlags
flags;
101 if (includeSubDomains)
105 if (
pos == knownHosts.end()) {
107 if (newPolicy.isExpired()) {
113 knownHosts.insert({hostName, newPolicy});
114#if QT_CONFIG(settings)
116 hstsStore->addToObserved(newPolicy);
121 if (newPolicy.isExpired())
122 knownHosts.erase(
pos);
123 else if (
pos->second != newPolicy)
124 pos->second = newPolicy;
128#if QT_CONFIG(settings)
130 hstsStore->addToObserved(newPolicy);
160 bool superDomainMatch =
false;
162 HostName nameToTest(
QStringView{hostNameAsString});
163 while (nameToTest.fragment.size()) {
164 auto const pos = knownHosts.find(nameToTest);
165 if (
pos != knownHosts.end()) {
166 if (
pos->second.isExpired()) {
167 knownHosts.erase(
pos);
168#if QT_CONFIG(settings)
171 hstsStore->addToObserved(
pos->second);
174 }
else if (!superDomainMatch ||
pos->second.includesSubDomains()) {
179 const qsizetype dot = nameToTest.fragment.indexOf(u
'.');
183 nameToTest.fragment = nameToTest.fragment.mid(
dot + 1);
184 superDomainMatch =
true;
197 QList<QHstsPolicy>
values;
199 for (
const auto &host : knownHosts)
204#if QT_CONFIG(settings)
208 if (store != hstsStore) {
217 if (knownHosts.size()) {
218 const QList<QHstsPolicy> observed(
policies());
219 for (
const auto &
policy : observed)
220 hstsStore->addToObserved(
policy);
221 hstsStore->synchronize();
228 const QList<QHstsPolicy> restored(store->
readPolicies());
247 return c >= 0 &&
c <= 127;
254 return (
c >= 0 &&
c <= 31) ||
c == 127;
270 return c ==
' ' ||
c ==
'\t';
286 static const char separators[] =
"()<>@,;:\\\"/[]?={}";
287 static const char *
end = separators +
sizeof separators - 1;
345 if (parseSTSHeader() && maxAgeFound) {
353 subDomainsFound =
false;
358bool QHstsHeaderParser::parseSTSHeader()
362 subDomainsFound =
false;
367 while (tokenPos < header.
size()) {
368 if (!parseDirective())
371 if (token.
size() && token !=
";") {
381bool QHstsHeaderParser::parseDirective()
413 return processDirective(directiveName, directiveValue);
417 if (!nextToken() || !token.
size())
419 directiveValue = token;
420 }
else if (token.
size()) {
425 if (!processDirective(directiveName, directiveValue))
449 if (!unescapedValue.size())
453 const qint64 age = unescapedValue.toLongLong(&
ok);
463 if (subDomainsFound) {
469 subDomainsFound =
true;
475bool QHstsHeaderParser::nextToken()
484 while (tokenPos < header.
size() &&
isLWS(header.
at(tokenPos)))
487 if (tokenPos == header.
size())
490 const char ch = header.
at(tokenPos);
491 if (
ch ==
';' ||
ch ==
'=') {
502 int last = tokenPos + 1;
503 while (last < header.
size()) {
504 if (header.
at(last) ==
'"') {
507 }
else if (header.
at(last) ==
'\\') {
509 if (last + 1 < header.
size() &&
isCHAR(header.
at(last + 1)))
520 if (last >= header.
size())
523 token = header.
mid(tokenPos, last - tokenPos + 1);
534 int last = tokenPos + 1;
538 token = header.
mid(tokenPos, last - tokenPos);
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
char at(qsizetype i) const
Returns the byte at index position i in the byte array.
void clear()
Clears the contents of the byte array and makes it null.
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray mid(qsizetype index, qsizetype len=-1) const &
\inmodule QtCore\reentrant
static QDateTime currentDateTimeUtc()
bool isKnownHost(const QUrl &url) const
void updateKnownHost(const QUrl &url, const QDateTime &expires, bool includeSubDomains)
QList< QHstsPolicy > policies() const
void updateFromHeaders(const QHttpHeaders &headers, const QUrl &url)
void updateFromPolicies(const QList< QHstsPolicy > &hosts)
The QHstsPolicy class specifies that a host supports HTTP Strict Transport Security policy (HSTS).
QList< QHstsPolicy > readPolicies()
qsizetype size() const noexcept
void reserve(qsizetype size)
\macro QT_RESTRICTED_CAST_FROM_ASCII
const_iterator constEnd() const
Returns a const \l{STL-style iterators}{STL-style iterator} pointing just after the last character in...
qsizetype size() const noexcept
Returns the number of characters in this string.
const_iterator constBegin() const
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in the st...
bool isValid() const
Returns true if the URL is non-empty and valid; otherwise returns false.
QString host(ComponentFormattingOptions=FullyDecoded) const
Returns the host of the URL if it is defined; otherwise an empty string is returned.
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static QByteArrayView unescapeMaxAge(QByteArrayView value)
static bool isCHAR(int c)
static bool isTEXT(char c)
static bool isTOKEN(char c)
static QT_BEGIN_NAMESPACE bool is_valid_domain_name(const QString &host)
static bool isSeparator(char c)
GLenum GLsizei GLsizei GLint * values
[15]
static qreal dot(const QPointF &a, const QPointF &b)
static const QChar * parseIp6(QString &host, const QChar *begin, const QChar *end, QUrl::ParsingMode mode)
QUrl url("example.com")
[constructor-url-reference]