QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
realpass.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
8#ifndef SRC_REALPASS_H_
9#define SRC_REALPASS_H_
10
11#include "nativegrep.h"
12#include "pass.h"
13#include <QHash>
14#include <optional>
15
16class GpgIdSigner;
17class QFileInfo;
18#include <QQueue>
19#include <QSet>
20
35class RealPass : public Pass {
41 struct LinkCommit {
42 QString rel;
46 QProcessEnvironment environment;
47 };
48
50 QQueue<LinkCommit> m_linkCommits;
51
61 void reportReencryptFailure(Enums::PROCESS pid, const QString &out,
62 const QString &err);
73 void finishRecipientRun(Enums::PROCESS pid, int exitCode, const QString &out,
74 const QString &err);
82 void removeLinkedFolder(const QString &full);
89 void sendDeferredPush();
97 void finishLinkCommit(const LinkCommit &commit, const QString &out,
98 const QString &err);
99
108 void executePass(PROCESS id, const QStringList &args,
109 QString input = QString(), bool readStdout = true,
110 bool readStderr = true);
121 void passMoveOrCopy(PROCESS id, const QString &subcommand, const QString &src,
122 const QString &dest, bool force);
125 QString passSrc;
126 QString passDest;
129 QString newPath;
132 QString written;
133 };
134
148 auto passMoveTarget(const QString &src, const QString &dest) const
163 auto stopsAtOccupiedTarget(PROCESS id, const QString &src,
164 const QFileInfo &srcFileInfo, const QString &dest,
165 const QString &occupied, bool force) -> bool;
177 auto refuseMoveOrCopyRisks(PROCESS id, const QString &src,
178 const QFileInfo &srcFileInfo,
179 const PassMoveTarget &target) -> bool;
191 [[nodiscard]] auto linesPassEncryptsTo(const QString &src,
192 const PassMoveTarget &target,
193 bool srcIsDir, bool intoFolder)
194 -> QStringList;
203 auto passName(const QString &path, bool stripGpg) const -> QString;
204
214 [[nodiscard]] auto insertWritten(const QString &err) const -> bool override;
215
226 auto refuseUnverifiedList(const QString &file) -> bool;
235 auto listLinesUnder(const QString &dir, const QString &except) -> QStringList;
247 auto entryWouldGain(const QString &entry, const QStringList &target,
248 const QStringList &before,
249 QHash<QString, std::optional<QSet<QString>>> &probes)
250 -> bool;
251
266 auto refuseLinkedList(const QString &file, const QString &within = QString(),
267 const QString &except = QString(),
268 LinkedWalks *walks = nullptr) -> bool;
269
286 auto refuseMisreadList(const QString &file, const QString &within,
287 const QString &except, QSet<QString> &checked) -> bool;
288
295 auto storeGit(const QStringList &args, QString *out) -> bool override;
296
305 auto repositoryOf(const QString &path) -> QString;
306
317 auto statusEntries(const QStringList &args,
318 const QString &repository = QString()) -> QStringList;
319
327 auto unrecorded(const QStringList &paths, bool ignored) -> QStringList;
328
347 auto refuseUnrecordedChanges(const QStringList &paths,
348 const QStringList &committing) -> bool;
349
357 void reportUnrecorded(const QStringList &paths);
358
373 auto refuseLinkInCopiedFolder(const QString &src) -> bool;
374
385 auto refuseIgnoredThatMoves(const QString &src, const QString &dest) -> bool;
386
396 auto ignoredByRulesWithin(const QString &repository, const QString &from,
397 const QStringList &moving) -> QStringList;
398
409 auto checkIgnore(const QString &repository, const QStringList &paths,
410 bool verbose, QStringList *fields) -> bool;
411
418 auto refuseSpecialEntry(const QString &entry) -> bool;
419
433 auto refuseLineBreakName(const QString &path) -> bool;
434
452 auto refuseUnverifiedTree(const QString &dir, bool onlyListsWithin,
453 const QString &except = QString()) -> bool;
454
459 auto listSigner() -> GpgIdSigner;
460
476 auto refuseList(const QString &file, const GpgIdSigner &signer,
477 QSet<QString> &verified, const QString &within = QString(),
478 const QString &except = QString(),
479 SkippedWalks *walks = nullptr) -> bool;
480
494 void onDequeuing(int id, bool completes);
495
506 static auto entryFingerprint(const QString &path) -> QByteArray;
507
511 QString target;
512 QByteArray before;
513 };
514
515 QQueue<QString> m_insertQueue;
519 QQueue<InsertRecord> m_insertPending;
524 QQueue<QString> m_reencryptScopes;
528 QQueue<QString> m_reencryptPending;
534
535public:
539 RealPass();
554 static auto reencryptFailed(const QString &out, const QString &err) -> bool;
565 static auto reencryptFailed(const QString &out,
566 const QHash<QString, qint64> &status) -> bool;
570 ~RealPass() override;
571
572 // Git operations
576 void GitInit() override;
580 void GitPull() override;
585 void GitPull_b(int timeoutMs) override;
589 void GitPush() override;
590
591 // Password operations
596 void Show(QString file) override;
603 void Insert(QString file, QString newValue, bool overwrite) override;
615 void Remove(QString file, bool isDir) override;
616 auto entriesInitWouldWiden(const QString &dir, const QList<UserInfo> &users)
617 -> QStringList override;
618 auto entriesMoveWouldWiden(const QString &src, const QString &dest)
619 -> QStringList override;
626 [[nodiscard]] auto recipientArgument(const QString &line) const
627 -> QString override {
628 return line;
629 }
630
635 void Init(QString path, const QList<UserInfo> &users) override;
636
637protected:
646 void finished(int id, int exitCode, const QString &out,
647 const QString &err) override;
648
649 // Pass interface
650public:
657 void Move(const QString src, const QString dest, const bool force) override;
664 void Copy(const QString src, const QString dest, const bool force) override;
675 void Grep(QString pattern, bool caseInsensitive) override;
679 void CancelGrep() override { m_grep.cancel(); }
680};
681
682#endif // SRC_REALPASS_H_
The detached signature on a store's .gpg-id: whether the configured signing key is usable,...
Definition gpgidsigner.h:29
Full-text search over a password store without pass grep: every .gpg file is decrypted with gpg on a ...
Definition nativegrep.h:31
void cancel()
Ask running searches to stop without waiting for them: the walk ends at the next file and a gpg that ...
Enums::PROCESS PROCESS
Alias for Enums::PROCESS used throughout this class.
Definition pass.h:154
Pass()
Construct a Pass instance.
Definition pass.cpp:83
QHash< QString, SkippedWalk > SkippedWalks
SkippedWalk per absolute folder, for one check of many folders.
Definition pass.h:165
QHash< QString, std::optional< QString > > LinkedWalks
Definition pass.h:168
NativeGrep m_grep
Definition realpass.h:38
void finishLinkCommit(const LinkCommit &commit, const QString &out, const QString &err)
Judge a queued linked-folder removal commit by what is left staged in the store it ran in: pass git e...
void reportReencryptFailure(Enums::PROCESS pid, const QString &out, const QString &err)
Report a pass init, mv or cp that exited 0 having left entries encrypted to the previous recipients: ...
QQueue< QString > m_reencryptPending
Definition realpass.h:528
void Remove(QString file, bool isDir) override
Remove an entry or folder with pass rm.
void Init(QString path, const QList< UserInfo > &users) override
Initialize password store.
auto refuseUnrecordedChanges(const QStringList &paths, const QStringList &committing) -> bool
Refuse a pass init, mv, cp or insert when paths hold changes git has not recorded,...
Definition realpass.cpp:782
void Copy(const QString src, const QString dest, const bool force) override
Copy password file or directory.
auto entryWouldGain(const QString &entry, const QStringList &target, const QStringList &before, QHash< QString, std::optional< QSet< QString > > > &probes) -> bool
Whether pass re-encrypting entry to target would hand it to someone who cannot read it now,...
Definition realpass.cpp:360
auto unrecorded(const QStringList &paths, bool ignored) -> QStringList
What git has not recorded at paths: git status --porcelain lines, through pass git....
Definition realpass.cpp:672
auto storeGit(const QStringList &args, QString *out) -> bool override
Run a git command in the store through pass git, blocking.
Definition realpass.cpp:574
bool m_pushAfterReencrypt
Definition realpass.h:531
QQueue< InsertRecord > m_insertPending
Definition realpass.h:519
auto recipientArgument(const QString &line) const -> QString override
As written: pass hands each line to gpg itself, so the probe must reach what pass will.
Definition realpass.h:626
auto checkIgnore(const QString &repository, const QStringList &paths, bool verbose, QStringList *fields) -> bool
git check-ignore --stdin -z on paths through pass git.
auto refuseSpecialEntry(const QString &entry) -> bool
Refuse, and tell the user, when entry is set: an entry named like a password that is no regular file,...
Definition realpass.cpp:307
auto refuseIgnoredThatMoves(const QString &src, const QString &dest) -> bool
Refuse a pass mv or cp of the folder src when a file in it that Git ignores would not be ignored wher...
Definition realpass.cpp:919
auto passMoveTarget(const QString &src, const QString &dest) const -> PassMoveTarget
Name src and dest for pass mv/pass cp, and work out where pass 1.7.4 then puts the source.
auto stopsAtOccupiedTarget(PROCESS id, const QString &src, const QFileInfo &srcFileInfo, const QString &dest, const QString &occupied, bool force) -> bool
Whether a move or copy stops at what already lies where pass writes: a file dest the user declined to...
auto ignoredByRulesWithin(const QString &repository, const QString &from, const QStringList &moving) -> QStringList
Those of moving that a .gitignore inside the folder from ignores, by git check-ignore -v: the rule mo...
Definition realpass.cpp:992
auto entriesInitWouldWiden(const QString &dir, const QList< UserInfo > &users) -> QStringList override
Entries a pass init of dir with users would hand to someone who cannot read them now (an entry copied...
Definition realpass.cpp:405
auto entriesMoveWouldWiden(const QString &src, const QString &dest) -> QStringList override
Entries already in the place a pass mv or pass cp of src to dest re-encrypts (the whole destination f...
Definition realpass.cpp:440
auto refuseMoveOrCopyRisks(PROCESS id, const QString &src, const QFileInfo &srcFileInfo, const PassMoveTarget &target) -> bool
Whether a move or copy is refused for what pass would do along the way: re-encrypt to an unverified l...
void Insert(QString file, QString newValue, bool overwrite) override
Insert new password.
static auto reencryptFailed(const QString &out, const QString &err) -> bool
Whether a pass init, mv or cp that exited 0 left entries as they were: pass carries on past an entry ...
void Show(QString file) override
Show decrypted password.
Definition realpass.cpp:108
InsertRecord m_insertDone
The insert whose completion is being handled.
Definition realpass.h:521
void reportUnrecorded(const QStringList &paths)
After a pass insert, init, mv or cp that exited 0, say so when git did not record the entries it wrot...
Definition realpass.cpp:857
RealPass()
Construct a RealPass instance.
Definition realpass.cpp:46
void onDequeuing(int id, bool completes)
The executor is about to run (or drop) its next item: for an insert, take its entry from m_insertQueu...
auto refuseLinkInCopiedFolder(const QString &src) -> bool
Refuse a pass cp of the folder src when anything in it is a symbolic link or NTFS junction,...
Definition realpass.cpp:876
auto refuseLinkedList(const QString &file, const QString &within=QString(), const QString &except=QString(), LinkedWalks *walks=nullptr) -> bool
Refuse to have pass encrypt file when the walk to its list meets a .gpg-id that is a link or junction...
Definition realpass.cpp:163
void passMoveOrCopy(PROCESS id, const QString &subcommand, const QString &src, const QString &dest, bool force)
Shared implementation of Move and Copy via pass mv/pass cp.
auto passName(const QString &path, bool stripGpg) const -> QString
path as pass names it: relative to the store, without the .gpg pass appends itself.
auto refuseUnverifiedList(const QString &file) -> bool
Refuse to have pass encrypt file when the list it would use is a link (refuseLinkedList()),...
Definition realpass.cpp:233
auto refuseList(const QString &file, const GpgIdSigner &signer, QSet< QString > &verified, const QString &within=QString(), const QString &except=QString(), SkippedWalks *walks=nullptr) -> bool
The checks of refuseUnverifiedList() for file's nearest list, once per list.
Definition realpass.cpp:134
auto repositoryOf(const QString &path) -> QString
The Git repository pass commits path in: the store's own, or one a folder in it holds (pass looks for...
Definition realpass.cpp:602
void sendDeferredPush()
Once the last queued init, move or copy has completed, make the push asked for meanwhile (GitPush())....
Definition realpass.cpp:91
static auto entryFingerprint(const QString &path) -> QByteArray
A SHA-256 of the size and first 64 KiB of the regular file path (opened without following a link or b...
void GitInit() override
Initialize Git repository in password store.
Definition realpass.cpp:53
QQueue< QString > m_reencryptScopes
Definition realpass.h:524
auto statusEntries(const QStringList &args, const QString &repository=QString()) -> QStringList
git status --porcelain -z through pass git, read: one "XY name" per entry, a rename's old name droppe...
Definition realpass.cpp:638
void GitPull() override
Pull changes from remote.
Definition realpass.cpp:77
auto listLinesUnder(const QString &dir, const QString &except) -> QStringList
The lines of every folder's own .gpg-id that pass's walk of dir meets, for keyLinesHeldTwice(): pass ...
Definition realpass.cpp:340
bool m_deferredPushByHand
One of those pushes was asked for by hand: it goes despite a hold.
Definition realpass.h:533
QQueue< LinkCommit > m_linkCommits
Definition realpass.h:50
void removeLinkedFolder(const QString &full)
Remove a linked folder for Remove(): unlink it here, so that pass rm -rf cannot follow it,...
void Move(const QString src, const QString dest, const bool force) override
Move password file or directory.
auto linesPassEncryptsTo(const QString &src, const PassMoveTarget &target, bool srcIsDir, bool intoFolder) -> QStringList
The recipient lines pass re-encrypts to when it moves or copies src as target says: the destination's...
void finished(int id, int exitCode, const QString &out, const QString &err) override
Finish a process; a linked-folder removal commit (GIT_COMMIT, which RealPass uses for nothing else) i...
void GitPull_b(int timeoutMs) override
Run pass git pull and wait for it, at most timeoutMs.
Definition realpass.cpp:55
void finishRecipientRun(Enums::PROCESS pid, int exitCode, const QString &out, const QString &err)
Finish a pass init, mv or cp: hold the automatic push for a run that left entries to the previous rec...
auto refuseLineBreakName(const QString &path) -> bool
Refuse, and tell the user, when the store-relative name of path holds a line feed or carriage return.
Definition realpass.cpp:322
void CancelGrep() override
Stop the running search (NativeGrep::cancel()).
Definition realpass.h:679
void executePass(PROCESS id, const QStringList &args, QString input=QString(), bool readStdout=true, bool readStderr=true)
Execute pass command with arguments.
void GitPush() override
Push changes to remote.
Definition realpass.cpp:79
auto insertWritten(const QString &err) const -> bool override
Whether the failed pass insert wrote its entry before its git step failed. pass does not say,...
auto refuseMisreadList(const QString &file, const QString &within, const QString &except, QSet< QString > &checked) -> bool
Refuse to have pass encrypt file when its nearest .gpg-id holds lines pass reads differently from the...
Definition realpass.cpp:188
void Grep(QString pattern, bool caseInsensitive) override
Search all password content by GPG-decrypting each real .gpg file, as ImitatePass does.
auto refuseUnverifiedTree(const QString &dir, bool onlyListsWithin, const QString &except=QString()) -> bool
For a folder pass is about to re-encrypt in a move or copy: refuse when an entry pass's walk takes (h...
Definition realpass.cpp:499
auto listSigner() -> GpgIdSigner
The verifier for signed lists, gpg in the store's environment.
Definition realpass.cpp:120
QQueue< QString > m_insertQueue
The entries of the queued inserts, oldest first.
Definition realpass.h:515
PROCESS
Identifies different subprocess operations used in QtPass.
Definition enums.h:43
NativeGrep, the content search that decrypts every entry on a worker thread instead of running pass g...
Pass, the abstract password-store backend that RealPass and ImitatePass implement,...
QString target
The entry's file.
Definition realpass.h:511
QByteArray before
Its fingerprint when the insert started.
Definition realpass.h:512
What pass mv/pass cp is handed and what it then does with it.
Definition realpass.h:124
QString passSrc
The source name handed to pass.
Definition realpass.h:125