mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-01-02 09:10:51 -05:00
Add CLI tests and improve coding style and i18n
The CLI module was lacking unit test coverage and showed some severe coding style violations, which this patch addresses. In addition, all uses of qCritical() with untranslatble raw char* sequences were removed in favor of proper locale strings. These are written to STDERR through QTextStreams and support output redirection for testing purposes. With this change, error messages don't depend on the global Qt logging settings and targets anymore and go directly to the terminal or into a file if needed. This patch also fixes a bug discovered during unit test development, where the extract command would just dump the raw XML contents without decrypting embedded Salsa20-protected values first, making the XML export mostly useless, since passwords are scrambled. Lastly, all CLI commands received a dedicated -h/--help option.
This commit is contained in:
parent
18b22834c1
commit
113c8eb702
67 changed files with 2259 additions and 1250 deletions
|
|
@ -1,3 +1,5 @@
|
|||
#include <utility>
|
||||
|
||||
/*
|
||||
* Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
|
|
@ -18,6 +20,9 @@
|
|||
#include "KdbxReader.h"
|
||||
#include "core/Database.h"
|
||||
#include "core/Endian.h"
|
||||
#include "format/KdbxXmlWriter.h"
|
||||
|
||||
#include <QBuffer>
|
||||
|
||||
#define UUID_LENGTH 16
|
||||
|
||||
|
|
@ -92,7 +97,14 @@ Database* KdbxReader::readDatabase(QIODevice* device, QSharedPointer<const Compo
|
|||
}
|
||||
|
||||
// read payload
|
||||
return readDatabaseImpl(device, headerStream.storedData(), key, keepDatabase);
|
||||
auto* db = readDatabaseImpl(device, headerStream.storedData(), std::move(key), keepDatabase);
|
||||
|
||||
if (saveXml()) {
|
||||
m_xmlData.clear();
|
||||
decryptXmlInnerStream(m_xmlData, db);
|
||||
}
|
||||
|
||||
return db;
|
||||
}
|
||||
|
||||
bool KdbxReader::hasError() const
|
||||
|
|
@ -258,6 +270,23 @@ void KdbxReader::setInnerRandomStreamID(const QByteArray& data)
|
|||
m_irsAlgo = irsAlgo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt protected inner stream fields in XML dump on demand.
|
||||
* Without the stream key from the KDBX header, the values become worthless.
|
||||
*
|
||||
* @param xmlOutput XML dump with decrypted fields
|
||||
* @param db the database object for which to generate the decrypted XML dump
|
||||
*/
|
||||
void KdbxReader::decryptXmlInnerStream(QByteArray& xmlOutput, Database* db) const
|
||||
{
|
||||
QBuffer buffer;
|
||||
buffer.setBuffer(&xmlOutput);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
KdbxXmlWriter writer(m_kdbxVersion);
|
||||
writer.disableInnerStreamProtection(true);
|
||||
writer.writeDatabase(&buffer, db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Raise an error. Use in case of an unexpected read error.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue