mirror of
https://github.com/QRouland/UTPass.git
synced 2025-02-11 15:07:16 +00:00
WIP Rewrite get all key with rnp
This commit is contained in:
parent
4bec3dcbc9
commit
74a001eefc
@ -13,8 +13,7 @@ Pass::Pass():
|
|||||||
QStandardPaths::AppDataLocation).append("/.password-store")),
|
QStandardPaths::AppDataLocation).append("/.password-store")),
|
||||||
m_gpg_home (QStandardPaths::writableLocation(
|
m_gpg_home (QStandardPaths::writableLocation(
|
||||||
QStandardPaths::AppDataLocation).append("/.rnp")),
|
QStandardPaths::AppDataLocation).append("/.rnp")),
|
||||||
m_sem(std::unique_ptr<QSemaphore>(new QSemaphore(1))),
|
m_sem(std::unique_ptr<QSemaphore>(new QSemaphore(1)))
|
||||||
m_show_filename(QString())
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -173,6 +172,7 @@ bool Pass::getAllGPGKeys()
|
|||||||
qInfo() << "[Pass] A job is already running";
|
qInfo() << "[Pass] A job is already running";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
this->m_keyring_model = nullptr;
|
||||||
auto job = new GetKeysJob(this->m_gpg_home);
|
auto job = new GetKeysJob(this->m_gpg_home);
|
||||||
QObject::connect(job, &GetKeysJob::resultError, this, &Pass::slotGetAllGPGKeysError);
|
QObject::connect(job, &GetKeysJob::resultError, this, &Pass::slotGetAllGPGKeysError);
|
||||||
QObject::connect(job, &GetKeysJob::resultSuccess, this, &Pass::slotGetAllGPGKeysSucceed);
|
QObject::connect(job, &GetKeysJob::resultSuccess, this, &Pass::slotGetAllGPGKeysSucceed);
|
||||||
@ -184,6 +184,7 @@ bool Pass::getAllGPGKeys()
|
|||||||
void Pass::slotGetAllGPGKeysError(rnp_result_t err)
|
void Pass::slotGetAllGPGKeysError(rnp_result_t err)
|
||||||
{
|
{
|
||||||
qInfo() << "[Pass] Get all GPG Keys Failed";
|
qInfo() << "[Pass] Get all GPG Keys Failed";
|
||||||
|
this->m_keyring_model = nullptr;
|
||||||
emit getAllGPGKeysFailed(rnp_result_to_string(err));
|
emit getAllGPGKeysFailed(rnp_result_to_string(err));
|
||||||
this->m_sem->release(1);
|
this->m_sem->release(1);
|
||||||
}
|
}
|
||||||
@ -191,23 +192,11 @@ void Pass::slotGetAllGPGKeysError(rnp_result_t err)
|
|||||||
void Pass::slotGetAllGPGKeysSucceed(QSet<QString> result)
|
void Pass::slotGetAllGPGKeysSucceed(QSet<QString> result)
|
||||||
{
|
{
|
||||||
qInfo() << "[Pass] Get all GPG Keys Succeed";
|
qInfo() << "[Pass] Get all GPG Keys Succeed";
|
||||||
emit getAllGPGKeysSucceed(result.values());
|
this->m_keyring_model = std::unique_ptr<PassKeyringModel>(new PassKeyringModel(result));
|
||||||
|
emit getAllGPGKeysSucceed(this->m_keyring_model.get());
|
||||||
this->m_sem->release(1);
|
this->m_sem->release(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// void Pass::getAllGPGKeysResult(Error err, std::vector<GpgME::Key> keys_info)
|
|
||||||
// {
|
|
||||||
// qDebug() << "Get GPG keys Result";
|
|
||||||
// if (err) {
|
|
||||||
// qInfo() << "Get GPG Failed";
|
|
||||||
// emit getAllGPGKeysFailed(err.asString());
|
|
||||||
// } else {
|
|
||||||
// qInfo() << "Get GPG Succeed";
|
|
||||||
// emit getAllGPGKeysSucceed(QVariant::fromValue(PassKeyModel::keysToPassKey(keys_info)));
|
|
||||||
// }
|
|
||||||
// this->m_sem->release(1);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void Pass::responsePassphraseDialog(bool cancel, QString passphrase)
|
// void Pass::responsePassphraseDialog(bool cancel, QString passphrase)
|
||||||
// {
|
// {
|
||||||
// qDebug() << "Propagate responsePassphraseDialog";
|
// qDebug() << "Propagate responsePassphraseDialog";
|
||||||
|
@ -97,7 +97,7 @@ signals:
|
|||||||
* @brief Emitted when all GPG keys are successfully retrieved.
|
* @brief Emitted when all GPG keys are successfully retrieved.
|
||||||
* @param keys_info The list of retrieved keys.
|
* @param keys_info The list of retrieved keys.
|
||||||
*/
|
*/
|
||||||
void getAllGPGKeysSucceed(QList<QString> keys_info);
|
void getAllGPGKeysSucceed(QObject* keys_info);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Emitted when retrieving GPG keys fails.
|
* @brief Emitted when retrieving GPG keys fails.
|
||||||
@ -146,9 +146,9 @@ signals:
|
|||||||
private:
|
private:
|
||||||
QString m_password_store; /**< The path to the password store. */
|
QString m_password_store; /**< The path to the password store. */
|
||||||
QString m_gpg_home; /**< The path to the gpg home. */
|
QString m_gpg_home; /**< The path to the gpg home. */
|
||||||
PassphraseProvider *m_passphrase_provider; /**< Semaphore for managing concurrent operations. */
|
std::unique_ptr<PassKeyringModel> m_keyring_model; /**< Meta data on the keyring uid, name, secrecy ... of the availble keys. */
|
||||||
|
PassphraseProvider *m_passphrase_provider; /**< Pointer on passphrase povider for operations using secret keys. */
|
||||||
std::unique_ptr<QSemaphore> m_sem; /**< Semaphore for managing concurrent operations. */
|
std::unique_ptr<QSemaphore> m_sem; /**< Semaphore for managing concurrent operations. */
|
||||||
QString m_show_filename; /**< The filename associated with the password to show. */
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
#ifndef PASSKEYMODEL_H
|
#ifndef PASSKEYMODEL_H
|
||||||
#define PASSKEYMODEL_H
|
#define PASSKEYMODEL_H
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QSet>
|
||||||
#include <gpgme++/key.h>
|
#include <gpgme++/key.h>
|
||||||
|
|
||||||
using namespace GpgME;
|
using namespace GpgME;
|
||||||
@ -69,85 +71,117 @@ public:
|
|||||||
class PassKeyModel : public QObject
|
class PassKeyModel : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(Key key READ key MEMBER m_key CONSTANT)
|
Q_PROPERTY(QString fingeprint READ fingeprint MEMBER m_fingeprint CONSTANT)
|
||||||
Q_PROPERTY(QString uid READ uid CONSTANT)
|
// Q_PROPERTY(QString uid READ uid CONSTANT)
|
||||||
Q_PROPERTY(QList<QObject *> userIds READ userIds CONSTANT)
|
// Q_PROPERTY(QList<QObject *> userIds READ userIds CONSTANT)
|
||||||
Q_PROPERTY(bool isSecret READ isSecret CONSTANT)
|
// Q_PROPERTY(bool isSecret READ isSecret CONSTANT)
|
||||||
Q_PROPERTY(bool isExpired READ isExpired CONSTANT)
|
// Q_PROPERTY(bool isExpired READ isExpired CONSTANT)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Key m_key; /**< The GPG key associated with the model. */
|
QString m_fingeprint; /**< The key fingeprint. */
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Constructs a PassKeyModel for the given GPG key.
|
* @brief Constructs a PassKeyModel for the given GPG key.
|
||||||
* @param key The GPG key to model.
|
* @param key The GPG key to model.
|
||||||
*/
|
*/
|
||||||
PassKeyModel(Key key) : m_key(key) {}
|
PassKeyModel(QString fingeprint) : m_fingeprint(fingeprint) {}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Converts a vector of GPG keys into a list of PassKeyModel objects.
|
QString fingeprint() const
|
||||||
* @param keys The vector of GPG keys to convert.
|
|
||||||
* @return A QList of PassKeyModel objects representing the keys.
|
|
||||||
*/
|
|
||||||
static QList<QObject *> keysToPassKey(std::vector<Key> keys)
|
|
||||||
{
|
{
|
||||||
QList<QObject *> ret;
|
return m_fingeprint;
|
||||||
std::for_each(keys.begin(), keys.end(), [&ret](Key k) {
|
|
||||||
ret.append(new PassKeyModel(k));
|
|
||||||
});
|
|
||||||
return ret;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* @brief Gets the GPG key associated with this model.
|
// * @brief Gets the GPG key associated with this model.
|
||||||
* @return The GPG key.
|
// * @return The GPG key.
|
||||||
*/
|
// */
|
||||||
Key key() const
|
// Key key() const
|
||||||
{
|
// {
|
||||||
return m_key;
|
// return m_key;
|
||||||
};
|
// };
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* @brief Gets the unique identifier (UID) for this GPG key.
|
// * @brief Gets the unique identifier (UID) for this GPG key.
|
||||||
* @return The UID as a QString.
|
// * @return The UID as a QString.
|
||||||
*/
|
// */
|
||||||
QString uid() const
|
// QString uid() const
|
||||||
{
|
// {
|
||||||
return QString::fromUtf8(m_key.keyID());
|
// return QString::fromUtf8(m_key.keyID());
|
||||||
};
|
// };
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* @brief Gets the list of user IDs associated with this GPG key.
|
// * @brief Gets the list of user IDs associated with this GPG key.
|
||||||
* @return A list of UserIdModel objects representing the user IDs.
|
// * @return A list of UserIdModel objects representing the user IDs.
|
||||||
*/
|
// */
|
||||||
QList<QObject *> userIds() const
|
// QList<QObject *> userIds() const
|
||||||
{
|
// {
|
||||||
auto user_ids = m_key.userIDs();
|
// auto user_ids = m_key.userIDs();
|
||||||
QList<QObject *> ret;
|
// QList<QObject *> ret;
|
||||||
std::for_each(user_ids.begin(), user_ids.end(), [&ret](UserID k) {
|
// std::for_each(user_ids.begin(), user_ids.end(), [&ret](UserID k) {
|
||||||
ret.append(new UserIdModel(k));
|
// ret.append(new UserIdModel(k));
|
||||||
});
|
// });
|
||||||
return ret;
|
// return ret;
|
||||||
};
|
// };
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* @brief Checks if the GPG key is a secret key.
|
// * @brief Checks if the GPG key is a secret key.
|
||||||
* @return True if the key is a secret key, false otherwise.
|
// * @return True if the key is a secret key, false otherwise.
|
||||||
*/
|
// */
|
||||||
bool isSecret() const
|
// bool isSecret() const
|
||||||
{
|
// {
|
||||||
return m_key.hasSecret();
|
// return m_key.hasSecret();
|
||||||
};
|
// };
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* @brief Checks if the GPG key is expired.
|
// * @brief Checks if the GPG key is expired.
|
||||||
* @return True if the key is expired, false otherwise.
|
// * @return True if the key is expired, false otherwise.
|
||||||
*/
|
// */
|
||||||
bool isExpired() const
|
// bool isExpired() const
|
||||||
{
|
// {
|
||||||
return m_key.isExpired();
|
// return m_key.isExpired();
|
||||||
};
|
// };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class PassKeyModel
|
||||||
|
* @brief A model representing a GPG key.
|
||||||
|
*
|
||||||
|
* This class encapsulates the properties of a GPG key, including its key ID, associated
|
||||||
|
* user IDs, secret key status, and expiration status. It is used as a model for managing
|
||||||
|
* GPG keys within an application, providing access to the key's data and its associated user IDs.
|
||||||
|
*/
|
||||||
|
class PassKeyringModel : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int length READ length CONSTANT)
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<PassKeyModel*> m_keys;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Constructs a PassKeyModel for the given GPG key.
|
||||||
|
* @param key The GPG key to model.
|
||||||
|
*/
|
||||||
|
PassKeyringModel(QSet<QString> fingeprints)
|
||||||
|
{
|
||||||
|
QSet<QString>::iterator i;
|
||||||
|
for (auto i = fingeprints.begin(), end = fingeprints.end(); i != end; ++i) {
|
||||||
|
this->m_keys.append(new PassKeyModel(*i));
|
||||||
|
}
|
||||||
|
qDebug() << "Test : " << this->m_keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
~PassKeyringModel() {
|
||||||
|
qDeleteAll(this->m_keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
int length() {
|
||||||
|
qDebug() << "Test2 : " << this->m_keys.length();
|
||||||
|
return this->m_keys.length();
|
||||||
|
}
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,7 +8,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: utpass.qrouland\n"
|
"Project-Id-Version: utpass.qrouland\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2025-01-30 16:16+0100\n"
|
"POT-Creation-Date: 2025-01-30 22:45+0100\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
@ -43,7 +43,7 @@ msgid "Ok"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/dialogs/PassphraseDialog.qml:41
|
#: ../qml/dialogs/PassphraseDialog.qml:41
|
||||||
#: ../qml/dialogs/SimpleValidationDialog.qml:29
|
#: ../qml/dialogs/SimpleValidationDialog.qml:28
|
||||||
msgid "Cancel"
|
msgid "Cancel"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@ -112,31 +112,31 @@ msgstr ""
|
|||||||
msgid "Search"
|
msgid "Search"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/settings/DeleteRepo.qml:43
|
#: ../qml/pages/settings/DeleteRepo.qml:42
|
||||||
#: ../qml/pages/settings/Settings.qml:58
|
#: ../qml/pages/settings/Settings.qml:58
|
||||||
msgid "Delete Password Store"
|
msgid "Delete Password Store"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/settings/DeleteRepo.qml:56
|
#: ../qml/pages/settings/DeleteRepo.qml:55
|
||||||
msgid "You're are about to delete<br>the current Password Store.<br>Continue ?"
|
msgid "You're are about to delete<br>the current Password Store.<br>Continue ?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/settings/DeleteRepo.qml:57
|
#: ../qml/pages/settings/DeleteRepo.qml:56
|
||||||
#: ../qml/pages/settings/ImportZip.qml:64
|
#: ../qml/pages/settings/ImportZip.qml:64
|
||||||
#: ../qml/pages/settings/InfoKeys.qml:170
|
#: ../qml/pages/settings/InfoKeys.qml:170
|
||||||
#: ../qml/pages/settings/git/ImportGitClone.qml:56
|
#: ../qml/pages/settings/git/ImportGitClone.qml:56
|
||||||
msgid "Yes"
|
msgid "Yes"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/settings/DeleteRepo.qml:70
|
#: ../qml/pages/settings/DeleteRepo.qml:69
|
||||||
msgid "Password Store removal failed !"
|
msgid "Password Store removal failed !"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/settings/DeleteRepo.qml:79
|
#: ../qml/pages/settings/DeleteRepo.qml:78
|
||||||
msgid "Password Store deleted !"
|
msgid "Password Store deleted !"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/settings/DeleteRepo.qml:91
|
#: ../qml/pages/settings/DeleteRepo.qml:90
|
||||||
#: ../qml/pages/settings/InfoKeys.qml:212
|
#: ../qml/pages/settings/InfoKeys.qml:212
|
||||||
msgid "Info Keys"
|
msgid "Info Keys"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@ -171,11 +171,11 @@ msgstr ""
|
|||||||
msgid "Zip Password Store Import"
|
msgid "Zip Password Store Import"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/settings/InfoKeys.qml:49
|
#: ../qml/pages/settings/InfoKeys.qml:50
|
||||||
msgid "No key found"
|
msgid "No key found"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/settings/InfoKeys.qml:85
|
#: ../qml/pages/settings/InfoKeys.qml:86
|
||||||
msgid "Key ID :"
|
msgid "Key ID :"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user