2011-12-21 23:22:07 +01:00
|
|
|
/*
|
2018-11-01 04:27:38 +01:00
|
|
|
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
|
|
|
* Copyright (C) 2011 Felix Geyer <debfx@fobos.de>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2011-12-21 23:22:07 +01:00
|
|
|
|
|
|
|
#ifndef KEEPASSX_FILEKEY_H
|
|
|
|
#define KEEPASSX_FILEKEY_H
|
|
|
|
|
2023-11-19 11:05:21 -06:00
|
|
|
#include <botan/mem_ops.h>
|
2021-04-04 08:56:00 -04:00
|
|
|
#include <botan/secmem.h>
|
2011-12-21 23:22:07 +01:00
|
|
|
|
|
|
|
#include "keys/Key.h"
|
|
|
|
|
|
|
|
class QIODevice;
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
class FileKey : public Key
|
2011-12-21 23:22:07 +01:00
|
|
|
{
|
|
|
|
public:
|
2018-05-13 23:21:43 +02:00
|
|
|
static QUuid UUID;
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
enum Type
|
|
|
|
{
|
2017-12-27 14:20:28 +01:00
|
|
|
None,
|
|
|
|
Hashed,
|
|
|
|
KeePass2XML,
|
2020-12-10 01:28:01 +01:00
|
|
|
KeePass2XMLv2,
|
2017-12-27 14:20:28 +01:00
|
|
|
FixedBinary,
|
|
|
|
FixedBinaryHex
|
|
|
|
};
|
|
|
|
|
2018-05-13 23:21:43 +02:00
|
|
|
FileKey();
|
2021-04-04 08:56:00 -04:00
|
|
|
~FileKey() override = default;
|
2020-12-10 01:28:01 +01:00
|
|
|
bool load(QIODevice* device, QString* errorMsg = nullptr);
|
2015-07-24 18:28:12 +02:00
|
|
|
bool load(const QString& fileName, QString* errorMsg = nullptr);
|
2017-12-26 21:55:08 +01:00
|
|
|
QByteArray rawKey() const override;
|
2022-02-18 10:17:21 -05:00
|
|
|
void setRawKey(const QByteArray& data) override;
|
2017-12-27 14:20:28 +01:00
|
|
|
Type type() const;
|
2020-12-10 01:28:01 +01:00
|
|
|
static void createRandom(QIODevice* device, int size = 128);
|
|
|
|
static void createXMLv2(QIODevice* device, int size = 32);
|
|
|
|
static bool create(const QString& fileName, QString* errorMsg = nullptr);
|
2011-12-21 23:22:07 +01:00
|
|
|
|
2022-02-18 10:17:21 -05:00
|
|
|
QByteArray serialize() const override;
|
|
|
|
void deserialize(const QByteArray& data) override;
|
|
|
|
|
2011-12-21 23:22:07 +01:00
|
|
|
private:
|
2019-02-21 22:28:45 +01:00
|
|
|
static constexpr int SHA256_SIZE = 32;
|
|
|
|
|
2020-12-10 01:28:01 +01:00
|
|
|
bool loadXml(QIODevice* device, QString* errorMsg = nullptr);
|
2011-12-21 23:22:07 +01:00
|
|
|
bool loadBinary(QIODevice* device);
|
|
|
|
bool loadHex(QIODevice* device);
|
|
|
|
bool loadHashed(QIODevice* device);
|
|
|
|
|
2021-04-04 08:56:00 -04:00
|
|
|
Botan::secure_vector<char> m_key;
|
2017-12-27 14:20:28 +01:00
|
|
|
Type m_type = None;
|
2022-02-18 10:17:21 -05:00
|
|
|
QString m_file;
|
2011-12-21 23:22:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // KEEPASSX_FILEKEY_H
|