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
This commit is contained in:
Floris Bos 2022-07-31 13:17:08 +02:00
parent b1606dd1fb
commit ef4abc661f
5 changed files with 107 additions and 3 deletions

12
debian/changelog vendored
View file

@ -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 <bos@je-eigen-domein.nl> Sun, 31 Jul 2022 12:15:17 +0200
rpi-imager (1.7.2) unstable; urgency=medium rpi-imager (1.7.2) unstable; urgency=medium
* Remove overscan/piwiz supression advanced options * Remove overscan/piwiz supression advanced options

View file

@ -12,8 +12,8 @@ OPTION (ENABLE_TELEMETRY "Enable sending telemetry" ON)
project(rpi-imager LANGUAGES CXX C) project(rpi-imager LANGUAGES CXX C)
set(IMAGER_VERSION_MAJOR 1) set(IMAGER_VERSION_MAJOR 1)
set(IMAGER_VERSION_MINOR 7) set(IMAGER_VERSION_MINOR 7)
set(IMAGER_VERSION_STR "${IMAGER_VERSION_MAJOR}.${IMAGER_VERSION_MINOR}.2") set(IMAGER_VERSION_STR "${IMAGER_VERSION_MAJOR}.${IMAGER_VERSION_MINOR}.3")
set(IMAGER_VERSION_CSV "${IMAGER_VERSION_MAJOR},${IMAGER_VERSION_MINOR},2,0") set(IMAGER_VERSION_CSV "${IMAGER_VERSION_MAJOR},${IMAGER_VERSION_MINOR},3,0")
add_definitions(-DIMAGER_VERSION_STR="${IMAGER_VERSION_STR}") add_definitions(-DIMAGER_VERSION_STR="${IMAGER_VERSION_STR}")
add_definitions(-DIMAGER_VERSION_CSV=${IMAGER_VERSION_CSV}) 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) set(DEPENDENCIES dependencies/mountutils/src/linux/functions.cpp linux/linuxdrivelist.cpp)
find_package(Qt5DBus) find_package(Qt5DBus)
if(Qt5DBus_FOUND) 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) set(EXTRALIBS Qt5::DBus)
message("udisks2 support enabled") message("udisks2 support enabled")
else() else()

View file

@ -57,6 +57,11 @@
#include <QtPlatformHeaders/QEglFSFunctions> #include <QtPlatformHeaders/QEglFSFunctions>
#endif #endif
#ifdef Q_OS_LINUX
#ifndef QT_NO_DBUS
#include "linux/networkmanagerapi.h"
#endif
#endif
ImageWriter::ImageWriter(QObject *parent) ImageWriter::ImageWriter(QObject *parent)
: QObject(parent), _repo(QUrl(QString(OSLIST_URL))), _dlnow(0), _verifynow(0), : QObject(parent), _repo(QUrl(QString(OSLIST_URL))), _dlnow(0), _verifynow(0),
@ -990,11 +995,16 @@ QString ImageWriter::getPSK(const QString &ssid)
} }
return psk; return psk;
#else
#ifndef QT_NO_DBUS
NetworkManagerApi nm;
return nm.getPSK();
#else #else
Q_UNUSED(ssid) Q_UNUSED(ssid)
return QString(); return QString();
#endif #endif
#endif #endif
#endif
} }
bool ImageWriter::getBoolSetting(const QString &key) bool ImageWriter::getBoolSetting(const QString &key)

View file

@ -0,0 +1,59 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright (C) 2022 Raspberry Pi Ltd
*/
#include "networkmanagerapi.h"
#include <QDBusMetaType>
#include <QDBusInterface>
#include <QDBusReply>
#include <QDebug>
typedef QMap<QString, QVariantMap> VariantMapMap;
Q_DECLARE_METATYPE(VariantMapMap)
NetworkManagerApi::NetworkManagerApi(QObject *parent)
: QObject{parent}
{
}
QString NetworkManagerApi::getPSK()
{
qDBusRegisterMetaType<VariantMapMap>();
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<QList<QDBusObjectPath>>();
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<QDBusObjectPath>().path();
if (settingsPath.isEmpty())
continue;
QDBusInterface settings("org.freedesktop.NetworkManager", settingsPath,
"org.freedesktop.NetworkManager.Settings.Connection", QDBusConnection::systemBus());
if (!settings.isValid())
continue;
QDBusReply<VariantMapMap> 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();
}

View file

@ -0,0 +1,22 @@
#ifndef NETWORKMANAGERAPI_H
#define NETWORKMANAGERAPI_H
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright (C) 2022 Raspberry Pi Ltd
*/
#include <QObject>
class NetworkManagerApi : public QObject
{
Q_OBJECT
public:
explicit NetworkManagerApi(QObject *parent = nullptr);
QString getPSK();
signals:
};
#endif // NETWORKMANAGERAPI_H