mirror of
https://github.com/QRouland/UTPass.git
synced 2025-07-04 03:02:28 +00:00
Update build : use prebuild binaries + Add libgit2
This commit is contained in:
@ -4,6 +4,7 @@ set(PLUGIN "Pass")
|
||||
set(
|
||||
SRC
|
||||
plugin.cpp
|
||||
git.cpp
|
||||
pass.cpp
|
||||
gpg.cpp
|
||||
passkeymodel.h
|
||||
@ -26,29 +27,29 @@ add_library(${PLUGIN} MODULE ${SRC})
|
||||
set_target_properties(${PLUGIN} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PLUGIN})
|
||||
qt5_use_modules(${PLUGIN} Qml Quick DBus)
|
||||
|
||||
set(EXTERNAL_LIBS "${CMAKE_SOURCE_DIR}/build/${ARCH_TRIPLET}/gpg/local/")
|
||||
|
||||
INCLUDE_DIRECTORIES(${EXTERNAL_LIBS}/include)
|
||||
add_library(gpgerror SHARED IMPORTED)
|
||||
set_property(TARGET gpgerror PROPERTY IMPORTED_LOCATION "/usr/lib/${ARCH_TRIPLET}/libgpg-error.so.0.28.0")
|
||||
|
||||
add_library(GpgError STATIC IMPORTED)
|
||||
set_property(TARGET GpgError PROPERTY IMPORTED_LOCATION "${EXTERNAL_LIBS}/lib/libgpg-error.a")
|
||||
add_library(libassuan SHARED IMPORTED)
|
||||
set_property(TARGET libassuan PROPERTY IMPORTED_LOCATION "/usr/lib/${ARCH_TRIPLET}/libassuan.so")
|
||||
|
||||
add_library(GpgAssuan STATIC IMPORTED)
|
||||
set_property(TARGET GpgAssuan PROPERTY IMPORTED_LOCATION "${EXTERNAL_LIBS}/lib/libassuan.a")
|
||||
add_library(libgpgme SHARED IMPORTED)
|
||||
set_property(TARGET libgpgme PROPERTY IMPORTED_LOCATION "/usr/lib/${ARCH_TRIPLET}/libgpgme.so")
|
||||
|
||||
add_library(Gpgme STATIC IMPORTED)
|
||||
set_property(TARGET Gpgme PROPERTY IMPORTED_LOCATION "${EXTERNAL_LIBS}/lib/libgpgme.a")
|
||||
add_library(libgpgmepp SHARED IMPORTED)
|
||||
set_property(TARGET libgpgmepp PROPERTY IMPORTED_LOCATION "/usr/lib/${ARCH_TRIPLET}/libgpgmepp.so")
|
||||
|
||||
add_library(Gpgmepp STATIC IMPORTED)
|
||||
set_property(TARGET Gpgmepp PROPERTY IMPORTED_LOCATION "${EXTERNAL_LIBS}/lib/libgpgmepp.a")
|
||||
add_library(libqgpgme SHARED IMPORTED)
|
||||
set_property(TARGET libqgpgme PROPERTY IMPORTED_LOCATION "/usr/lib/${ARCH_TRIPLET}/libqgpgme.so.7")
|
||||
|
||||
add_library(QGpgme STATIC IMPORTED)
|
||||
set_property(TARGET QGpgme PROPERTY IMPORTED_LOCATION "${EXTERNAL_LIBS}/lib/libqgpgme.a")
|
||||
|
||||
target_link_libraries(${PLUGIN} QGpgme Gpgmepp Gpgme GpgAssuan GpgError)
|
||||
add_library(libgit2 SHARED IMPORTED)
|
||||
set_property(TARGET libgit2 PROPERTY IMPORTED_LOCATION "/usr/lib/${ARCH_TRIPLET}/libgit2.so")
|
||||
|
||||
target_link_libraries(${PLUGIN} gpgerror libassuan libgpgme libgpgmepp libgit2)
|
||||
|
||||
|
||||
set(QT_IMPORTS_DIR "/lib/${ARCH_TRIPLET}")
|
||||
|
||||
install(TARGETS ${PLUGIN} DESTINATION ${QT_IMPORTS_DIR}/${PLUGIN}/)
|
||||
install(FILES qmldir DESTINATION ${QT_IMPORTS_DIR}/${PLUGIN}/)
|
||||
|
26
plugins/Pass/git.cpp
Normal file
26
plugins/Pass/git.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
|
||||
|
||||
#include <QDebug>
|
||||
#include <QUrl>
|
||||
extern "C" {
|
||||
#include <git2.h>
|
||||
}
|
||||
|
||||
#include "git.h"
|
||||
|
||||
|
||||
|
||||
Git::Git()
|
||||
{
|
||||
git_libgit2_init();
|
||||
}
|
||||
|
||||
Git::~Git() {
|
||||
git_libgit2_shutdown();
|
||||
}
|
||||
|
||||
bool Git::clone(QString url)
|
||||
{
|
||||
return false;
|
||||
}
|
27
plugins/Pass/git.h
Normal file
27
plugins/Pass/git.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef GIT_H
|
||||
#define GIT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
#include <memory>
|
||||
|
||||
class Git
|
||||
{
|
||||
private:
|
||||
Git();
|
||||
public:
|
||||
|
||||
~Git();
|
||||
|
||||
static std::shared_ptr<Git> instance()
|
||||
{
|
||||
static std::shared_ptr<Git> s{new Git};
|
||||
return s;
|
||||
}
|
||||
Git(Git const &) = delete;
|
||||
void operator=(Git const &) = delete;
|
||||
|
||||
bool clone(QString url);
|
||||
};
|
||||
|
||||
#endif
|
@ -23,8 +23,8 @@
|
||||
#include <qgpgme/changeownertrustjob.h>
|
||||
|
||||
#include "gpg.h"
|
||||
#include "pass.h"
|
||||
#include "passphraseprovider.h"
|
||||
#include "qprocess.h"
|
||||
|
||||
|
||||
|
||||
@ -36,11 +36,9 @@ Gpg::Gpg()
|
||||
{
|
||||
m_window = nullptr;
|
||||
|
||||
initializeLibrary();
|
||||
|
||||
Gpg::initGpgConfig();
|
||||
|
||||
auto error = checkEngine(OpenPGP);
|
||||
auto error = checkEngine(OpenPGP);
|
||||
if (error) {
|
||||
qDebug() << "Code Error : " << error.code();
|
||||
qDebug() << "Error str : " << error.asString();
|
||||
@ -65,15 +63,32 @@ QString Gpg::initGpgHome()
|
||||
}
|
||||
|
||||
|
||||
QString Gpg::findCommandPath(const QString &command) {
|
||||
// Retrieve the PATH environment variable
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
QString pathEnv = env.value("PATH");
|
||||
|
||||
// Split the PATH by colon
|
||||
QStringList pathDirs = pathEnv.split(":", QString::SkipEmptyParts);
|
||||
|
||||
// Check each directory in the PATH
|
||||
foreach (const QString &dir, pathDirs) {
|
||||
QFileInfo fileInfo(QDir(dir).filePath(command));
|
||||
|
||||
// If the file exists and is executable, return the path
|
||||
if (fileInfo.exists() && fileInfo.isExecutable()) {
|
||||
return fileInfo.absoluteFilePath();
|
||||
}
|
||||
}
|
||||
|
||||
return QString::null;
|
||||
}
|
||||
|
||||
QString Gpg::initGpgExec()
|
||||
{
|
||||
QString path = QDir::currentPath().append("/lib/bin/gpg");
|
||||
QFileInfo file(path);
|
||||
if (!file.isFile()) {
|
||||
qFatal("GNUPGEXEC file not found !");
|
||||
}
|
||||
if (!file.isExecutable()) {
|
||||
qFatal("GNUPGEXEC file not executable !");
|
||||
QString path = findCommandPath("gpg");
|
||||
if (path.isNull()) {
|
||||
qFatal("No valid gpg exec found !");
|
||||
}
|
||||
return path;
|
||||
}
|
||||
@ -81,20 +96,30 @@ QString Gpg::initGpgExec()
|
||||
|
||||
void Gpg::initGpgConfig()
|
||||
{
|
||||
auto home = initGpgHome();
|
||||
auto exec = initGpgExec();
|
||||
initializeLibrary();
|
||||
gpgme_set_global_flag("disable-gpgconf", "1");
|
||||
|
||||
QString home = initGpgHome();
|
||||
qDebug() << "Gpg home is " << home;
|
||||
QString exec = initGpgExec();
|
||||
qDebug() << "Gpg exec is " << exec;
|
||||
|
||||
QFile agentConf(home + QStringLiteral("/gpg-agent.conf"));
|
||||
agentConf.remove();
|
||||
agentConf.open(QIODevice::WriteOnly);
|
||||
agentConf.write("allow-loopback-pinentry");
|
||||
agentConf.write("allow-loopback-pinentry\n");
|
||||
agentConf.close();
|
||||
|
||||
gpgme_set_engine_info (
|
||||
auto err = gpgme_set_engine_info (
|
||||
GPGME_PROTOCOL_OpenPGP,
|
||||
exec.toLocal8Bit().data(),
|
||||
home.toLocal8Bit().data()
|
||||
);
|
||||
if (err != GPG_ERR_NO_ERROR) {
|
||||
qDebug() << "Error code : " << err;
|
||||
qDebug() << "Error str : " << gpg_strerror(err);
|
||||
qFatal("GPGME set engine info failed !");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,6 +15,7 @@ private:
|
||||
Gpg();
|
||||
QObject *m_window;
|
||||
|
||||
QString findCommandPath(const QString &command);
|
||||
QString initGpgHome();
|
||||
QString initGpgExec();
|
||||
void initGpgConfig();
|
||||
|
@ -3,8 +3,8 @@
|
||||
#include <QtCore/QDir>
|
||||
|
||||
#include "pass.h"
|
||||
#include "git.h"
|
||||
#include "gpg.h"
|
||||
#include "passphraseprovider.h"
|
||||
#include "passkeymodel.h"
|
||||
|
||||
|
||||
@ -18,44 +18,46 @@ void Pass::init(QObject *window)
|
||||
if (!window) {
|
||||
qFatal("window is invalid. Abording.");
|
||||
}
|
||||
|
||||
Gpg::instance()->setWindow(window);
|
||||
|
||||
QDir dir(m_password_store);
|
||||
if (!dir.exists())
|
||||
dir.mkpath(".");
|
||||
qDebug() << "Password Store is :" << m_password_store;
|
||||
qInfo() << "Password Store is :" << m_password_store;
|
||||
}
|
||||
|
||||
void Pass::decrypt(QUrl url)
|
||||
{
|
||||
qDebug() << "Start decrypting";
|
||||
qInfo() << "Decrypting";
|
||||
auto decrypt_ret = Gpg::instance()->decryptFromFile(url.toLocalFile());
|
||||
if (decrypt_ret.first) {
|
||||
qDebug() << "Decrypt Failed";
|
||||
qInfo() << "Decrypt Failed";
|
||||
emit decryptFailed();
|
||||
} else if (decrypt_ret.second.isNull()) {
|
||||
qDebug() << "Decrypt Canceled";
|
||||
qInfo() << "Decrypt Canceled";
|
||||
emit decryptCanceled();
|
||||
} else {
|
||||
qDebug() << "Decrypt OK";
|
||||
qInfo() << "Decrypt OK";
|
||||
emit decrypted(decrypt_ret.second);
|
||||
}
|
||||
}
|
||||
|
||||
bool Pass::gpgDeleteKeyId(QString id)
|
||||
{
|
||||
qDebug() << "Start deleting Key id " << id;
|
||||
qInfo() << "Deleting Key id " << id;
|
||||
return !Gpg::instance()->deleteKeyId(id);
|
||||
}
|
||||
|
||||
bool Pass::gpgImportKeyFromFile(QUrl url)
|
||||
{
|
||||
qDebug() << "Start importing Key from " << url;
|
||||
qInfo() << "Importing Key from " << url;
|
||||
return !Gpg::instance()->importKeysFromFile(url.toLocalFile());
|
||||
}
|
||||
|
||||
QVariant Pass::gpgGetAllKeysModel()
|
||||
{
|
||||
qInfo() << "Getting all key form gpg ";
|
||||
return QVariant::fromValue(PassKeyModel::keysToPassKeyQObjectList(
|
||||
Gpg::instance()->getAllKeys().second));
|
||||
}
|
||||
@ -64,3 +66,9 @@ QString Pass::getPasswordStore()
|
||||
{
|
||||
return m_password_store;
|
||||
}
|
||||
|
||||
bool Pass::gitClone(QString url)
|
||||
{
|
||||
qInfo() << "Cloning . password_store from " << url;
|
||||
return Git::instance()->clone(url);
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ public:
|
||||
Q_INVOKABLE bool gpgDeleteKeyId(QString id);
|
||||
Q_INVOKABLE bool gpgImportKeyFromFile(QUrl url);
|
||||
Q_INVOKABLE QVariant gpgGetAllKeysModel();
|
||||
Q_INVOKABLE bool gitClone(QString url);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user