6#include "QtCore/private/qipaddress_p.h"
7#include "QtCore/qlist.h"
31 IPv6Address ipv6Addr = {};
50 if (parser.
parse(headers)) {
52#if QT_CONFIG(settings)
54 hstsStore->synchronize();
64#if QT_CONFIG(settings)
69 hstsStore->synchronize();
75 bool includeSubDomains)
81#if QT_CONFIG(settings)
83 hstsStore->synchronize();
88 bool includeSubDomains)
96 const HostName hostName(host);
97 const auto pos = knownHosts.find(hostName);
98 QHstsPolicy::PolicyFlags
flags;
99 if (includeSubDomains)
103 if (
pos == knownHosts.end()) {
105 if (newPolicy.isExpired()) {
111 knownHosts.insert({hostName, newPolicy});
112#if QT_CONFIG(settings)
114 hstsStore->addToObserved(newPolicy);
119 if (newPolicy.isExpired())
120 knownHosts.erase(
pos);
121 else if (
pos->second != newPolicy)
122 pos->second = newPolicy;
126#if QT_CONFIG(settings)
128 hstsStore->addToObserved(newPolicy);
158 bool superDomainMatch =
false;
160 HostName nameToTest(
QStringView{hostNameAsString});
161 while (nameToTest.fragment.size()) {
162 auto const pos = knownHosts.find(nameToTest);
163 if (
pos != knownHosts.end()) {
164 if (
pos->second.isExpired()) {
165 knownHosts.erase(
pos);
166#if QT_CONFIG(settings)
169 hstsStore->addToObserved(
pos->second);
172 }
else if (!superDomainMatch ||
pos->second.includesSubDomains()) {
177 const qsizetype dot = nameToTest.fragment.indexOf(u
'.');
181 nameToTest.fragment = nameToTest.fragment.mid(
dot + 1);
182 superDomainMatch =
true;
196 values.reserve(
int(knownHosts.size()));
197 for (
const auto &host : knownHosts)
202#if QT_CONFIG(settings)
206 if (store != hstsStore) {
215 if (knownHosts.size()) {
217 for (
const auto &
policy : observed)
218 hstsStore->addToObserved(
policy);
219 hstsStore->synchronize();
245 return c >= 0 &&
c <= 127;
252 return (
c >= 0 &&
c <= 31) ||
c == 127;
268 return c ==
' ' ||
c ==
'\t';
284 static const char separators[] =
"()<>@,;:\\\"/[]?={}";
285 static const char *
end = separators +
sizeof separators - 1;
329 for (
const auto &
h : headers) {
344 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())
463 if (subDomainsFound) {
469 subDomainsFound =
true;
475bool QHstsHeaderParser::nextToken()
484 while (tokenPos < header.
size() &&
isLWS(header[tokenPos]))
487 if (tokenPos == header.
size())
490 const char ch = header[tokenPos];
491 if (
ch ==
';' ||
ch ==
'=') {
502 int last = tokenPos + 1;
503 while (last < header.
size()) {
504 if (header[last] ==
'"') {
507 }
else if (header[last] ==
'\\') {
509 if (last + 1 < header.
size() &&
isCHAR(header[last + 1]))
514 if (!
isTEXT(header[last]))
520 if (last >= header.
size())
523 token = header.
mid(tokenPos, last - tokenPos + 1);
534 int last = tokenPos + 1;
535 while (last < header.
size() &&
isTOKEN(header[last]))
538 token = header.
mid(tokenPos, last - tokenPos);
qlonglong toLongLong(bool *ok=nullptr, int base=10) const
Returns the byte array converted to a {long long} using base base, which is ten by default.
qsizetype size() const noexcept
Returns the number of bytes in this 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
Returns a byte array containing len bytes from this byte array, starting at position pos.
\inmodule QtCore\reentrant
QDateTime addSecs(qint64 secs) const
Returns a QDateTime object containing a datetime s seconds later than the datetime of this object (or...
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 QList< QPair< QByteArray, QByteArray > > &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
\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
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.
std::pair< T1, T2 > QPair
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static QByteArray unescapeMaxAge(const QByteArray &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]
GLfloat GLfloat GLfloat GLfloat h
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]