|
11 | 11 | #include "driveformatthread.h"
|
12 | 12 | #include "localfileextractthread.h"
|
13 | 13 | #include "downloadstatstelemetry.h"
|
| 14 | +#include "wlancredentials.h" |
14 | 15 | #include <archive.h>
|
15 | 16 | #include <archive_entry.h>
|
16 | 17 | #include <random>
|
|
38 | 39 | #endif
|
39 | 40 | #ifdef Q_OS_DARWIN
|
40 | 41 | #include <QMessageBox>
|
41 |
| -#include <security/security.h> |
42 | 42 | #endif
|
43 | 43 |
|
44 | 44 | #ifdef Q_OS_WIN
|
45 | 45 | #include <windows.h>
|
46 |
| -#include <winioctl.h> |
47 |
| -#include <wlanapi.h> |
48 |
| -#ifndef WLAN_PROFILE_GET_PLAINTEXT_KEY |
49 |
| -#define WLAN_PROFILE_GET_PLAINTEXT_KEY 4 |
50 |
| -#endif |
51 |
| - |
52 | 46 | #include <QWinTaskbarButton>
|
53 | 47 | #include <QWinTaskbarProgress>
|
54 | 48 | #endif
|
|
57 | 51 | #include <QtPlatformHeaders/QEglFSFunctions>
|
58 | 52 | #endif
|
59 | 53 |
|
60 |
| -#ifdef Q_OS_LINUX |
61 |
| -#ifndef QT_NO_DBUS |
62 |
| -#include "linux/networkmanagerapi.h" |
63 |
| -#endif |
64 |
| -#endif |
65 |
| - |
66 | 54 | ImageWriter::ImageWriter(QObject *parent)
|
67 | 55 | : QObject(parent), _repo(QUrl(QString(OSLIST_URL))), _dlnow(0), _verifynow(0),
|
68 | 56 | _engine(nullptr), _thread(nullptr), _verifyEnabled(false), _cachingEnabled(false),
|
@@ -863,173 +851,23 @@ QStringList ImageWriter::getKeymapLayoutList()
|
863 | 851 |
|
864 | 852 | QString ImageWriter::getSSID()
|
865 | 853 | {
|
866 |
| - /* Qt used to have proper bearer management that was able to provide a list of |
867 |
| - SSIDs, but since they retired it, resort to calling platform specific tools for now. |
868 |
| - Minimal implementation that only gets the currently connected SSID */ |
869 |
| - |
870 |
| - QString program, regexpstr, ssid; |
871 |
| - QStringList args; |
872 |
| - QProcess proc; |
873 |
| - |
874 |
| -#ifdef Q_OS_WIN |
875 |
| - program = "netsh"; |
876 |
| - args << "wlan" << "show" << "interfaces"; |
877 |
| - regexpstr = "[ \t]+SSID[ \t]*: (.+)"; |
878 |
| -#else |
879 |
| -#ifdef Q_OS_DARWIN |
880 |
| - program = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport"; |
881 |
| - args << "-I"; |
882 |
| - regexpstr = "[ \t]+SSID: (.+)"; |
883 |
| -#else |
884 |
| - program = "iwgetid"; |
885 |
| - args << "-r"; |
886 |
| -#endif |
887 |
| -#endif |
888 |
| - |
889 |
| - proc.start(program, args); |
890 |
| - if (proc.waitForStarted(2000) && proc.waitForFinished(2000)) |
891 |
| - { |
892 |
| - if (regexpstr.isEmpty()) |
893 |
| - { |
894 |
| - ssid = proc.readAll().trimmed(); |
895 |
| - } |
896 |
| - else |
897 |
| - { |
898 |
| - QRegularExpression rx(regexpstr); |
899 |
| - const QList<QByteArray> outputlines = proc.readAll().replace('\r', "").split('\n'); |
900 |
| - |
901 |
| - for (const QByteArray &line : outputlines) { |
902 |
| - QRegularExpressionMatch match = rx.match(line); |
903 |
| - if (match.hasMatch()) |
904 |
| - { |
905 |
| - ssid = match.captured(1); |
906 |
| - break; |
907 |
| - } |
908 |
| - } |
909 |
| - } |
910 |
| - } |
911 |
| - |
912 |
| - return ssid; |
913 |
| -} |
914 |
| - |
915 |
| -inline QString unescapeXml(QString str) |
916 |
| -{ |
917 |
| - static const char *table[] = { |
918 |
| - "<", "<", |
919 |
| - ">", ">", |
920 |
| - """, "\"", |
921 |
| - "'", "'", |
922 |
| - "&", "&" |
923 |
| - }; |
924 |
| - int tableLen = sizeof(table) / sizeof(table[0]); |
925 |
| - |
926 |
| - for (int i=0; i < tableLen; i+=2) |
927 |
| - { |
928 |
| - str.replace(table[i], table[i+1]); |
929 |
| - } |
930 |
| - |
931 |
| - return str; |
| 854 | + return WlanCredentials::instance()->getSSID(); |
932 | 855 | }
|
933 | 856 |
|
934 |
| -QString ImageWriter::getPSK(const QString &ssid) |
| 857 | +QString ImageWriter::getPSK() |
935 | 858 | {
|
936 |
| -#ifdef Q_OS_WIN |
937 |
| - /* Windows allows retrieving wifi PSK */ |
938 |
| - HANDLE h; |
939 |
| - DWORD ret = 0; |
940 |
| - DWORD supportedVersion = 0; |
941 |
| - DWORD clientVersion = 2; |
942 |
| - QString psk; |
943 |
| - |
944 |
| - if (WlanOpenHandle(clientVersion, NULL, &supportedVersion, &h) != ERROR_SUCCESS) |
945 |
| - return QString(); |
946 |
| - |
947 |
| - PWLAN_INTERFACE_INFO_LIST ifList = NULL; |
948 |
| - |
949 |
| - if (WlanEnumInterfaces(h, NULL, &ifList) == ERROR_SUCCESS) |
950 |
| - { |
951 |
| - for (int i=0; i < ifList->dwNumberOfItems; i++) |
952 |
| - { |
953 |
| - PWLAN_PROFILE_INFO_LIST profileList = NULL; |
954 |
| - |
955 |
| - if (WlanGetProfileList(h, &ifList->InterfaceInfo[i].InterfaceGuid, |
956 |
| - NULL, &profileList) == ERROR_SUCCESS) |
957 |
| - { |
958 |
| - for (int j=0; j < profileList->dwNumberOfItems; j++) |
959 |
| - { |
960 |
| - QString s = QString::fromWCharArray(profileList->ProfileInfo[j].strProfileName); |
961 |
| - qDebug() << "Enumerating wifi profiles, SSID found:" << s << " looking for:" << ssid; |
962 |
| - |
963 |
| - if (s == ssid) { |
964 |
| - DWORD flags = WLAN_PROFILE_GET_PLAINTEXT_KEY; |
965 |
| - DWORD access = 0; |
966 |
| - DWORD ret = 0; |
967 |
| - LPWSTR xmlstr = NULL; |
968 |
| - |
969 |
| - if ( (ret = WlanGetProfile(h, &ifList->InterfaceInfo[i].InterfaceGuid, profileList->ProfileInfo[j].strProfileName, |
970 |
| - NULL, &xmlstr, &flags, &access)) == ERROR_SUCCESS && xmlstr) |
971 |
| - { |
972 |
| - QString xml = QString::fromWCharArray(xmlstr); |
973 |
| - qDebug() << "XML wifi profile:" << xml; |
974 |
| - QRegularExpression rx("<keyMaterial>(.+)</keyMaterial>"); |
975 |
| - QRegularExpressionMatch match = rx.match(xml); |
976 |
| - |
977 |
| - if (match.hasMatch()) { |
978 |
| - psk = unescapeXml(match.captured(1)); |
979 |
| - } |
980 |
| - |
981 |
| - WlanFreeMemory(xmlstr); |
982 |
| - break; |
983 |
| - } |
984 |
| - } |
985 |
| - } |
986 |
| - } |
987 |
| - |
988 |
| - if (profileList) { |
989 |
| - WlanFreeMemory(profileList); |
990 |
| - } |
991 |
| - } |
992 |
| - } |
993 |
| - |
994 |
| - if (ifList) |
995 |
| - WlanFreeMemory(ifList); |
996 |
| - WlanCloseHandle(h, NULL); |
997 |
| - |
998 |
| - return psk; |
999 |
| - |
1000 |
| -#else |
1001 | 859 | #ifdef Q_OS_DARWIN
|
1002 |
| - SecKeychainRef keychainRef; |
1003 |
| - QString psk; |
1004 |
| - QByteArray ssidAscii = ssid.toLatin1(); |
1005 |
| - |
| 860 | + /* On OSX the user is presented with a prompt for the admin password when opening the system key chain. |
| 861 | + * Ask if user wants to obtain the wlan password first to make sure this is desired and |
| 862 | + * to provide the user with context. */ |
1006 | 863 | if (QMessageBox::question(nullptr, "",
|
1007 |
| - tr("Would you like to prefill the wifi password from the system keychain?")) == QMessageBox::Yes) |
| 864 | + tr("Would you like to prefill the wifi password from the system keychain?")) != QMessageBox::Yes) |
1008 | 865 | {
|
1009 |
| - if (SecKeychainOpen("/Library/Keychains/System.keychain", &keychainRef) == errSecSuccess) |
1010 |
| - { |
1011 |
| - UInt32 resultLen; |
1012 |
| - void *result; |
1013 |
| - if (SecKeychainFindGenericPassword(keychainRef, 0, NULL, ssidAscii.length(), ssidAscii.constData(), &resultLen, &result, NULL) == errSecSuccess) |
1014 |
| - { |
1015 |
| - psk = QByteArray((char *) result, resultLen); |
1016 |
| - SecKeychainItemFreeContent(NULL, result); |
1017 |
| - } |
1018 |
| - CFRelease(keychainRef); |
1019 |
| - } |
| 866 | + return QString(); |
1020 | 867 | }
|
1021 |
| - |
1022 |
| - return psk; |
1023 |
| -#else |
1024 |
| -#ifndef QT_NO_DBUS |
1025 |
| - NetworkManagerApi nm; |
1026 |
| - return nm.getPSK(); |
1027 |
| -#else |
1028 |
| - Q_UNUSED(ssid) |
1029 |
| - return QString(); |
1030 |
| -#endif |
1031 |
| -#endif |
1032 | 868 | #endif
|
| 869 | + |
| 870 | + return WlanCredentials::instance()->getPSK(); |
1033 | 871 | }
|
1034 | 872 |
|
1035 | 873 | bool ImageWriter::getBoolSetting(const QString &key)
|
|
0 commit comments