diff --git a/OptionsPopup.qml b/OptionsPopup.qml index 992fe66..3908b9b 100644 --- a/OptionsPopup.qml +++ b/OptionsPopup.qml @@ -438,6 +438,10 @@ Popup { fieldWifiPassword.text = imageWriter.getPSK(fieldWifiSSID.text) if (fieldWifiPassword.text.length) { chkShowPassword.checked = false + if (Qt.platform.os == "osx") { + /* User indicated wifi must be prefilled */ + chkWifi.checked = true + } } } } diff --git a/imagewriter.cpp b/imagewriter.cpp index 0f7921f..a9f61b1 100644 --- a/imagewriter.cpp +++ b/imagewriter.cpp @@ -37,6 +37,8 @@ #endif #ifdef Q_OS_DARWIN #include +#include +#include #else #include "openssl/evp.h" #include "openssl/sha.h" @@ -883,10 +885,34 @@ QString ImageWriter::getPSK(const QString &ssid) return psk; +#else +#ifdef Q_OS_DARWIN + SecKeychainRef keychainRef; + QString psk; + QByteArray ssidAscii = ssid.toLatin1(); + + if (QMessageBox::question(nullptr, "", + tr("Would you like to prefill the wifi password from the system keychain?")) == QMessageBox::Yes) + { + if (SecKeychainOpen("/Library/Keychains/System.keychain", &keychainRef) == errSecSuccess) + { + UInt32 resultLen; + void *result; + if (SecKeychainFindGenericPassword(keychainRef, 0, NULL, ssidAscii.length(), ssidAscii.constData(), &resultLen, &result, NULL) == errSecSuccess) + { + psk = QByteArray((char *) result, resultLen); + SecKeychainItemFreeContent(NULL, result); + } + CFRelease(keychainRef); + } + } + + return psk; #else Q_UNUSED(ssid) return QString(); #endif +#endif } bool ImageWriter::getBoolSetting(const QString &key)