1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-05-12 13:30:54 +00:00

Compare commits

..

No commits in common. "00116aea8c61d0541328eef5a947f2e8fcb63b35" and "8ec593becc6f3ad7e9a26763916b7b41477537ae" have entirely different histories.

15 changed files with 135 additions and 198 deletions

View File

@ -9,7 +9,7 @@
#include "utils.h"
QDir Git::cloneSetup()
QDir Git::clone_setup()
{
QDir tmp_dir(QStandardPaths::writableLocation( QStandardPaths::CacheLocation).append("/clone"));
@ -20,12 +20,12 @@ QDir Git::cloneSetup()
}
bool Git::cloneTearDown(QDir tmp_dir)
bool Git::clone_tear_down(QDir tmp_dir)
{
return tmp_dir.removeRecursively();
}
bool Git::moveToDestination(QString path, QDir tmp_dir)
bool Git::move_to_destination(QString path, QDir tmp_dir)
{
qDebug() << "Removing password_store " << path;
QDir destination_dir(path);
@ -37,40 +37,42 @@ bool Git::moveToDestination(QString path, QDir tmp_dir)
return dir.rename(tmp_dir.absolutePath(), destination_dir.absolutePath()); // TODO Better error handling
}
bool Git::clone(QString url, QString path, mode_type mode) //, GitPlugin::RepoType type, QString pass)
{
auto v = overload {
[](const Unset & x) { return "Unset"; },
[](const HTTP & x) { return "HTTP"; },
[](const HTTP & x) { return "Unset"; },
[](const HTTPAuth & x) { return "HTTPAuth"; },
[](const SSHAuth & x) { return "SSHAuth"; },
[](const SSHKey & x) { return "SSHKey"; },
};
qInfo() << "Cloning " << url << " to destination " << path << " using " << std::visit(v, mode);
LibGit::instance()->setMode(mode);
auto tmp_dir = this->cloneSetup();
LibGit::instance()->set_mode(mode);
auto tmp_dir = this->clone_setup();
qDebug() << "Cloning " << url << " to tmp dir " << tmp_dir.absolutePath();
auto ret = LibGit::instance()->clone(url, tmp_dir.absolutePath()); // TODO Better error handling
if (ret) {
this->moveToDestination(path, tmp_dir);
this->move_to_destination(path, tmp_dir);
}
this->cloneTearDown(tmp_dir);
LibGit::instance()->setMode(Unset());
this->clone_tear_down(tmp_dir);
LibGit::instance()->set_mode(Unset());
return ret ;
}
bool Git::cloneHttp(QString url, QString path)
bool Git::clone_http(QString url, QString path) //, GitPlugin::RepoType type, QString pass)
{
HTTP mode = {};
return this->clone(url, path, mode);
}
bool Git::cloneHttpPass(QString url, QString path, QString pass)
bool Git::clone_http_pass(QString url, QString path, QString pass)
{
HTTPAuth mode = { pass };
return this->clone(url, path, mode);

View File

@ -7,17 +7,14 @@
#include "libgit.h"
/**
* @brief The Git class is class that provide Git functionnly to clone and update a repo.
*/
class Git : public QObject
{
Q_OBJECT
private:
QDir cloneSetup();
bool moveToDestination(QString path, QDir tmp_dir);
bool cloneTearDown(QDir tmp_dir);
QDir clone_setup();
bool move_to_destination(QString path, QDir tmp_dir);
bool clone_tear_down(QDir tmp_dir);
bool clone(QString url, QString path, mode_type mode);
@ -25,8 +22,8 @@ public:
Git() = default;
~Git() override = default;
Q_INVOKABLE bool cloneHttp(QString url, QString path);
Q_INVOKABLE bool cloneHttpPass(QString url, QString path, QString pass);
Q_INVOKABLE bool clone_http(QString url, QString path);
Q_INVOKABLE bool clone_http_pass(QString url, QString path, QString pass);
// Q_INVOKABLE bool clone_ssh_pass(QString url, QString path, QString pass);
// Q_INVOKABLE bool clone_ssh_key(QString url, QString path, QString pub_key, QString priv_key, QString passphrase);
// Q_INVOKABLE bool update(QUrl url, QString path);

View File

@ -21,13 +21,13 @@ LibGit::~LibGit()
git_libgit2_shutdown();
}
void LibGit::setMode(mode_type type)
void LibGit::set_mode(mode_type type)
{
this->mode = type;
}
int LibGit::credentialsCB(git_cred **out, const char *url, const char *username_from_url,
unsigned int allowed_types, void *payload)
int LibGit::credentials_cb(git_cred **out, const char *url, const char *username_from_url,
unsigned int allowed_types, void *payload)
{
// TODO : More precise Error Handling for UI
auto instance = LibGit::instance();
@ -73,7 +73,7 @@ bool LibGit::clone(QString url, QString path)
git_repository *repo = NULL;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
opts.fetch_opts.callbacks.credentials = *credentialsCB;
opts.fetch_opts.callbacks.credentials = *credentials_cb;
int ret = git_clone(&repo, url.toLocal8Bit().data(), path.toLocal8Bit().data(), &opts);
if (ret != 0) {

View File

@ -26,8 +26,8 @@ private:
mode_type mode;
static int credentialsCB(git_cred **out, const char *url, const char *username_from_url,
unsigned int allowed_types, void *payload);
static int credentials_cb(git_cred **out, const char *url, const char *username_from_url,
unsigned int allowed_types, void *payload);
public:
~LibGit();
@ -40,7 +40,7 @@ public:
void operator=(LibGit const &) = delete;
bool clone(QString url, QString path);
void setMode(mode_type type);
void set_mode(mode_type type);
};
#endif

View File

@ -137,7 +137,6 @@ QPair<Error, QString> Gpg::decrypt(QByteArray cipherText)
auto decResult = job->exec(cipherText, plain_text);
delete job;
delete provider;
if (decResult.error()) {
qWarning() << "something gone wrong on decrypt";
@ -246,6 +245,9 @@ Error Gpg::importKeysFromFile(QString path)
auto job = openpgp()->importJob();
auto ctx = ImportJob::context(job);
auto provider = new UTPassphraseProvider;
ctx->setPassphraseProvider(provider);
ctx->setPinentryMode(Context::PinentryLoopback);
auto result = job->exec(file.readAll());
qDebug() << "numImported" << result.numImported();
@ -256,6 +258,7 @@ Error Gpg::importKeysFromFile(QString path)
file.close();
delete job;
delete provider;
if (result.error()) {
qWarning() << "Import go wrong";

View File

@ -12,7 +12,7 @@ Pass::Pass(): m_password_store (QStandardPaths::writableLocation(
QStandardPaths::AppDataLocation).append("/.password-store"))
{}
void Pass::initialize(QObject *window)
void Pass::init(QObject *window)
{
if (!window) {
qFatal("window is invalid. Abording.");
@ -27,7 +27,7 @@ void Pass::initialize(QObject *window)
qInfo() << "Password Store is :" << m_password_store;
}
void Pass::show(QUrl url)
void Pass::decrypt(QUrl url)
{
qInfo() << "Decrypting";
auto decrypt_ret = Gpg::instance()->decryptFromFile(url.toLocalFile());
@ -39,26 +39,26 @@ void Pass::show(QUrl url)
emit decryptCanceled();
} else {
qInfo() << "Decrypt OK";
emit decrypted(url.fileName(), decrypt_ret.second);
emit decrypted(decrypt_ret.second);
}
}
bool Pass::deleteGPGKey(QString id)
bool Pass::gpgDeleteKeyId(QString id)
{
qInfo() << "Deleting Key id " << id;
return !Gpg::instance()->deleteKeyId(id);
}
bool Pass::importGPGKey(QUrl url)
bool Pass::gpgImportKeyFromFile(QUrl url)
{
qInfo() << "Importing Key from " << url;
return !Gpg::instance()->importKeysFromFile(url.toLocalFile());
}
QVariant Pass::getAllGPGKeys()
QVariant Pass::gpgGetAllKeysModel()
{
qInfo() << "Getting all key form gpg ";
return QVariant::fromValue(PassKeyModel::keysToPassKey(
Gpg::instance()->getAllKeys().second)); // TODO Error handling
return QVariant::fromValue(PassKeyModel::keysToPassKeyQObjectList(
Gpg::instance()->getAllKeys().second));
}

View File

@ -15,7 +15,7 @@ private:
QString m_password_store;
signals:
void decrypted(QString name, QString text);
void decrypted(QString text);
void decryptCanceled();
void decryptFailed();
@ -28,11 +28,11 @@ public:
return m_password_store;
}
Q_INVOKABLE void initialize(QObject *window);
Q_INVOKABLE void show(QUrl url);
Q_INVOKABLE bool deleteGPGKey(QString id);
Q_INVOKABLE bool importGPGKey(QUrl url);
Q_INVOKABLE QVariant getAllGPGKeys();
Q_INVOKABLE void init(QObject *window);
Q_INVOKABLE void decrypt(QUrl url);
Q_INVOKABLE bool gpgDeleteKeyId(QString id);
Q_INVOKABLE bool gpgImportKeyFromFile(QUrl url);
Q_INVOKABLE QVariant gpgGetAllKeysModel();
};
#endif

View File

@ -6,84 +6,69 @@
using namespace GpgME;
class UserIdModel : public QObject
{
Q_OBJECT
Q_PROPERTY(QString uid READ uid MEMBER m_uid CONSTANT)
Q_PROPERTY(QString name READ name MEMBER m_name CONSTANT)
Q_PROPERTY(QString email READ email MEMBER m_email CONSTANT)
UserID m_user_id;
public:
UserIdModel(UserID key):
m_user_id(key)
{};
QString uid() const
{
return QString::fromUtf8(m_user_id.id());
};
QString name() const
{
return QString::fromUtf8(m_user_id.name());
};
QString email() const
{
return QString::fromUtf8(m_user_id.email());
};
};
class PassKeyModel : public QObject
{
Q_OBJECT
Q_PROPERTY(QString uid READ uid MEMBER m_uid CONSTANT)
Q_PROPERTY(QList<QObject *> userIds READ userIds MEMBER m_user_ids CONSTANT)
Q_PROPERTY(bool isSecret READ isSecret MEMBER m_secret CONSTANT)
Q_PROPERTY(bool isExpired READ isExpired MEMBER m_expired CONSTANT)
Q_PROPERTY(QString uid READ uid WRITE setUid NOTIFY uidChanged MEMBER m_uid)
Q_PROPERTY(bool secret READ secret WRITE setSecret NOTIFY secretChanged MEMBER m_secret)
Q_PROPERTY(bool expired READ expired WRITE setExpired NOTIFY expiredChanged MEMBER m_expired)
QString m_uid;
bool m_secret;
bool m_expired;
Key m_key;
public:
PassKeyModel(Key key):
m_key(key)
PassKeyModel(QString uid, bool secret, bool expired):
m_uid(uid),
m_secret(secret),
m_expired(expired)
{};
static QList<QObject *> keysToPassKey(std::vector<Key> keys)
PassKeyModel(Key key):
PassKeyModel(QString::fromUtf8(key.keyID()), key.hasSecret(), key.isExpired())
{};
static QList<QObject *> keysToPassKeyQObjectList(std::vector<Key> keys)
{
QList<QObject *> ret;
std::for_each(keys.begin(), keys.end(), [&ret](Key k) {
ret.append(new PassKeyModel(k));
QList<QObject *> r;
std::for_each(keys.begin(), keys.end(), [&r](Key k) {
r.append(new PassKeyModel(k));
});
return ret;
return r;
};
QString uid() const
{
return QString::fromUtf8(m_key.keyID());
return m_uid;
};
bool secret() const
{
return m_secret;
};
bool expired() const
{
return m_expired;
};
QList<QObject *> userIds() const
void setUid(QString uid)
{
auto user_ids = m_key.userIDs();
QList<QObject *> ret;
std::for_each(user_ids.begin(), user_ids.end(), [&ret](UserID k) {
ret.append(new UserIdModel(k));
});
return ret;
};
m_uid = uid;
emit uidChanged(uid);
}
void setSecret(bool secret)
{
m_secret = secret;
emit secretChanged(secret);
}
void setExpired(bool expired)
{
m_expired = expired;
emit expiredChanged(expired);
}
bool isSecret() const
{
return m_key.hasSecret();
};
bool isExpired() const
{
return m_key.hasSecret();
};
signals:
void uidChanged(QString);
void secretChanged(bool);
void expiredChanged(bool);
};
#endif

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: utpass.qrouland\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-14 13:57+0100\n"
"POT-Creation-Date: 2025-01-13 20:49+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,7 +17,7 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: ../qml/components/FileDir.qml:59
#: ../qml/components/FileDir.qml:72
msgid "Decryption failed !"
msgstr ""
@ -47,7 +47,7 @@ msgid "Ok"
msgstr ""
#: ../qml/dialogs/PassphraseDialog.qml:41
#: ../qml/dialogs/SimpleValidationDialog.qml:34
#: ../qml/dialogs/SimpleValidationDialog.qml:33
msgid "Cancel"
msgstr ""
@ -83,18 +83,18 @@ msgstr ""
msgid "Info"
msgstr ""
#: ../qml/pages/PasswordList.qml:22
#: ../qml/pages/PasswordList.qml:26
msgid ""
"No password found<br>You can import a password store by cloning or importing "
"a zip in the settings"
msgstr ""
#: ../qml/pages/PasswordList.qml:61
#: ../qml/pages/PasswordList.qml:65
msgid "Back"
msgstr ""
#: ../qml/pages/PasswordList.qml:68 ../qml/pages/headers/MainHeader.qml:9
#: ../qml/pages/headers/StackHeader.qml:9 UTPass.desktop.in.h:1
#: ../qml/pages/headers/MainHeader.qml:9 ../qml/pages/headers/StackHeader.qml:9
#: UTPass.desktop.in.h:1
msgid "UTPass"
msgstr ""
@ -125,8 +125,7 @@ msgid ""
msgstr ""
#: ../qml/pages/settings/ImportGitClone.qml:91
#: ../qml/pages/settings/ImportZip.qml:62
#: ../qml/pages/settings/InfoKeys.qml:122
#: ../qml/pages/settings/ImportZip.qml:62 ../qml/pages/settings/InfoKeys.qml:77
msgid "Yes"
msgstr ""
@ -168,31 +167,27 @@ msgstr ""
msgid "Zip Password Store Import"
msgstr ""
#: ../qml/pages/settings/InfoKeys.qml:39
msgid "Key ID :"
#: ../qml/pages/settings/InfoKeys.qml:41
msgid "Key id : %1"
msgstr ""
#: ../qml/pages/settings/InfoKeys.qml:73
msgid "Users IDs : "
msgstr ""
#: ../qml/pages/settings/InfoKeys.qml:99
#: ../qml/pages/settings/InfoKeys.qml:54
msgid "Delete this key"
msgstr ""
#: ../qml/pages/settings/InfoKeys.qml:121
#: ../qml/pages/settings/InfoKeys.qml:76
msgid "You're are about to delete<br>%1<br>Continue ?"
msgstr ""
#: ../qml/pages/settings/InfoKeys.qml:139
#: ../qml/pages/settings/InfoKeys.qml:94
msgid "Key removal failed !"
msgstr ""
#: ../qml/pages/settings/InfoKeys.qml:148
#: ../qml/pages/settings/InfoKeys.qml:103
msgid "Key successfully deleted !"
msgstr ""
#: ../qml/pages/settings/InfoKeys.qml:159
#: ../qml/pages/settings/InfoKeys.qml:114
msgid "Info Keys"
msgstr ""

View File

@ -13,7 +13,7 @@ MainView {
signal responsePassphraseDialog(bool canceled, string passphrase)
function initPass(rootView) {
Pass.initialize(rootView);
Pass.init(rootView);
pageStack.push(Qt.resolvedUrl("pages/PasswordList.qml"));
}

View File

@ -8,6 +8,10 @@ import QtQuick 2.4
Component {
Rectangle {
id: fileDir
property string activePasswordName
anchors.right: parent.right
anchors.left: parent.left
height: units.gu(5)
@ -36,9 +40,18 @@ Component {
if (fileIsDir) {
folderModel.folder = folderModel.folder + "/" + fileName;
backAction.visible = true;
passwordListHeader.title = fileName;
} else {
Pass.show(folderModel.folder + "/" + fileName);
fileDir.activePasswordName = fileBaseName;
Pass.onDecrypted.connect(function(text) {
pageStack.push(Qt.resolvedUrl("../pages/Password.qml"), {
"plainText": text,
"title": fileDir.activePasswordName
});
});
Pass.onDecryptFailed.connect(function() {
PopupUtils.open(passwordPageDecryptError);
});
Pass.decrypt(folderModel.folder + "/" + fileName);
}
}
}

View File

@ -49,11 +49,11 @@ Page {
iconName: "back"
text: "Back"
onTriggered: {
// passwordPage.plainText = "";
// for (var object in objects) {
// object.text = "";
// object.destroy();
// }
passwordPage.plainText = "";
for (var object in objects) {
object.text = "";
object.destroy();
}
pageStack.pop();
}
}

View File

@ -13,15 +13,6 @@ Page {
anchors.fill: parent
Component.onCompleted: {
passwordStorePath = "file:" + Pass.password_store;
Pass.onDecrypted.connect(function(filename, text) {
pageStack.push(Qt.resolvedUrl("../pages/Password.qml"), {
"plainText": text,
"title": filename
});
});
Pass.onDecryptFailed.connect(function() {
PopupUtils.open(passwordPageDecryptError);
});
}
Rectangle {
@ -75,13 +66,9 @@ Page {
visible: false
onTriggered: {
folderModel.folder = folderModel.parentFolder;
console.debug(folderModel.folder);
if (folderModel.rootFolder === folderModel.folder) {
if (folderModel.rootFolder === folderModel.folder)
backAction.visible = false;
passwordListHeader.title = i18n.tr("UTPass");
} else {
passwordListHeader.title = folderModel.folder;
}
}
}
]

View File

@ -28,7 +28,7 @@ Page {
if (importKeyFilePage.activeTransfer.state === ContentTransfer.Charged) {
console.log("Charged");
console.log(importKeyFilePage.activeTransfer.items[0].url);
var status = Pass.importGPGKey(importKeyFilePage.activeTransfer.items[0].url);
var status = Pass.gpgImportKeyFromFile(importKeyFilePage.activeTransfer.items[0].url);
Utils.rmFile(importKeyFilePage.activeTransfer.items[0].url);
if (status)
PopupUtils.open(dialogImportKeyPageSucess);

View File

@ -18,7 +18,7 @@ Page {
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.left: parent.left
model: Pass.getAllGPGKeys()
model: Pass.gpgGetAllKeysModel()
delegate: Grid {
columns: 1
@ -33,60 +33,15 @@ Page {
}
Text {
id: uidKey
width: parent.width
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: i18n.tr('Key ID :')
text: i18n.tr('Key id : %1').arg(model.modelData.uid)
color: theme.palette.normal.backgroundText
}
Text {
width: parent.width
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: model.modelData.uid
color: theme.palette.normal.backgroundText
}
Rectangle {
width: parent.width
height: units.gu(1)
color: theme.palette.normal.background
}
ListModel {
id: userIdsModel
Component.onCompleted: {
for (var i = 0; i < model.modelData.userIds.length; ++i) {
userIdsModel.append({
"model": model.modelData.userIds[i]
});
}
}
}
Text {
width: parent.width
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: i18n.tr('Users IDs : ')
color: theme.palette.normal.backgroundText
}
Repeater {
model: userIdsModel
Text {
width: parent.width
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: modelData.uid
color: theme.palette.normal.backgroundText
}
}
Rectangle {
width: parent.width
height: units.gu(1)
@ -122,7 +77,7 @@ Page {
continueText: i18n.tr("Yes")
continueColor: theme.palette.normal.negative
onValidated: {
var status = Pass.deleteGPGKey(infoKeysPage.currentKey);
var status = Pass.gpgDeleteKeyId(infoKeysPage.currentKey);
if (status)
PopupUtils.open(infoKeysPageDeleteSuccess);
else
@ -147,7 +102,7 @@ Page {
SuccessDialog {
textSuccess: i18n.tr("Key successfully deleted !")
onDialogClosed: {
infoKeysListView.model = Pass.getAllGPGKeys();
infoKeysListView.model = Pass.gpgGetAllKeysModel();
}
}