19#include <QProcessEnvironment>
77class Pass :
public QObject {
87 QProcessEnvironment
env;
108 static auto enabledKeyLines(
const QList<UserInfo> &users) -> QStringList;
137 -> QProcessEnvironment;
192 ~Pass()
override =
default;
227 virtual void Show(QString file) = 0;
234 virtual void Insert(QString file, QString value,
bool force) = 0;
297 const QList<UserInfo> &users)
344 virtual void Remove(QString file,
bool isDir) = 0;
351 virtual void Move(
const QString srcDir,
const QString dest,
352 const bool force) = 0;
359 virtual void Copy(
const QString srcDir,
const QString dest,
360 const bool force) = 0;
366 virtual void Init(QString path,
const QList<UserInfo> &users) = 0;
377 virtual void Grep(QString pattern,
bool caseInsensitive) = 0;
407 auto listKeys(QStringList keystrings,
bool secret =
false) -> QList<UserInfo>;
422 -> std::optional<QStringList>;
460 -> std::optional<QHash<QString, QStringList>>;
471 QString *out, QString *err) -> int;
480 const QString &listing)
481 -> QHash<QString, QStringList>;
490 const std::optional<QHash<QString, QStringList>> &held) -> QString;
497 auto listKeys(
const QString &keystring =
"",
bool secret =
false)
518 [[nodiscard]]
static auto pullTimedOut(
int timeoutMs) -> QString;
540 static auto getGpgIdPath(
const QString &for_file,
const QString &passStore)
568 static auto skippedGpgId(
const QString &forFile,
const QString &passStore,
569 QString *recordError =
nullptr,
571 -> std::optional<QString>;
588 static auto linkedGpgId(
const QString &forFile,
const QString &passStore,
590 -> std::optional<QString>;
598 const QString &passStore) -> QStringList;
672 auto initIfUnchanged(
const QString &path,
const QList<UserInfo> &users,
673 const QString &dir,
const QString &passStore,
683 const QString &sourceName) -> QStringList;
705 static auto loggableArgs(
const QStringList &args) -> QStringList;
803 const QString &except = QString(),
819 QByteArray *contents, QString *why) const ->
bool;
828 [[nodiscard]] virtual auto
insertWritten(const QString &err) const ->
bool {
918 QString *relative =
nullptr) -> bool;
932 virtual auto storeGit(
const QStringList &args, QString *out) ->
bool {
1018 bool readStdout =
true,
bool readStderr =
true);
1039 void setEnvVar(
const QString &name,
const QString &value);
1065 QString input,
bool readStdout,
bool readStderr);
1084 virtual void finished(
int id,
int exitCode,
const QString &out,
1085 const QString &err);
1097 static auto gpgIdVerdictIn(
const QString &dir) -> std::optional<SkippedWalk>;
1110 [[nodiscard]]
auto scopePath(
const QString &path)
const -> QString;
1153 const QString &err);
1176 const QString &err);
1229 void critical(
const QString &title,
const QString &message);
1308 bool lossless =
true);
AppSettings, the value object holding every flat QtPass setting.
Runs non-interactive external commands in FIFO order using a single QProcess.
auto stopRunning() -> bool
Stop the command that is running, if any: terminate it (its whole process group on Unix),...
auto isIdle() const -> bool
Whether no command is running and nothing is queued.
auto runningSerial() const -> quint64
Which run is going: a number no other run of this executor had.
auto hasQueued(int id) const -> bool
Whether a command with process id id is queued or running.
auto runningId() const -> int
The id of the command that is running.
The detached signature on a store's .gpg-id: whether the configured signing key is usable,...
auto storeEnvironment() const -> QProcessEnvironment
The environment QtPass runs the store's processes in.
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.
void startingExecuteWrapper()
Emitted each time a queued process is about to start, and by the refusals that go on to emit processE...
bool wrapperRunning
Unused; kept from the time Pass tracked the running wrapper.
virtual void beforeExecute(PROCESS id)
Hook invoked just before a wrapped command is dispatched.
void GenerateGPGKeys(QString batch)
Generate GPG keys using batch script.
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...
virtual void CancelGrep()
Stop a running Grep(): the walk ends at the next entry and the gpg decrypting one is terminated....
static QString getDefaultKeyTemplate(const QString &gpgExecutable={})
Get default key template for new GPG keys.
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 finishedInsert(const QString &out, const QString &err)
An Insert() succeeded: the entry is in the store and, with Git in use, committed.
void pinStoreGitAttributes()
Pin byte-for-byte Git attributes for the store's encrypted files.
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 (encr...
auto isPushing() const -> bool
Whether a Git push of this backend is queued or running.
AppSettings m_settings
Application settings snapshot injected at init() time.
static auto passReadsDifferently(const QByteArray &contents) -> QString
Why pass would read a .gpg-id differently from parseRecipients(), if it would.
static auto getGpgIdPath(const QString &for_file, const QString &passStore) -> QString
Get .gpg-id file path for a password file.
void handleProcessError(PROCESS pid, int exitCode, const QString &out, const QString &err)
Report a process that exited non-zero; called by finished().
auto reportedInsert() const -> QString
The entry whose insert is reporting now: set while finishedInsert() or insertFailed() goes out,...
virtual auto encryptionReaches(const QStringList &recipients) -> std::optional< QStringList >
The keys a gpg encryption to recipients reaches: a throwaway encryption outside the store,...
auto scopePath(const QString &path) const -> QString
path as an absolute, cleaned path, relative ones taken from the current store.
virtual void GitInit()=0
Initialize Git repository in password store.
auto refusePendingPull() -> bool
Refuse a store change while a Git pull is still queued or running.
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().
void releaseAutoPush(const QString &folder)
Release the holds a clean re-encryption of folder covers: those for folder itself and everything unde...
QString m_reportedInsert
The entry of the insert whose report is going out; see reportedInsert().
void finishedGenerateGPGKeys(const QString &out, const QString &err)
GenerateGPGKeys() succeeded; the new key pair is in the keyring.
virtual void Copy(const QString srcDir, const QString dest, const bool force)=0
Copy password file or directory.
Enums::PROCESS PROCESS
Alias for Enums::PROCESS used throughout this class.
void queueInsert(const QString &entry=QString())
Count one insert that has started queueing but not yet reported.
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.
virtual void GitPull()=0
Pull changes from remote Git repository.
virtual auto generatePassword(unsigned int length, const QString &charset) -> QString
Generate random password.
void queueShow(const QString &file)
Remember what a Show() asked for, so its completion can say so.
virtual void Move(const QString srcDir, const QString dest, const bool force)=0
Move password file or directory.
void statusMsg(const QString &msg, int timeout)
Progress or a non-fatal problem worth a line in the status bar ("Creating backup commit",...
QProcessEnvironment env
The environment the store's processes run in: the system environment plus what updateEnv() sets (PASS...
virtual void Grep(QString pattern, bool caseInsensitive)=0
Search password content for a pattern.
auto unfinishedGitOperationReason() -> QString
The unfinished git operation in progress in the store, if any.
void GitPushAutomatic()
GitPush() for an automatic push, the one after a change. A backend that has to make the push later dr...
PathSpelling
How a path handed to refuseLinkedPath() is spelled.
@ Configured
As the store is configured or relative to it, the class's path rule. A path spelled through the targe...
virtual auto fullKeyListing(QString *listing) -> int
The whole public keyring as keyLinesHeldTwice() reads it.
auto boundedRandom(quint32 bound) -> quint32
Generate random number in range.
void insertFailed(const QString &err, bool written)
Emitted when an Insert() fails through a queued command, before the generic processErrorExit(): the p...
static auto gpgIdVerdictIn(const QString &dir) -> std::optional< SkippedWalk >
What skippedGpgId() concludes at one folder on its way up.
auto pushIsAutomatic() const -> bool
Whether the GitPush() running now is an automatic one.
static auto keyLinesHeldTwiceIn(const QStringList &lines, const QString &listing) -> QHash< QString, QStringList >
keyLinesHeldTwice() on a listing already made.
auto runningProcess() const -> Enums::PROCESS
What kind of command is running now.
void emitProcessFinishedSignal(PROCESS pid, const QString &out, const QString &err)
Emit the signals for a process that exited with 0; called by finished() for everything but PASS_SHOW.
static bool gpgSupportsEd25519(const QString &gpgExecutable={})
Check if GPG supports Ed25519 encryption.
void refuseAsNotPartOfStore(const QString &why)
Refuse an operation on something that is not part of the store.
static auto maxOutputArgs() -> QStringList
The gpg options that enforce kMaxPlaintextBytes.
virtual void Remove(QString file, bool isDir)=0
Remove password file or directory.
virtual auto storeGit(const QStringList &args, QString *out) -> bool
Run a git command in the store's repository, blocking.
Pass()
Construct a Pass instance.
virtual auto insertWritten(const QString &err) const -> bool
Whether the insert that just failed had put its entry in the store before a later step failed....
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...
void holdAutoPush(const QString &scope)
Hold automatic pushes of the store that holds scope (autoPushHeld()): its re-encryption did not finis...
void finishedCopy(const QString &out, const QString &err)
A Copy() succeeded; the copy exists beside the original.
virtual void Show(QString file)=0
Show decrypted password file.
void finishedMove(const QString &out, const QString &err)
A Move() succeeded; the entry or folder is under its new name.
auto isIdle() const -> bool
Whether no gpg, git or pass of this backend runs or waits.
void executeWrapper(PROCESS id, const QString &app, const QStringList &args, bool readStdout=true, bool readStderr=true)
Execute external wrapper command.
void finishedShow(const QString &out, const QString &file, bool lossless=true)
Emitted when a Show() succeeds.
static auto resolveGpgconfCommand(const QString &gpgPath) -> ResolvedGpgconfCommand
Resolve the gpgconf command to kill agents.
static auto exactRecipientArg(const QString &line) -> QString
A bare mail address in gpg's exact form, <address>; any other line as written.
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...
auto listKeys(QStringList keystrings, bool secret=false) -> QList< UserInfo >
List GPG keys matching patterns.
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 f...
QQueue< QString > m_insertedEntries
The entries of the inserts counted in m_insertsPending, in queue order.
void finishedGrep(const QList< QPair< QString, QStringList > > &results)
The newest Grep() is over; an empty list means no entry matched.
QHash< QString, SkippedWalk > SkippedWalks
SkippedWalk per absolute folder, for one check of many folders.
static auto enabledKeyLines(const QList< UserInfo > &users) -> QStringList
The enabled users' key IDs, as Init() writes them to .gpg-id.
void finishedGitPull(const QString &out, const QString &err)
git pull succeeded; entries may have changed on disk.
virtual void GitPush()=0
Push changes to remote Git repository.
bool m_expectedListRefused
Set when refuseChangedList() or refuseBusyForExpectedList() refused during initIfUnchanged().
void finishedGitPush(const QString &out, const QString &err)
git push succeeded.
auto recipientsForEditing(const QString &dir, const QString &passStore) -> RecipientsForEditing
The recipients a dialog may preselect for editing the list of dir.
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,...
virtual void Insert(QString file, QString value, bool force)=0
Insert or update password.
auto refuseBusyForExpectedList() -> bool
Refuse an Init() under initIfUnchanged() while the executor has work queued or running,...
virtual void GitPull_b(int timeoutMs)=0
Pull from the remote and wait for it, at most timeoutMs: the pull before an edit, on the GUI thread.
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,...
Executor exec
Internal command executor for queuing and running subprocesses.
std::optional< ExpectedList > m_expectedList
Set during initIfUnchanged().
void processErrorExit(int exitCode, const QString &err)
An operation ended in failure: its process exited non-zero, could not be started or crashed,...
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 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())...
void init(const AppSettings &settings)
Initialize the Pass instance with a settings snapshot.
auto refuseChangedList() -> bool
Refuse an Init() under initIfUnchanged() when the folder's list no longer reads as the caller read it...
bool m_pushIsAutomatic
Set while GitPushAutomatic() runs GitPush().
auto insertsPending() const -> int
How many inserts have started queueing but not yet reported.
auto formatInsertError(const QString &friendly, const QString &err) -> QString
Put the translated reason for a failed insert above what gpg itself printed, leaving out the machine-...
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).
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.
static auto withoutStatusLines(const QString &err) -> QString
gpg's stderr without its machine-readable [GNUPG:] lines (and without carriage returns),...
static auto heldScopes() -> QSet< QString > &
The folders (cleaned absolute paths) whose re-encryption did not finish, for every store and both bac...
auto withCurrentGitPin(QProcessEnvironment base) const -> QProcessEnvironment
base with GIT_DIR and GIT_WORK_TREE as the store is now (Util::gitStoreVariables()),...
void setEnvVar(const QString &name, const QString &value)
Set or remove an environment variable.
static auto loggableArgs(const QStringList &args) -> QStringList
The arguments as they may appear in the debug log: the value of --passphrase and friends,...
auto autoPushHeld() const -> bool
Whether automatic pushes of the current store are held because its last re-encryption did not finish ...
static auto pullTimedOut(int timeoutMs) -> QString
The status-bar text for a blocking pull stopped at its deadline.
void updateEnv()
Update environment for subprocesses.
void finishedInit(const QString &out, const QString &err)
An Init() succeeded: the folder's .gpg-id holds the new recipient list.
QHash< QString, std::optional< QString > > LinkedWalks
void idle()
Nothing of the store's runs or waits any more (isIdle()).
virtual void finished(int id, int exitCode, const QString &out, const QString &err)
Handle process completion.
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 fail...
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 (skippedGpg...
virtual auto readersAnEditWouldAdd(const QString &file) -> EditReaders
Who saving over an existing entry would let read it who may not now.
auto refuseKeyLinesHeldTwice(const QStringList &lines) -> bool
Refuse, with critical(), a recipient list with a line that more than one key block holds (keyLinesHel...
void generateGPGKeysFailed(const QString &err)
Emitted when GPG key generation fails, alongside the generic processErrorExit(); lets the keygen dial...
static constexpr qint64 kMaxPlaintextBytes
Most bytes of plaintext a gpg decryption may produce.
int m_insertsPending
Inserts that have started queueing but not yet reported; see queueInsert.
static auto getRecipientList(const QString &for_file, const QString &passStore) -> QStringList
Get list of recipients for a password file.
virtual void Init(QString path, const QList< UserInfo > &users)=0
Initialize new password store.
LinkScope
What refuseLinkedPath() judges.
@ EntryAndParents
The entry itself and every folder above it in the store.
void finishedRemove(const QString &out, const QString &err)
A Remove() succeeded; the entry or folder is gone from the store.
auto refuseUnfinishedGitOperation() -> bool
Refuse to change the store while git is mid-rebase, -merge, -cherry-pick or -revert.
QQueue< QString > m_pendingShows
Files of the Show() calls still in flight, oldest first.
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 logge...
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.
static constexpr int kBlockingPullMs
How long the pull before an edit may block the window.
auto generateRandomPassword(const QString &charset, unsigned int length) -> QString
Generate random password from charset.
The Enums namespace: clipboard behaviour and the identifiers of the subprocess kinds QtPass queues.
Executor, the FIFO queue every gpg, git and pass child process of QtPass goes through,...
Rollback detection for signed .gpg-id files: the generation counter and the record of what was last s...
Enumerators for QtPass configuration and runtime operations.
PROCESS
Identifies different subprocess operations used in QtPass.
auto gpgErrorMessage(const QString &err) -> QString
Maps GPG stderr (which may include –status-fd 2 tokens) to a translated user-friendly encryption erro...
PROCESS
Identifies different subprocess operations used in QtPass.
Plain value-object holding all flat QtPass configuration.
What saving over an existing entry would change about who reads it (readersAnEditWouldAdd()).
auto operator==(const EditReaders &other) const -> bool
Equal when both say the same.
QStringList names
Who would read the entry after the save and the question is about, as "name (key ID)"; empty for no q...
bool notSavedHere
The entry's path was never saved from this device and its folder takes a parent's list,...
What initIfUnchanged() expects the list to read as, for refuseChangedList(); empty outside it.
QString passStore
The store root given to recipientsForEditing().
QString dir
The folder given to recipientsForEditing().
QStringList recipients
The recipients read then.
RecipientsForEditing::State state
The state read then.
What a dialog may do with the list of a folder (recipientsForEditing()).
QStringList recipients
The recipients to preselect; empty when Rejected.
State state
How the list on disk stood up.
QString warning
What the dialog should show, if anything.
State
How the list on disk stood up.
@ Unsigned
No signing key: the list as it is.
What skippedGpgId() found on its way up from one folder.
std::optional< QString > skipped
The skipped .gpg-id, if any.
QString recordError
The generation record's error, when that is why it was named.
Represents a command invocation for gpgconf operations.
QStringList arguments
Full argv list, including any wrapper/prefix args followed by the actual gpgconf operation flags (e....
QString program
Executable to run — may be a bare name resolved via PATH or a wrapper (e.g. wsl.exe) rather than a di...
UserInfo, one GPG key as listed by gpg, with the selection flag the recipient dialogs use.