summaryrefslogtreecommitdiffstats
path: root/tests/manual/qdnslookup/main.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2024-04-19 20:45:00 -0700
committerThiago Macieira <thiago.macieira@intel.com>2024-05-08 21:13:43 -0700
commit9724b039cac2cc309575ce5a030841939eeb1acd (patch)
tree235d2a2d574214742b2d3c1b18662c5050443df7 /tests/manual/qdnslookup/main.cpp
parentfd6cfd22831c6ff7078bb97e62439375cfc849f6 (diff)
QDnsLookup: add initial support for DNS-over-TLS (DoT)
This is just an empty shell for now. The implementation will come in the next commit. [ChangeLog][QtNetwork][QDnsLookup] The class now supports DNS-over-TLS and some other DNSSEC experimental features, on some platforms. Use QDnsLookup::isProtocolSupported to know if the protocol is supported on a given platform. Change-Id: I455fe22ef4ad4b2f9b01fffd17c7e034dee75533 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/manual/qdnslookup/main.cpp')
-rw-r--r--tests/manual/qdnslookup/main.cpp45
1 files changed, 38 insertions, 7 deletions
diff --git a/tests/manual/qdnslookup/main.cpp b/tests/manual/qdnslookup/main.cpp
index a07eac6d45..129c79bb44 100644
--- a/tests/manual/qdnslookup/main.cpp
+++ b/tests/manual/qdnslookup/main.cpp
@@ -11,6 +11,11 @@
#include <QtNetwork/QHostInfo>
#include <QtNetwork/QDnsLookup>
+#if QT_CONFIG(ssl)
+# include <QtNetwork/QSslCipher>
+# include <QtNetwork/QSslConfiguration>
+#endif
+
#include <stdlib.h>
#include <stdio.h>
@@ -32,6 +37,12 @@ static QDnsLookup::Type typeFromString(QString str)
return QDnsLookup::Type(value);
}
+template <typename Enum> [[maybe_unused]] static const char *enumToKey(Enum e)
+{
+ QMetaEnum me = QMetaEnum::fromType<Enum>();
+ return me.valueToKey(int(e));
+}
+
static int showHelp(const char *argv0, int exitcode)
{
// like dig
@@ -43,7 +54,7 @@ static auto parseServerAddress(QString server)
{
struct R {
QHostAddress address;
- int port = -1;
+ int port;
} r;
// let's use QUrl to help us
@@ -52,7 +63,7 @@ static auto parseServerAddress(QString server)
if (!url.isValid() || !url.userInfo().isNull())
return r; // failed
- r.port = url.port();
+ r.port = url.port(0);
r.address.setAddress(url.host());
if (r.address.isNull()) {
// try to resolve a hostname
@@ -121,8 +132,21 @@ static void printResults(const QDnsLookup &lookup, QElapsedTimer::Duration durat
printAnswers(lookup);
printf("\n;; Query time: %lld ms\n", qint64(duration_cast<milliseconds>(duration).count()));
- if (QHostAddress server = lookup.nameserver(); !server.isNull())
- printf(";; SERVER: %s#%d\n", qPrintable(server.toString()), lookup.nameserverPort());
+ if (QHostAddress server = lookup.nameserver(); !server.isNull()) {
+ quint16 port = lookup.nameserverPort();
+ if (port == 0)
+ port = QDnsLookup::defaultPortForProtocol(lookup.nameserverProtocol());
+ printf(";; SERVER: %s#%d", qPrintable(server.toString()), port);
+#if QT_CONFIG(ssl)
+ if (lookup.nameserverProtocol() != QDnsLookup::Standard) {
+ if (QSslConfiguration conf = lookup.sslConfiguration(); !conf.isNull()) {
+ printf(" (%s %s)", enumToKey(conf.sessionProtocol()),
+ qPrintable(conf.sessionCipher().name()));
+ }
+ }
+#endif
+ puts("");
+ }
}
int main(int argc, char *argv[])
@@ -130,6 +154,7 @@ int main(int argc, char *argv[])
QCoreApplication a(argc, argv);
QDnsLookup::Type type = {};
+ QDnsLookup::Protocol protocol = QDnsLookup::Standard;
QString domain, server;
const QStringList args = QCoreApplication::arguments().sliced(1);
for (const QString &arg : args) {
@@ -139,6 +164,14 @@ int main(int argc, char *argv[])
}
if (arg == u"-h")
return showHelp(argv[0], EXIT_SUCCESS);
+ if (arg == "+tls") {
+ protocol = QDnsLookup::DnsOverTls;
+ continue;
+ } else if (arg == "+notls") {
+ protocol = QDnsLookup::Standard;
+ continue;
+ }
+
if (domain.isNull()) {
domain = arg;
continue;
@@ -170,9 +203,7 @@ int main(int argc, char *argv[])
argv[0], qPrintable(server));
return EXIT_FAILURE;
}
- lookup.setNameserver(addr.address);
- if (addr.port > 0)
- lookup.setNameserverPort(addr.port);
+ lookup.setNameserver(protocol, addr.address, addr.port);
}
// execute the lookup