QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
ProfileInit Class Reference

Turn a directory into a password store without going through the Pass backend of the currently active store. More...

#include <profileinit.h>

Static Public Member Functions

static auto gpgEnvironment (const AppSettings &s) -> QProcessEnvironment
 The environment QtPass runs gpg in outside the active store's backend: the system's, with GNUPGHOME set to the configured GPG home when there is one, so lookups and signatures use the keyring that signs.
static auto needsInit (const QString &path) -> bool
 Check if a profile path needs initialization.
static auto initialise (const QString &dir, const QList< UserInfo > &users, const AppSettings &settings, bool useGit, QString *note) -> bool
 Write the recipients and, if wanted, put the folder under git.
static auto initGit (const QString &dir, const AppSettings &s, QString *note) -> bool
 Put an existing store under Git: git init, stage the .gpg entries and the .gpg-id files (nothing else that may lie around in the folder) and make a first commit, with blocking processes of their own in dir.
static auto gitIdentityConfigured (const QString &dir, const AppSettings &s) -> bool
 Whether git has a name and e-mail to commit with, i.e. user.name and user.email resolve (globally or in dir).

Static Private Member Functions

static auto signingKeyUnavailable (const AppSettings &s, QString *note) -> bool
 Whether the profile has a signing key whose secret key gpg does not hold, so no list may be written: writing one takes the next generation, and an unsigned list then leaves this device's record ahead of the store's own.
static auto entriesOnThisList (const QString &dir, bool viaPass) -> QStringList
 The encrypted entries under dir that the new root list covers: visible regular .gpg files, sub-folders included, except those under a sub-folder whose own .gpg-id decides for them (as pass reads it with viaPass, as the native backend does without).
static auto writeGpgId (const QString &gpgIdFile, const QList< UserInfo > &users, bool signed_, QString *note, QByteArray *written=nullptr) -> bool
 Write the enabled recipients to gpgIdFile, whole or not at all; with signed_ the list carries the generation and folder header a signed store's lists are checked against (GpgIdGeneration).
static auto signGpgId (const QString &gpgIdFile, const QByteArray &contents, const AppSettings &s, QString *note) -> bool
 Sign the list just written as gpgIdFile, over the bytes contents that were written.
static auto commitGpgId (const QString &dir, const QString &gpgIdFile, const QString &sigFile, const AppSettings &s, QString *note) -> bool
 git init in dir, stage the .gpg-id and its signature, and commit them (signed when pass.signcommits is set), with a QProcess of its own in the store's Git environment.
static auto runGit (QProcess &git, const AppSettings &s, const QString &dir, const QStringList &args, QString *note) -> bool
 Run one set-up git command on git and wait for it: init and add, which read what lies in the folder, for at most two minutes, as the window waits too; a commit, which git may sign and so wait for the passphrase, without a limit.
static auto refusedForGit (const QString &dir, const QStringList &files, QString *note) -> bool
 Whether staging files in dir is refused because git could wait on something there for good: a .gitattributes or .gitignore on the way that is not a regular file, or a repository in a sub-folder.

Detailed Description

Turn a directory into a password store without going through the Pass backend of the currently active store.

The backend is a shared singleton bound to the active store (settings snapshot, PASSWORD_STORE_DIR, one FIFO of asynchronous processes), so a new profile cannot be initialised through it without racing the active store (#1774). Everything here is synchronous and touches only dir.

Definition at line 31 of file profileinit.h.

Member Function Documentation

◆ commitGpgId()

auto ProfileInit::commitGpgId ( const QString & dir,
const QString & gpgIdFile,
const QString & sigFile,
const AppSettings & s,
QString * note ) -> bool
staticprivate

git init in dir, stage the .gpg-id and its signature, and commit them (signed when pass.signcommits is set), with a QProcess of its own in the store's Git environment.

Parameters
dirThe store, absolute.
gpgIdFileThe .gpg-id just written.
sigFileIts .sig, or empty when the store is not signed.
sSettings for the git executable and the GPG home.
noteReceives a translated error naming the failed git command.
Returns
Whether the commit was made.

Definition at line 439 of file profileinit.cpp.

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

◆ entriesOnThisList()

auto ProfileInit::entriesOnThisList ( const QString & dir,
bool viaPass ) -> QStringList
staticprivate

The encrypted entries under dir that the new root list covers: visible regular .gpg files, sub-folders included, except those under a sub-folder whose own .gpg-id decides for them (as pass reads it with viaPass, as the native backend does without).

Parameters
dirThe store, absolute.
viaPassWhether the profile uses the pass backend.
Returns
The entries that kept their old recipients.

Definition at line 246 of file profileinit.cpp.

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

◆ gitIdentityConfigured()

auto ProfileInit::gitIdentityConfigured ( const QString & dir,
const AppSettings & s ) -> bool
static

Whether git has a name and e-mail to commit with, i.e. user.name and user.email resolve (globally or in dir).

Parameters
dirDirectory to ask in; a repository's own config counts.
sSettings for the git executable.
Returns
true when a commit would not fail for lack of an identity.

Definition at line 509 of file profileinit.cpp.

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

◆ gpgEnvironment()

auto ProfileInit::gpgEnvironment ( const AppSettings & s) -> QProcessEnvironment
static

The environment QtPass runs gpg in outside the active store's backend: the system's, with GNUPGHOME set to the configured GPG home when there is one, so lookups and signatures use the keyring that signs.

Parameters
sThe settings naming the GPG home.
Returns
The environment for a gpg process.

Definition at line 151 of file profileinit.cpp.

Here is the caller graph for this function:

◆ initGit()

auto ProfileInit::initGit ( const QString & dir,
const AppSettings & s,
QString * note ) -> bool
static

Put an existing store under Git: git init, stage the .gpg entries and the .gpg-id files (nothing else that may lie around in the folder) and make a first commit, with blocking processes of their own in dir.

Parameters
dirThe store.
sSettings for the git executable.
noteReceives a translated error on failure.
Returns
true when the repository exists and the commit is made.

Definition at line 471 of file profileinit.cpp.

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

◆ initialise()

auto ProfileInit::initialise ( const QString & dir,
const QList< UserInfo > & users,
const AppSettings & settings,
bool useGit,
QString * note ) -> bool
static

Write the recipients and, if wanted, put the folder under git.

Writes <dir>/.gpg-id with the enabled key ids, signs it when s.passSigningKey is set, and when useGit runs git init, git add and git commit inside dir with blocking processes. Existing *.gpg files are left alone: re-encrypting them needs the backend, i.e. the profile has to be the active store; note says so.

Parameters
dirDirectory to initialise; created if missing.
usersKey list; only entries with enabled == true are written.
settingsSettings for the gpg/git executables and the signing key; with no signing key set, one exported for pass counts (GpgIdSigner::settingOrExported()).
useGitWhether to create a repository and commit the file.
noteReceives a translated message for the user (empty on a quiet success): the error, or the warning about existing entries.
Returns
true when the .gpg-id (and signature/commit if requested) is in place.

Definition at line 166 of file profileinit.cpp.

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

◆ needsInit()

auto ProfileInit::needsInit ( const QString & path) -> bool
static

Check if a profile path needs initialization.

Parameters
pathThe profile path to check.
Returns
true if the path exists but has no .gpg-id file.

Definition at line 155 of file profileinit.cpp.

Here is the caller graph for this function:

◆ refusedForGit()

auto ProfileInit::refusedForGit ( const QString & dir,
const QStringList & files,
QString * note ) -> bool
staticprivate

Whether staging files in dir is refused because git could wait on something there for good: a .gitattributes or .gitignore on the way that is not a regular file, or a repository in a sub-folder.

Parameters
dirThe store.
filesPaths relative to dir that git is to stage.
noteReceives a translated reason naming the path.
Returns
true when git must not be run.

Definition at line 422 of file profileinit.cpp.

Here is the caller graph for this function:

◆ runGit()

auto ProfileInit::runGit ( QProcess & git,
const AppSettings & s,
const QString & dir,
const QStringList & args,
QString * note ) -> bool
staticprivate

Run one set-up git command on git and wait for it: init and add, which read what lies in the folder, for at most two minutes, as the window waits too; a commit, which git may sign and so wait for the passphrase, without a limit.

Parameters
gitThe process, set up for the store.
sSettings for the git executable.
dirThe store, named in the note.
argsThe git arguments; the first names the command.
noteReceives a translated error naming the command, or that it ran out of time.
Returns
Whether the command succeeded.

Definition at line 395 of file profileinit.cpp.

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

◆ signGpgId()

auto ProfileInit::signGpgId ( const QString & gpgIdFile,
const QByteArray & contents,
const AppSettings & s,
QString * note ) -> bool
staticprivate

Sign the list just written as gpgIdFile, over the bytes contents that were written.

Parameters
gpgIdFileThe .gpg-id; <gpgIdFile>.sig is written.
contentsThe bytes written as that file.
sThe settings naming gpg and the signing key.
noteReceives the reason on failure.
Returns
Whether the signature is in place.

Definition at line 368 of file profileinit.cpp.

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

◆ signingKeyUnavailable()

auto ProfileInit::signingKeyUnavailable ( const AppSettings & s,
QString * note ) -> bool
staticprivate

Whether the profile has a signing key whose secret key gpg does not hold, so no list may be written: writing one takes the next generation, and an unsigned list then leaves this device's record ahead of the store's own.

Parameters
sThe settings naming gpg, its home and the signing key.
noteReceives the translated reason, naming a configured GPG home that does not exist.
Returns
true when initialising must stop.

Definition at line 225 of file profileinit.cpp.

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

◆ writeGpgId()

auto ProfileInit::writeGpgId ( const QString & gpgIdFile,
const QList< UserInfo > & users,
bool signed_,
QString * note,
QByteArray * written = nullptr ) -> bool
staticprivate

Write the enabled recipients to gpgIdFile, whole or not at all; with signed_ the list carries the generation and folder header a signed store's lists are checked against (GpgIdGeneration).

Parameters
gpgIdFileThe .gpg-id to write.
usersThe recipients; the enabled ones are written.
signed_Whether the store gets a signing key, i.e. the header.
noteReceives the reason on failure.
writtenReceives the exact bytes written, if not null.
Returns
Whether the file was written.

Definition at line 311 of file profileinit.cpp.

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

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