32#include <QSystemTrayIcon>
43auto pathRow(QLineEdit *edit, QWidget *parent,
44 const std::function<QString()> &pick) -> QWidget * {
45 auto *row =
new QWidget(parent);
46 auto *layout =
new QHBoxLayout(row);
47 layout->setContentsMargins(0, 0, 0, 0);
48 layout->addWidget(edit);
49 auto *browse =
new QToolButton(row);
50 browse->setText(QStringLiteral(
"…"));
51 browse->setToolTip(FirstRunWizard::tr(
"Browse"));
52 layout->addWidget(browse);
53 QObject::connect(browse, &QToolButton::clicked, edit, [edit, pick]() {
54 const QString chosen = pick();
55 if (!chosen.isEmpty()) {
56 edit->setText(chosen);
57 emit edit->textEdited(chosen);
63auto runnable(
const QString &exe) ->
bool {
65 (!exe.isEmpty() && QFileInfo(exe).isExecutable());
77 setWindowTitle(tr(
"Welcome to QtPass"));
78 setWizardStyle(QWizard::ModernStyle);
79 setOption(QWizard::NoBackButtonOnStartPage);
80 setOption(QWizard::HaveHelpButton,
false);
82 auto *intro =
new QWizardPage(
this);
83 intro->setTitle(tr(
"Welcome to QtPass"));
84 auto *introLayout =
new QVBoxLayout(intro);
85 auto *introText =
new QLabel(
86 tr(
"QtPass is a graphical front-end for <i>pass</i>, the standard Unix "
87 "password manager: every password is a file encrypted with GnuPG, "
88 "kept in a folder you can put under Git.<br><br>The next pages find "
89 "GnuPG, make sure you have a key to encrypt to and pick the folder "
90 "your passwords live in. Nothing is written until you press "
93 introText->setWordWrap(
true);
94 introText->setTextFormat(Qt::RichText);
95 introLayout->addWidget(introText);
107 if (!runnable(gpgExecutable)) {
114 {QStringLiteral(
"--no-tty"), QStringLiteral(
"--with-colons"),
115 QStringLiteral(
"--with-fingerprint"),
116 QStringLiteral(
"--list-secret-keys")},
118 if (rc != 0 && problem !=
nullptr) {
119 constexpr qsizetype kMaxProblem = 400;
123 if (problem->size() > kMaxProblem) {
124 *problem = problem->left(kMaxProblem) + QChar(0x2026);
129 if (rc != 0 && rc != 2) {
136 return !path.isEmpty() &&
137 QFile::exists(QDir(path).filePath(QStringLiteral(
".gpg-id")));
141 QList<UserInfo> recipients;
144 recipients.append(key);
147 const bool created = !QDir(store).exists();
151 tr(
"Failed to create password-store at: %1").arg(store));
158 SetFileAttributes(store.toStdWString().c_str(), FILE_ATTRIBUTE_HIDDEN);
167 QFile::remove(QDir(store).filePath(QStringLiteral(
".gpg-id")));
168 QFile::remove(QDir(store).filePath(QStringLiteral(
".gpg-id.sig")));
172 if (!note.isEmpty()) {
176 this, QMessageBox::Information, tr(
"Password store"),
177 tr(
"%1 already contains encrypted files; they were not "
178 "re-encrypted to the ticked keys. Open Users after the start "
180 .arg(QDir::toNativeSeparators(store)));
192 QDir(QDir(store).filePath(QStringLiteral(
".git"))).removeRecursively();
200 if (currentPage() !=
nullptr && !currentPage()->validatePage()) {
214 const bool needsGit =
237 : QWizardPage(wizard),
m_wizard(wizard),
m_gpg(new QLineEdit(this)),
238 m_git(new QLineEdit(this)),
m_pass(new QLineEdit(this)),
239 m_usePass(new QCheckBox(tr(
"Use the pass command-line tool"), this)),
241 setTitle(tr(
"Programs"));
242 setSubTitle(tr(
"GnuPG does the encrypting. pass and Git are optional; "
243 "QtPass can do their work itself."));
244 auto *layout =
new QFormLayout(
this);
245 auto pickExe = [
this]() {
246 return QFileDialog::getOpenFileName(
this, tr(
"Select executable"),
247 QString(), tr(
"All files (*)"));
249 layout->addRow(tr(
"GnuPG"), pathRow(
m_gpg,
this, pickExe));
252 layout->addRow(tr(
"Git"), pathRow(
m_git,
this, pickExe));
253 layout->addRow(tr(
"pass"), pathRow(
m_pass,
this, pickExe));
254 m_usePass->setToolTip(tr(
"Run the pass script for every operation instead "
255 "of calling gpg and git directly"));
258 connect(edit, &QLineEdit::textEdited,
this,
268 auto detect = [](QString &stored,
const QStringList &names) {
269 if (runnable(stored)) {
272 for (
const QString &name : names) {
274 if (!found.isEmpty()) {
280 detect(s.
gpgExecutable, {QStringLiteral(
"gpg2"), QStringLiteral(
"gpg")});
297 const QString gpg =
m_gpg->text().trimmed();
299 m_gpgStatus->setText(tr(
"GnuPG was not found. Install it (gpg or gpg2) "
300 "and enter its location here."));
301 }
else if (!runnable(gpg)) {
302 m_gpgStatus->setText(tr(
"%1 is not an executable file.").arg(gpg));
310 emit completeChanged();
314 return runnable(
m_gpg->text().trimmed());
329 : QWizardPage(wizard),
m_wizard(wizard),
m_list(new QListWidget(this)),
330 m_generate(new QPushButton(tr(
"Generate a new key pair…"), this)),
332 setTitle(tr(
"Your key"));
333 setSubTitle(tr(
"Passwords are encrypted to GnuPG keys. Tick the keys that "
334 "should be able to open a new store; you need at least one "
335 "with its secret half on this machine."));
336 auto *layout =
new QVBoxLayout(
this);
337 layout->addWidget(
m_list);
339 m_status->setTextFormat(Qt::PlainText);
342 auto *buttons =
new QHBoxLayout;
343 buttons->addStretch();
345 layout->addLayout(buttons);
347 connect(
m_list, &QListWidget::itemChanged,
this,
348 [
this]() { emit completeChanged(); });
358 const QDateTime now = QDateTime::currentDateTime();
366 why = tr(
"not usable");
368 const bool usable = why.isEmpty();
375 QString label = QStringLiteral(
"%1\n%2").arg(key.
name, key.
key_id);
377 label += QStringLiteral(
" (%1)").arg(why);
379 auto *item =
new QListWidgetItem(label,
m_list);
380 item->setFlags(usable ? (item->flags() | Qt::ItemIsUserCheckable)
381 : (item->flags() & ~Qt::ItemIsEnabled));
382 item->setCheckState(key.
enabled ? Qt::Checked : Qt::Unchecked);
386 if (!problem.isEmpty()) {
388 m_status->setText(tr(
"GnuPG reported a problem while listing the secret "
394 ? tr(
"GnuPG has no secret key yet. Generate one here, "
395 "or import your existing key with gpg first.")
398 emit completeChanged();
415 for (
int i = 0; i <
m_list->count() && i < m_wizard->m_keys.size(); ++i) {
416 m_wizard->m_keys[i].enabled =
m_list->item(i)->checkState() == Qt::Checked;
424 : QWizardPage(wizard),
m_wizard(wizard),
m_path(new QLineEdit(this)),
425 m_useGit(new QCheckBox(tr(
"Keep the store under Git"), this)),
427 setTitle(tr(
"Password store"));
428 setSubTitle(tr(
"The folder your passwords live in. An existing store is "
429 "used as it is; an empty or missing folder is set up for "
430 "the keys you ticked."));
431 auto *layout =
new QFormLayout(
this);
432 layout->addRow(tr(
"Folder"), pathRow(
m_path,
this, [
this]() {
433 return QFileDialog::getExistingDirectory(
434 this, tr(
"Choose the password store folder"),
438 layout->addRow(QString(),
m_status);
439 layout->addRow(QString(),
m_useGit);
445 if (path.isEmpty()) {
448 m_path->setText(QDir::toNativeSeparators(QDir::cleanPath(path)));
449 const QString clean = QDir::cleanPath(path);
450 const bool repository = QDir(clean).exists(QStringLiteral(
".git"));
454 const bool identity =
459 ? tr(
"Git has no name and e-mail to commit with yet. Run\n"
460 "git config --global user.name \"Your Name\"\n"
461 "git config --global user.email you@example.org\n"
462 "and turn Git on in Settings afterwards.")
463 : tr(
"Every change becomes a commit; a folder that is no "
464 "repository yet gets one"));
465 haveGit = haveGit && identity;
482 ticked += key.enabled ? 1 : 0;
488 const QString path = QDir::cleanPath(
m_path->text().trimmed());
490 if (path.isEmpty()) {
491 text = tr(
"Enter a folder.");
493 const int entries =
static_cast<int>(
495 text = tr(
"An existing password store with %n entries.",
nullptr, entries);
496 }
else if (QDir(path).exists()) {
497 text = QDir(path).isEmpty()
498 ? tr(
"An empty folder; it will be set up as a password store.")
499 : tr(
"This folder is not a password store yet; a .gpg-id for "
500 "the ticked keys will be written into it.");
502 text = tr(
"The folder does not exist yet; it will be created.");
505 text += QLatin1Char(
' ') +
506 tr(
"Go back and tick at least one key to encrypt it to.");
509 emit completeChanged();
513 const QString path = QDir::cleanPath(
m_path->text().trimmed());
514 if (path.isEmpty()) {
522 QDir::fromNativeSeparators(
m_path->text().trimmed());
531 m_hidePassword(new QCheckBox(tr(
"Hide passwords until asked"), this)),
532 m_trayIcon(new QCheckBox(tr(
"Show an icon in the system tray"), this)) {
533 setTitle(tr(
"Ready"));
534 setSubTitle(tr(
"Everything else can be changed later in Settings."));
535 auto *layout =
new QVBoxLayout(
this);
539 layout->addSpacing(12);
541 tr(
"Show the password line as dots; Show password reveals it"));
544 layout->addStretch();
550 const QString store = QDir::toNativeSeparators(QDir::cleanPath(s.
passStore));
552 lines << tr(
"Store: %1").arg(store.toHtmlEscaped());
554 lines << tr(
"It is already a password store and is used as it is.");
556 lines << tr(
"It will be set up for the ticked keys and put under Git.");
558 lines << tr(
"It will be set up for the ticked keys.");
560 lines << tr(
"GnuPG: %1").arg(s.
gpgExecutable.toHtmlEscaped());
561 lines << (s.
usePass ? tr(
"Operations run through pass.")
562 : tr(
"Operations run through gpg and git directly."));
563 m_summary->setText(lines.join(QStringLiteral(
"<br>")));
565 const bool tray = QSystemTrayIcon::isSystemTrayAvailable();
QLabel * m_summary
Store, what Finish does with it, gpg, mode.
void initializePage() override
Fill the summary from the settings.
QCheckBox * m_trayIcon
Tray icon; hidden when there is no tray.
FirstRunWizard * m_wizard
Owner; its settings get the preferences.
QCheckBox * m_hidePassword
Show the password line as dots; on.
DoneWizardPage(FirstRunWizard *wizard)
Build the page.
auto validatePage() -> bool override
Store the preferences.
static auto executeBlocking(const QString &app, const QStringList &args, const QString &input=QString(), QString *process_out=nullptr, QString *process_err=nullptr) -> int
Run a command synchronously and return its exit code.
static auto parseWslCommand(const QString &app) -> std::optional< WslCommand >
Parse a configured executable as a WSL command.
The first start of QtPass: find GnuPG (and pass and Git), make sure there is a secret key,...
static auto secretKeys(const QString &gpgExecutable, QString *problem=nullptr) -> QList< UserInfo >
The secret keys gpg lists for gpgExecutable.
@ DonePage
DoneWizardPage: summary and two preferences.
@ ProgramsPage
ProgramsWizardPage: where gpg, pass and git are.
@ KeyPage
KeyWizardPage: the secret keys, with generation.
@ StorePage
StoreWizardPage: the store folder and the Git choice.
@ IntroPage
What QtPass is and what the wizard will do.
auto initialiseStore(const QString &store) -> bool
Make store a password store for the ticked keys: create the folder when it is missing,...
void accept() override
Write the settings and, when the chosen store has no .gpg-id yet, create and initialise it for the ch...
auto initialiseGit(const QString &store) -> bool
Give an existing store the Git repository it was chosen to have.
static auto isStore(const QString &path) -> bool
Whether path points at an initialised store.
FirstRunWizard(QWidget *parent=nullptr)
Build the wizard from the current settings.
Implementation that imitates 'pass' when the real tool is unavailable.
QListWidget * m_list
One checkable row per secret key.
void initializePage() override
List the secret keys for the gpg chosen on the previous page.
void reload()
List the secret keys of the chosen gpg into the wizard and the widget, ticking every usable key and g...
auto isComplete() const -> bool override
Always passable: an existing store needs no recipient choice here (and its key may not be imported ye...
QPushButton * m_generate
Opens KeygenDialog.
void generate()
Run KeygenDialog on a private ImitatePass built from the wizard's settings, so the chosen gpg is used...
FirstRunWizard * m_wizard
Owner; holds the key list this page fills.
QLabel * m_status
Says so when gpg has no secret key yet.
auto validatePage() -> bool override
Remember which keys are enabled.
KeyWizardPage(FirstRunWizard *wizard)
Build the page.
Handles GPG keypair generation.
static void invalidate()
Forget the currently active backend.
void init(const AppSettings &settings)
Initialize the Pass instance with a settings snapshot.
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...
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 ...
QLineEdit * m_gpg
The gpg executable; required.
QLineEdit * m_pass
The pass executable; optional.
QLineEdit * m_git
The git executable; optional.
FirstRunWizard * m_wizard
Owner; its settings are what the page edits.
void initializePage() override
Fill the fields from the settings (autodetection already ran).
QLabel * m_gpgStatus
Under the gpg field: why it cannot be used.
void updateStatus()
After an edit: say under the gpg field when it is missing or not executable, allow "use pass" only fo...
auto isComplete() const -> bool override
Whether the gpg path points at something that can run.
ProgramsWizardPage(FirstRunWizard *wizard)
Build the page.
auto validatePage() -> bool override
Store the paths and the pass/Git choices in the settings.
QCheckBox * m_usePass
Run pass instead of gpg/git; needs m_pass.
Singleton that stores QtPass settings, handles persistence and defaults.
static auto getInstance() -> QtPassSettings *
Get the singleton instance.
static auto getProfiles() -> Profiles
Get all configured profiles.
static void takeProfileOfStore(AppSettings &settings, const Profiles &profiles)
Make settings use the profile whose store it opens.
static void save(const AppSettings &settings)
Persist an AppSettings value object to the singleton store.
The names of the keys in the settings file, one constant per key.
static const QString firstRunPending
Set on a fresh install until QtPass is first set up: the first-run wizard finished,...
StoreWizardPage(FirstRunWizard *wizard)
Build the page.
QLabel * m_status
What Finish will do with the folder.
auto validatePage() -> bool override
Store the path and the Git choice.
void initializePage() override
Show the configured store path.
auto recipients() const -> int
How many keys are ticked on the key page.
auto isComplete() const -> bool override
Whether a path is given and, for a folder that is not a store yet, at least one key was ticked to enc...
QLineEdit * m_path
The store folder, in native separators.
QCheckBox * m_useGit
Keep the store under Git; off without git.
FirstRunWizard * m_wizard
Owner; its settings get the path and flag.
void updateStatus()
After an edit: describe the folder (existing store with its entry count, empty folder,...
static auto findPasswordStore() -> QString
Locate the password store directory.
static auto regularFilesUnder(const QString &dir, const QStringList &nameFilters, QStringList *skipped=nullptr, bool hiddenFiles=false, QStringList *unlisted=nullptr) -> QStringList
Regular files under dir whose name matches one of nameFilters, found by walking only real directories...
static auto mkpathForStore(const QString &path) -> bool
Create path and any missing parents as pass would.
static auto displayable(const QString &text, bool lineBreaks=true) -> QString
text with the characters that change how the text around them reads replaced by U+FFFD,...
static auto normalizeFolderPath(const QString &path) -> QString
Ensure a folder path always ends with '/'.
static auto findBinaryInPath(const QString &binary) -> QString
Locate an executable by searching the process PATH and (on Windows) falling back to WSL.
Executor, the FIFO queue every gpg, git and pass child process of QtPass goes through,...
The first-run wizard and its four pages: programs, key, store and summary.
auto parseGpgColonOutput(const QString &output, bool secret) -> QList< UserInfo >
Parse a gpg colon listing into one UserInfo per key.
Parsing of gpg --with-colons key listings into UserInfo records.
ImitatePass, the backend that does what pass does by running gpg and git itself.
Dialog that collects name, e-mail and passphrase for a new GPG keypair and drives gpg --gen-key --bat...
auto show(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, QMessageBox::StandardButtons buttons=QMessageBox::Ok) -> QMessageBox::StandardButton
Show a modal message box with plain text and wait for it.
void warning(QWidget *parent, const QString &title, const QString &text)
Show a warning in plain text.
PassBackendFactory, which constructs the two Pass backends on demand and hands out the one the settin...
QMessageBox helpers that force Qt::PlainText so store-controlled names can never be read as rich-text...
Initialising a new profile's store (.gpg-id, signature, Git) with blocking processes,...
QtPassSettings, the QSettings singleton behind every saved setting, the profiles and the Pass backend...
Names of the keys QtPass stores its settings under.
Plain value-object holding all flat QtPass configuration.
QString gpgExecutable
Path to the gpg/gpg2 executable.
QString passSigningKey
GPG key used to sign .gpg-id files.
bool usePass
Use the pass CLI (true) or native git/gpg.
QString pwgenExecutable
Path to the pwgen executable.
QString passStore
Password-store root path.
QString gitExecutable
Path to the git executable.
bool useTrayIcon
Show a system tray icon.
QString passExecutable
Path to the pass executable.
bool useGit
Enable git integration.
QString activeProfile
Name of the active profile.
Stores GPG key info including validity, creation date, and more.
bool enabled
Whether this user/key is enabled for normal use.
QString key_id
Hexadecimal representation of the GnuPG key identifier.
auto isValid() const -> bool
Check whether the key has any usable validity level.
QString name
GPG user ID / full name.
char validity
GnuPG representation of validity. http://git.gnupg.org/cgi-bin/gitweb.cgi?p=gnupg....
QDateTime expiry
Date/time when key expires.
Util: static helpers for the process environment, binary discovery, store paths, URL safety and the l...