QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
gpgidsigner.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
8#ifndef SRC_GPGIDSIGNER_H_
9#define SRC_GPGIDSIGNER_H_
10
11#include <QString>
12#include <QStringList>
13#include <functional>
14#include <optional>
15
30public:
41 static constexpr qint64 kMaxSignatureBytes = qint64{4} * 1024;
42
47 using Exec =
48 std::function<int(const QString &app, const QStringList &args,
49 const QString &input, QString *out, QString *err)>;
50
63 GpgIdSigner(QString gpgExecutable, QStringList signingKeys,
64 Exec exec = Exec());
65
76 void setStoreRoot(const QString &root) { m_storeRoot = root; }
77
84 static auto keysFromSetting(const QString &passSigningKey) -> QStringList;
85
98 static auto settingOrExported(const QString &passSigningKey) -> QString;
99
104 auto enabled() const -> bool { return !m_keys.isEmpty(); }
105
110 auto keys() const -> const QStringList & { return m_keys; }
117 auto refusal() const -> QString { return m_refusal; }
118
127 auto haveSecretKey() const -> bool;
128
154 auto sign(const QString &gpgIdFile, const QByteArray &contents,
155 QString *error = nullptr) const -> bool;
156
170 auto verify(const QByteArray &contents, const QString &signatureFile) const
171 -> bool;
172
181 auto verifyFile(const QString &gpgIdFile, QByteArray *contents) const -> bool;
182
190 static auto validSigFingerprints(const QString &statusOutput) -> QStringList;
191
192private:
207 auto heldByOneKey(const QString &signingFingerprint) const -> bool;
208
210 QString m_gpg;
215 QStringList m_keys;
217 mutable QString m_refusal;
225 [[nodiscard]] auto readOwnFile(const QString &path, qint64 maxBytes) const
226 -> std::optional<QByteArray>;
228 QString m_storeRoot;
231
240 auto run(const QStringList &args, QString *out = nullptr,
241 QString *err = nullptr, const QString &input = QString()) const
242 -> int;
243};
244
245#endif // SRC_GPGIDSIGNER_H_
static auto validSigFingerprints(const QString &statusOutput) -> QStringList
Pick the fingerprints out of gpg's --status-fd VALIDSIG line.
Exec m_exec
How gpg is run; replaced by a fake in the unit tests.
void setStoreRoot(const QString &root)
The store the lists and signatures this signer reads belong to.
Definition gpgidsigner.h:76
auto enabled() const -> bool
Whether any signing key is configured at all.
auto run(const QStringList &args, QString *out=nullptr, QString *err=nullptr, const QString &input=QString()) const -> int
Run gpg with args through m_exec.
auto sign(const QString &gpgIdFile, const QByteArray &contents, QString *error=nullptr) const -> bool
Write <file>.sig, a detached signature by the first key over contents, the bytes the caller just wrot...
QString m_refusal
See refusal(); set by the last verify().
static auto settingOrExported(const QString &passSigningKey) -> QString
The signing key to use: the setting, or with none set, the PASSWORD_STORE_SIGNING_KEY exported for pa...
GpgIdSigner(QString gpgExecutable, QStringList signingKeys, Exec exec=Exec())
Create a signer.
std::function< int(const QString &app, const QStringList &args, const QString &input, QString *out, QString *err)> Exec
Blocking process runner: Executor::executeBlocking()'s shape.
Definition gpgidsigner.h:47
QStringList m_keys
The configured signing keys. The first one signs; a signature by any of them verifies.
auto refusal() const -> QString
Why the last verify() refused a signature gpg called good, for the user: the signing key held by more...
auto keys() const -> const QStringList &
The keys this signer was given.
auto verifyFile(const QString &gpgIdFile, QByteArray *contents) const -> bool
Read gpgIdFile and verify it against <file>.sig.
static constexpr qint64 kMaxSignatureBytes
Most bytes of a .gpg-id.sig verify() hands to gpg.
Definition gpgidsigner.h:41
auto heldByOneKey(const QString &signingFingerprint) const -> bool
Whether exactly one key block holds the key that made a signature.
QString m_gpg
The gpg executable, as configured.
QString m_storeRoot
See setStoreRoot(); empty when not set.
auto readOwnFile(const QString &path, qint64 maxBytes) const -> std::optional< QByteArray >
Read a list or signature of the store: under m_storeRoot when set (see setStoreRoot()).
static auto keysFromSetting(const QString &passSigningKey) -> QStringList
Split the settings value into keys, upper-cased the way gpg prints fingerprints.
auto verify(const QByteArray &contents, const QString &signatureFile) const -> bool
Check a detached signature against the given bytes: gpg must report a VALIDSIG whose key or primary-k...
auto haveSecretKey() const -> bool
Whether gpg has the secret key that sign() will use, i.e. the first configured key....