QtPass 1.6.0
Multi-platform GUI for pass, the standard unix password manager.
Loading...
Searching...
No Matches
ImitatePass Class Reference

Implementation that imitates 'pass' when the real tool is unavailable. More...

#include <imitatepass.h>

Inheritance diagram for ImitatePass:
Collaboration diagram for ImitatePass:

Classes

class  transactionHelper
 RAII helper for wrapping operations in transactions. More...

Signals

void startReencryptPath ()
 Emitted before starting re-encryption.
void endReencryptPath ()
 Emitted after finishing re-encryption.
Signals inherited from Pass
void error (QProcess::ProcessError)
 Emitted when a process error occurs.
void startingExecuteWrapper ()
 Emitted before executing a command.
void statusMsg (const QString &, int)
 Emit status message.
void critical (const QString &, const QString &)
 Emit critical error.
void processErrorExit (int exitCode, const QString &err)
 Emitted on process error exit.
void finishedAny (const QString &, const QString &)
 Emitted when any operation finishes.
void finishedGitInit (const QString &, const QString &)
 Emitted when Git init finishes.
void finishedGitPull (const QString &, const QString &)
 Emitted when Git pull finishes.
void finishedGitPush (const QString &, const QString &)
 Emitted when Git push finishes.
void finishedShow (const QString &)
 Emitted when show finishes.
void finishedOtpGenerate (const QString &)
 Emitted when OTP generation finishes.
void finishedInsert (const QString &, const QString &)
 Emitted when insert finishes.
void finishedRemove (const QString &, const QString &)
 Emitted when remove finishes.
void finishedInit (const QString &, const QString &)
 Emitted when init finishes.
void finishedMove (const QString &, const QString &)
 Emitted when move finishes.
void finishedCopy (const QString &, const QString &)
 Emitted when copy finishes.
void finishedGenerate (const QString &, const QString &)
 Emitted when generate finishes.
void finishedGenerateGPGKeys (const QString &, const QString &)
 Emitted when GPG key generation finishes.

Public Member Functions

void executeMoveGit (const QString &src, const QString &destFile, bool force)
 Execute git move operation.
void gitCommit (const QString &file, const QString &msg)
 Commit changes to git.
void executeGit (PROCESS id, const QStringList &args, QString input=QString(), bool readStdout=true, bool readStderr=true)
 Execute git command.
void executeGpg (PROCESS id, const QStringList &args, QString input=QString(), bool readStdout=true, bool readStderr=true)
 Execute GPG command.
 ImitatePass ()
 Construct ImitatePass instance.
 ~ImitatePass () override=default
 Destructor.
void GitInit () override
 Initialize Git repository.
void GitPull () override
 Pull from remote.
void GitPull_b () override
 Pull with rebase.
void GitPush () override
 Push to remote.
void Show (QString file) override
 Show decrypted password.
void OtpGenerate (QString file) override
 Generate OTP.
void Insert (QString file, QString newValue, bool overwrite=false) override
 Insert new password.
void Remove (QString file, bool isDir=false) override
 Remove password.
void Init (QString path, const QList< UserInfo > &users) override
 Initialize store.
void reencryptPath (const QString &dir)
 Re-encrypt entire directory.
void Move (const QString src, const QString dest, const bool force=false) override
 Move password file.
void Copy (const QString src, const QString dest, const bool force=false) override
 Copy password file.
Public Member Functions inherited from Pass
 Pass ()
 Construct a Pass instance.
void init ()
 Initialize the Pass instance.
 ~Pass () override=default
virtual auto generatePassword (unsigned int length, const QString &charset) -> QString
 Generate random password.
void GenerateGPGKeys (QString batch)
 Generate GPG keys using batch script.
auto listKeys (QStringList keystrings, bool secret=false) -> QList< UserInfo >
 List GPG keys matching patterns.
auto listKeys (const QString &keystring="", bool secret=false) -> QList< UserInfo >
 List GPG keys.
void updateEnv ()
 Update environment for subprocesses.

Protected Member Functions

auto verifyGpgIdFile (const QString &file) -> bool
 Verify .gpg-id file exists and is valid.
auto removeDir (const QString &dirName) -> bool
 Remove directory recursively.
auto checkSigningKeys (const QStringList &signingKeys) -> bool
 Check if signing keys are valid.
void writeGpgIdFile (const QString &gpgIdFile, const QList< UserInfo > &users)
 Write recipients to .gpg-id file.
auto signGpgIdFile (const QString &gpgIdFile, const QStringList &signingKeys) -> bool
 Sign .gpg-id file with signing keys.
void gitAddGpgId (const QString &gpgIdFile, const QString &gpgIdSigFile, bool addFile, bool addSigFile)
 Add .gpg-id to git staging.
auto verifyGpgIdForDir (const QString &file, QStringList &gpgIdFilesVerified, QStringList &gpgId) -> bool
 Verify .gpg-id file for a directory.
auto createBackupCommit () -> bool
 Create git backup commit before re-encryption.
auto getKeysFromFile (const QString &fileName) -> QStringList
 Read recipients from file.
auto reencryptSingleFile (const QString &fileName, const QStringList &recipients) -> bool
 Re-encrypt single file with new recipients.
auto resolveMoveDestination (const QString &src, const QString &dest, bool force) -> QString
 Resolve destination for move operation.
void finished (int id, int exitCode, const QString &out, const QString &err) override
 Handle process completion.
void executeWrapper (PROCESS id, const QString &app, const QStringList &args, QString input, bool readStdout=true, bool readStderr=true) override
 Execute command wrapper.
Protected Member Functions inherited from Pass
void executeWrapper (PROCESS id, const QString &app, const QStringList &args, bool readStdout=true, bool readStderr=true)
 Execute external wrapper command.
auto generateRandomPassword (const QString &charset, unsigned int length) -> QString
 Generate random password from charset.
auto boundedRandom (quint32 bound) -> quint32
 Generate random number in range.

Friends

class tst_util

Additional Inherited Members

Static Public Member Functions inherited from Pass
static bool gpgSupportsEd25519 ()
 Check if GPG supports Ed25519 encryption.
static QString getDefaultKeyTemplate ()
 Get default key template for new GPG keys.
static auto resolveGpgconfCommand (const QString &gpgPath) -> ResolvedGpgconfCommand
 Resolve the gpgconf command to kill agents.
static auto getGpgIdPath (const QString &for_file) -> QString
 Get .gpg-id file path for a password file.
static auto getRecipientList (const QString &for_file) -> QStringList
 Get list of recipients for a password file.
static auto getRecipientString (const QString &for_file, const QString &separator=" ", int *count=nullptr) -> QStringList
 Get recipients as string.
Protected Types inherited from Pass
using PROCESS = Enums::PROCESS
Protected Attributes inherited from Pass
Executor exec

Detailed Description

Implementation that imitates 'pass' when the real tool is unavailable.

ImitatePass provides a complete password store implementation using direct GPG operations when 'pass' is not installed or not enabled. It handles:

  • Direct GPG encryption/decryption
  • Git operations via direct subprocess calls
  • GPG key management and recipient lists
  • File-based password storage (.gpg files)
  • Re-encryption when recipients change

This is used as a fallback when RealPass cannot be initialized.

Examples
/home/annejan/Projects/QtPass/src/qtpasssettings.cpp.

Definition at line 23 of file imitatepass.h.

Constructor & Destructor Documentation

◆ ImitatePass()

ImitatePass::ImitatePass ( )
default

Construct ImitatePass instance.

ImitatePass::ImitatePass for situations when pass is not available we imitate the behavior of pass https://www.passwordstore.org/.

Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

◆ ~ImitatePass()

ImitatePass::~ImitatePass ( )
overridedefault

Destructor.

Member Function Documentation

◆ checkSigningKeys()

auto ImitatePass::checkSigningKeys ( const QStringList & signingKeys) -> bool
protected

Check if signing keys are valid.

ImitatePass::Init initialize pass repository.

Parameters
signingKeysList of key IDs.
Returns
true if all keys valid.
Parameters
pathpath in which new password-store will be created
userslist of users who shall be able to decrypt passwords in path
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 201 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Copy()

void ImitatePass::Copy ( const QString src,
const QString dest,
const bool force = false )
overridevirtual

Copy password file.

Implements Pass.

Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 910 of file imitatepass.cpp.

Here is the call graph for this function:

◆ createBackupCommit()

auto ImitatePass::createBackupCommit ( ) -> bool
protected

Create git backup commit before re-encryption.

Returns
true if backup created or not needed, false if backup failed.
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 664 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endReencryptPath

void ImitatePass::endReencryptPath ( )
signal

Emitted after finishing re-encryption.

Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.
Here is the caller graph for this function:

◆ executeGit()

void ImitatePass::executeGit ( PROCESS id,
const QStringList & args,
QString input = QString(),
bool readStdout = true,
bool readStderr = true )

Execute git command.

ImitatePass::executeGit easy wrapper for running git commands.

Parameters
idProcess identifier.
argsGit arguments.
inputInput to stdin.
readStdoutCapture stdout.
readStderrCapture stderr.
args
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 956 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeGpg()

void ImitatePass::executeGpg ( PROCESS id,
const QStringList & args,
QString input = QString(),
bool readStdout = true,
bool readStderr = true )

Execute GPG command.

ImitatePass::executeGpg easy wrapper for running gpg commands.

Parameters
idProcess identifier.
argsGPG arguments.
inputInput to stdin.
readStdoutCapture stdout.
readStderrCapture stderr.
args
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 946 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeMoveGit()

void ImitatePass::executeMoveGit ( const QString & src,
const QString & destFile,
bool force )

Execute git move operation.

Parameters
srcSource path.
destFileDestination path.
forceOverwrite existing.
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 842 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeWrapper()

void ImitatePass::executeWrapper ( PROCESS id,
const QString & app,
const QStringList & args,
QString input,
bool readStdout = true,
bool readStderr = true )
overrideprotectedvirtual

Execute command wrapper.

executeWrapper overrided so that every execution is a transaction

Parameters
id
app
args
input
readStdout
readStderr

Reimplemented from Pass.

Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 1011 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ finished()

void ImitatePass::finished ( int id,
int exitCode,
const QString & out,
const QString & err )
overrideprotectedvirtual

Handle process completion.

ImitatePass::finished this function is overloaded to ensure identical behaviour to RealPass ie. only PASS_* processes are visible inside Pass::finish, so that interface-wise it all looks the same.

Parameters
id
exitCode
out
err

Reimplemented from Pass.

Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 972 of file imitatepass.cpp.

Here is the call graph for this function:

◆ getKeysFromFile()

auto ImitatePass::getKeysFromFile ( const QString & fileName) -> QStringList
protected

Read recipients from file.

Parameters
fileNamePath to file.
Returns
List of key IDs.
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 504 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gitAddGpgId()

void ImitatePass::gitAddGpgId ( const QString & gpgIdFile,
const QString & gpgIdSigFile,
bool addFile,
bool addSigFile )
protected

Add .gpg-id to git staging.

Parameters
gpgIdFile.gpg-id file path.
gpgIdSigFileSignature file path.
addFileStage .gpg-id file.
addSigFileStage signature file.
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 316 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gitCommit()

void ImitatePass::gitCommit ( const QString & file,
const QString & msg )

Commit changes to git.

ImitatePass::gitCommit commit a file to git with an appropriate commit message.

Parameters
fileChanged file path.
msgCommit message.
file
msg
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 161 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GitInit()

void ImitatePass::GitInit ( )
overridevirtual

Initialize Git repository.

ImitatePass::GitInit git init wrapper.

Implements Pass.

Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 61 of file imitatepass.cpp.

Here is the call graph for this function:

◆ GitPull()

void ImitatePass::GitPull ( )
overridevirtual

Pull from remote.

ImitatePass::GitPull git pull wrapper.

Implements Pass.

Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 68 of file imitatepass.cpp.

Here is the call graph for this function:

◆ GitPull_b()

void ImitatePass::GitPull_b ( )
overridevirtual

Pull with rebase.

ImitatePass::GitPull_b git pull wrapper.

Implements Pass.

Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 73 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GitPush()

void ImitatePass::GitPush ( )
overridevirtual

Push to remote.

ImitatePass::GitPush git push wrapper.

Implements Pass.

Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 80 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Init()

void ImitatePass::Init ( QString path,
const QList< UserInfo > & users )
overridevirtual

Initialize store.

Implements Pass.

Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 347 of file imitatepass.cpp.

Here is the call graph for this function:

◆ Insert()

void ImitatePass::Insert ( QString file,
QString newValue,
bool overwrite = false )
overridevirtual

Insert new password.

ImitatePass::Insert create new file with encrypted content.

Parameters
filefile to be created
newValuevalue to be stored in file
overwritewhether to overwrite existing file

Implements Pass.

Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 115 of file imitatepass.cpp.

Here is the call graph for this function:

◆ Move()

void ImitatePass::Move ( const QString src,
const QString dest,
const bool force = false )
overridevirtual

Move password file.

Implements Pass.

Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 874 of file imitatepass.cpp.

Here is the call graph for this function:

◆ OtpGenerate()

void ImitatePass::OtpGenerate ( QString file)
overridevirtual

Generate OTP.

ImitatePass::OtpGenerate generates an otp code.

Implements Pass.

Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 99 of file imitatepass.cpp.

◆ reencryptPath()

void ImitatePass::reencryptPath ( const QString & dir)

Re-encrypt entire directory.

Re-encrypts all .gpg files under the given directory using the verified GPG key configuration for each folder.

Parameters
dirDirectory path.

This method optionally pulls the latest changes before starting, creates a backup commit, verifies .gpg-id files per directory, and re-encrypts files whose current recipients do not match the expected keys. It emits progress, status, and error signals throughout the process, and optionally pushes the updated password-store when finished.

Parameters
dir- Root directory to scan recursively for .gpg files.
Returns
void
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 705 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reencryptSingleFile()

auto ImitatePass::reencryptSingleFile ( const QString & fileName,
const QStringList & recipients ) -> bool
protected

Re-encrypt single file with new recipients.

Parameters
fileNameFile to re-encrypt.
recipientsNew recipient key IDs.
Returns
true on success, false on failure.
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 550 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Remove()

void ImitatePass::Remove ( QString file,
bool isDir = false )
overridevirtual

Remove password.

ImitatePass::Remove custom implementation of "pass remove".

Implements Pass.

Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 172 of file imitatepass.cpp.

Here is the call graph for this function:

◆ removeDir()

auto ImitatePass::removeDir ( const QString & dirName) -> bool
protected

Remove directory recursively.

ImitatePass::removeDir delete folder recursive.

Parameters
dirNameDirectory path.
Returns
true if removed.
Parameters
dirNamewhich folder.
Returns
was removal successful?
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 443 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resolveMoveDestination()

auto ImitatePass::resolveMoveDestination ( const QString & src,
const QString & dest,
bool force ) -> QString
protected

Resolve destination for move operation.

Parameters
srcSource path.
destDestination path.
forceOverwrite existing.
Returns
Resolved destination path.
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 784 of file imitatepass.cpp.

Here is the caller graph for this function:

◆ Show()

void ImitatePass::Show ( QString file)
overridevirtual

Show decrypted password.

ImitatePass::Show shows content of file.

Implements Pass.

Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 89 of file imitatepass.cpp.

Here is the call graph for this function:

◆ signGpgIdFile()

auto ImitatePass::signGpgIdFile ( const QString & gpgIdFile,
const QStringList & signingKeys ) -> bool
protected

Sign .gpg-id file with signing keys.

Parameters
gpgIdFilePath to .gpg-id file.
signingKeysKey IDs to sign with.
Returns
true on success, false on failure.
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 270 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ startReencryptPath

void ImitatePass::startReencryptPath ( )
signal

Emitted before starting re-encryption.

Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.
Here is the caller graph for this function:

◆ verifyGpgIdFile()

auto ImitatePass::verifyGpgIdFile ( const QString & file) -> bool
protected

Verify .gpg-id file exists and is valid.

ImitatePass::verifyGpgIdFile verify detached gpgid file signature.

Parameters
filePath to check.
Returns
true if valid.
Parameters
filewhich gpgid file.
Returns
was verification successful?
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 399 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ verifyGpgIdForDir()

auto ImitatePass::verifyGpgIdForDir ( const QString & file,
QStringList & gpgIdFilesVerified,
QStringList & gpgId ) -> bool
protected

Verify .gpg-id file for a directory.

ImitatePass::reencryptPath reencrypt all files under the chosen directory.

Parameters
filePassword file path.
gpgIdFilesVerifiedList of already verified .gpg-id files.
gpgIdOutput parameter for recipient key IDs.
Returns
true on success, false on failure.

This is still quite experimental..

Parameters
dir
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 474 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeGpgIdFile()

void ImitatePass::writeGpgIdFile ( const QString & gpgIdFile,
const QList< UserInfo > & users )
protected

Write recipients to .gpg-id file.

Writes the selected users' GPG key IDs to a .gpg-id file.

Parameters
gpgIdFilePath to .gpg-id file.
usersList of recipients.

Opens the specified file for writing, stores the key ID of each enabled user on a separate line, and warns if none of the selected users has a secret key available.

Parameters
QString&gpgIdFile - Path to the .gpg-id file to be written.
QList<UserInfo>&users - List of users to evaluate and write to the file.
Returns
void - This function does not return a value.
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp.

Definition at line 233 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tst_util

friend class tst_util
friend

Definition at line 26 of file imitatepass.h.


The documentation for this class was generated from the following files: