mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-07-29 09:38:48 -04:00
Remove obsolete database repair feature
This commit is contained in:
parent
d4112fe2bf
commit
44c9469221
13 changed files with 4 additions and 391 deletions
|
@ -120,11 +120,6 @@ QByteArray KdbxReader::xmlData() const
|
|||
return m_xmlData;
|
||||
}
|
||||
|
||||
QByteArray KdbxReader::streamKey() const
|
||||
{
|
||||
return m_protectedStreamKey;
|
||||
}
|
||||
|
||||
KeePass2::ProtectedStreamAlgo KdbxReader::protectedStreamAlgo() const
|
||||
{
|
||||
return m_irsAlgo;
|
||||
|
|
|
@ -48,7 +48,6 @@ public:
|
|||
bool saveXml() const;
|
||||
void setSaveXml(bool save);
|
||||
QByteArray xmlData() const;
|
||||
QByteArray streamKey() const;
|
||||
KeePass2::ProtectedStreamAlgo protectedStreamAlgo() const;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -1,102 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2016 Felix Geyer <debfx@fobos.de>
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 or (at your option)
|
||||
* version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "KeePass2Repair.h"
|
||||
|
||||
#include <QBuffer>
|
||||
|
||||
#include "core/Group.h"
|
||||
#include "format/Kdbx4Reader.h"
|
||||
#include "format/KdbxXmlReader.h"
|
||||
#include "format/KeePass2.h"
|
||||
#include "format/KeePass2RandomStream.h"
|
||||
#include "format/KeePass2Reader.h"
|
||||
|
||||
KeePass2Repair::RepairOutcome KeePass2Repair::repairDatabase(QIODevice* device, QSharedPointer<const CompositeKey> key)
|
||||
{
|
||||
m_errorStr.clear();
|
||||
|
||||
KeePass2Reader reader;
|
||||
reader.setSaveXml(true);
|
||||
|
||||
QScopedPointer<Database> db(reader.readDatabase(device, key, true));
|
||||
if (!reader.hasError()) {
|
||||
return qMakePair(NothingTodo, nullptr);
|
||||
}
|
||||
|
||||
QByteArray xmlData = reader.reader()->xmlData();
|
||||
if (!db || xmlData.isEmpty()) {
|
||||
m_errorStr = reader.errorString();
|
||||
return qMakePair(UnableToOpen, nullptr);
|
||||
}
|
||||
|
||||
bool repairAction = false;
|
||||
|
||||
QString xmlStart = QString::fromLatin1(xmlData.constData(), qMin(100, xmlData.size()));
|
||||
QRegExp encodingRegExp("encoding=\"([^\"]+)\"", Qt::CaseInsensitive, QRegExp::RegExp2);
|
||||
if (encodingRegExp.indexIn(xmlStart) != -1) {
|
||||
if (encodingRegExp.cap(1).compare("utf-8", Qt::CaseInsensitive) != 0
|
||||
&& encodingRegExp.cap(1).compare("utf8", Qt::CaseInsensitive) != 0) {
|
||||
// database is not utf-8 encoded, we don't support repairing that
|
||||
return qMakePair(RepairFailed, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
// try to fix broken databases because of bug #392
|
||||
for (int i = (xmlData.size() - 1); i >= 0; i--) {
|
||||
auto ch = static_cast<quint8>(xmlData.at(i));
|
||||
if (ch < 0x20 && ch != 0x09 && ch != 0x0A && ch != 0x0D) {
|
||||
xmlData.remove(i, 1);
|
||||
repairAction = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!repairAction) {
|
||||
// we were unable to find the problem
|
||||
return qMakePair(RepairFailed, nullptr);
|
||||
}
|
||||
|
||||
KeePass2RandomStream randomStream(reader.reader()->protectedStreamAlgo());
|
||||
randomStream.init(reader.reader()->streamKey());
|
||||
bool hasError;
|
||||
|
||||
QBuffer buffer(&xmlData);
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
if ((reader.version() & KeePass2::FILE_VERSION_CRITICAL_MASK) < KeePass2::FILE_VERSION_4) {
|
||||
KdbxXmlReader xmlReader(KeePass2::FILE_VERSION_3_1);
|
||||
xmlReader.readDatabase(&buffer, db.data(), &randomStream);
|
||||
hasError = xmlReader.hasError();
|
||||
} else {
|
||||
auto reader4 = reader.reader().staticCast<Kdbx4Reader>();
|
||||
QHash<QString, QByteArray> pool = reader4->binaryPool();
|
||||
KdbxXmlReader xmlReader(KeePass2::FILE_VERSION_4, pool);
|
||||
xmlReader.readDatabase(&buffer, db.data(), &randomStream);
|
||||
hasError = xmlReader.hasError();
|
||||
}
|
||||
|
||||
if (hasError) {
|
||||
return qMakePair(RepairFailed, nullptr);
|
||||
} else {
|
||||
return qMakePair(RepairSuccess, db.take());
|
||||
}
|
||||
}
|
||||
|
||||
QString KeePass2Repair::errorString() const
|
||||
{
|
||||
return m_errorStr;
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2016 Felix Geyer <debfx@fobos.de>
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 or (at your option)
|
||||
* version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef KEEPASSX_KEEPASS2REPAIR_H
|
||||
#define KEEPASSX_KEEPASS2REPAIR_H
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QIODevice>
|
||||
#include <QPair>
|
||||
|
||||
#include "core/Database.h"
|
||||
#include "keys/CompositeKey.h"
|
||||
|
||||
class KeePass2Repair
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(KeePass2Repair)
|
||||
|
||||
public:
|
||||
enum RepairResult
|
||||
{
|
||||
NothingTodo,
|
||||
UnableToOpen,
|
||||
RepairSuccess,
|
||||
RepairFailed
|
||||
};
|
||||
using RepairOutcome = QPair<RepairResult, Database*>;
|
||||
|
||||
RepairOutcome repairDatabase(QIODevice* device, QSharedPointer<const CompositeKey> key);
|
||||
QString errorString() const;
|
||||
|
||||
private:
|
||||
QString m_errorStr;
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_KEEPASS2REPAIR_H
|
Loading…
Add table
Add a link
Reference in a new issue