diff --git a/KeePit/database.cpp b/KeePit/database.cpp index e3dc3e2..d9a4a36 100644 --- a/KeePit/database.cpp +++ b/KeePit/database.cpp @@ -415,9 +415,14 @@ 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 more than one byte. + // 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); uint uNumRounds = ByteStream::ReadByte(m_pwDatabaseKeyEncryptionRounds); diff --git a/KeePit/readxmlfile.cpp b/KeePit/readxmlfile.cpp index 1d67172..3b9dfc6 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,29 @@ 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);