Optimize QSslSocketPrivate::isMatchingHostname()
- Lowercase 'peerName' only once instead of each time though the loop - Use C++11 range-for instead of Q_FOREACH - Use QMap::equal_range instead of values(Key), saving the creation of a QList. Change-Id: I1229f62d706d1478960b08bb63ee9fb894364f87 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com> Reviewed-by: Richard J. Moore <rich@kde.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
b034a14dc5
commit
8a54950646
@ -2621,18 +2621,19 @@ QSharedPointer<QSslContext> QSslSocketPrivate::sslContext(QSslSocket *socket)
|
|||||||
|
|
||||||
bool QSslSocketPrivate::isMatchingHostname(const QSslCertificate &cert, const QString &peerName)
|
bool QSslSocketPrivate::isMatchingHostname(const QSslCertificate &cert, const QString &peerName)
|
||||||
{
|
{
|
||||||
QStringList commonNameList = cert.subjectInfo(QSslCertificate::CommonName);
|
const QString lowerPeerName = peerName.toLower();
|
||||||
|
const QStringList commonNames = cert.subjectInfo(QSslCertificate::CommonName);
|
||||||
|
|
||||||
foreach (const QString &commonName, commonNameList) {
|
for (const QString &commonName : commonNames) {
|
||||||
if (isMatchingHostname(commonName.toLower(), peerName.toLower())) {
|
if (isMatchingHostname(commonName.toLower(), lowerPeerName))
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (const QString &altName, cert.subjectAlternativeNames().values(QSsl::DnsEntry)) {
|
const auto subjectAlternativeNames = cert.subjectAlternativeNames();
|
||||||
if (isMatchingHostname(altName.toLower(), peerName.toLower())) {
|
const auto altNames = subjectAlternativeNames.equal_range(QSsl::DnsEntry);
|
||||||
|
for (auto it = altNames.first; it != altNames.second; ++it) {
|
||||||
|
if (isMatchingHostname(it->toLower(), lowerPeerName))
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user