Mac OS X: advanced options. offer to prefill system wifi PSK

Offer to prefill the wifi password of the system running
Imager, like we do on Windows.

Ask user first if that is desired, as it does cause OS X to
generate a prompt asking for admin password.
This commit is contained in:
Floris Bos 2021-05-04 22:51:08 +02:00
parent b57da413a6
commit e2296deb1a
2 changed files with 30 additions and 0 deletions

View file

@ -37,6 +37,8 @@
#endif
#ifdef Q_OS_DARWIN
#include <QtNetwork>
#include <QMessageBox>
#include <security/security.h>
#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)