mirror of
https://github.com/QRouland/UTPass.git
synced 2025-07-04 03:02:28 +00:00
Rewrite import key with rnp
This commit is contained in:
14
plugins/Pass/jobs/decryptjob.cpp
Normal file
14
plugins/Pass/jobs/decryptjob.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include "decryptjob.h"
|
||||
|
||||
DecryptJob::DecryptJob(QString path, QString keyfile):
|
||||
m_path(path)
|
||||
{
|
||||
this->setObjectName("DecryptJob");
|
||||
}
|
||||
|
||||
|
||||
void DecryptJob::run()
|
||||
{
|
||||
rnp_input_from_path(&keyfile, "secring.pgp"));
|
||||
qFatal("To be implemented !")
|
||||
}
|
47
plugins/Pass/jobs/decryptjob.h
Normal file
47
plugins/Pass/jobs/decryptjob.h
Normal file
@ -0,0 +1,47 @@
|
||||
#ifndef DECRYPTJOB_H
|
||||
#define DECRYPTJOB_H
|
||||
|
||||
#include <QThread>
|
||||
#include <QDir>
|
||||
|
||||
/**
|
||||
* @class DecryptJob
|
||||
* @brief A class to handle decrypt a file in a separate thread.
|
||||
*
|
||||
*/
|
||||
class DecryptJob : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
/**
|
||||
* @brief The main function that performs the decrypt operation.
|
||||
*
|
||||
* Handles the process of removing recursively a target path.
|
||||
*/
|
||||
void run() override;
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted when the decrypt operation is complete.
|
||||
*
|
||||
* @param err A boolean indicating whether an error occurred during removing.
|
||||
* `true` if an error occurred, `false` if the clone was successful.
|
||||
*/
|
||||
void resultReady(const bool err);
|
||||
|
||||
private:
|
||||
QString m_encryped_file_path; ///< The path of the encrypted file.
|
||||
QString m_keyfile_path; ///< The path of the key file.
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor for the RmJob class.
|
||||
*
|
||||
* Initializes the DecryptJob with the specified file to decrypt.
|
||||
*
|
||||
* @param path Path of the file to decrypt.
|
||||
*/
|
||||
DecryptJob(QString path);
|
||||
};
|
||||
|
||||
#endif // DECRYPTJO_H
|
46
plugins/Pass/jobs/importkeyjob.cpp
Normal file
46
plugins/Pass/jobs/importkeyjob.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <QDebug>
|
||||
#include "importkeyjob.h"
|
||||
extern "C" {
|
||||
#include <rnp/rnp.h>
|
||||
#include <rnp/rnp_err.h>
|
||||
}
|
||||
|
||||
ImportKeyJob::ImportKeyJob(QDir rnp_homedir, QString key_file_path):
|
||||
RnpJob(rnp_homedir),
|
||||
m_key_file_path(key_file_path)
|
||||
{
|
||||
this->setObjectName("DecryptJob");
|
||||
}
|
||||
|
||||
|
||||
void ImportKeyJob::run()
|
||||
{
|
||||
qDebug() << "ImportKeyJob Starting ";
|
||||
rnp_input_t input = NULL;
|
||||
auto ret = rnp_input_from_path(&input, this->m_key_file_path.toLocal8Bit().constData());
|
||||
if(ret == RNP_SUCCESS) {
|
||||
ret = rnp_load_keys(this->m_ffi,
|
||||
"GPG",
|
||||
input,
|
||||
RNP_LOAD_SAVE_PUBLIC_KEYS | RNP_LOAD_SAVE_SECRET_KEYS);
|
||||
}
|
||||
rnp_input_destroy(input);
|
||||
terminateWithError(ret);
|
||||
|
||||
rnp_output_t output = NULL;
|
||||
ret = rnp_output_to_file(&output, this->pubringPath().toLocal8Bit().constData(), RNP_OUTPUT_FILE_RANDOM);
|
||||
if(ret == RNP_SUCCESS) {
|
||||
ret = rnp_save_keys(this->m_ffi, RNP_KEYSTORE_GPG, output, RNP_LOAD_SAVE_SECRET_KEYS);
|
||||
}
|
||||
rnp_output_destroy(output);
|
||||
terminateWithError(ret);
|
||||
|
||||
ret = rnp_output_to_file(&output, this->secringPath().toLocal8Bit().constData(), RNP_OUTPUT_FILE_OVERWRITE);
|
||||
if(ret == RNP_SUCCESS) {
|
||||
ret = rnp_save_keys(this->m_ffi, RNP_KEYSTORE_GPG, output, RNP_LOAD_SAVE_SECRET_KEYS);
|
||||
}
|
||||
rnp_output_destroy(output);
|
||||
terminateWithError(ret);
|
||||
emit resultSuccess();
|
||||
qDebug() << "ImportKeyJob Finished Successfully ";
|
||||
}
|
38
plugins/Pass/jobs/importkeyjob.h
Normal file
38
plugins/Pass/jobs/importkeyjob.h
Normal file
@ -0,0 +1,38 @@
|
||||
#ifndef IMPORTKEYJOB_H
|
||||
#define IMPORTKEYJOB_H
|
||||
|
||||
|
||||
|
||||
#include "rnpjob.h"
|
||||
/**
|
||||
* @class ImportKeyJob
|
||||
* @brief A class to handle import a key file in a separate thread.
|
||||
*
|
||||
*/
|
||||
class ImportKeyJob : public RnpJob
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
/**
|
||||
* @brief The main function that performs the import operation.
|
||||
*
|
||||
* Handles the process of removing recursively a target path.
|
||||
*/
|
||||
void run() override;
|
||||
|
||||
|
||||
private:
|
||||
QString m_key_file_path; ///< The path of the key file to import.
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor for the RmJob class.
|
||||
*
|
||||
* Initializes the ImportKeyJob with the file to import.
|
||||
*
|
||||
* @param path Path of the key file to import.
|
||||
*/
|
||||
ImportKeyJob(QDir rnp_homedir, QString key_file_path);
|
||||
};
|
||||
|
||||
#endif // IMPORTKEYJOB_H
|
42
plugins/Pass/jobs/rnpjob.cpp
Normal file
42
plugins/Pass/jobs/rnpjob.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include <QDebug>
|
||||
|
||||
#include "rnpjob.h"
|
||||
extern "C" {
|
||||
#include <rnp/rnp.h>
|
||||
#include <rnp/rnp_err.h>
|
||||
}
|
||||
|
||||
RnpJob::RnpJob(QDir rnp_homedir):
|
||||
m_rnp_homedir(rnp_homedir)
|
||||
{
|
||||
auto ret = rnp_ffi_create(&this->m_ffi,
|
||||
RNP_KEYSTORE_GPG,
|
||||
RNP_KEYSTORE_GPG);
|
||||
if(ret != RNP_SUCCESS) {
|
||||
qDebug() << "Err : " << ret;
|
||||
qFatal("Error on rnp ffi init!");
|
||||
}
|
||||
}
|
||||
|
||||
RnpJob::~RnpJob(){
|
||||
auto ret = rnp_ffi_destroy(this->m_ffi);
|
||||
if(ret != RNP_SUCCESS) {
|
||||
qDebug() << "Err : " << ret;
|
||||
qFatal("Something go wrong on rnp ffi detroy");
|
||||
}
|
||||
}
|
||||
|
||||
bool RnpJob::passProvider(rnp_ffi_t ffi,
|
||||
void * app_ctx,
|
||||
rnp_key_handle_t key,
|
||||
const char * pgp_context,
|
||||
char buf[],
|
||||
size_t buf_len)
|
||||
{
|
||||
if (strcmp(pgp_context, "protect")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
strncpy(buf, "password", buf_len);
|
||||
return true;
|
||||
}
|
82
plugins/Pass/jobs/rnpjob.h
Normal file
82
plugins/Pass/jobs/rnpjob.h
Normal file
@ -0,0 +1,82 @@
|
||||
#ifndef RNPJOB_H
|
||||
#define RNPJOB_H
|
||||
|
||||
#include <QThread>
|
||||
#include <QDir>
|
||||
extern "C" {
|
||||
#include <rnp/rnp.h>
|
||||
}
|
||||
#include <variant>
|
||||
|
||||
|
||||
#define terminateWithError(ret) \
|
||||
if(ret != RNP_SUCCESS) { \
|
||||
qDebug() << "Err : " << ret; \
|
||||
qDebug() << "Err Msg : " << rnp_result_to_string(ret); \
|
||||
emit resultError(ret); \
|
||||
return; \
|
||||
} \
|
||||
|
||||
/**
|
||||
* @class RmpJob
|
||||
* @brief A class that manages Git-related tasks using libgit2.
|
||||
*
|
||||
* The GitJob class is used abstraction class to perform rnp (opengpg) operations,
|
||||
* such as decrypt, encrypt, key managments operations
|
||||
*/
|
||||
class RnpJob : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
signals:
|
||||
void resultError(const rnp_result_t err);
|
||||
void resultSuccess();
|
||||
|
||||
private:
|
||||
static bool passProvider(rnp_ffi_t ffi,
|
||||
void * app_ctx,
|
||||
rnp_key_handle_t key,
|
||||
const char * pgp_context,
|
||||
char buf[],
|
||||
size_t buf_len);
|
||||
QDir m_rnp_homedir; ///< rmp ffi.
|
||||
|
||||
protected:
|
||||
rnp_ffi_t m_ffi; ///< rmp ffi.
|
||||
|
||||
/**
|
||||
* @brief Get the path to public keys keyring.
|
||||
*
|
||||
* @return The path to public keys keyring
|
||||
*/
|
||||
QString pubringPath() {
|
||||
return this->m_rnp_homedir.filePath("pubring.pgp");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the path to secret keys keyring.
|
||||
*
|
||||
* @return The path to secret keys keyring
|
||||
*/
|
||||
QString secringPath() {
|
||||
return this->m_rnp_homedir.filePath("secring.pgp");
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor for the RnpJob class.
|
||||
*
|
||||
* Initializes the RnpJob instance.
|
||||
*/
|
||||
RnpJob(QDir rnp_homedir);
|
||||
|
||||
/**
|
||||
* @brief Destructor for the RnpJob class.
|
||||
*
|
||||
* Cleans up any resources used by the RnpJob.
|
||||
*/
|
||||
~RnpJob();
|
||||
};
|
||||
|
||||
#endif // RNPJOB_H
|
Reference in New Issue
Block a user