QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
gpgkeystate.cpp File Reference

Implements the colon-listing parser: record classification, one handler per record type, and primary-fingerprint lookup. More...

#include "gpgkeystate.h"
#include "gpgkeystate_p.h"
#include "util.h"
#include <QDateTime>
#include <QRegularExpression>
Include dependency graph for gpgkeystate.cpp:

Go to the source code of this file.

Functions

auto classifyRecord (const QString &record_type) -> GpgRecordType
 Classify a record of a gpg colon listing by its first field.
void handlePubSecRecord (const QStringList &props, bool secret, UserInfo &current_user)
 Start a key from a pub or sec record: key ID, the user ID the record may carry, validity, creation and expiry time.
void handleUidRecord (const QStringList &props, UserInfo &current_user)
 Handle a uid record in GPG colon output.
void handleFprRecord (const QStringList &props, UserInfo &current_user)
 Replace the key ID of the key being built with its fingerprint.
auto parseGpgColonOutput (const QString &output, bool secret) -> QList< UserInfo >
 Parse a gpg colon listing into one UserInfo per key.
auto primaryFingerprintOf (const QString &output, const QString &key) -> QString
 The primary key fingerprint of the key that key names.

Variables

constexpr int GPG_MIN_FIELDS = 10
 Fewest fields a record must have to be read at all.
constexpr int GPG_FIELD_VALIDITY = 1
 Field index of the validity letter (u, f, r, ...).
constexpr int GPG_FIELD_KEY_ID = 4
 Field index of the key ID.
constexpr int GPG_FIELD_CREATED = 5
 Field index of the creation time, in seconds since the epoch.
constexpr int GPG_FIELD_EXPIRY = 6
 Field index of the expiry time; empty for a key without one.
constexpr int GPG_FIELD_USERID = 9
 Field index of the user ID.
constexpr int GPG_FIELD_FINGERPRINT = 9
 Field 9 of an fpr record: the fingerprint, in the slot the user ID occupies in a uid record.

Detailed Description

Implements the colon-listing parser: record classification, one handler per record type, and primary-fingerprint lookup.

Definition in file gpgkeystate.cpp.

Function Documentation

◆ classifyRecord()

auto classifyRecord ( const QString & record_type)

Classify a record of a gpg colon listing by its first field.

Parameters
record_typeThe first field of the record (pub, sec, uid, and so on).
Returns
The matching GpgRecordType, or GpgRecordType::Unknown.

Definition at line 34 of file gpgkeystate.cpp.

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

◆ handleFprRecord()

void handleFprRecord ( const QStringList & props,
UserInfo & current_user )

Replace the key ID of the key being built with its fingerprint.

Only when the fpr record's value is shaped like a fingerprint (40 or 64 hex digits) and ends in the key ID already there, so a subkey's fingerprint is never taken for the primary key's.

Parameters
propsThe colon-split fields of the record.
current_userThe key being built; its key ID may be replaced.

Definition at line 96 of file gpgkeystate.cpp.

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

◆ handlePubSecRecord()

void handlePubSecRecord ( const QStringList & props,
bool secret,
UserInfo & current_user )

Start a key from a pub or sec record: key ID, the user ID the record may carry, validity, creation and expiry time.

An empty expiry field (gpg's "no expiry") leaves the date null. A record with fewer than ten fields changes nothing.

Parameters
propsThe colon-split fields of the record.
secretWhether to mark the key as having a secret part.
current_userThe key being built; filled in.

Definition at line 59 of file gpgkeystate.cpp.

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

◆ handleUidRecord()

void handleUidRecord ( const QStringList & props,
UserInfo & current_user )

Handle a uid record in GPG colon output.

Parameters
propsThe colon-split fields of the record
current_userUserInfo to populate with user name

Definition at line 92 of file gpgkeystate.cpp.

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

◆ parseGpgColonOutput()

auto parseGpgColonOutput ( const QString & output,
bool secret )

Parse a gpg colon listing into one UserInfo per key.

A pub or sec record starts a key; the first uid after it supplies the name when the key record carried none, and an fpr record whose value ends in the key ID replaces the key ID with the full fingerprint. Lines with fewer than ten fields are skipped.

Parameters
outputRaw output of gpg --with-colons --with-fingerprint.
secretTrue when output lists secret keys (--list-secret-keys); the keys are then marked as having a secret part.
Returns
The keys, in the order gpg listed them.

Definition at line 112 of file gpgkeystate.cpp.

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

◆ primaryFingerprintOf()

auto primaryFingerprintOf ( const QString & output,
const QString & key )

The primary key fingerprint of the key that key names.

gpg accepts a signature by a subkey for its primary key, and verification here takes either fingerprint from VALIDSIG: a key written as a subkey's fingerprint, or as a key ID, signs as its primary key. Only the block that holds key is taken, whatever else gpg printed; when several do (a short ID, which collides easily), none is.

Parameters
outputRaw output from GPG –with-colons –with-fingerprint –with-subkey-fingerprint –list-keys.
keyA fingerprint (40 or 64 hex) or a key ID (8 or 16 hex), optionally with 0x; any case. A key ID is matched against the record's own key ID, so it works for v4 keys (the fingerprint's tail) and v5/v6 keys (its head) alike.
Returns
The primary fingerprint in upper case, or empty when no block, or more than one, in output holds key.

Definition at line 160 of file gpgkeystate.cpp.

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

Variable Documentation

◆ GPG_FIELD_CREATED

int GPG_FIELD_CREATED = 5
constexpr

Field index of the creation time, in seconds since the epoch.

Definition at line 23 of file gpgkeystate.cpp.

◆ GPG_FIELD_EXPIRY

int GPG_FIELD_EXPIRY = 6
constexpr

Field index of the expiry time; empty for a key without one.

Definition at line 25 of file gpgkeystate.cpp.

◆ GPG_FIELD_FINGERPRINT

int GPG_FIELD_FINGERPRINT = 9
constexpr

Field 9 of an fpr record: the fingerprint, in the slot the user ID occupies in a uid record.

Definition at line 32 of file gpgkeystate.cpp.

◆ GPG_FIELD_KEY_ID

int GPG_FIELD_KEY_ID = 4
constexpr

Field index of the key ID.

Definition at line 21 of file gpgkeystate.cpp.

◆ GPG_FIELD_USERID

int GPG_FIELD_USERID = 9
constexpr

Field index of the user ID.

Definition at line 27 of file gpgkeystate.cpp.

◆ GPG_FIELD_VALIDITY

int GPG_FIELD_VALIDITY = 1
constexpr

Field index of the validity letter (u, f, r, ...).

Definition at line 19 of file gpgkeystate.cpp.

◆ GPG_MIN_FIELDS

int GPG_MIN_FIELDS = 10
constexpr

Fewest fields a record must have to be read at all.

Definition at line 17 of file gpgkeystate.cpp.