1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-02-11 15:07:16 +00:00

258 lines
7.3 KiB
C
Raw Normal View History

2019-09-20 21:29:39 +02:00
#ifndef PASS_H
#define PASS_H
2025-02-03 18:45:25 +01:00
2025-01-29 16:42:37 +01:00
#include <QDebug>
2019-09-20 21:29:39 +02:00
#include <QObject>
#include <QUrl>
#include <QVariant>
2025-01-29 16:42:37 +01:00
#include <QSemaphore>
2025-02-03 18:45:25 +01:00
#include <memory>
2025-01-29 16:42:37 +01:00
extern "C" {
#include <rnp/rnp.h>
}
2025-02-03 18:45:25 +01:00
#include "passkeyringmodel.h"
2025-01-15 23:40:35 +01:00
/**
* @class Pass
* @brief A class for managing password storage using GPG encryption.
*
* This class provides functionalities for interacting with password storage, including
* storing, showing, importing, and deleting passwords securely using GPG encryption.
*/
2019-09-20 21:29:39 +02:00
class Pass : public QObject
{
Q_OBJECT
2025-02-04 15:51:47 +01:00
Q_PROPERTY(QString password_store MEMBER m_password_store WRITE set_password_store )
Q_PROPERTY(QString gpg_home MEMBER m_gpg_home WRITE set_gpg_home )
2025-01-10 13:48:38 +01:00
private slots:
2025-01-15 23:40:35 +01:00
/**
* @brief Slot to handle the result of a GPG decryption operation (to show password).
* @param err The error that occurred during the operation.
* @param plain_text The decrypted plain text (password).
*/
2025-02-03 17:48:30 +01:00
void slotShowError(rnp_result_t err);
void slotShowSucceed(QString encrypted_file_path, QString plain_text);
2025-01-15 23:40:35 +01:00
2025-02-03 21:46:21 +01:00
void slotDeleteGPGKeyError(rnp_result_t err);
void slotDeleteGPGKeySucceed();
2025-01-15 23:40:35 +01:00
/**
2025-01-29 16:42:37 +01:00
* @brief Slot to handle the error result of a GPG key import operation.
2025-01-15 23:40:35 +01:00
* @param err The error that occurred during the operation.
*/
2025-01-29 16:42:37 +01:00
void slotImportGPGKeyError(rnp_result_t err);
2025-01-15 23:40:35 +01:00
2025-01-29 16:42:37 +01:00
/**
* @brief Slot to handle the succeed result of a GPG key import operation.
*/
void slotImportGPGKeySucceed();
2025-01-15 23:40:35 +01:00
/**
* @brief Slot to handle the result of retrieving all GPG keys.
* @param err The error that occurred during the operation.
*/
void slotGetAllGPGKeysError(rnp_result_t err);
/**
* @brief Slot to handle the succeed result of a GPG key get all keys operation.
*/
2025-02-01 13:45:55 +01:00
void slotGetAllGPGKeysSucceed(QList<QJsonDocument> result);
2019-09-20 21:29:39 +02:00
2025-01-20 14:46:47 +01:00
/**
* @brief Slot to handle the result of a delete Password Store operation.
* @param err True if an error occurred during the operation.
*/
2025-02-03 21:46:21 +01:00
void slotDeletePasswordStoreResult(bool err);
2025-01-20 14:46:47 +01:00
2019-09-20 21:29:39 +02:00
signals:
2025-01-15 23:40:35 +01:00
// GPG-related signals
/**
* @brief Emitted when a GPG key is successfully deleted.
*/
void deleteGPGKeySucceed();
2025-01-15 23:40:35 +01:00
/**
* @brief Emitted when a GPG key deletion fails.
* @param message The error message describing the failure.
*/
void deleteGPGKeyFailed(QString message);
2025-01-15 23:40:35 +01:00
/**
* @brief Emitted when a GPG key is successfully imported.
*/
void importGPGKeySucceed();
2025-01-15 23:40:35 +01:00
/**
* @brief Emitted when a GPG key import fails.
* @param message The error message describing the failure.
*/
void importGPGKeyFailed(QString message);
2025-01-15 23:40:35 +01:00
/**
* @brief Emitted when all GPG keys are successfully retrieved.
* @param keys_info The list of retrieved keys.
*/
2025-01-30 22:46:46 +01:00
void getAllGPGKeysSucceed(QObject* keys_info);
2025-01-15 23:40:35 +01:00
/**
* @brief Emitted when retrieving GPG keys fails.
* @param message The error message describing the failure.
*/
void getAllGPGKeysFailed(QString message);
2025-01-15 23:40:35 +01:00
// Pass-related signals
/**
* @brief Emitted to propagate passphrase dialog response.
* @param cancel Whether the dialog was cancelled.
* @param passphrase The passphrase entered, if not cancelled.
*/
void responsePassphraseDialogPropagate(bool cancel, QString passphrase);
2025-01-15 23:40:35 +01:00
/**
* @brief Emitted when a password is successfully retrieved and shown.
* @param name The name of the password (e.g., service).
* @param text The password text.
*/
void showSucceed(QString name, QString text);
void lsSucceed(QList<QString>);
2025-01-15 23:40:35 +01:00
/**
* @brief Emitted when showing a password fails.
* @param message The error message describing the failure.
*/
void showFailed(QString message);
2025-01-17 10:40:54 +01:00
/**
* @brief Emitted hen showing a password cancelled.
*/
void showCancelled();
2025-01-20 14:46:47 +01:00
/**
* @brief Emitted when the password store is successfully deleted.
*/
void deletePasswordStoreSucceed();
/**
* @brief Emitted when deleting the password store fails.
* @param message The error message describing the failure.
*/
void deletePasswordStoreFailed(QString message);
private:
2025-01-15 23:40:35 +01:00
QString m_password_store; /**< The path to the password store. */
2025-01-29 16:42:37 +01:00
QString m_gpg_home; /**< The path to the gpg home. */
2025-02-03 21:46:21 +01:00
std::unique_ptr<PassKeyringModel>
m_keyring_model; /**< Meta data on the keyring uid, name, secrecy ... of the availble keys. */
2025-02-03 17:48:30 +01:00
rnp_password_cb m_passphrase_provider; /**< Pointer on passphrase povider for operations using secret keys. */
2025-01-15 23:40:35 +01:00
std::unique_ptr<QSemaphore> m_sem; /**< Semaphore for managing concurrent operations. */
2019-09-20 21:29:39 +02:00
/**
* @brief Initialize gpg home.
*/
void initGpgHome();
/**
* @brief Initialize password store.
*/
void initPasswordStore();
void lsJob();
2019-09-20 21:29:39 +02:00
public:
2025-01-15 23:40:35 +01:00
/**
2025-01-20 15:46:57 +01:00
* @brief Constructs the Pass object.
2025-01-15 23:40:35 +01:00
*/
2019-09-20 21:29:39 +02:00
Pass();
2025-01-15 23:40:35 +01:00
2025-01-29 16:42:37 +01:00
/**
* @brief Set the path to the password store.
* @param The path to the password store.
*/
void set_password_store(QString password_store)
{
qInfo() << "[Pass] Password Store changed to :" << password_store;
2025-01-29 16:42:37 +01:00
this->m_password_store = password_store;
2025-01-15 23:40:35 +01:00
};
2025-01-10 13:48:38 +01:00
2025-01-29 16:42:37 +01:00
/**
* @brief Set the path to the gpg hom.
* @param The path to the gpg hom
*/
void set_gpg_home(QString gpg_home)
{
qInfo() << "[Pass] GPG Home changed to :" << gpg_home;
2025-01-29 16:42:37 +01:00
this->m_gpg_home = gpg_home;
};
2025-02-03 17:48:30 +01:00
void set_passphrase_provider(rnp_password_cb passphrase_provider)
2025-01-29 16:42:37 +01:00
{
this->m_passphrase_provider = passphrase_provider;
}
2025-01-15 23:40:35 +01:00
/**
* @brief Initializes the Pass object with the given window.
* @param window The QObject window to interact with.
*/
2025-01-14 08:15:03 +01:00
Q_INVOKABLE void initialize(QObject *window);
2025-01-15 23:40:35 +01:00
// GPG-related methods
/**
2025-01-20 14:46:47 +01:00
* @brief Launch the job to delete the specified GPG key.
2025-01-20 11:23:40 +01:00
* @param key The PassKeyModel to delete.
2025-01-20 14:46:47 +01:00
* @return True if the job was start successfully, false otherwise.
2025-01-15 23:40:35 +01:00
*/
2025-01-20 11:23:40 +01:00
Q_INVOKABLE bool deleteGPGKey(PassKeyModel* key);
2025-01-15 23:40:35 +01:00
/**
2025-01-20 14:46:47 +01:00
* @brief Launch the job to import a GPG key from the given URL.
2025-01-15 23:40:35 +01:00
* @param url The URL to import the GPG key from.
2025-01-20 14:46:47 +01:00
* @return True if the job was start was successfully, false otherwise.
2025-01-15 23:40:35 +01:00
*/
2025-01-14 08:15:03 +01:00
Q_INVOKABLE bool importGPGKey(QUrl url);
2025-01-15 23:40:35 +01:00
/**
2025-01-20 14:46:47 +01:00
* @brief Launch the to retrieve all GPG keys.
* @return True if the job was start was successfully, false otherwise.
2025-01-15 23:40:35 +01:00
*/
Q_INVOKABLE bool getAllGPGKeys();
2025-01-15 23:40:35 +01:00
/**
* @brief Return the response from the passphrase dialog.
* @param cancel Whether the dialog was cancelled.
* @param passphrase The passphrase entered, if not cancelled.
*/
Q_INVOKABLE void responsePassphraseDialog(bool cancel, QString passphrase);
2025-01-15 23:40:35 +01:00
// Password store-related methods
/**
* @brief Get the list of password.
* @return The list of password in the password store.
*/
Q_INVOKABLE bool ls();
2025-01-15 23:40:35 +01:00
/**
2025-01-20 14:46:47 +01:00
* @brief Launch the job to shows the password associated with the specified URL.
2025-01-15 23:40:35 +01:00
* @param url The URL pointing to the password store entry.
2025-01-20 14:46:47 +01:00
* @return True if the job was start successfully, false otherwise.
2025-01-15 23:40:35 +01:00
*/
Q_INVOKABLE bool show(QUrl url);
2025-01-20 14:46:47 +01:00
/**
* @brief Launch the job to delete the password store.
* @return True if if the job was start successfully, false otherwise.
*/
Q_INVOKABLE bool deletePasswordStore();
2019-09-20 21:29:39 +02:00
};
#endif