libQuotient
A Qt library for building matrix clients
sssshandler.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
2 // SPDX-License-Identifier: LGPL-2.0-or-later
3 
4 #pragma once
5 
6 #include "cryptoutils.h"
7 
8 #include "../connection.h"
9 
10 #include <QtCore/QObject>
11 #include <QtCore/QPointer>
12 
13 namespace Quotient {
14 class QUOTIENT_API SSSSHandler : public QObject
15 {
16  Q_OBJECT
17  Q_PROPERTY(Quotient::Connection* connection READ connection WRITE setConnection NOTIFY connectionChanged)
18 
19 public:
20  enum Error
21  {
22  WrongKeyError,
23  NoKeyError,
24  DecryptionError,
25  InvalidSignatureError,
26  UnsupportedAlgorithmError,
27  };
28  Q_ENUM(Error)
29 
30  using QObject::QObject;
31 
32  //! \brief Unlock the secret backup from the given passprhase
33  Q_INVOKABLE void unlockSSSSWithPassphrase(const QString& passphrase);
34 
35  //! \brief Unlock the secret backup by requesting the decryption keys from other devices
36  Q_INVOKABLE void unlockSSSSFromCrossSigning();
37 
38  //! \brief Unlock the secret backup from the given security key
39  Q_INVOKABLE void unlockSSSSFromSecurityKey(const QString& encodedKey);
40 
41  Connection* connection() const;
42  void setConnection(Connection* connection);
43 
44 Q_SIGNALS:
45  void keyBackupUnlocked();
46  void error(Error error);
47  void connectionChanged();
48 
49  //! \brief Emitted after keys are loaded
50  void finished();
51 
52 private:
53  QPointer<Connection> m_connection;
54 
55  //! \brief Decrypt the key with this name from the account data
56  QByteArray decryptKey(event_type_t keyType, const QString& defaultKey, key_view_t decryptionKey);
57 
58  void loadMegolmBackup(const QByteArray& megolmDecryptionKey);
59  struct UnlockData;
60  void unlockAndLoad(const UnlockData& unlockData, key_view_t decryptingKey);
61 };
62 } // namespace Quotient