tReplace pass(1)+gpg(1) with safe(1) - sailfish-safe - Sailfish frontend for safe(1)
 (HTM) git clone git://git.z3bra.org/sailfish-safe.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 864a07f398fc313613b2a9fc589f53a90129f5b1
 (DIR) parent c35f952e28e75d02cd12522f7e8c1989ece5ea63
 (HTM) Author: Willy Goiffon <contact@z3bra.org>
       Date:   Tue, 13 Jul 2021 10:58:08 +0200
       
       Replace pass(1)+gpg(1) with safe(1)
       
       Diffstat:
         M harbour-passilic.pro                |       2 ++
         M qml/pages/PasswordListPage.qml      |       2 +-
         M src/passwordprovider.cpp            |      42 ++++++++++++++-----------------
         M src/passwordsmodel.cpp              |      28 ++++++++--------------------
         M translations/harbour-passilic.ts    |       2 +-
       
       5 files changed, 31 insertions(+), 45 deletions(-)
       ---
 (DIR) diff --git a/harbour-passilic.pro b/harbour-passilic.pro
       t@@ -18,6 +18,7 @@ INCLUDEPATH += 3rdparty/kitemmodels/
        
        SOURCES += \
            src/gpg.cpp \
       +    src/safe.cpp \
            src/main.cpp \
            src/abbreviations.cpp \
            src/imageprovider.cpp \
       t@@ -33,6 +34,7 @@ SOURCES += \
        HEADERS += \
            src/abbreviations.h \
            src/gpg.h \
       +    src/safe.h \
            src/imageprovider.h \
            src/passwordfiltermodel.h \
            src/passwordprovider.h \
 (DIR) diff --git a/qml/pages/PasswordListPage.qml b/qml/pages/PasswordListPage.qml
       t@@ -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 {
 (DIR) diff --git a/src/passwordprovider.cpp b/src/passwordprovider.cpp
       t@@ -19,7 +19,7 @@
        
        #include "passwordprovider.h"
        #include "settings.h"
       -#include "gpg.h"
       +#include "safe.h"
        
        #include <QClipboard>
        #include <QGuiApplication>
       t@@ -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"
        
        }
        
       t@@ -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)
 (DIR) diff --git a/src/passwordsmodel.cpp b/src/passwordsmodel.cpp
       t@@ -19,7 +19,7 @@
        
        #include "passwordsmodel.h"
        #include "passwordprovider.h"
       -#include "gpg.h"
       +#include "safe.h"
        
        #include <QDir>
        #include <QDebug>
       t@@ -27,7 +27,7 @@
        #include <QTemporaryFile>
        #include <QFile>
        
       -#define PASSWORD_STORE_DIR "PASSWORD_STORE_DIR"
       +#define SAFE_DIR "SAFE_DIR"
        
        class PasswordsModel::Node
        {
       t@@ -56,9 +56,6 @@ public:
                    return name;
                } else {
                    QString fileName = name;
       -            if (type == PasswordsModel::PasswordEntry) {
       -                fileName += QStringLiteral(".gpg");
       -            }
                    return parent->path() + QLatin1Char('/') + fileName;
                }
            }
       t@@ -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
       t@@ -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);
            }
       t@@ -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();
 (DIR) diff --git a/translations/harbour-passilic.ts b/translations/harbour-passilic.ts
       t@@ -95,7 +95,7 @@
        <context>
            <name>PasswordListPage</name>
            <message>
       -        <source>Passilic</source>
       +        <source>Safe</source>
                <translation type="unfinished"></translation>
            </message>
        </context>