Fix handling of wifi password with special characters

We could cover the backtic case by using nowdoc instead of
heredoc, but then there may still be problems with double quotes.
Put the PBKDF2 hash instead of plaintext password in
wpa_supplicant.conf to solve such problems.

Closes #206
This commit is contained in:
Floris Bos 2021-04-11 14:09:28 +02:00
parent 0c6a9359fd
commit b57da413a6
3 changed files with 54 additions and 5 deletions

View file

@ -35,6 +35,12 @@
#include <QFileDialog>
#include <QApplication>
#endif
#ifdef Q_OS_DARWIN
#include <QtNetwork>
#else
#include "openssl/evp.h"
#include "openssl/sha.h"
#endif
#ifdef Q_OS_WIN
#include <windows.h>
@ -926,6 +932,22 @@ QString ImageWriter::crypt(const QByteArray &password)
return sha256_crypt(password.constData(), salt.constData());
}
QString ImageWriter::pbkdf2(const QByteArray &psk, const QByteArray &ssid)
{
/* Qt has support for calculating Pbkdf2 starting from Qt 5.12 but
* older Linux distributions may not have that.
* We can use OpenSSL instead on platforms that have that.
* But Mac OS X lacks that, so do use Qt there */
#ifdef Q_OS_DARWIN
return QPasswordDigestor::deriveKeyPbkdf2(QCryptographicHash::Sha1, psk, ssid, 4096, 32).toHex();
#else
QByteArray digest(32, 0);
PKCS5_PBKDF2_HMAC_SHA1(psk.constData(), psk.length(), (const unsigned char*) ssid.constData(), ssid.length(), 4096, digest.length(), (unsigned char *) digest.data());
return digest.toHex();
#endif
}
void ImageWriter::setSavedCustomizationSettings(const QVariantMap &map)
{
_settings.beginGroup("imagecustomization");