| 1 |
/* |
| 2 |
* Copyright (C) 2019 Aetf <[email protected]> |
| 3 |
* |
| 4 |
* This program is free software: you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation, either version 2 or (at your option) |
| 7 |
* version 3 of the License. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#ifndef KEEPASSXC_FDOSECRETS_SESSIONCIPHER_H |
| 19 |
#define KEEPASSXC_FDOSECRETS_SESSIONCIPHER_H |
| 20 |
|
| 21 |
#include "fdosecrets/dbus/DBusTypes.h" |
| 22 |
|
| 23 |
#include <QSharedPointer> |
| 24 |
|
| 25 |
namespace Botan |
| 26 |
{ |
| 27 |
class DH_PrivateKey; |
| 28 |
} |
| 29 |
|
| 30 |
namespace FdoSecrets |
| 31 |
{ |
| 32 |
class CipherPair |
| 33 |
{ |
| 34 |
Q_DISABLE_COPY(CipherPair) |
| 35 |
public: |
| 36 |
CipherPair() = default; |
| 37 |
virtual ~CipherPair() = default; |
| 38 |
virtual Secret encrypt(const Secret& input) = 0; |
| 39 |
virtual Secret decrypt(const Secret& input) = 0; |
| 40 |
virtual bool isValid() const = 0; |
| 41 |
virtual QVariant negotiationOutput() const = 0; |
| 42 |
}; |
| 43 |
|
| 44 |
class PlainCipher : public CipherPair |
| 45 |
{ |
| 46 |
Q_DISABLE_COPY(PlainCipher) |
| 47 |
public: |
| 48 |
static constexpr const char Algorithm[] = "plain"; |
| 49 |
|
| 50 |
PlainCipher() = default; |
| 51 |
Secret encrypt(const Secret& input) override |
| 52 |
{ |
| 53 |
return input; |
| 54 |
} |
| 55 |
|
| 56 |
Secret decrypt(const Secret& input) override |
| 57 |
{ |
| 58 |
return input; |
| 59 |
} |
| 60 |
|
| 61 |
bool isValid() const override |
| 62 |
{ |
| 63 |
return true; |
| 64 |
} |
| 65 |
|
| 66 |
QVariant negotiationOutput() const override |
| 67 |
{ |
| 68 |
return QStringLiteral(""); |
| 69 |
} |
| 70 |
}; |
| 71 |
|
| 72 |
class DhIetf1024Sha256Aes128CbcPkcs7 : public CipherPair |
| 73 |
{ |
| 74 |
public: |
| 75 |
static constexpr const char Algorithm[] = "dh-ietf1024-sha256-aes128-cbc-pkcs7"; |
| 76 |
|
| 77 |
explicit DhIetf1024Sha256Aes128CbcPkcs7(const QByteArray& clientPublicKey); |
| 78 |
|
| 79 |
Secret encrypt(const Secret& input) override; |
| 80 |
Secret decrypt(const Secret& input) override; |
| 81 |
bool isValid() const override; |
| 82 |
QVariant negotiationOutput() const override; |
| 83 |
|
| 84 |
bool updateClientPublicKey(const QByteArray& clientPublicKey); |
| 85 |
|
| 86 |
private: |
| 87 |
Q_DISABLE_COPY(DhIetf1024Sha256Aes128CbcPkcs7); |
| 88 |
|
| 89 |
bool m_valid = false; |
| 90 |
QSharedPointer<Botan::DH_PrivateKey> m_privateKey; |
| 91 |
QByteArray m_aesKey; |
| 92 |
}; |
| 93 |
|
| 94 |
} // namespace FdoSecrets |
| 95 |
|
| 96 |
#endif // KEEPASSXC_FDOSECRETS_SESSIONCIPHER_H |