From 1b54254f3f5f8ddf38c3874db788168aa84ec5bd Mon Sep 17 00:00:00 2001 From: Lukas Fluri Date: Sun, 22 Mar 2020 20:23:45 +0100 Subject: [PATCH 1/3] Fix decryption issues --- KeePit/database.cpp | 6 +++++- KeePit/readxmlfile.cpp | 21 +++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/KeePit/database.cpp b/KeePit/database.cpp index e3dc3e2..99731e3 100644 --- a/KeePit/database.cpp +++ b/KeePit/database.cpp @@ -415,9 +415,13 @@ void Database::openFile(QString url, QString password, QString passKey) { vKeyFileData = readKeyFile.read(passKeyMemblock, (int)passKeySize); } + // 'toStdString' encodes the password string in UTF-8 string stringKey = password.toStdString(); const byte * key = reinterpret_cast(stringKey.c_str()); - vector vKey = ae.toVector((char*)key, (uint)password.size()); + + // Some UTF-8 characters are represented with omre than one byte. + // Therefore use the length of 'stringKey' and not the length of 'password' + vector vKey = ae.toVector((char*)key, (uint)stringKey.length()); vector vKeySeed = ae.toVector(m_pbTransformSeed, TRANSFORMSEEDSIZE); uint uNumRounds = ByteStream::ReadByte(m_pwDatabaseKeyEncryptionRounds); diff --git a/KeePit/readxmlfile.cpp b/KeePit/readxmlfile.cpp index 1d67172..101359c 100644 --- a/KeePit/readxmlfile.cpp +++ b/KeePit/readxmlfile.cpp @@ -159,7 +159,7 @@ TreeNode* ReadXmlFile::ExtractEntryNode(XMLElement* elem) } } - if(strcmp(key->GetText(), "Password") == 0) { + else if(strcmp(key->GetText(), "Password") == 0) { const char* p = key->NextSiblingElement("Value")->GetText(); if(p != 0){ std::string strt(p); @@ -176,17 +176,30 @@ TreeNode* ReadXmlFile::ExtractEntryNode(XMLElement* elem) entry.passwordProtected(key->NextSiblingElement("Value")->Attribute("Protected")); } - if(strcmp(key->GetText(), "UserName") == 0) { + else if(strcmp(key->GetText(), "UserName") == 0) { entry.username(key->NextSiblingElement("Value")->GetText()); } - if(strcmp(key->GetText(), "URL") == 0) { + else if(strcmp(key->GetText(), "URL") == 0) { entry.url(key->NextSiblingElement("Value")->GetText()); } - if(strcmp(key->GetText(), "Notes") == 0) { + else if(strcmp(key->GetText(), "Notes") == 0) { entry.notes(key->NextSiblingElement("Value")->GetText()); } + else { + // This case covers all other (potentially encrypted) fields. + // For the moment, just check whether the field is encrypted, + // and if it is, decrypt it. + const char* p = key->NextSiblingElement("Value")->GetText(); + if(p != 0){ + std::string strt(p); + vector plainEncrypted = base64.base64_decode(strt); + byte* bytes = m_salsa->decrypt(plainEncrypted); + } + entry.passwordProtected(key->NextSiblingElement("Value")->Attribute("Protected")); + + } } assert(str != 0); From a70a2130dd5a6451d385e1b055144a13331600fb Mon Sep 17 00:00:00 2001 From: Lukas Fluri Date: Sun, 22 Mar 2020 20:39:46 +0100 Subject: [PATCH 2/3] Fix code alignment --- KeePit/database.cpp | 3 ++- KeePit/readxmlfile.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/KeePit/database.cpp b/KeePit/database.cpp index 99731e3..7afc9b4 100644 --- a/KeePit/database.cpp +++ b/KeePit/database.cpp @@ -419,7 +419,8 @@ void Database::openFile(QString url, QString password, QString passKey) { string stringKey = password.toStdString(); const byte * key = reinterpret_cast(stringKey.c_str()); - // Some UTF-8 characters are represented with omre than one byte. + // Some UTF-8 characters are represented with more than one byte. + // Only 'strinKey.length()' returns the length of the string in bytes. // Therefore use the length of 'stringKey' and not the length of 'password' vector vKey = ae.toVector((char*)key, (uint)stringKey.length()); vector vKeySeed = ae.toVector(m_pbTransformSeed, TRANSFORMSEEDSIZE); diff --git a/KeePit/readxmlfile.cpp b/KeePit/readxmlfile.cpp index 101359c..05318a6 100644 --- a/KeePit/readxmlfile.cpp +++ b/KeePit/readxmlfile.cpp @@ -186,11 +186,11 @@ TreeNode* ReadXmlFile::ExtractEntryNode(XMLElement* elem) else if(strcmp(key->GetText(), "Notes") == 0) { entry.notes(key->NextSiblingElement("Value")->GetText()); - } - else { - // This case covers all other (potentially encrypted) fields. - // For the moment, just check whether the field is encrypted, - // and if it is, decrypt it. + } + else { + // This case covers all other (potentially encrypted) fields. + // For the moment, just check whether the field is encrypted, + // and if it is, decrypt it. const char* p = key->NextSiblingElement("Value")->GetText(); if(p != 0){ std::string strt(p); From 4d7eac3e58ca104e54d959eebbbe2d47c16b4b22 Mon Sep 17 00:00:00 2001 From: Lukas Fluri Date: Sat, 11 Apr 2020 10:32:37 +0200 Subject: [PATCH 3/3] Indentation fix --- KeePit/database.cpp | 2 +- KeePit/readxmlfile.cpp | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/KeePit/database.cpp b/KeePit/database.cpp index 7afc9b4..d9a4a36 100644 --- a/KeePit/database.cpp +++ b/KeePit/database.cpp @@ -420,7 +420,7 @@ void Database::openFile(QString url, QString password, QString passKey) { const byte * key = reinterpret_cast(stringKey.c_str()); // Some UTF-8 characters are represented with more than one byte. - // Only 'strinKey.length()' returns the length of the string in bytes. + // Only 'stringKey.length()' returns the length of the string in bytes. // Therefore use the length of 'stringKey' and not the length of 'password' vector vKey = ae.toVector((char*)key, (uint)stringKey.length()); vector vKeySeed = ae.toVector(m_pbTransformSeed, TRANSFORMSEEDSIZE); diff --git a/KeePit/readxmlfile.cpp b/KeePit/readxmlfile.cpp index 05318a6..3b9dfc6 100644 --- a/KeePit/readxmlfile.cpp +++ b/KeePit/readxmlfile.cpp @@ -186,7 +186,7 @@ TreeNode* ReadXmlFile::ExtractEntryNode(XMLElement* elem) else if(strcmp(key->GetText(), "Notes") == 0) { entry.notes(key->NextSiblingElement("Value")->GetText()); - } + } else { // This case covers all other (potentially encrypted) fields. // For the moment, just check whether the field is encrypted, @@ -198,8 +198,7 @@ TreeNode* ReadXmlFile::ExtractEntryNode(XMLElement* elem) byte* bytes = m_salsa->decrypt(plainEncrypted); } entry.passwordProtected(key->NextSiblingElement("Value")->Attribute("Protected")); - - } + } } assert(str != 0);