QtPass 2.0.0
Developer documentation
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...
struct  PendingMove
 A move whose re-encryption is decided once it has run. More...
struct  PendingInsert
struct  UncommittedGpgId
 A .gpg-id Init() wrote but could not commit. More...
struct  WrittenGpgId
 The .gpg-id Init() wrote for the run it starts: the recipients the user ticked, as written. More...
struct  PreviousList
 The list a folder had before Init() replaced it, for the run it starts. It tells whom the change added (who then gains every entry, as adding someone means) and whom it removed (who may still read an entry left alone). An entry is not compared with it: the worker asks before an entry gains anyone on the new list other than those added. More...
struct  Agreed
 What the user was shown for an entry: its bytes and its folder's keys. More...
struct  ReencryptResult
 Outcome of one reencryptPath() run; filled on the worker thread and consumed by finishReencrypt() on the owning thread. More...
struct  ListKeys
struct  WhoReads
struct  ReaderChange
 How re-encrypting one entry changes who can read it. More...

Signals

void startReencryptPath ()
 A reencryptPath() run is about to start its worker thread.
void endReencryptPath ()
 A reencryptPath() run is over, whether it finished, failed, was cancelled or was refused; the main window releases the interface.
void reencryptProgress (int current, int total)
 Re-encryption progress: current of total files checked.
void unexpectedRecipients (const QString &dir, const QStringList &files, const QStringList &details)
 A run left files alone: re-encrypting one would let someone on its folder's list read it who cannot now, and whom the change of the list did not add. An entry copied in from a folder they cannot read must not reach them without the user's say. reencryptAlso() takes them once the user agreed. Emitted after endReencryptPath().
Signals inherited from Pass
void idle ()
 Nothing of the store's runs or waits any more (isIdle()).
void startingExecuteWrapper ()
 Emitted each time a queued process is about to start, and by the refusals that go on to emit processErrorExit().
void statusMsg (const QString &msg, int timeout)
 Progress or a non-fatal problem worth a line in the status bar ("Creating backup commit", "Git pull failed: ...").
void critical (const QString &title, const QString &message)
 Something went wrong that the user has to be told about in a dialog, such as a refused path or a failed backup commit.
void processErrorExit (int exitCode, const QString &err)
 An operation ended in failure: its process exited non-zero, could not be started or crashed, or the operation was refused.
void finishedAnyWithPid (const QString &out, const QString &err, Enums::PROCESS pid)
 A process of any kind finished successfully and its output cannot contain a secret.
void finishedGitInit (const QString &out, const QString &err)
 git init in the store succeeded; the store is a repository now and the tree is re-read.
void finishedGitPull (const QString &out, const QString &err)
 git pull succeeded; entries may have changed on disk.
void finishedGitPush (const QString &out, const QString &err)
 git push succeeded.
void finishedShow (const QString &out, const QString &file, bool lossless=true)
 Emitted when a Show() succeeds.
void finishedInsert (const QString &out, const QString &err)
 An Insert() succeeded: the entry is in the store and, with Git in use, committed.
void finishedRemove (const QString &out, const QString &err)
 A Remove() succeeded; the entry or folder is gone from the store.
void finishedInit (const QString &out, const QString &err)
 An Init() succeeded: the folder's .gpg-id holds the new recipient list.
void finishedMove (const QString &out, const QString &err)
 A Move() succeeded; the entry or folder is under its new name.
void finishedCopy (const QString &out, const QString &err)
 A Copy() succeeded; the copy exists beside the original.
void finishedGenerateGPGKeys (const QString &out, const QString &err)
 GenerateGPGKeys() succeeded; the new key pair is in the keyring.
void generateGPGKeysFailed (const QString &err)
 Emitted when GPG key generation fails, alongside the generic processErrorExit(); lets the keygen dialog react to its own failure only, not to any other command failing meanwhile.
void insertFailed (const QString &err, bool written)
 Emitted when an Insert() fails through a queued command, before the generic processErrorExit(): the process exited non-zero, crashed or could not be started, or the entry could not be put in place afterwards. Lets the password dialog keep what was typed and say why, without reacting to any other command failing meanwhile. An insert refused before anything is queued does not emit it.
void finishedGrep (const QList< QPair< QString, QStringList > > &results)
 The newest Grep() is over; an empty list means no entry matched.

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 one path to git.
void gitCommit (const QStringList &files, const QString &msg)
 Commit these paths and nothing else: a change someone staged meanwhile stays staged, out of a commit autoPush would send.
void executeGit (PROCESS id, const QStringList &args, QString input=QString(), bool readStdout=true, bool readStderr=true)
 Execute git command.
auto gitConfigured () const -> bool
 Git is enabled and an executable is configured.
auto gitReady () -> bool
 gitConfigured() plus a status message when git is enabled but no executable is configured.
void executeGpg (PROCESS id, const QStringList &args, QString input=QString(), bool readStdout=true, bool readStderr=true)
 Execute GPG command.
 ImitatePass ()
 Construct the backend and connect its content search.
 ~ImitatePass () override
 Cancel a running content search, and cancel and join a running re-encryption worker, before the members they use go away.
void GitInit () override
 Initialize Git repository.
void GitPull () override
 Pull from remote.
void GitPull_b (int timeoutMs) override
 Run git pull in the store and wait for it, at most timeoutMs.
void GitPush () override
 Push to remote. While a re-encryption runs the push is held (Users ▸ OK and a copy ask for it as soon as their commit is made, before the worker is done) and made when the run ends with every file re-encrypted; after a failed or cancelled run nothing is pushed.
void Show (QString file) override
 Show decrypted password.
void Insert (QString file, QString newValue, bool overwrite) override
 Insert new password.
auto readersAnEditWouldAdd (const QString &file) -> EditReaders override
 Who saving over an existing entry would let read it who may not now.
void Remove (QString file, bool isDir) override
 Remove password.
void Init (QString path, const QList< UserInfo > &users) override
 Initialize store.
void reencryptPath (const QString &dir)
 Re-encrypt entire directory.
void reencryptPath (const QString &dir, const AppSettings &settings)
 Re-encrypt dir under settings, the current profile's.
void cancelReencryptPath ()
 Ask a running reencryptPath() to stop.
void reencryptAlso (const QString &dir, const QStringList &files, const AppSettings &settings)
 Re-encrypt files in dir after the user agreed to it.
void Move (const QString src, const QString dest, const bool force) override
 Move password file.
void Copy (const QString src, const QString dest, const bool force) override
 Copy password file.
void Grep (QString pattern, bool caseInsensitive) override
 Search all password content by GPG-decrypting each .gpg file.
void CancelGrep () override
 Stop the running search (NativeGrep::cancel()).
Public Member Functions inherited from Pass
 Pass ()
 Construct a Pass instance.
void init (const AppSettings &settings)
 Initialize the Pass instance with a settings snapshot.
auto insertsPending () const -> int
 How many inserts have started queueing but not yet reported.
virtual auto entriesInitWouldWiden (const QString &dir, const QList< UserInfo > &users) -> QStringList
 Entries a pass init of dir with users would hand to someone who cannot read them now (an entry copied in from a folder they are not on), less whom the change adds. pass re-encrypts every entry itself, so the caller asks before it runs. None by default; the pass backend tells.
virtual auto entriesMoveWouldWiden (const QString &src, const QString &dest) -> QStringList
 Entries already in the place a pass mv or pass cp of src to dest re-encrypts (the whole destination folder) that would gain a reader they do not have. What is moved or copied itself is the user's own and not counted. None by default.
auto entryReaders (const QString &path) -> QStringList
 The long key IDs an entry is encrypted to, as gpg lists them without anyone's secret key (ENC_TO).
auto reportedInsert () const -> QString
 The entry whose insert is reporting now: set while finishedInsert() or insertFailed() goes out, empty otherwise.
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.
virtual auto encryptionReaches (const QStringList &recipients) -> std::optional< QStringList >
 The keys a gpg encryption to recipients reaches: a throwaway encryption outside the store, read back for whom it went to.
virtual auto recipientArgument (const QString &line) const -> QString
 The -r argument for one recipient line, as this backend's encryption hands it to gpg: the probe (encryptionReaches()) must reach what the encryption will. The native backend matches a bare address exactly (exactRecipientArg()).
auto keyLinesHeldTwice (const QStringList &lines) -> std::optional< QHash< QString, QStringList > >
 The key ID and fingerprint lines of a recipient list that more than one key block holds, with those blocks.
auto exportPublicKeys (const QString &gpg, const QStringList &keys, QString *out, QString *err) -> int
 gpg --armor --export of keys, in the store's environment: the keyring keyLinesHeldTwice() reads.
auto listKeys (const QString &keystring="", bool secret=false) -> QList< UserInfo >
 List GPG keys.
void updateEnv ()
 Update environment for subprocesses.
auto recipientsForEditing (const QString &dir, const QString &passStore) -> RecipientsForEditing
 The recipients a dialog may preselect for editing the list of dir.
auto initIfUnchanged (const QString &path, const QList< UserInfo > &users, const QString &dir, const QString &passStore, const RecipientsForEditing &read) -> bool
 Init(), but only while the list of dir still reads as the caller read it with recipientsForEditing().
auto isIdle () const -> bool
 Whether no gpg, git or pass of this backend runs or waits.
auto stopRunning () -> bool
 Stop the queued command that is running now (Executor::stopRunning()); it then ends as a failed run.
auto runningSerial () const -> quint64
 Which run is going (Executor::runningSerial()).
auto runningProcess () const -> Enums::PROCESS
 What kind of command is running now.
auto isPushing () const -> bool
 Whether a Git push of this backend is queued or running.
auto autoPushHeld () const -> bool
 Whether automatic pushes of the current store are held because its last re-encryption did not finish cleanly.
void GitPushAutomatic ()
 GitPush() for an automatic push, the one after a change. A backend that has to make the push later drops it then if the store is held by that time (autoPushHeld()); a push by hand (GitPush()) still goes.

Protected Member Functions

auto gpgIdSigner () -> GpgIdSigner
 The signer for this store's .gpg-id, bound to the configured gpg and signing keys and to execBlocking(), so a verification on the re-encryption worker can be interrupted like every other gpg run there.
auto loadVerifiedRecipients (const QString &gpgIdFile, QStringList *recipients, QString *why=nullptr) -> bool
 Read a .gpg-id, verify its detached signature and parse the recipients from the bytes that were verified.
auto writeGpgIdFile (const QString &gpgIdFile, const QList< UserInfo > &users, QByteArray *written=nullptr) -> bool
 Write the enabled recipients to a .gpg-id, atomically: a write that fails halfway (full disk, dead network share) leaves the previous file in place instead of a truncated list that would then be signed and encrypted to.
auto signGpgIdFile (const QString &gpgIdFile, const QByteArray &contents) -> bool
 Sign a .gpg-id with the configured key and verify the result; failures are reported through critical().
auto refuseLinkedGpgIdFolder (const QString &path) -> bool
 Refuse a folder, or a .gpg-id/.gpg-id.sig in it, that is a link: writing there would reach outside the store.
auto recipientsForEntry (const QString &file, QStringList *recipients) -> bool
 The recipients to encrypt file to: its folder's .gpg-id, verified when a signing key is set.
auto copyDestination (const QString &src, const QString &dest, bool force) -> QString
 The file a copy of src to dest writes: like pass cp, into an existing folder with .gpg appended. Refused (the user told) when it is a link, the source itself, or taken and force is off.
auto addGenerationHeader (const QString &gpgIdFile, const GpgIdSigner &signer, QByteArray *contents) -> bool
 Put the generation header on a list that is about to be signed: reserve a generation above what this device accepted and what the verified list on disk says, and bind the list to its folder, so no older or relocated signed list comes back.
auto settleSignature (const QString &gpgIdFile, const QByteArray &written, const GpgIdSigner &signer, bool useGit, QString *sigToCommit) -> bool
 Bring the signature in line with the list just written: a new one when signing is on, the old one removed when it is off (pass and other clients would reject the new list under it).
auto gitAddGpgId (const QString &gpgIdFile, const QString &gpgIdSigFile, QString *out, QString *err) -> int
 Stage a .gpg-id and, when given, its .sig, and commit both in one commit, so no commit in the history has a recipient list without the signature that covers it. Nothing is committed when neither file changed.
auto commitName (const QString &path) const -> QString
 How a commit message names a file of the store: relative to the store, without .gpg ("work/bank", "work/.gpg-id"), never the local path, which the shared history would carry to everyone.
auto gitTracks (const QString &file) -> bool
 Check whether git already tracks a file in the store.
auto commitArgs () -> QStringList
 The start of a git commit for the store: "commit", and "-S" when git config pass.signcommits is true there, as pass signs its own.
auto verifyGpgIdForDir (const QString &file, QHash< QString, QStringList > &verified, QStringList &gpgId) -> bool
 Recipients for the directory of file, from its verified .gpg-id.
auto createBackupCommit () -> bool
 Create git backup commit before re-encryption.
auto getKeysFromFile (const QString &fileName) -> QStringList
 Read recipients from file.
auto primaryKeysOf (const QStringList &ids, QHash< QString, QString > &primaries, QHash< QString, QString > &names) -> QSet< QString >
 The primary keys behind key IDs from an entry (ENC_TO).
auto keysEncryptedTo (const QStringList &recipients, QHash< QString, QString > &primaries, QHash< QString, QString > &names, bool lookUp=true) -> std::optional< QSet< QString > >
 The primary keys gpg encrypts to for recipients, found by a throwaway encryption outside the store with the arguments a real one uses, so groups, ! suffixes and key lookups count as -r makes them.
auto entryHash (const QString &file) const -> QByteArray
 SHA-256 of an entry's bytes, read as a regular file without following a link.
auto reencryptSingleFile (const QString &fileName, const QStringList &recipients, QString *why) -> bool
 Re-encrypt single file with new recipients.
auto decryptEntry (const QString &fileName, QByteArray *plaintext, QString *why) -> bool
 Decrypt fileName for re-encryption.
auto encryptFor (const QString &output, const QStringList &recipients, const QByteArray &plaintext) -> bool
 Encrypt plaintext to recipients, into output.
auto ciphertextHolds (const QString &ciphertext, const QByteArray &plaintext) -> bool
 Decrypt ciphertext again and compare it with plaintext, byte for byte, so nothing replaces an entry until it is known to hold what it held.
auto commitReencrypted (const QString &fileName) -> bool
 Stage and commit a re-encrypted entry, when the store is a Git repository QtPass manages.
auto resolveMoveDestination (const QString &src, const QString &dest, bool force) -> QString
 Resolve destination for move operation.
auto execBlocking (const QString &app, const QStringList &args, const QString &input=QString(), QString *process_out=nullptr, QString *process_err=nullptr) -> int
 Executor::executeBlocking() for the re-encryption helpers.
auto execBlocking (const QString &app, const QStringList &args, QString *process_out, QString *process_err=nullptr) -> int
 Overload capturing stdout (and stderr) without stdin input.
auto execBlockingRaw (const QString &app, const QStringList &args, const QByteArray &input, QByteArray *process_out) -> int
 execBlocking() on bytes (Executor::executeBlockingRaw()), for an entry's plaintext, which need not be UTF-8.
auto prepareBlocking (QProcess &process) -> const std::atomic_bool *
 Give process the environment for the calling thread: the store's on the owning thread, the re-encryption run's on its worker.
auto storeGit (const QStringList &args, QString *out) -> bool override
 Run git with -C <Store tree and entries> in the store, blocking.
void finished (int id, int exitCode, const QString &out, const QString &err) override
 Handle process completion.
auto insertWritten (const QString &err) const -> bool override
 Whether the failed insert had placed its entry (see placeEncryptedFile()) before a later git step failed.
void beforeExecute (PROCESS id) override
 Open a transaction for every execution.
auto fullKeyListing (QString *listing) -> int override
 Pass::fullKeyListing() in the calling thread's environment, so a re-encryption run's worker lists the store's keyring.
Protected Member Functions inherited from Pass
auto refuseKeyLinesHeldTwice (const QStringList &lines) -> bool
 Refuse, with critical(), a recipient list with a line that more than one key block holds (keyLinesHeldTwice()).
auto storeEnvironment () const -> QProcessEnvironment
 The environment QtPass runs the store's processes in.
auto withCurrentGitPin (QProcessEnvironment base) const -> QProcessEnvironment
 base with GIT_DIR and GIT_WORK_TREE as the store is now (Util::gitStoreVariables()), not as it was at updateEnv(): a .git that appeared or changed hands since then is judged when Git runs.
auto pushIsAutomatic () const -> bool
 Whether the GitPush() running now is an automatic one.
void holdAutoPush (const QString &scope)
 Hold automatic pushes of the store that holds scope (autoPushHeld()): its re-encryption did not finish cleanly.
void releaseAutoPush (const QString &folder)
 Release the holds a clean re-encryption of folder covers: those for folder itself and everything under it. Holds for other folders stay.
auto refuseSkippedGpgId (const QString &file, bool signing, const QString &except=QString(), SkippedWalks *walks=nullptr) -> bool
 With signing on, refuse to encrypt file when the lookup passed over its folder's own list (skippedGpgId()): the parent's list is not what was signed for it.
auto verifySignedList (const GpgIdSigner &signer, const QString &gpgIdFile, QByteArray *contents, QString *why) const -> bool
 Whether gpgIdFile is a signed list QtPass accepts: its signature verifies (GpgIdSigner::verifyFile()), and it is current and bound to the folder it lies in (GpgIdGeneration::accept()), so an older authentic list put back, or one signed for another folder, is refused.
void queueShow (const QString &file)
 Remember what a Show() asked for, so its completion can say so.
void queueInsert (const QString &entry=QString())
 Count one insert that has started queueing but not yet reported.
auto refuseLinkedPath (const QString &path, LinkScope scope=LinkScope::EntryAndParents, PathSpelling spelling=PathSpelling::Configured) -> bool
 Refuse an operation on something that is, or lies behind, a symbolic link or NTFS junction inside the store.
auto refuseFolderOutsideStore (const QString &folder, QString *relative=nullptr) -> bool
 Refuse recipients for a folder outside the store, as pass refuses a path with .. in it.
auto refuseUnfinishedGitOperation () -> bool
 Refuse to change the store while git is mid-rebase, -merge, -cherry-pick or -revert.
auto unfinishedGitOperationReason () -> QString
 The unfinished git operation in progress in the store, if any.
auto refusePendingPull () -> bool
 Refuse a store change while a Git pull is still queued or running.
auto refuseChangedList () -> bool
 Refuse an Init() under initIfUnchanged() when the folder's list no longer reads as the caller read it.
auto refuseBusyForExpectedList () -> bool
 Refuse an Init() under initIfUnchanged() while the executor has work queued or running, for a backend whose external tool writes the list only when its process runs.
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 &name, const QString &value)
 Set or remove an environment variable.
void pinStoreGitAttributes ()
 Pin byte-for-byte Git attributes for the store's encrypted files.
void executeWrapper (PROCESS id, const QString &app, const QStringList &args, QString input, bool readStdout, bool readStderr)
 Execute wrapper with input.

Protected Attributes

QProcessEnvironment m_reencryptEnv
Protected Attributes inherited from Pass
AppSettings m_settings
 Application settings snapshot injected at init() time.
Executor exec
 Internal command executor for queuing and running subprocesses.

Private Member Functions

void startMovedReencrypts ()
 Start the runs in m_movedToReencrypt, one at a time, while none is in flight; then send a deferred push once nothing is left.
void sendDeferredPush ()
 Make the push GitPush() deferred, once no run is in flight and no move is waiting; an automatic one only while the store is not held.
void reencryptMoved (const PendingMove &move)
 Queue a re-encryption of what move moved, if it moved and another .gpg-id applies where it landed; a folder that has its own list is left as it is. Only that entry or folder, not what is around it; startMovedReencrypts() starts it.
auto refuseOverlappingMove (const QString &src, const QString &destFile) -> bool
 Refuse a move of src to destFile that touches what an earlier move or a re-encryption still has to settle: moving it again meanwhile would leave the run for the place it is no longer at.
auto placeEncryptedFile (const QString &output, const QString &file, bool overwrite, QString *error) -> bool
 Bring the ciphertext gpg wrote to output into the store as file (Util::copyFileReplacing): through a temporary created next to the entry and written by its open handle, then the operating system's rename, which replaces the entry under that name (or, without overwrite, fails when one has appeared) and follows nothing. Reports nothing itself: Insert()'s finished() routes the reason through the failed-operation path once the queued git steps are cancelled, and re-encryption lists it in the run's summary.
auto placePendingInsert (int exitCode, QString *error) -> int
 Finish the oldest pending insert after its gpg step: place the ciphertext with placeEncryptedFile(), unless gpg failed or a Git operation stopped half-way meanwhile. Sets m_insertPlaced.
void startReencryptWorker (const QString &dir)
 Start the worker thread once the Executor queue is idle.
auto reencryptFiles (const QString &dir) -> ReencryptResult
 Worker-thread body: scan dir and re-encrypt stale files.
auto startReencryptRun (const QString &dir, ReencryptResult &result) -> bool
 The checks a run makes after its own pull, before it writes: no unfinished Git operation, dir not a link or behind one, the list Init() wrote unchanged by the pull; then the leftovers of an interrupted run, and the backup commit.
auto isTrustedEntry (const QString &fileName, const QSet< QString > &listNow) const -> bool
 Whether an entry that would gain readers is taken without a question: the user moved or copied it in, or agreed to it in reencryptAlso() while its bytes and its list's keys are unchanged.
auto listKeysFor (const QString &gpgIdPath, const QStringList &gpgId, WhoReads &who) -> const ListKeys &
 The keys of the list at gpgIdPath, worked out once per run.
auto readerChangeOf (const QString &fileName, const QStringList &keys, const ListKeys &lk, WhoReads &who) -> ReaderChange
 Who would gain an entry by re-encrypting it to its list, other than those this change added, and who was taken off and still reads it.
auto holdForAgreement (const QString &fileName, const QStringList &keys, const ReaderChange &change, const WhoReads &who, ReencryptResult &result) -> bool
 Leave an entry that would gain readers for the user: named in the question after the run, with the bytes it is named for, or reported as failed when its bytes cannot be read to hold a yes to.
auto reencryptEntry (const QString &fileName, const QStringList &gpgId, WhoReads &who, ReencryptResult &result) -> bool
 Check one entry and re-encrypt it to gpgId when it is not encrypted to those keys yet, unless it would gain readers no one agreed to.
auto pullBeforeReencrypt () -> bool
 Pull before a run, when the store is a Git repository and automatic pulling is on.
auto entriesToReencrypt (const QString &dir, QStringList *failed) -> QStringList
 The entries under dir a run considers, telling the user about anything skipped for not being a regular file.
auto recipientsForDir (const QString &fileName, QHash< QString, QStringList > &verified, QStringList &gpgId, ReencryptResult &result) -> bool
 The verified recipients for the folder fileName sits in.
auto recoverReencryptLeftovers (const QString &dir) -> bool
 Deal with what a crashed or failed earlier run left under dir before touching anything: stale temporaries (today's staged .qtpass-XXXXXX.tmp, 1.8.x's <entry>.reencrypt.tmp, the <entry>.XXXXXX.tmp of builds in between) are removed unless they were modified within the hour, where they may be another QtPass's write in flight on a shared store; a 1.8.x <entry>.reencrypt.bak whose original is missing is put back, one next to a present original is reported and left alone (both are valid ciphertexts, the choice is the user's). Whatever needs a human is reported in one critical(), the list capped.
void dropStaleTemporary (const QString &path)
 Remove a stale temporary a crashed run left, unless it was modified within the hour: on a shared store it may be another QtPass's write in flight under the same name.
auto restoreBackup (const QString &path, QStringList &problems) -> bool
 Put a 1.8.x backup back in its entry's place when the entry is missing; report it when both exist (both are valid ciphertexts, the choice is the user's) or when the rename fails.
void reportUnrestorable (const QString &path, QStringList &problems)
 Note for the user that a leftover is not a regular file and was left.
void finishReencrypt (const ReencryptResult &result)
 Report the outcome of a run and emit endReencryptPath().
void reportFailedEntries (const QStringList &failed)
 Tell the user which entries a run could not re-encrypt, the first few by name.
auto settleAutoPushHold (const ReencryptResult &result, bool agreedRun) -> bool
 Bring the record of entries a removed recipient still reads up to date with a run, and hold the automatic push for the run's folder when the change is not done there, or release it after a full, clean run.
void reportReencryptOutcome (const ReencryptResult &result, bool stillRead)
 The status line for a run, and the push after it when one is due and nothing holds it.
void rememberUnexpected (const ReencryptResult &result)
 Keep what the run named in unexpectedRecipients(), with the bytes and readers it was named for: reencryptAlso() takes the user's yes from there.
auto refuseInitBeforeWrite (const QString &gpgIdFile, const GpgIdSigner &signer) -> bool
 The checks Init() runs before it writes anything: no re-encryption running, the signing key's secret key available, the list and its signature free or regular files, and the list unchanged since the users dialog read it. Each refusal is shown.
auto previousListOf (const QString &path, const QString &gpgIdFile) -> std::optional< PreviousList >
 The verified list the entries of path were encrypted to before Init() replaces it, as the PreviousList of the run it starts.
void keepPreviousList (const QString &gpgIdFile, const std::optional< PreviousList > &previous)
 Take previous as the PreviousList of the run Init() starts for gpgIdFile, unless a run is active or an earlier, unfinished run of the same list left one: that one still tells whom the changes removed.
void reencryptAfterFailedCommit (const QString &path, int gitExit, const QString &gitOut, const QString &gitErr, const QString &gpgIdFile, const std::optional< PreviousList > &previous)
 After Init() wrote the new list but could not commit it: report Git's failure and re-encrypt without Git all the same, so nobody just removed can still read the entries.
auto reencryptUsesGit () const -> bool
 gitConfigured(), unless the current run is one reencryptWithoutGit() started.
void reencryptWithoutGit (const QString &dir, const QString &gitError)
 Re-encrypt dir to the .gpg-id Init() wrote although its commit failed, without any Git step (they would fail the same way), and tell the user afterwards that the change is not committed.
void reportUncommittedGpgId (const QString &dir, const QString &gitError, bool reencrypted)
 Tell the user that the recipients of dir changed on disk but the change is not committed, and whether the entries were re-encrypted.
auto translatePathForWsl (const QString &path, const QString &exe) const -> QString
 Translate path for the given exe when WSL-routed: wraps in wslpath substitution, otherwise returns path unchanged.
auto pgit (const QString &path) const -> QString
 Translate path for git when WSL-routed: wraps in wslpath substitution, otherwise returns path unchanged.
auto pgpg (const QString &path) const -> QString
 Translate path for gpg when WSL-routed: wraps in wslpath substitution, otherwise returns path unchanged.

Static Private Member Functions

static auto namedReaders (const QSet< QString > &fprs, const QHash< QString, QString > &names) -> QString
 The names of fprs for a question or a failure, sorted.

Private Attributes

SimpleTransaction m_transaction
QQueue< PendingMove > m_pendingMoves
 Moves through Git, in order, each settled when its PASS_MOVE ends.
QStringList m_movedToReencrypt
bool m_deferredPushByHand = false
NativeGrep m_grep
 Background search over the decrypted store; relays to finishedGrep.
QString m_transactionOutput
 stdout of the steps of the transaction in flight, collected by finished() and handed on, then cleared, when its last step ends.
QQueue< PendingInsert > m_pendingInserts
 The inserts whose gpg step has not ended yet, oldest first.
bool m_insertPlaced = false
bool m_reencryptActive = false
 Set while a re-encryption run is pending or on the worker thread.
bool m_pushAfterReencrypt = false
QString m_reencryptScope
 The folder the re-encryption in flight covers, for the push hold.
bool m_reencryptPushing = false
 Set while finishReencrypt() pushes, so GitPush() does not hold it.
std::atomic< bool > m_reencryptCancel {false}
QThread * m_reencryptThread = nullptr
 The re-encryption worker while it runs, null otherwise. The destructor sets m_reencryptCancel and joins it.
std::optional< UncommittedGpgId > m_uncommittedGpgId
std::optional< WrittenGpgId > m_writtenGpgId
std::optional< PreviousList > m_previousList
QStringList m_reencryptTrusted
QHash< QString, Agreed > m_reencryptAgreed
QHash< QString, Agreed > m_lastUnexpected
QHash< QString, QSet< QString > > m_removedReaders

Friends

class tst_util
class tst_imitatepass

Additional Inherited Members

Public Types inherited from Pass
using SkippedWalks = QHash<QString, SkippedWalk>
 SkippedWalk per absolute folder, for one check of many folders.
using LinkedWalks = QHash<QString, std::optional<QString>>
Static Public Member Functions inherited from Pass
static bool gpgSupportsEd25519 (const QString &gpgExecutable={})
 Check if GPG supports Ed25519 encryption.
static QString getDefaultKeyTemplate (const QString &gpgExecutable={})
 Get default key template for new GPG keys.
static auto exactRecipientArg (const QString &line) -> QString
 A bare mail address in gpg's exact form, <address>; any other line as written.
static auto keyLinesHeldTwiceIn (const QStringList &lines, const QString &listing) -> QHash< QString, QStringList >
 keyLinesHeldTwice() on a listing already made.
static auto describeKeyLinesHeldTwice (const std::optional< QHash< QString, QStringList > > &held) -> QString
 A message naming each line keyLinesHeldTwice() found and what the user can do about it.
static auto pullTimedOut (int timeoutMs) -> QString
 The status-bar text for a blocking pull stopped at its deadline.
static auto maxOutputArgs () -> QStringList
 The gpg options that enforce kMaxPlaintextBytes.
static auto resolveGpgconfCommand (const QString &gpgPath) -> ResolvedGpgconfCommand
 Resolve the gpgconf command to kill agents.
static auto getGpgIdPath (const QString &for_file, const QString &passStore) -> QString
 Get .gpg-id file path for a password file.
static auto skippedGpgId (const QString &forFile, const QString &passStore, QString *recordError=nullptr, SkippedWalks *walks=nullptr) -> std::optional< QString >
 The folder list getGpgIdPath() passed over on its way up to the one it returns, if it passed one over that a signed store must not.
static auto linkedGpgId (const QString &forFile, const QString &passStore, LinkedWalks *walks=nullptr) -> std::optional< QString >
 The link or junction under the name .gpg-id that getGpgIdPath() skips on its way up from forFile, if it skips one before the list it returns.
static auto getRecipientList (const QString &for_file, const QString &passStore) -> QStringList
 Get list of recipients for a password file.
static auto parseRecipients (const QByteArray &contents, const QString &sourceName) -> QStringList
 Parse the contents of a .gpg-id: one recipient per line, # starts a comment, unusable lines are logged and skipped.
static auto passReadsDifferently (const QByteArray &contents) -> QString
 Why pass would read a .gpg-id differently from parseRecipients(), if it would.
static auto loggableArgs (const QStringList &args) -> QStringList
 The arguments as they may appear in the debug log: the value of --passphrase and friends, and otpauth URIs, are replaced.
Static Public Attributes inherited from Pass
static constexpr int kBlockingPullMs = 30000
 How long the pull before an edit may block the window.
static constexpr qint64 kMaxPlaintextBytes = 64LL * 1024 * 1024
 Most bytes of plaintext a gpg decryption may produce.
Protected Types inherited from Pass
enum class  LinkScope { EntryAndParents , ParentsOnly }
 What refuseLinkedPath() judges. More...
enum class  PathSpelling { Configured , PlacedByCaller }
 How a path handed to refuseLinkedPath() is spelled. More...
using PROCESS = Enums::PROCESS
 Alias for Enums::PROCESS used throughout this class.
Static Protected Member Functions inherited from Pass
static auto enabledKeyLines (const QList< UserInfo > &users) -> QStringList
 The enabled users' key IDs, as Init() writes them to .gpg-id.
static auto withoutStatusLines (const QString &err) -> QString
 gpg's stderr without its machine-readable [GNUPG:] lines (and without carriage returns), as a person reads it.

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 41 of file imitatepass.h.

Constructor & Destructor Documentation

◆ ImitatePass()

ImitatePass::ImitatePass ( )

Construct the backend and connect its content search.

Definition at line 54 of file imitatepass.cpp.

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

◆ ~ImitatePass()

ImitatePass::~ImitatePass ( )
override

Cancel a running content search, and cancel and join a running re-encryption worker, before the members they use go away.

Definition at line 58 of file imitatepass.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ addGenerationHeader()

auto ImitatePass::addGenerationHeader ( const QString & gpgIdFile,
const GpgIdSigner & signer,
QByteArray * contents ) -> bool
protected

Put the generation header on a list that is about to be signed: reserve a generation above what this device accepted and what the verified list on disk says, and bind the list to its folder, so no older or relocated signed list comes back.

Parameters
gpgIdFileThe .gpg-id being written.
signerIts signer, which verifies the list on disk.
contentsThe key IDs, one per line; receives the header too.
Returns
false when no generation could be reserved (the user was told); an unrecordable list must not be written, it would let the old one back.

Definition at line 505 of file imitatepass.cpp.

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

◆ beforeExecute()

void ImitatePass::beforeExecute ( PROCESS id)
overrideprotectedvirtual

Open a transaction for every execution.

In native (imitate) mode each wrapped command is a git/gpg transaction; register it before the subprocess runs.

Parameters
idProcess identifier.

Reimplemented from Pass.

Definition at line 2790 of file imitatepass.cpp.

Here is the call graph for this function:

◆ CancelGrep()

void ImitatePass::CancelGrep ( )
inlineoverridevirtual

Stop the running search (NativeGrep::cancel()).

Reimplemented from Pass.

Definition at line 694 of file imitatepass.h.

Here is the call graph for this function:

◆ cancelReencryptPath()

void ImitatePass::cancelReencryptPath ( )

Ask a running reencryptPath() to stop.

Only sets a flag. The worker starts no further gpg or git process, and the one it is blocked on (gpg waiting on pinentry, say) is terminated by the worker itself, and killed if it is still running after a short grace period, so the cancel takes effect promptly rather than after the current file. The store stays consistent: reencryptSingleFile() only replaces a file once the new ciphertext is verified, so an interrupted file is left untouched, or already re-encrypted but not yet committed when git was the process that was interrupted. The remaining files are left untouched and the interrupted file is not reported as a failure. endReencryptPath() is still emitted when the worker has stopped.

Definition at line 1626 of file imitatepass.cpp.

◆ ciphertextHolds()

auto ImitatePass::ciphertextHolds ( const QString & ciphertext,
const QByteArray & plaintext ) -> bool
protected

Decrypt ciphertext again and compare it with plaintext, byte for byte, so nothing replaces an entry until it is known to hold what it held.

Parameters
ciphertextThe file gpg just wrote.
plaintextWhat it must decrypt to.
Returns
Whether it does.

Definition at line 1326 of file imitatepass.cpp.

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

◆ commitArgs()

auto ImitatePass::commitArgs ( ) -> QStringList
protected

The start of a git commit for the store: "commit", and "-S" when git config pass.signcommits is true there, as pass signs its own.

Returns
The arguments, to which the message and paths are appended.

Definition at line 406 of file imitatepass.cpp.

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

◆ commitName()

auto ImitatePass::commitName ( const QString & path) const -> QString
nodiscardprotected

How a commit message names a file of the store: relative to the store, without .gpg ("work/bank", "work/.gpg-id"), never the local path, which the shared history would carry to everyone.

Parameters
pathAbsolute path, normally inside the store.
Returns
The store-relative name; for a path outside the store, its file name alone.

Definition at line 2443 of file imitatepass.cpp.

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

◆ commitReencrypted()

auto ImitatePass::commitReencrypted ( const QString & fileName) -> bool
protected

Stage and commit a re-encrypted entry, when the store is a Git repository QtPass manages.

Parameters
fileNameThe entry that was replaced.
Returns
Whether the repository is up to date with the file; false makes the run count the file as failed, so a partial store is not pushed.

Definition at line 1348 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 )
overridevirtual

Copy password file.

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

Implements Pass.

Definition at line 2615 of file imitatepass.cpp.

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

◆ copyDestination()

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

The file a copy of src to dest writes: like pass cp, into an existing folder with .gpg appended. Refused (the user told) when it is a link, the source itself, or taken and force is off.

Parameters
srcThe entry to copy.
destWhere to, a file or a folder.
forceWhether an existing entry may be replaced.
Returns
The file, or an empty string when refused.

Definition at line 2586 of file imitatepass.cpp.

Here is the call graph for this function:
Here is the caller 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.

Definition at line 1455 of file imitatepass.cpp.

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

◆ decryptEntry()

auto ImitatePass::decryptEntry ( const QString & fileName,
QByteArray * plaintext,
QString * why ) -> bool
protected

Decrypt fileName for re-encryption.

Bytes, not text: an entry that is not UTF-8 (a Latin-1 password, a binary key) went through QString before, and every such byte came back as U+FFFD in the re-encrypted entry. The entry is read without following a link and given to gpg on stdin, so a link put under its name since the run listed it is refused.

Parameters
fileNameThe entry to read.
plaintextReceives exactly what gpg printed.
whySet when the entry is no longer a regular file; may be null.
Returns
Whether gpg decrypted it to something.

Definition at line 1272 of file imitatepass.cpp.

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

◆ dropStaleTemporary()

void ImitatePass::dropStaleTemporary ( const QString & path)
private

Remove a stale temporary a crashed run left, unless it was modified within the hour: on a shared store it may be another QtPass's write in flight under the same name.

Parameters
pathThe temporary, a regular file.

Definition at line 950 of file imitatepass.cpp.

Here is the caller graph for this function:

◆ encryptFor()

auto ImitatePass::encryptFor ( const QString & output,
const QStringList & recipients,
const QByteArray & plaintext ) -> bool
protected

Encrypt plaintext to recipients, into output.

Parameters
outputWhere gpg writes the ciphertext; outside the store.
recipientsThe keys to encrypt to; gpg.conf adds none.
plaintextThe bytes to encrypt, fed on stdin.
Returns
Whether gpg wrote the ciphertext.

Definition at line 1313 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

A reencryptPath() run is over, whether it finished, failed, was cancelled or was refused; the main window releases the interface.

Also emitted without a preceding startReencryptPath() when the folder is refused before anything starts.

Here is the caller graph for this function:

◆ entriesToReencrypt()

auto ImitatePass::entriesToReencrypt ( const QString & dir,
QStringList * failed ) -> QStringList
private

The entries under dir a run considers, telling the user about anything skipped for not being a regular file.

Parameters
dirDirectory to walk, recursively.
failedReceives a failure line for every folder that could not be read: its entries are not in the result, and the run must not pass for complete.
Returns
The .gpg files, links and special files left out.

Definition at line 1745 of file imitatepass.cpp.

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

◆ entryHash()

auto ImitatePass::entryHash ( const QString & file) const -> QByteArray
protected

SHA-256 of an entry's bytes, read as a regular file without following a link.

Parameters
fileThe entry, absolute.
Returns
The hash; empty when it cannot be read so.

Definition at line 1223 of file imitatepass.cpp.

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

◆ execBlocking() [1/2]

auto ImitatePass::execBlocking ( const QString & app,
const QStringList & args,
const QString & input = QString(),
QString * process_out = nullptr,
QString * process_err = nullptr ) -> int
nodiscardprotected

Executor::executeBlocking() for the re-encryption helpers.

Runs in the store's environment (storeEnvironment(); on the worker, the copy taken when it started), which carries the git ceiling QtPass's own does not. On the owning thread this is a plain blocking run. On the worker thread it hands m_reencryptCancel to the cancellable executeBlocking() overload: nothing is started once the flag is set, and a process that is running when it gets set is terminated (then killed) by the worker thread, which is what lets cancelReencryptPath() and the destructor interrupt an active gpg or git without touching its QProcess or pid.

Parameters
appThe program.
argsIts arguments.
inputWhat to write to its stdin.
process_outReceives stdout, if not null.
process_errReceives stderr, if not null.
Returns
Exit code, or -1 when refused, failed to start or interrupted.

Definition at line 84 of file imitatepass.cpp.

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

◆ execBlocking() [2/2]

auto ImitatePass::execBlocking ( const QString & app,
const QStringList & args,
QString * process_out,
QString * process_err = nullptr ) -> int
nodiscardprotected

Overload capturing stdout (and stderr) without stdin input.

Parameters
appThe program.
argsIts arguments.
process_outReceives stdout.
process_errReceives stderr, if not null.
Returns
As the overload above.

Definition at line 102 of file imitatepass.cpp.

Here is the call graph for this function:

◆ execBlockingRaw()

auto ImitatePass::execBlockingRaw ( const QString & app,
const QStringList & args,
const QByteArray & input,
QByteArray * process_out ) -> int
nodiscardprotected

execBlocking() on bytes (Executor::executeBlockingRaw()), for an entry's plaintext, which need not be UTF-8.

Parameters
appThe program.
argsIts arguments.
inputBytes to write to its stdin (empty = none).
process_outReceives stdout as written, if not null.
Returns
As execBlocking().

Definition at line 93 of file imitatepass.cpp.

Here is the call graph for this function:
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.

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

Definition at line 2691 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.

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

Definition at line 2669 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.

Definition at line 2426 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.

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

Reimplemented from Pass.

Definition at line 2701 of file imitatepass.cpp.

Here is the call graph for this function:

◆ finishReencrypt()

void ImitatePass::finishReencrypt ( const ReencryptResult & result)
private

Report the outcome of a run and emit endReencryptPath().

Parameters
resultOutcome produced by reencryptFiles().

Definition at line 2147 of file imitatepass.cpp.

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

◆ fullKeyListing()

auto ImitatePass::fullKeyListing ( QString * listing) -> int
overrideprotectedvirtual

Pass::fullKeyListing() in the calling thread's environment, so a re-encryption run's worker lists the store's keyring.

Parameters
listingReceives the colon listing.
Returns
As Pass::fullKeyListing().

Reimplemented from Pass.

Definition at line 730 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.

Definition at line 1106 of file imitatepass.cpp.

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

◆ gitAddGpgId()

auto ImitatePass::gitAddGpgId ( const QString & gpgIdFile,
const QString & gpgIdSigFile,
QString * out,
QString * err ) -> int
protected

Stage a .gpg-id and, when given, its .sig, and commit both in one commit, so no commit in the history has a recipient list without the signature that covers it. Nothing is committed when neither file changed.

Parameters
gpgIdFileAbsolute path of the .gpg-id.
gpgIdSigFileAbsolute path of the .gpg-id.sig, or empty when no signing key is configured.
outReceives the concatenated stdout of the git commands.
errReceives the concatenated stderr of the git commands.
Returns
Exit code of the first failing git command, 0 on success.

Definition at line 637 of file imitatepass.cpp.

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

◆ gitCommit() [1/2]

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

Commit one path to git.

Parameters
fileChanged file path.
msgCommit message.

Definition at line 419 of file imitatepass.cpp.

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

◆ gitCommit() [2/2]

void ImitatePass::gitCommit ( const QStringList & files,
const QString & msg )

Commit these paths and nothing else: a change someone staged meanwhile stays staged, out of a commit autoPush would send.

Parameters
filesChanged paths (a moved entry's old and new path).
msgCommit message.

Definition at line 423 of file imitatepass.cpp.

Here is the call graph for this function:

◆ gitConfigured()

auto ImitatePass::gitConfigured ( ) const -> bool

Git is enabled and an executable is configured.

Returns
true when git commands can actually run.

Definition at line 2677 of file imitatepass.cpp.

Here is the caller graph for this function:

◆ GitInit()

void ImitatePass::GitInit ( )
overridevirtual

Initialize Git repository.

Implements Pass.

Definition at line 133 of file imitatepass.cpp.

Here is the call graph for this function:

◆ GitPull()

void ImitatePass::GitPull ( )
overridevirtual

Pull from remote.

Implements Pass.

Definition at line 137 of file imitatepass.cpp.

Here is the call graph for this function:

◆ GitPull_b()

void ImitatePass::GitPull_b ( int timeoutMs)
overridevirtual

Run git pull in the store and wait for it, at most timeoutMs.

Parameters
timeoutMsMost milliseconds to wait (Pass::kBlockingPullMs).

Implements Pass.

Definition at line 144 of file imitatepass.cpp.

Here is the call graph for this function:

◆ GitPush()

void ImitatePass::GitPush ( )
overridevirtual

Push to remote. While a re-encryption runs the push is held (Users ▸ OK and a copy ask for it as soon as their commit is made, before the worker is done) and made when the run ends with every file re-encrypted; after a failed or cancelled run nothing is pushed.

Implements Pass.

Definition at line 166 of file imitatepass.cpp.

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

◆ gitReady()

auto ImitatePass::gitReady ( ) -> bool

gitConfigured() plus a status message when git is enabled but no executable is configured.

Returns
true when git commands can actually run.

Definition at line 2683 of file imitatepass.cpp.

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

◆ gitTracks()

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

Check whether git already tracks a file in the store.

Parameters
fileAbsolute path inside the password store.
Returns
true when the file is in the git index.

Definition at line 681 of file imitatepass.cpp.

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

◆ gpgIdSigner()

auto ImitatePass::gpgIdSigner ( ) -> GpgIdSigner
protected

The signer for this store's .gpg-id, bound to the configured gpg and signing keys and to execBlocking(), so a verification on the re-encryption worker can be interrupted like every other gpg run there.

Returns
A signer; cheap to build, valid while m_settings is.

Definition at line 494 of file imitatepass.cpp.

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

◆ Grep()

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

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

Pattern is interpreted as a QRegularExpression (PCRE-like); RealPass::Grep uses the same search, so both backends match alike.

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

Implements Pass.

Definition at line 2796 of file imitatepass.cpp.

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

◆ holdForAgreement()

auto ImitatePass::holdForAgreement ( const QString & fileName,
const QStringList & keys,
const ReaderChange & change,
const WhoReads & who,
ReencryptResult & result ) -> bool
private

Leave an entry that would gain readers for the user: named in the question after the run, with the bytes it is named for, or reported as failed when its bytes cannot be read to hold a yes to.

Parameters
fileNameThe entry.
keysThe recipient key IDs it is encrypted to.
changeWho gains it and who still reads it.
whoThe run's record of key IDs and names.
resultGets the question or the failure.
Returns
Whether its removed-reader record is kept (reported as failed).

Definition at line 2032 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.

Writes (and signs) the folder's .gpg-id, commits it when Git is used and re-encrypts the folder to it. When that commit fails the entries are still re-encrypted, without any Git step, and a critical() afterwards says the change is not committed and whether the re-encryption completed. Nothing is written while .gpg-id or .gpg-id.sig is there as something other than a regular file (a folder).

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

Implements Pass.

Definition at line 741 of file imitatepass.cpp.

Here is the call graph for this function:

◆ Insert()

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

Insert new password.

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

Implements Pass.

Definition at line 347 of file imitatepass.cpp.

Here is the call graph for this function:

◆ insertWritten()

auto ImitatePass::insertWritten ( const QString & err) const -> bool
inlinenodiscardoverrideprotectedvirtual

Whether the failed insert had placed its entry (see placeEncryptedFile()) before a later git step failed.

Parameters
errNot needed: the placement is known, not inferred.
Returns
true when the entry is in the store.

Reimplemented from Pass.

Definition at line 469 of file imitatepass.h.

◆ isTrustedEntry()

auto ImitatePass::isTrustedEntry ( const QString & fileName,
const QSet< QString > & listNow ) const -> bool
nodiscardprivate

Whether an entry that would gain readers is taken without a question: the user moved or copied it in, or agreed to it in reencryptAlso() while its bytes and its list's keys are unchanged.

Parameters
fileNameThe entry.
listNowThe keys its list encrypts to now.
Returns
Whether it is re-encrypted without asking.

Definition at line 1924 of file imitatepass.cpp.

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

◆ keepPreviousList()

void ImitatePass::keepPreviousList ( const QString & gpgIdFile,
const std::optional< PreviousList > & previous )
private

Take previous as the PreviousList of the run Init() starts for gpgIdFile, unless a run is active or an earlier, unfinished run of the same list left one: that one still tells whom the changes removed.

Parameters
gpgIdFileThe .gpg-id Init() wrote.
previousThe list it replaced, if verified.

Definition at line 823 of file imitatepass.cpp.

Here is the caller graph for this function:

◆ keysEncryptedTo()

auto ImitatePass::keysEncryptedTo ( const QStringList & recipients,
QHash< QString, QString > & primaries,
QHash< QString, QString > & names,
bool lookUp = true ) -> std::optional< QSet< QString > >
protected

The primary keys gpg encrypts to for recipients, found by a throwaway encryption outside the store with the arguments a real one uses, so groups, ! suffixes and key lookups count as -r makes them.

Parameters
recipientsA recipient list.
primariesAs for primaryKeysOf().
namesAs for primaryKeysOf().
lookUpWhether gpg may look keys up (auto-key-locate, WKD) as a real encryption would; false for a list being replaced, whose removed recipients should not be fetched over the network.
Returns
The fingerprints; nothing when gpg cannot encrypt to the list.

Definition at line 1231 of file imitatepass.cpp.

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

◆ listKeysFor()

auto ImitatePass::listKeysFor ( const QString & gpgIdPath,
const QStringList & gpgId,
WhoReads & who ) -> const ListKeys &
private

The keys of the list at gpgIdPath, worked out once per run.

Parameters
gpgIdPathThe .gpg-id the entry falls under.
gpgIdThe recipients read from it.
whoThe run's record; the result is kept in it.
Returns
Its keys now and before Init() replaced it.

Definition at line 1942 of file imitatepass.cpp.

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

◆ loadVerifiedRecipients()

auto ImitatePass::loadVerifiedRecipients ( const QString & gpgIdFile,
QStringList * recipients,
QString * why = nullptr ) -> bool
protected

Read a .gpg-id, verify its detached signature and parse the recipients from the bytes that were verified.

One read serves both the check and the parse, so a file swapped in between cannot smuggle in a recipient the signature never covered.

Parameters
gpgIdFileThe .gpg-id.
recipientsReceives the recipients; empty on failure.
whyReceives, if not null, what to tell the user on failure: a bad signature, or a signed list older than one accepted before (GpgIdGeneration).
Returns
false when the file cannot be read, the signature is bad or the list is a rollback (with a signing key configured). true otherwise, also for an empty list; the caller decides what an empty list means.

Definition at line 901 of file imitatepass.cpp.

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

◆ Move()

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

Move password file.

As pass mv, what moved is then re-encrypted for the recipients where it landed, when another .gpg-id applies there than where it came from (a folder with its own list takes that along): see reencryptMoved(). With Git that happens once the queued git mv has run. No message box opens while the move's Git commands are being queued.

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

Implements Pass.

Definition at line 2456 of file imitatepass.cpp.

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

◆ namedReaders()

auto ImitatePass::namedReaders ( const QSet< QString > & fprs,
const QHash< QString, QString > & names ) -> QString
staticprivate

The names of fprs for a question or a failure, sorted.

Parameters
fprsPrimary fingerprints, or kUnknownReader.
namesFingerprint to name, as the run learnt them.
Returns
The names, comma-separated.

Definition at line 2017 of file imitatepass.cpp.

Here is the caller graph for this function:

◆ pgit()

auto ImitatePass::pgit ( const QString & path) const -> QString
private

Translate path for git when WSL-routed: wraps in wslpath substitution, otherwise returns path unchanged.

Parameters
pathNative filesystem path.
Returns
Path suitable for the configured git executable.

Definition at line 125 of file imitatepass.cpp.

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

◆ pgpg()

auto ImitatePass::pgpg ( const QString & path) const -> QString
private

Translate path for gpg when WSL-routed: wraps in wslpath substitution, otherwise returns path unchanged.

Parameters
pathNative filesystem path.
Returns
Path suitable for the configured gpg executable.

Definition at line 129 of file imitatepass.cpp.

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

◆ placeEncryptedFile()

auto ImitatePass::placeEncryptedFile ( const QString & output,
const QString & file,
bool overwrite,
QString * error ) -> bool
private

Bring the ciphertext gpg wrote to output into the store as file (Util::copyFileReplacing): through a temporary created next to the entry and written by its open handle, then the operating system's rename, which replaces the entry under that name (or, without overwrite, fails when one has appeared) and follows nothing. Reports nothing itself: Insert()'s finished() routes the reason through the failed-operation path once the queued git steps are cancelled, and re-encryption lists it in the run's summary.

Parameters
outputThe file gpg wrote, in a directory of QtPass's own.
fileThe entry's path.
overwriteWhether an entry already there may be replaced.
errorReceives why file could not be written, if not.
Returns
Whether file now holds the new ciphertext.

Definition at line 2778 of file imitatepass.cpp.

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

◆ placePendingInsert()

auto ImitatePass::placePendingInsert ( int exitCode,
QString * error ) -> int
private

Finish the oldest pending insert after its gpg step: place the ciphertext with placeEncryptedFile(), unless gpg failed or a Git operation stopped half-way meanwhile. Sets m_insertPlaced.

Parameters
exitCodeThe gpg step's exit code.
errorReceives why the entry was not placed, if so.
Returns
exitCode when gpg failed, 1 when the entry was not placed, else 0.

Definition at line 2748 of file imitatepass.cpp.

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

◆ prepareBlocking()

auto ImitatePass::prepareBlocking ( QProcess & process) -> const std::atomic_bool *
protected

Give process the environment for the calling thread: the store's on the owning thread, the re-encryption run's on its worker.

Parameters
processThe process to set up.
Returns
The cancel flag to pass on: null on the owning thread, the re-encryption run's on the worker.

Definition at line 72 of file imitatepass.cpp.

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

◆ previousListOf()

auto ImitatePass::previousListOf ( const QString & path,
const QString & gpgIdFile ) -> std::optional< PreviousList >
private

The verified list the entries of path were encrypted to before Init() replaces it, as the PreviousList of the run it starts.

Parameters
pathThe folder, in the store's own spelling, with a trailing separator.
gpgIdFileThe .gpg-id Init() writes there.
Returns
That list, or nothing when there was none or it was empty or unverified.

Definition at line 888 of file imitatepass.cpp.

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

◆ primaryKeysOf()

auto ImitatePass::primaryKeysOf ( const QStringList & ids,
QHash< QString, QString > & primaries,
QHash< QString, QString > & names ) -> QSet< QString >
protected

The primary keys behind key IDs from an entry (ENC_TO).

Parameters
idsLong key IDs of encryption subkeys.
primariesKey ID to primary fingerprint, filled from one key listing on first use.
namesPrimary fingerprint to its first user ID, filled with it.
Returns
The fingerprints; a key ID gpg does not know is left out.

Definition at line 1192 of file imitatepass.cpp.

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

◆ pullBeforeReencrypt()

auto ImitatePass::pullBeforeReencrypt ( ) -> bool
private

Pull before a run, when the store is a Git repository and automatic pulling is on.

Pull before re-encryption when automatic pulling is configured.

Returns
Whether re-encrypting may go ahead: false when a failed pull left unmerged files, the check for them fails, or HEAD is still behind its upstream (the checkout may have stopped half-way).
true if no pull is needed, the pull succeeds, or a failed pull leaves no unmerged files and HEAD not behind its upstream; false otherwise.

Definition at line 1693 of file imitatepass.cpp.

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

◆ readerChangeOf()

auto ImitatePass::readerChangeOf ( const QString & fileName,
const QStringList & keys,
const ListKeys & lk,
WhoReads & who ) -> ReaderChange
private

Who would gain an entry by re-encrypting it to its list, other than those this change added, and who was taken off and still reads it.

Parameters
fileNameThe entry.
keysThe recipient key IDs it is encrypted to.
lkIts list's keys (listKeysFor()).
whoThe run's record of key IDs and names.
Returns
The change; nobody gains when gpg cannot encrypt to the list.

Definition at line 1967 of file imitatepass.cpp.

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

◆ readersAnEditWouldAdd()

auto ImitatePass::readersAnEditWouldAdd ( const QString & file) -> EditReaders
overridevirtual

Who saving over an existing entry would let read it who may not now.

Asked by the edit dialog before Insert(), so a list that changed under the entry (a folder renamed past its own signed list, say) does not widen it unasked. Those who read it now come from the entry's recipient IDs, which whoever can push can write; so with a signing key, an entry at a path this device never saved (EntryRecord) whose folder takes a parent's list is asked about whatever its IDs say. None by default; the native backend tells.

Parameters
fileThe entry, relative to the store, without ".gpg".
Returns
The answer; empty names when nothing needs asking or it cannot be told (new entry, unreadable list).

Reimplemented from Pass.

Definition at line 282 of file imitatepass.cpp.

Here is the call graph for this function:

◆ recipientsForDir()

auto ImitatePass::recipientsForDir ( const QString & fileName,
QHash< QString, QStringList > & verified,
QStringList & gpgId,
ReencryptResult & result ) -> bool
private

The verified recipients for the folder fileName sits in.

Parameters
fileNameAn entry in the folder.
verifiedCache of the .gpg-id files already checked.
gpgIdReceives the recipients to encrypt that folder to.
resultMarked cancelled or aborted when the answer is no.
Returns
Whether the run may go on with this folder.

Definition at line 1781 of file imitatepass.cpp.

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

◆ recipientsForEntry()

auto ImitatePass::recipientsForEntry ( const QString & file,
QStringList * recipients ) -> bool
protected

The recipients to encrypt file to: its folder's .gpg-id, verified when a signing key is set.

Parameters
fileThe entry, absolute.
recipientsReceives the key IDs.
Returns
false when there are none to use (the user was told why).

Definition at line 261 of file imitatepass.cpp.

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

◆ recoverReencryptLeftovers()

auto ImitatePass::recoverReencryptLeftovers ( const QString & dir) -> bool
private

Deal with what a crashed or failed earlier run left under dir before touching anything: stale temporaries (today's staged .qtpass-XXXXXX.tmp, 1.8.x's <entry>.reencrypt.tmp, the <entry>.XXXXXX.tmp of builds in between) are removed unless they were modified within the hour, where they may be another QtPass's write in flight on a shared store; a 1.8.x <entry>.reencrypt.bak whose original is missing is put back, one next to a present original is reported and left alone (both are valid ciphertexts, the choice is the user's). Whatever needs a human is reported in one critical(), the list capped.

Parameters
dirDirectory to scan, recursively.
Returns
false when something was reported that needs a human first.

Definition at line 999 of file imitatepass.cpp.

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

◆ reencryptAfterFailedCommit()

void ImitatePass::reencryptAfterFailedCommit ( const QString & path,
int gitExit,
const QString & gitOut,
const QString & gitErr,
const QString & gpgIdFile,
const std::optional< PreviousList > & previous )
private

After Init() wrote the new list but could not commit it: report Git's failure and re-encrypt without Git all the same, so nobody just removed can still read the entries.

Parameters
pathThe folder, in the store's own spelling.
gitExitGit's exit code.
gitOutGit's standard output.
gitErrGit's error output, shown as the reason when not empty.
gpgIdFileThe .gpg-id Init() wrote.
previousThe list it replaced, if verified.

Definition at line 835 of file imitatepass.cpp.

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

◆ reencryptAlso()

void ImitatePass::reencryptAlso ( const QString & dir,
const QStringList & files,
const AppSettings & settings )

Re-encrypt files in dir after the user agreed to it.

A run leaves alone an entry encrypted to other keys than its folder had (unexpectedRecipients()): someone who can read one folder could have copied it in from a folder they cannot read, and re-encrypting it would hand them its plaintext. This runs dir again with files taken as they are. Only entries the last run named, each only while its bytes are those it was named with; the run takes those and nothing else.

Parameters
dirThe folder of the run that found them.
filesThe entries, as unexpectedRecipients() named them.
settingsThe current settings, as for reencryptPath().

Definition at line 2307 of file imitatepass.cpp.

Here is the call graph for this function:

◆ reencryptEntry()

auto ImitatePass::reencryptEntry ( const QString & fileName,
const QStringList & gpgId,
WhoReads & who,
ReencryptResult & result ) -> bool
private

Check one entry and re-encrypt it to gpgId when it is not encrypted to those keys yet, unless it would gain readers no one agreed to.

Parameters
fileNameThe entry.
gpgIdThe recipients of its folder.
whoThe run's record of who reads what.
resultGets the entry's outcome.
Returns
false when the run was cancelled meanwhile.

Definition at line 2087 of file imitatepass.cpp.

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

◆ reencryptFiles()

auto ImitatePass::reencryptFiles ( const QString & dir) -> ReencryptResult
private

Worker-thread body: scan dir and re-encrypt stale files.

Parameters
dirDirectory passed to reencryptPath().
Returns
Counts and the list of files that could not be re-encrypted.

Definition at line 1805 of file imitatepass.cpp.

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

◆ reencryptMoved()

void ImitatePass::reencryptMoved ( const PendingMove & move)
private

Queue a re-encryption of what move moved, if it moved and another .gpg-id applies where it landed; a folder that has its own list is left as it is. Only that entry or folder, not what is around it; startMovedReencrypts() starts it.

Parameters
moveThe move, as Move() recorded it.

Definition at line 2554 of file imitatepass.cpp.

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

◆ reencryptPath() [1/2]

void ImitatePass::reencryptPath ( const QString & dir)

Re-encrypt entire directory.

Emits startReencryptPath() synchronously, then runs the scan and the per-file gpg calls on a worker thread. Progress is reported through reencryptProgress(); per-file failures are collected and reported in a single critical() once the run is over, followed by endReencryptPath(). A second call while a run is active is ignored. Dot-named entries (.env.gpg) are re-encrypted too, as with pass init; hidden folders (.git, .stversions) are not entered.

Parameters
dirDirectory path, or one entry's .gpg file (a move re-encrypts what it moved, not the folder around it).

Definition at line 1590 of file imitatepass.cpp.

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

◆ reencryptPath() [2/2]

void ImitatePass::reencryptPath ( const QString & dir,
const AppSettings & settings )

Re-encrypt dir under settings, the current profile's.

This backend re-encrypts also when pass is the active one, and then is not re-initialised on a profile switch: without this it would decrypt the current profile's entries and encrypt them to the recipients and signing policy of the profile it last ran for. The settings are taken only when no run is active, so a running one keeps its own.

Parameters
dirDirectory path.
settingsThe current settings.

Definition at line 1581 of file imitatepass.cpp.

Here is the call graph for this function:

◆ reencryptProgress

void ImitatePass::reencryptProgress ( int current,
int total )
signal

Re-encryption progress: current of total files checked.

Emitted from the worker thread; connect with a queued (or automatic) connection.

Parameters
currentNumber of files checked so far, including this one.
totalTotal number of files found by the scan.
Here is the caller graph for this function:

◆ reencryptSingleFile()

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

Re-encrypt single file with new recipients.

Parameters
fileNameFile to re-encrypt.
recipientsNew recipient key IDs.
whyReceives, for a failure the user can act on (the new ciphertext could not be put under the entry's name), the reason for the run's summary; left empty for a gpg failure, which is logged.
Returns
true on success, false on failure.

Definition at line 1375 of file imitatepass.cpp.

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

◆ reencryptUsesGit()

auto ImitatePass::reencryptUsesGit ( ) const -> bool
private

gitConfigured(), unless the current run is one reencryptWithoutGit() started.

Returns
Whether the re-encryption run may call Git.

Definition at line 2336 of file imitatepass.cpp.

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

◆ reencryptWithoutGit()

void ImitatePass::reencryptWithoutGit ( const QString & dir,
const QString & gitError )
private

Re-encrypt dir to the .gpg-id Init() wrote although its commit failed, without any Git step (they would fail the same way), and tell the user afterwards that the change is not committed.

Parameters
dirThe folder whose recipients changed.
gitErrorWhat Git said when the commit failed.

Definition at line 2340 of file imitatepass.cpp.

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

◆ refuseInitBeforeWrite()

auto ImitatePass::refuseInitBeforeWrite ( const QString & gpgIdFile,
const GpgIdSigner & signer ) -> bool
private

The checks Init() runs before it writes anything: no re-encryption running, the signing key's secret key available, the list and its signature free or regular files, and the list unchanged since the users dialog read it. Each refusal is shown.

Parameters
gpgIdFileThe .gpg-id Init() is to write.
signerThe store's signer.
Returns
true when Init() must stop.

Definition at line 851 of file imitatepass.cpp.

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

◆ refuseLinkedGpgIdFolder()

auto ImitatePass::refuseLinkedGpgIdFolder ( const QString & path) -> bool
protected

Refuse a folder, or a .gpg-id/.gpg-id.sig in it, that is a link: writing there would reach outside the store.

Parameters
pathThe folder, with its trailing separator.
Returns
Whether it was refused (and the user told).

Definition at line 687 of file imitatepass.cpp.

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

◆ refuseOverlappingMove()

auto ImitatePass::refuseOverlappingMove ( const QString & src,
const QString & destFile ) -> bool
private

Refuse a move of src to destFile that touches what an earlier move or a re-encryption still has to settle: moving it again meanwhile would leave the run for the place it is no longer at.

Parameters
srcWhat is to be moved.
destFileWhere to, as resolveMoveDestination() gave it.
Returns
true if refused (the user told).

Definition at line 2521 of file imitatepass.cpp.

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

◆ rememberUnexpected()

void ImitatePass::rememberUnexpected ( const ReencryptResult & result)
private

Keep what the run named in unexpectedRecipients(), with the bytes and readers it was named for: reencryptAlso() takes the user's yes from there.

Parameters
resultThe run's outcome.

Definition at line 2296 of file imitatepass.cpp.

Here is the caller graph for this function:

◆ Remove()

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

Remove password.

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

Implements Pass.

Definition at line 431 of file imitatepass.cpp.

Here is the call graph for this function:

◆ reportFailedEntries()

void ImitatePass::reportFailedEntries ( const QStringList & failed)
private

Tell the user which entries a run could not re-encrypt, the first few by name.

Parameters
failedThe entries that failed; nothing is shown when empty.

Definition at line 2192 of file imitatepass.cpp.

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

◆ reportReencryptOutcome()

void ImitatePass::reportReencryptOutcome ( const ReencryptResult & result,
bool stillRead )
private

The status line for a run, and the push after it when one is due and nothing holds it.

Parameters
resultThe run's outcome.
stillReadWhether a removed recipient still reads an entry in the run's folder (settleAutoPushHold()).

Definition at line 2247 of file imitatepass.cpp.

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

◆ reportUncommittedGpgId()

void ImitatePass::reportUncommittedGpgId ( const QString & dir,
const QString & gitError,
bool reencrypted )
private

Tell the user that the recipients of dir changed on disk but the change is not committed, and whether the entries were re-encrypted.

Parameters
dirThe folder whose recipients changed.
gitErrorWhat Git said when the commit failed.
reencryptedWhether every entry was re-encrypted to the new recipients; false means some or all are still encrypted to the previous ones.

Definition at line 2357 of file imitatepass.cpp.

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

◆ reportUnrestorable()

void ImitatePass::reportUnrestorable ( const QString & path,
QStringList & problems )
private

Note for the user that a leftover is not a regular file and was left.

Parameters
pathThe leftover.
problemsGets the sentence for it.

Definition at line 943 of file imitatepass.cpp.

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.

Definition at line 2381 of file imitatepass.cpp.

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

◆ restoreBackup()

auto ImitatePass::restoreBackup ( const QString & path,
QStringList & problems ) -> bool
private

Put a 1.8.x backup back in its entry's place when the entry is missing; report it when both exist (both are valid ciphertexts, the choice is the user's) or when the rename fails.

Parameters
pathThe <entry>.reencrypt.bak file.
problemsGets what to tell the user, if anything.
Returns
Whether nothing needs a human first.

Definition at line 962 of file imitatepass.cpp.

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

◆ sendDeferredPush()

void ImitatePass::sendDeferredPush ( )
private

Make the push GitPush() deferred, once no run is in flight and no move is waiting; an automatic one only while the store is not held.

Definition at line 182 of file imitatepass.cpp.

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

◆ settleAutoPushHold()

auto ImitatePass::settleAutoPushHold ( const ReencryptResult & result,
bool agreedRun ) -> bool
private

Bring the record of entries a removed recipient still reads up to date with a run, and hold the automatic push for the run's folder when the change is not done there, or release it after a full, clean run.

Parameters
resultThe run's outcome.
agreedRunWhether the run took only entries the user agreed to, which settles those, not the folder's other holds.
Returns
Whether an entry in the run's folder is still read by someone the change removed.

Definition at line 2207 of file imitatepass.cpp.

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

◆ settleSignature()

auto ImitatePass::settleSignature ( const QString & gpgIdFile,
const QByteArray & written,
const GpgIdSigner & signer,
bool useGit,
QString * sigToCommit ) -> bool
protected

Bring the signature in line with the list just written: a new one when signing is on, the old one removed when it is off (pass and other clients would reject the new list under it).

Parameters
gpgIdFileThe .gpg-id that was written.
writtenIts bytes, which are what gets signed.
signerWhether and with which keys to sign.
useGitWhether the store is a Git repository QtPass manages.
sigToCommitReceives the signature file to commit, if any.
Returns
false when signing or removing failed (the user was told).

Definition at line 701 of file imitatepass.cpp.

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

◆ Show()

void ImitatePass::Show ( QString file)
overridevirtual

Show decrypted password.

Parameters
filePath to the password file relative to store root.

Implements Pass.

Definition at line 217 of file imitatepass.cpp.

Here is the call graph for this function:

◆ signGpgIdFile()

auto ImitatePass::signGpgIdFile ( const QString & gpgIdFile,
const QByteArray & contents ) -> bool
protected

Sign a .gpg-id with the configured key and verify the result; failures are reported through critical().

Parameters
gpgIdFilePath to .gpg-id file.
contentsThe bytes just written as that file: the signature is made over these, not over whatever is under the name by then.
Returns
true on success, false on failure.

Definition at line 613 of file imitatepass.cpp.

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

◆ startMovedReencrypts()

void ImitatePass::startMovedReencrypts ( )
private

Start the runs in m_movedToReencrypt, one at a time, while none is in flight; then send a deferred push once nothing is left.

Definition at line 199 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

A reencryptPath() run is about to start its worker thread.

The main window disables the interface and shows a progress dialog with a Cancel button on it. Always followed by endReencryptPath().

Here is the caller graph for this function:

◆ startReencryptRun()

auto ImitatePass::startReencryptRun ( const QString & dir,
ReencryptResult & result ) -> bool
private

The checks a run makes after its own pull, before it writes: no unfinished Git operation, dir not a link or behind one, the list Init() wrote unchanged by the pull; then the leftovers of an interrupted run, and the backup commit.

Parameters
dirDirectory passed to reencryptPath().
resultMarked aborted or cancelled when the run stops.
Returns
Whether the run goes on.

Definition at line 1849 of file imitatepass.cpp.

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

◆ startReencryptWorker()

void ImitatePass::startReencryptWorker ( const QString & dir)
private

Start the worker thread once the Executor queue is idle.

Parameters
dirDirectory passed to reencryptPath().

Definition at line 1637 of file imitatepass.cpp.

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

◆ storeGit()

auto ImitatePass::storeGit ( const QStringList & args,
QString * out ) -> bool
overrideprotectedvirtual

Run git with -C <Store tree and entries> in the store, blocking.

Parameters
argsThe git arguments (without the executable or -C).
outReceives stdout; may be null.
Returns
true when git ran and exited 0 (git on and configured).

Reimplemented from Pass.

Definition at line 113 of file imitatepass.cpp.

Here is the call graph for this function:

◆ translatePathForWsl()

auto ImitatePass::translatePathForWsl ( const QString & path,
const QString & exe ) const -> QString
private

Translate path for the given exe when WSL-routed: wraps in wslpath substitution, otherwise returns path unchanged.

Parameters
pathNative filesystem path.
exeExecutable path (checked for "wsl " prefix).
Returns
Path suitable for the given executable.

Definition at line 108 of file imitatepass.cpp.

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

◆ unexpectedRecipients

void ImitatePass::unexpectedRecipients ( const QString & dir,
const QStringList & files,
const QStringList & details )
signal

A run left files alone: re-encrypting one would let someone on its folder's list read it who cannot now, and whom the change of the list did not add. An entry copied in from a folder they cannot read must not reach them without the user's say. reencryptAlso() takes them once the user agreed. Emitted after endReencryptPath().

Parameters
dirThe folder of the run.
filesThe entries left alone, absolute.
detailsFor each, who would gain it, and who was removed from the list and still reads it (the run then holds the automatic push).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ verifyGpgIdForDir()

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

Recipients for the directory of file, from its verified .gpg-id.

Parameters
filePassword file path.
verifiedCache of .gpg-id path to the recipients its verified contents held; a hit skips gpg and reuses exactly that list.
gpgIdOutput parameter for recipient key IDs, sorted.
Returns
true on success, false when the file is unreadable or its signature is bad (reported through critical()).

Definition at line 1067 of file imitatepass.cpp.

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

◆ writeGpgIdFile()

auto ImitatePass::writeGpgIdFile ( const QString & gpgIdFile,
const QList< UserInfo > & users,
QByteArray * written = nullptr ) -> bool
protected

Write the enabled recipients to a .gpg-id, atomically: a write that fails halfway (full disk, dead network share) leaves the previous file in place instead of a truncated list that would then be signed and encrypted to.

Parameters
gpgIdFilePath to .gpg-id file.
usersList of recipients.
writtenReceives the exact bytes written, if not null: what the signature is then made over.
Returns
true when the file was written; false after reporting through critical().

Definition at line 566 of file imitatepass.cpp.

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

◆ tst_imitatepass

friend class tst_imitatepass
friend

Definition at line 45 of file imitatepass.h.

◆ tst_util

friend class tst_util
friend

Definition at line 44 of file imitatepass.h.

Member Data Documentation

◆ m_deferredPushByHand

bool ImitatePass::m_deferredPushByHand = false
private

The deferred push (m_pushAfterReencrypt) includes one asked for by hand, which a hold (autoPushHeld()) does not stop.

Definition at line 717 of file imitatepass.h.

◆ m_grep

NativeGrep ImitatePass::m_grep
private

Background search over the decrypted store; relays to finishedGrep.

Definition at line 747 of file imitatepass.h.

◆ m_insertPlaced

bool ImitatePass::m_insertPlaced = false
private

The insert whose gpg step ended last placed its entry in the store; its git steps may still fail. Set per gpg completion in finished(), not per Insert() call, so a second queued insert's failure is not reported with an earlier insert's answer.

Definition at line 774 of file imitatepass.h.

◆ m_lastUnexpected

QHash<QString, Agreed> ImitatePass::m_lastUnexpected
private

What the last run named (unexpectedRecipients()), with what was shown; reencryptAlso() takes the user's yes from here.

Definition at line 1132 of file imitatepass.h.

◆ m_movedToReencrypt

QStringList ImitatePass::m_movedToReencrypt
private

What settled moves still need re-encrypted: one run each, started by startMovedReencrypts() once no run is in flight. Pushes wait for them.

Definition at line 714 of file imitatepass.h.

◆ m_pendingInserts

QQueue<PendingInsert> ImitatePass::m_pendingInserts
private

The inserts whose gpg step has not ended yet, oldest first.

Definition at line 769 of file imitatepass.h.

◆ m_pendingMoves

QQueue<PendingMove> ImitatePass::m_pendingMoves
private

Moves through Git, in order, each settled when its PASS_MOVE ends.

Definition at line 711 of file imitatepass.h.

◆ m_previousList

std::optional<PreviousList> ImitatePass::m_previousList
private

Set by Init() for the run it starts and cleared by finishReencrypt(). Written only on the owning thread while no worker runs.

Definition at line 1068 of file imitatepass.h.

◆ m_pushAfterReencrypt

bool ImitatePass::m_pushAfterReencrypt = false
private

A push was asked for while a run was active (GitPush()); the run makes it at its end, when every file went through.

Definition at line 813 of file imitatepass.h.

◆ m_reencryptActive

bool ImitatePass::m_reencryptActive = false
private

Set while a re-encryption run is pending or on the worker thread.

Definition at line 810 of file imitatepass.h.

◆ m_reencryptAgreed

QHash<QString, Agreed> ImitatePass::m_reencryptAgreed
private

The entries the user agreed to in reencryptAlso(), with what they were shown: the run takes only these, and each only while its bytes and its folder's keys are unchanged. Same lifetime as m_reencryptTrusted.

Definition at line 1129 of file imitatepass.h.

◆ m_reencryptCancel

std::atomic<bool> ImitatePass::m_reencryptCancel {false}
private

Set by cancelReencryptPath() and the destructor; read by the worker between files and polled by Executor::executeBlocking() while the worker waits on a process, which the worker then ends itself. The flag is the only thing shared with the worker: its QProcess is not thread-safe and is never touched from another thread.

Definition at line 823 of file imitatepass.h.

◆ m_reencryptEnv

QProcessEnvironment ImitatePass::m_reencryptEnv
protected

storeEnvironment() as it was when the worker started; the worker's processes run in it.

Definition at line 391 of file imitatepass.h.

◆ m_reencryptPushing

bool ImitatePass::m_reencryptPushing = false
private

Set while finishReencrypt() pushes, so GitPush() does not hold it.

Definition at line 817 of file imitatepass.h.

◆ m_reencryptScope

QString ImitatePass::m_reencryptScope
private

The folder the re-encryption in flight covers, for the push hold.

Definition at line 815 of file imitatepass.h.

◆ m_reencryptThread

QThread* ImitatePass::m_reencryptThread = nullptr
private

The re-encryption worker while it runs, null otherwise. The destructor sets m_reencryptCancel and joins it.

Definition at line 828 of file imitatepass.h.

◆ m_reencryptTrusted

QStringList ImitatePass::m_reencryptTrusted
private

Entries or folders the current run re-encrypts whatever they are encrypted to: what the user moved or copied there. Cleared by finishReencrypt(); written only on the owning thread while no worker runs.

Definition at line 1120 of file imitatepass.h.

◆ m_removedReaders

QHash<QString, QSet<QString> > ImitatePass::m_removedReaders
private

Entries left alone that a recipient taken off their folder's list still reads, by whom: the automatic push for their folder waits until a run re-encrypts them, finds nobody removed reading them, or they are gone. Kept across runs; written only on the owning thread while no worker runs.

Definition at line 1138 of file imitatepass.h.

◆ m_transaction

SimpleTransaction ImitatePass::m_transaction
private

Groups the git/gpg processes of one operation (Insert, Remove, Move, Copy) into a single completion; see finished() and TransactionHelper.

Definition at line 699 of file imitatepass.h.

◆ m_transactionOutput

QString ImitatePass::m_transactionOutput
private

stdout of the steps of the transaction in flight, collected by finished() and handed on, then cleared, when its last step ends.

Definition at line 752 of file imitatepass.h.

◆ m_uncommittedGpgId

std::optional<UncommittedGpgId> ImitatePass::m_uncommittedGpgId
private

Set by reencryptWithoutGit() for the run it starts and cleared by finishReencrypt(): that run does no Git at all (no pull, backup commit, per-entry commit or push) and ends with reportUncommittedGpgId(). Written only on the owning thread while no worker runs; the worker only reads it, through reencryptUsesGit().

Definition at line 1040 of file imitatepass.h.

◆ m_writtenGpgId

std::optional<WrittenGpgId> ImitatePass::m_writtenGpgId
private

Set by Init() for the run it starts and cleared by finishReencrypt(), or at once when that run is refused before it starts. After its pull the worker stops when the list no longer holds these bytes: a merge changed the recipients the user chose. Written only on the owning thread while no worker runs; the worker only reads it.

Definition at line 1054 of file imitatepass.h.


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