QtPass 1.7.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 &msg, int timeout)
 Emit status message.
void critical (const QString &title, const QString &message)
 Emit critical error.
void processErrorExit (int exitCode, const QString &err)
 Emitted on process error exit.
void finishedAny (const QString &out, const QString &err)
 Emitted when any operation finishes.
void finishedGitInit (const QString &out, const QString &err)
 Emitted when Git init finishes.
void finishedGitPull (const QString &out, const QString &err)
 Emitted when Git pull finishes.
void finishedGitPush (const QString &out, const QString &err)
 Emitted when Git push finishes.
void finishedShow (const QString &out)
 Emitted when show finishes.
void finishedOtpGenerate (const QString &out)
 Emitted when OTP generation finishes.
void finishedInsert (const QString &out, const QString &err)
 Emitted when insert finishes.
void finishedRemove (const QString &out, const QString &err)
 Emitted when remove finishes.
void finishedInit (const QString &out, const QString &err)
 Emitted when init finishes.
void finishedMove (const QString &out, const QString &err)
 Emitted when move finishes.
void finishedCopy (const QString &out, const QString &err)
 Emitted when copy finishes.
void finishedGenerate (const QString &out, const QString &err)
 Emitted when generate finishes.
void finishedGenerateGPGKeys (const QString &out, const QString &err)
 Emitted when GPG key generation finishes.
void finishedGrep (const QList< QPair< QString, QStringList > > &results)
 Emitted when grep finishes with matching results.

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
 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.
void Grep (QString pattern, bool caseInsensitive=false) override
 Search all password content by GPG-decrypting each .gpg file.
Public Member Functions inherited from Pass
 Pass ()
 Construct a Pass instance.
void init ()
 Initialize the Pass instance.
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.
void setEnvVar (const QString &key, const QString &value)
 Set or remove an environment variable.

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
 Alias for Enums::PROCESS used throughout this class.
Protected Attributes inherited from Pass
Executor exec
 Internal command executor for queuing and running subprocesses.

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.

Definition at line 26 of file imitatepass.h.

Member Function Documentation

◆ checkSigningKeys()

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

Check if signing keys are valid.

Parameters
signingKeysList of key IDs.
Returns
true if all keys valid.

◆ Copy()

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

Copy password file.

Parameters
srcSource path.
destDestination path.
forcetrue to overwrite existing destination.

Implements Pass.

◆ 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.

◆ executeGit()

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

Execute git command.

Parameters
idProcess identifier.
argsGit arguments.
inputInput to stdin.
readStdoutCapture stdout.
readStderrCapture stderr.

◆ executeGpg()

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

Execute GPG command.

Parameters
idProcess identifier.
argsGPG arguments.
inputInput to stdin.
readStdoutCapture stdout.
readStderrCapture stderr.

◆ executeMoveGit()

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

Execute git move operation.

Parameters
srcSource path.
destFileDestination path.
forceOverwrite existing.

◆ executeWrapper()

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

Execute command wrapper.

Parameters
idProcess identifier.
appExecutable path.
argsCommand arguments.
inputData to write to stdin.
readStdoutWhether to capture stdout.
readStderrWhether to capture stderr.

Reimplemented from Pass.

◆ finished()

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

Handle process completion.

Parameters
idProcess identifier.
exitCodeProcess exit code.
outStandard output from the process.
errStandard error from the process.

Reimplemented from Pass.

◆ getKeysFromFile()

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

Read recipients from file.

Parameters
fileNamePath to file.
Returns
List of key IDs.

◆ 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.

◆ gitCommit()

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

Commit changes to git.

Parameters
fileChanged file path.
msgCommit message.

◆ GitInit()

void ImitatePass::GitInit ( )
overridevirtual

Initialize Git repository.

Implements Pass.

◆ GitPull()

void ImitatePass::GitPull ( )
overridevirtual

Pull from remote.

Implements Pass.

◆ GitPull_b()

void ImitatePass::GitPull_b ( )
overridevirtual

Pull with rebase.

Implements Pass.

◆ GitPush()

void ImitatePass::GitPush ( )
overridevirtual

Push to remote.

Implements Pass.

◆ Grep()

void ImitatePass::Grep ( QString pattern,
bool caseInsensitive = false )
overridevirtual

Search all password content by GPG-decrypting each .gpg file.

Pattern is interpreted as a QRegularExpression (PCRE-like), which differs from RealPass::Grep which uses system pass grep (POSIX BRE via grep). The same pattern may produce different matches across the two backends.

Parameters
patternSearch pattern (QRegularExpression).
caseInsensitivetrue for case-insensitive search.

Implements Pass.

◆ Init()

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

Initialize store.

Parameters
pathRoot path of the password store.
usersList of recipient GPG keys.

Implements Pass.

◆ Insert()

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

Insert new password.

Parameters
filePath to the password file.
newValuePassword content to store.
overwritetrue to overwrite an existing file.

Implements Pass.

◆ Move()

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

Move password file.

Parameters
srcSource path.
destDestination path.
forcetrue to overwrite existing destination.

Implements Pass.

◆ OtpGenerate()

void ImitatePass::OtpGenerate ( QString file)
overridevirtual

Generate OTP.

Parameters
filePath to the password file.

Implements Pass.

◆ reencryptPath()

void ImitatePass::reencryptPath ( const QString & dir)

Re-encrypt entire directory.

Parameters
dirDirectory path.

◆ 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.

◆ Remove()

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

Remove password.

Parameters
filePath to the file or directory to remove.
isDirtrue if removing a directory.

Implements Pass.

◆ removeDir()

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

Remove directory recursively.

Parameters
dirNameDirectory path.
Returns
true if removed.

◆ 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.

◆ Show()

void ImitatePass::Show ( QString file)
overridevirtual

Show decrypted password.

Parameters
filePath to the password file relative to store root.

Implements Pass.

◆ 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.

◆ verifyGpgIdFile()

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

Verify .gpg-id file exists and is valid.

Parameters
filePath to check.
Returns
true if valid.

◆ verifyGpgIdForDir()

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

Verify .gpg-id file for a 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.

◆ writeGpgIdFile()

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

Write recipients to .gpg-id file.

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

◆ tst_util

friend class tst_util
friend

Definition at line 29 of file imitatepass.h.


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