From ef4abc661ffdae9b98893637ab36a4bf7ded3c17 Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Sun, 31 Jul 2022 13:17:08 +0200 Subject: [PATCH] Linux distros that use NetworkManager: prefill WLAN PSK Only supported when NetworkManager is used on the Linux distro as wpa_supplicant itself does not support reading PSKs through DBus, only setting them. Closes #457 --- debian/changelog | 12 +++++++ src/CMakeLists.txt | 7 ++-- src/imagewriter.cpp | 10 ++++++ src/linux/networkmanagerapi.cpp | 59 +++++++++++++++++++++++++++++++++ src/linux/networkmanagerapi.h | 22 ++++++++++++ 5 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 src/linux/networkmanagerapi.cpp create mode 100644 src/linux/networkmanagerapi.h diff --git a/debian/changelog b/debian/changelog index 0da9096..bb3cb4a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,15 @@ +rpi-imager (1.7.3) unstable; urgency=medium + + * Linux: use GnuTLS instead of OpenSSL for computing SHA256 + * Fix persistenting public key authentication setting + * Linux: prefill wlan PSK if Linux distro uses NetworkManager + * Add digital signage icon + * Fix ""Cannot send events to objects owned by a different thread" warning + * Update Slovan/Korean language files + * Allow selecting file names without extension + + -- Floris Bos Sun, 31 Jul 2022 12:15:17 +0200 + rpi-imager (1.7.2) unstable; urgency=medium * Remove overscan/piwiz supression advanced options diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index be0066e..51546e3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,8 +12,8 @@ OPTION (ENABLE_TELEMETRY "Enable sending telemetry" ON) project(rpi-imager LANGUAGES CXX C) set(IMAGER_VERSION_MAJOR 1) set(IMAGER_VERSION_MINOR 7) -set(IMAGER_VERSION_STR "${IMAGER_VERSION_MAJOR}.${IMAGER_VERSION_MINOR}.2") -set(IMAGER_VERSION_CSV "${IMAGER_VERSION_MAJOR},${IMAGER_VERSION_MINOR},2,0") +set(IMAGER_VERSION_STR "${IMAGER_VERSION_MAJOR}.${IMAGER_VERSION_MINOR}.3") +set(IMAGER_VERSION_CSV "${IMAGER_VERSION_MAJOR},${IMAGER_VERSION_MINOR},3,0") add_definitions(-DIMAGER_VERSION_STR="${IMAGER_VERSION_STR}") add_definitions(-DIMAGER_VERSION_CSV=${IMAGER_VERSION_CSV}) @@ -35,7 +35,8 @@ elseif (UNIX) set(DEPENDENCIES dependencies/mountutils/src/linux/functions.cpp linux/linuxdrivelist.cpp) find_package(Qt5DBus) if(Qt5DBus_FOUND) - set(DEPENDENCIES ${DEPENDENCIES} linux/udisks2api.cpp linux/udisks2api.h) + set(DEPENDENCIES ${DEPENDENCIES} linux/udisks2api.cpp linux/udisks2api.h + linux/networkmanagerapi.h linux/networkmanagerapi.cpp) set(EXTRALIBS Qt5::DBus) message("udisks2 support enabled") else() diff --git a/src/imagewriter.cpp b/src/imagewriter.cpp index ad4d035..37e024b 100644 --- a/src/imagewriter.cpp +++ b/src/imagewriter.cpp @@ -57,6 +57,11 @@ #include #endif +#ifdef Q_OS_LINUX +#ifndef QT_NO_DBUS +#include "linux/networkmanagerapi.h" +#endif +#endif ImageWriter::ImageWriter(QObject *parent) : QObject(parent), _repo(QUrl(QString(OSLIST_URL))), _dlnow(0), _verifynow(0), @@ -990,11 +995,16 @@ QString ImageWriter::getPSK(const QString &ssid) } return psk; +#else +#ifndef QT_NO_DBUS + NetworkManagerApi nm; + return nm.getPSK(); #else Q_UNUSED(ssid) return QString(); #endif #endif +#endif } bool ImageWriter::getBoolSetting(const QString &key) diff --git a/src/linux/networkmanagerapi.cpp b/src/linux/networkmanagerapi.cpp new file mode 100644 index 0000000..3750eae --- /dev/null +++ b/src/linux/networkmanagerapi.cpp @@ -0,0 +1,59 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright (C) 2022 Raspberry Pi Ltd + */ + +#include "networkmanagerapi.h" +#include +#include +#include +#include + +typedef QMap VariantMapMap; +Q_DECLARE_METATYPE(VariantMapMap) + +NetworkManagerApi::NetworkManagerApi(QObject *parent) + : QObject{parent} +{ + +} + +QString NetworkManagerApi::getPSK() +{ + qDBusRegisterMetaType(); + QDBusInterface nm("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager", + "org.freedesktop.NetworkManager", QDBusConnection::systemBus()); + + if (!nm.isValid()) + { + qDebug() << "NetworkManager not available"; + return QString(); + } + + const auto activeConnections = nm.property("ActiveConnections").value>(); + for (const QDBusObjectPath &activeConnection : activeConnections) + { + QString activeConnectionPath = activeConnection.path(); + if (activeConnectionPath.isEmpty()) + continue; + QDBusInterface ac("org.freedesktop.NetworkManager", activeConnectionPath, + "org.freedesktop.NetworkManager.Connection.Active", QDBusConnection::systemBus()); + if (!ac.isValid()) + continue; + QString settingsPath = ac.property("Connection").value().path(); + if (settingsPath.isEmpty()) + continue; + QDBusInterface settings("org.freedesktop.NetworkManager", settingsPath, + "org.freedesktop.NetworkManager.Settings.Connection", QDBusConnection::systemBus()); + if (!settings.isValid()) + continue; + QDBusReply reply = settings.call("GetSecrets", "802-11-wireless-security"); + if (!reply.isValid()) + continue; + QVariantMap secrets = reply.value().value("802-11-wireless-security"); + if (secrets.contains("psk")) + return secrets.value("psk").toString(); + } + + return QString(); +} diff --git a/src/linux/networkmanagerapi.h b/src/linux/networkmanagerapi.h new file mode 100644 index 0000000..e3387a2 --- /dev/null +++ b/src/linux/networkmanagerapi.h @@ -0,0 +1,22 @@ +#ifndef NETWORKMANAGERAPI_H +#define NETWORKMANAGERAPI_H + +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright (C) 2022 Raspberry Pi Ltd + */ + +#include + +class NetworkManagerApi : public QObject +{ + Q_OBJECT +public: + explicit NetworkManagerApi(QObject *parent = nullptr); + QString getPSK(); + +signals: + +}; + +#endif // NETWORKMANAGERAPI_H