Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion KeePit/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const byte*>(stringKey.c_str());
vector<char> 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<char> vKey = ae.toVector((char*)key, (uint)stringKey.length());
vector<char> vKeySeed = ae.toVector(m_pbTransformSeed, TRANSFORMSEEDSIZE);

uint uNumRounds = ByteStream::ReadByte(m_pwDatabaseKeyEncryptionRounds);
Expand Down
20 changes: 16 additions & 4 deletions KeePit/readxmlfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<char> plainEncrypted = base64.base64_decode(strt);
byte* bytes = m_salsa->decrypt(plainEncrypted);
}
entry.passwordProtected(key->NextSiblingElement("Value")->Attribute("Protected"));
}
}

assert(str != 0);
Expand Down