sailfish-safe

Sailfish frontend for safe(1)
git clone git://git.z3bra.org/sailfish-safe.git
Log | Files | Refs | README | LICENSE

commit 864a07f398fc313613b2a9fc589f53a90129f5b1
parent c35f952e28e75d02cd12522f7e8c1989ece5ea63
Author: Willy Goiffon <contact@z3bra.org>
Date:   Tue, 13 Jul 2021 10:58:08 +0200

Replace pass(1)+gpg(1) with safe(1)

Diffstat:
Mharbour-passilic.pro | 2++
Mqml/pages/PasswordListPage.qml | 2+-
Msrc/passwordprovider.cpp | 42+++++++++++++++++++-----------------------
Msrc/passwordsmodel.cpp | 28++++++++--------------------
Mtranslations/harbour-passilic.ts | 2+-
5 files changed, 31 insertions(+), 45 deletions(-)

diff --git a/harbour-passilic.pro b/harbour-passilic.pro @@ -18,6 +18,7 @@ INCLUDEPATH += 3rdparty/kitemmodels/ SOURCES += \ src/gpg.cpp \ + src/safe.cpp \ src/main.cpp \ src/abbreviations.cpp \ src/imageprovider.cpp \ @@ -33,6 +34,7 @@ SOURCES += \ HEADERS += \ src/abbreviations.h \ src/gpg.h \ + src/safe.h \ src/imageprovider.h \ src/passwordfiltermodel.h \ src/passwordprovider.h \ diff --git a/qml/pages/PasswordListPage.qml b/qml/pages/PasswordListPage.qml @@ -46,7 +46,7 @@ Page { header: PageHeader { id: pageHeader width: parent.width - title: passwordListPage.currentPath === "" ? qsTr("Passilic") : passwordListPage.currentPath + title: passwordListPage.currentPath === "" ? qsTr("Safe") : passwordListPage.currentPath } GlobalPullDownMenu { diff --git a/src/passwordprovider.cpp b/src/passwordprovider.cpp @@ -19,7 +19,7 @@ #include "passwordprovider.h" #include "settings.h" -#include "gpg.h" +#include "safe.h" #include <QClipboard> #include <QGuiApplication> @@ -31,7 +31,8 @@ namespace { static const auto PasswordTimeoutUpdateInterval = 100; -#define PASSWORD_STORE_DIR "PASSWORD_STORE_DIR" +#define SAFE_DIR "SAFE_DIR" +#define SAFE_SOCK "SAFE_SOCK" } @@ -138,35 +139,30 @@ void PasswordProvider::cancel() void PasswordProvider::setPassphrase(const QString &passphrase) { - const QString root = qEnvironmentVariableIsSet(PASSWORD_STORE_DIR) - ? QString::fromUtf8(qgetenv(PASSWORD_STORE_DIR)) - : QStringLiteral("%1/.password-store").arg(QDir::homePath()); - QFile gpgIdFile(root + QStringLiteral("/.gpg-id")); - if (!gpgIdFile.exists()) { - qWarning() << "Missing .gpg-id file (" << gpgIdFile.fileName() << ")"; + const QString root = qEnvironmentVariableIsSet(SAFE_DIR) + ? QString::fromUtf8(qgetenv(SAFE_DIR)) + : QStringLiteral("%1/.safe.d").arg(QDir::homePath()); + + const QString socket = qEnvironmentVariableIsSet(SAFE_SOCK) + ? QString::fromUtf8(qgetenv(SAFE_SOCK)) + : QStringLiteral("%1/.safe.sock").arg(QDir::homePath()); + + QFile safeAgentSocket(socket); + if (!safeAgentSocket.exists()) { + qWarning() << "Missing socket file (" << safeAgentSocket.fileName() << ")"; return; } - gpgIdFile.open(QIODevice::ReadOnly); - const auto gpgId = QString::fromUtf8(gpgIdFile.readAll()).trimmed(); - gpgIdFile.close(); - - auto *job = Gpg::decrypt(mPath, Gpg::Key{gpgId}, passphrase); - connect(job, &Gpg::DecryptTask::finished, + /* + auto *job = Safe::unlock(passphrase); + connect(job, &Safe::UnlockTask::finished, this, [this, job]() { if (job->error()) { - qWarning() << "Failed to decrypt password: " << job->errorString(); + qWarning() << "Failed to unlock safe: " << job->errorString(); setError(job->errorString()); return; } - - const QStringList lines = job->content().split(QLatin1Char('\n')); - if (lines.empty()) { - qWarning() << "Failed to decrypt password or file empty"; - setError(tr("Failed to decrypt password")); - } else { - setPassword(lines[0]); - } }); + */ } void PasswordProvider::removePasswordFromClipboard(const QString &password) diff --git a/src/passwordsmodel.cpp b/src/passwordsmodel.cpp @@ -19,7 +19,7 @@ #include "passwordsmodel.h" #include "passwordprovider.h" -#include "gpg.h" +#include "safe.h" #include <QDir> #include <QDebug> @@ -27,7 +27,7 @@ #include <QTemporaryFile> #include <QFile> -#define PASSWORD_STORE_DIR "PASSWORD_STORE_DIR" +#define SAFE_DIR "SAFE_DIR" class PasswordsModel::Node { @@ -56,9 +56,6 @@ public: return name; } else { QString fileName = name; - if (type == PasswordsModel::PasswordEntry) { - fileName += QStringLiteral(".gpg"); - } return parent->path() + QLatin1Char('/') + fileName; } } @@ -96,10 +93,10 @@ PasswordsModel::PasswordsModel(QObject *parent) : QAbstractItemModel(parent) , mWatcher(this) { - if (qEnvironmentVariableIsSet(PASSWORD_STORE_DIR)) { - mPassStore = QDir(QString::fromUtf8(qgetenv(PASSWORD_STORE_DIR))); + if (qEnvironmentVariableIsSet(SAFE_DIR)) { + mPassStore = QDir(QString::fromUtf8(qgetenv(SAFE_DIR))); } else { - mPassStore = QDir(QStringLiteral("%1/.password-store").arg(QDir::homePath())); + mPassStore = QDir(QStringLiteral("%1/.safe.d").arg(QDir::homePath())); } // FIXME: Try to figure out what has actually changed and update the model @@ -212,7 +209,7 @@ void PasswordsModel::populate() void PasswordsModel::populateDir(const QDir& dir, Node *parent) { mWatcher.addPath(dir.absolutePath()); - auto entries = dir.entryInfoList({ QStringLiteral("*.gpg") }, QDir::Files, QDir::NoSort); + auto entries = dir.entryInfoList({ QStringLiteral("*") }, QDir::Files, QDir::NoSort); Q_FOREACH (const auto &entry, entries) { new Node(entry.completeBaseName(), PasswordEntry, parent); } @@ -238,22 +235,13 @@ void PasswordsModel::addPassword(const QModelIndex &parent, const QString &name, QString safeName = name; safeName.replace(QLatin1Char('/'), QLatin1Char(' ')); - QFile gpgIdFile(mRoot->path() + QStringLiteral("/.gpg-id")); - if (!gpgIdFile.exists()) { - qWarning() << "Missing .gpg-id file (" << gpgIdFile.fileName() << ")"; - return; - } - gpgIdFile.open(QIODevice::ReadOnly); - const auto gpgId = QString::fromUtf8(gpgIdFile.readAll()).trimmed(); - gpgIdFile.close(); - QString data = password; if (!extras.isEmpty()) { data += QStringLiteral("\n%1").arg(extras); } - auto *task = Gpg::encrypt(QStringLiteral("%1/%2.gpg").arg(node->path(), safeName), Gpg::Key{gpgId}, data); - connect(task, &Gpg::EncryptTask::finished, + auto *task = Safe::encrypt(QStringLiteral("%1/%2").arg(node->path(), safeName), data); + connect(task, &Safe::EncryptTask::finished, this, [safeName, task]() { if (task->error()) { qWarning() << "Error:" << task->errorString(); diff --git a/translations/harbour-passilic.ts b/translations/harbour-passilic.ts @@ -95,7 +95,7 @@ <context> <name>PasswordListPage</name> <message> - <source>Passilic</source> + <source>Safe</source> <translation type="unfinished"></translation> </message> </context>