Commit 5d6041ca authored by Andrea Scarpino's avatar Andrea Scarpino

Use QByteArray to store the master key

Fixes #1
parent c0640f0a
......@@ -119,7 +119,7 @@ Page {
onStatusChanged: {
if (status === PageStatus.Activating) {
var isReady = manager.getName() !== "" && manager.getKey() !== "";
var isReady = manager.getName() !== "";
site.enabled = isReady;
if (!isReady) {
......
......@@ -40,11 +40,6 @@ MPWManager::~MPWManager()
{
}
QString MPWManager::getKey() const
{
return m_key;
}
QString MPWManager::getName() const
{
return m_name;
......@@ -54,8 +49,14 @@ void MPWManager::setUserData(const QString &name, const QString &password)
{
m_name = name;
m_key = QString::fromLatin1((const char*) mpw_masterKeyForUser(name.toLatin1().data(),
password.toLatin1().data(), MPAlgorithmVersionCurrent));
const uint8_t* k = mpw_masterKeyForUser(name.toUtf8().data(), password.toUtf8().data(),
MPAlgorithmVersionCurrent);
if (k) {
m_key = QByteArray::fromRawData((const char*) k, MP_dkLen);
} else {
qCritical() << "Error during master key generation";
}
}
QString MPWManager::getPassword(const QString &site, PasswordType type, const int counter) const
......@@ -73,7 +74,12 @@ QString MPWManager::getPassword(const QString &site, PasswordType type, const in
default: qCritical() << "Unrecognized password type" << type;
}
return QString::fromLatin1(mpw_passwordForSite((const unsigned char*) m_key.toLatin1().data(),
site.toLatin1().data(), t, counter, MPSiteVariantPassword, NULL,
MPAlgorithmVersionCurrent));
const char* p = mpw_passwordForSite((const unsigned char*) m_key.data(), site.toUtf8().data(),
t, counter, MPSiteVariantPassword, NULL, MPAlgorithmVersionCurrent);
if (p) {
return QString::fromUtf8(p);
} else {
return QString();
}
}
......@@ -39,13 +39,12 @@ public:
explicit MPWManager(QObject *parent = 0);
virtual ~MPWManager();
Q_INVOKABLE QString getKey() const;
Q_INVOKABLE QString getName() const;
Q_INVOKABLE void setUserData(const QString &name, const QString &password);
Q_INVOKABLE QString getPassword(const QString &site, PasswordType type, const int counter) const;
private:
QString m_key;
QByteArray m_key;
QString m_name;
};
......
......@@ -39,7 +39,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="128"/>
<location filename="../qml/pages/MainPage.qml" line="126"/>
<source>Please fill your name and master key in the Settings page!</source>
<translation type="unfinished"></translation>
</message>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment