summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-06-27 11:38:53 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-06-28 06:06:52 +0000
commitee8c052395d484e2d094816beeb7a879947b72bd (patch)
tree0ae1bdcb3643a21651e150b13cd298590dfc78f5 /src/network
parentbc7194648792a354cc5d4b1673043908dcc15d0e (diff)
QtNetwork: Fix and streamline translations of QDtls
- Use %-placeholder formatting instead of string concatenation for messages of the form "XX failed: %1" - Introduce helper functions for duplicate messages - Introduce helper function for message reporting function failures to avoid duplication - Extract helper function for reporting SSL handshake errors Complemements ac583b686d0677517e7f8a10ce4e79c7fe227ccf. Change-Id: Iaf6c158ca8086d0b17a3e3c51955707734829615 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/network')
-rw-r--r--src/network/ssl/qdtls.cpp9
-rw-r--r--src/network/ssl/qdtls_openssl.cpp30
-rw-r--r--src/network/ssl/qsslsocket_openssl.cpp9
-rw-r--r--src/network/ssl/qsslsocket_openssl_p.h2
4 files changed, 36 insertions, 14 deletions
diff --git a/src/network/ssl/qdtls.cpp b/src/network/ssl/qdtls.cpp
index d241c0bb60..0f46f7f73e 100644
--- a/src/network/ssl/qdtls.cpp
+++ b/src/network/ssl/qdtls.cpp
@@ -151,6 +151,11 @@ QDtlsClientVerifier::GeneratorParameters QDtlsClientVerifier::cookieGeneratorPar
return {d->hashAlgorithm, d->secret};
}
+static QString msgUnsupportedMulticastAddress()
+{
+ return QDtls::tr("Multicast and broadcast addresses are not supported");
+}
+
bool QDtlsClientVerifier::verifyClient(QUdpSocket *socket, const QByteArray &dgram,
const QHostAddress &address, quint16 port)
{
@@ -164,7 +169,7 @@ bool QDtlsClientVerifier::verifyClient(QUdpSocket *socket, const QByteArray &dgr
if (address.isBroadcast() || address.isMulticast()) {
d->setDtlsError(QDtlsError::InvalidInputParameters,
- tr("Multicast and broadcast addresses are not supported"));
+ msgUnsupportedMulticastAddress());
return false;
}
@@ -222,7 +227,7 @@ bool QDtls::setRemote(const QHostAddress &address, quint16 port,
if (address.isBroadcast() || address.isMulticast()) {
d->setDtlsError(QDtlsError::InvalidInputParameters,
- tr("Multicast and broadcast addresses are not supported"));
+ msgUnsupportedMulticastAddress());
return false;
}
diff --git a/src/network/ssl/qdtls_openssl.cpp b/src/network/ssl/qdtls_openssl.cpp
index c3222bbd86..cba8e210cc 100644
--- a/src/network/ssl/qdtls_openssl.cpp
+++ b/src/network/ssl/qdtls_openssl.cpp
@@ -704,6 +704,12 @@ bool DtlsState::initTls(QDtlsBasePrivate *dtlsBase)
return true;
}
+static QString msgFunctionFailed(const char *function)
+{
+ //: %1: Some function
+ return QDtls::tr("%1 failed").arg(QLatin1String(function));
+}
+
bool DtlsState::initCtxAndConnection(QDtlsBasePrivate *dtlsBase)
{
Q_ASSERT(dtlsBase);
@@ -727,7 +733,8 @@ bool DtlsState::initCtxAndConnection(QDtlsBasePrivate *dtlsBase)
TlsConnection newConnection(newContext->createSsl(), dtlsutil::delete_connection);
if (!newConnection.data()) {
- dtlsBase->setDtlsError(QDtlsError::TlsInitializationError, QDtls::tr("SSL_new failed"));
+ dtlsBase->setDtlsError(QDtlsError::TlsInitializationError,
+ msgFunctionFailed("SSL_new"));
return false;
}
@@ -736,7 +743,8 @@ bool DtlsState::initCtxAndConnection(QDtlsBasePrivate *dtlsBase)
this);
if (set != 1 && configurationCopy->peerVerifyMode != QSslSocket::VerifyNone) {
- dtlsBase->setDtlsError(QDtlsError::TlsInitializationError, QDtls::tr("SSL_set_ex_data failed"));
+ dtlsBase->setDtlsError(QDtlsError::TlsInitializationError,
+ msgFunctionFailed("SSL_set_ex_data"));
return false;
}
@@ -764,7 +772,7 @@ bool DtlsState::initBIO(QDtlsBasePrivate *dtlsBase)
dtlsutil::delete_bio_method);
if (!customMethod.data()) {
dtlsBase->setDtlsError(QDtlsError::TlsInitializationError,
- QDtls::tr("BIO_meth_new failed"));
+ msgFunctionFailed("BIO_meth_new"));
return false;
}
@@ -782,7 +790,8 @@ bool DtlsState::initBIO(QDtlsBasePrivate *dtlsBase)
QScopedPointer<BIO, dtlsutil::bio_deleter> newBio(q_BIO_new(biom));
BIO *bio = newBio.data();
if (!bio) {
- dtlsBase->setDtlsError(QDtlsError::TlsInitializationError, QDtls::tr("BIO_new failed"));
+ dtlsBase->setDtlsError(QDtlsError::TlsInitializationError,
+ msgFunctionFailed("BIO_new"));
return false;
}
@@ -1025,8 +1034,8 @@ bool QDtlsPrivateOpenSSL::continueHandshake(QUdpSocket *socket, const QByteArray
return true; // The handshake is not yet complete.
default:
storePeerCertificates();
- setDtlsError(QDtlsError::TlsFatalError, QDtls::tr("Error during SSL handshake: ")
- + QSslSocketBackendPrivate::getErrorsFromOpenSsl());
+ setDtlsError(QDtlsError::TlsFatalError,
+ QSslSocketBackendPrivate::msgErrorsDuringHandshake());
dtls.reset();
handshakeState = QDtls::HandshakeNotStarted;
return false;
@@ -1166,8 +1175,8 @@ qint64 QDtlsPrivateOpenSSL::writeDatagramEncrypted(QUdpSocket *socket,
if (socket->error() != QAbstractSocket::UnknownSocketError && description.isEmpty()) {
setDtlsError(QDtlsError::UnderlyingSocketError, socket->errorString());
} else {
- setDtlsError(QDtlsError::TlsFatalError, QDtls::tr("Error while writing: ")
- + description);
+ setDtlsError(QDtlsError::TlsFatalError,
+ QDtls::tr("Error while writing: %1").arg(description));
}
}
@@ -1226,8 +1235,9 @@ QByteArray QDtlsPrivateOpenSSL::decryptDatagram(QUdpSocket *socket, const QByteA
// DTLSTODO: Apparently, some errors can be ignored, for example,
// ECONNRESET etc. This all needs a lot of testing!!!
default:
- setDtlsError(QDtlsError::TlsNonFatalError, QDtls::tr("Error while reading: ")
- + QSslSocketBackendPrivate::getErrorsFromOpenSsl());
+ setDtlsError(QDtlsError::TlsNonFatalError,
+ QDtls::tr("Error while reading: %1")
+ .arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl()));
return dgram;
}
}
diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp
index 9a5997253c..298475b100 100644
--- a/src/network/ssl/qsslsocket_openssl.cpp
+++ b/src/network/ssl/qsslsocket_openssl.cpp
@@ -891,6 +891,12 @@ QSslError _q_OpenSSL_to_QSslError(int errorCode, const QSslCertificate &cert)
return error;
}
+QString QSslSocketBackendPrivate::msgErrorsDuringHandshake()
+{
+ return QSslSocket::tr("Error during SSL handshake: %1")
+ .arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
+}
+
bool QSslSocketBackendPrivate::startHandshake()
{
Q_Q(QSslSocket);
@@ -926,8 +932,7 @@ bool QSslSocketBackendPrivate::startHandshake()
// The handshake is not yet complete.
break;
default:
- QString errorString
- = QSslSocket::tr("Error during SSL handshake: %1").arg(getErrorsFromOpenSsl());
+ QString errorString = QSslSocketBackendPrivate::msgErrorsDuringHandshake();
#ifdef QSSLSOCKET_DEBUG
qCDebug(lcSsl) << "QSslSocketBackendPrivate::startHandshake: error!" << errorString;
#endif
diff --git a/src/network/ssl/qsslsocket_openssl_p.h b/src/network/ssl/qsslsocket_openssl_p.h
index 2d0a5fe895..ce9096fea9 100644
--- a/src/network/ssl/qsslsocket_openssl_p.h
+++ b/src/network/ssl/qsslsocket_openssl_p.h
@@ -159,6 +159,8 @@ public:
QSslKey *key, QSslCertificate *cert,
QList<QSslCertificate> *caCertificates,
const QByteArray &passPhrase);
+
+ static QString msgErrorsDuringHandshake();
};
QT_END_NAMESPACE