Commit 613fb997 authored by Andrea Scarpino's avatar Andrea Scarpino

Use QByteArray to store the master key

Fixes #1
parent 3860dc09
...@@ -119,7 +119,7 @@ Page { ...@@ -119,7 +119,7 @@ Page {
onStatusChanged: { onStatusChanged: {
if (status === PageStatus.Activating) { if (status === PageStatus.Activating) {
var isReady = manager.getName() !== "" && manager.getKey() !== ""; var isReady = manager.getName() !== "";
site.enabled = isReady; site.enabled = isReady;
if (!isReady) { if (!isReady) {
......
...@@ -40,11 +40,6 @@ MPWManager::~MPWManager() ...@@ -40,11 +40,6 @@ MPWManager::~MPWManager()
{ {
} }
QString MPWManager::getKey() const
{
return m_key;
}
QString MPWManager::getName() const QString MPWManager::getName() const
{ {
return m_name; return m_name;
...@@ -54,8 +49,14 @@ void MPWManager::setUserData(const QString &name, const QString &password) ...@@ -54,8 +49,14 @@ void MPWManager::setUserData(const QString &name, const QString &password)
{ {
m_name = name; m_name = name;
m_key = QString::fromLatin1((const char*) mpw_masterKeyForUser(name.toLatin1().data(), const uint8_t* k = mpw_masterKeyForUser(name.toUtf8().data(), password.toUtf8().data(),
password.toLatin1().data(), MPAlgorithmVersionCurrent)); 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 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 ...@@ -73,7 +74,12 @@ QString MPWManager::getPassword(const QString &site, PasswordType type, const in
default: qCritical() << "Unrecognized password type" << type; default: qCritical() << "Unrecognized password type" << type;
} }
return QString::fromLatin1(mpw_passwordForSite((const unsigned char*) m_key.toLatin1().data(), const char* p = mpw_passwordForSite((const unsigned char*) m_key.data(), site.toUtf8().data(),
site.toLatin1().data(), t, counter, MPSiteVariantPassword, NULL, t, counter, MPSiteVariantPassword, NULL, MPAlgorithmVersionCurrent);
MPAlgorithmVersionCurrent));
if (p) {
return QString::fromUtf8(p);
} else {
return QString();
}
} }
...@@ -39,13 +39,12 @@ public: ...@@ -39,13 +39,12 @@ public:
explicit MPWManager(QObject *parent = 0); explicit MPWManager(QObject *parent = 0);
virtual ~MPWManager(); virtual ~MPWManager();
Q_INVOKABLE QString getKey() const;
Q_INVOKABLE QString getName() const; Q_INVOKABLE QString getName() const;
Q_INVOKABLE void setUserData(const QString &name, const QString &password); Q_INVOKABLE void setUserData(const QString &name, const QString &password);
Q_INVOKABLE QString getPassword(const QString &site, PasswordType type, const int counter) const; Q_INVOKABLE QString getPassword(const QString &site, PasswordType type, const int counter) const;
private: private:
QString m_key; QByteArray m_key;
QString m_name; QString m_name;
}; };
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<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> <source>Please fill your name and master key in the Settings page!</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </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