QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MAVLinkSigningKeys Class Reference

Bag of named MAVLink signing keys; correct key per vehicle is auto-detected from incoming signed packets. More...

#include <MAVLinkSigningKeys.h>

+ Inheritance diagram for MAVLinkSigningKeys:
+ Collaboration diagram for MAVLinkSigningKeys:

Signals

void keysChanged ()
 
void keyUsageChanged ()
 

Public Member Functions

 MAVLinkSigningKeys (QObject *parent=nullptr)
 
 ~MAVLinkSigningKeys () override
 
Q_INVOKABLE bool addKey (const QString &name, const QString &passphrase)
 
Q_INVOKABLE bool addRawKey (const QString &name, const QString &hexKey)
 
Q_INVOKABLE void removeKey (const QString &name)
 
Q_INVOKABLE void removeAllKeys ()
 Used by tests and full reset.
 
Q_INVOKABLE bool isKeyInUse (const QString &name) const
 True if any connected vehicle is using the key with the given name.
 
Q_INVOKABLE QString keyHexByName (const QString &name) const
 Hex-encoded key bytes for export (empty if not found).
 
MAVLinkSigningKeykeyAt (int index) const
 Key entry at the given index, or nullptr if invalid.
 
std::optional< MAVLinkSigning::SigningKeykeyBytesByName (const QString &name) const
 Key bytes for the key with the given name, or nullopt if not found.
 
uint64_t lastTimestamp (const QString &name) const
 Last persisted signing timestamp for name, or 0 if unknown / no entry.
 
void recordTimestamp (const QString &name, uint64_t ts)
 Update in-memory + persisted last-timestamp for name. Monotonic — older values are dropped.
 
void recordTimestamps (const QHash< QString, uint64_t > &batch)
 Batch update with single QSettings + sync; per-entry monotonic guard still applies.
 
void flushAllTimestamps ()
 Walk every signing channel and persist its current timestamp under the active key's name.
 
QString tryDetectKey (SigningController *controller, const mavlink_message_t &message)
 Try every stored key against message's signature; on match, configures channel and returns the key name.
 
QmlObjectListModelkeys () const
 
int keyUsageRevision () const
 

Static Public Member Functions

static MAVLinkSigningKeysinstance ()
 
static Q_INVOKABLE QString generateRandomHexKey ()
 Cryptographically random 64-char hex string (32 bytes).
 
static void setPbkdf2IterationsForTesting (int iterations)
 Test-only override for PBKDF2 iteration count; 0 restores production default.
 

Friends

class SigningTest
 

Detailed Description

Bag of named MAVLink signing keys; correct key per vehicle is auto-detected from incoming signed packets.

Definition at line 49 of file MAVLinkSigningKeys.h.

Constructor & Destructor Documentation

◆ MAVLinkSigningKeys()

MAVLinkSigningKeys::MAVLinkSigningKeys ( QObject *  parent = nullptr)
explicit

◆ ~MAVLinkSigningKeys()

MAVLinkSigningKeys::~MAVLinkSigningKeys ( )
override

Definition at line 70 of file MAVLinkSigningKeys.cc.

Member Function Documentation

◆ addKey()

bool MAVLinkSigningKeys::addKey ( const QString &  name,
const QString &  passphrase 
)

Derives a 32-byte key via PBKDF2-HMAC-SHA256 with a fixed app salt — deterministic across installs so the same passphrase yields the same key on multiple GCS stations sharing one vehicle. Returns false on duplicate name, passphrase below kMinPassphraseLength, or capacity limit.

Definition at line 147 of file MAVLinkSigningKeys.cc.

References keysChanged(), MAVLinkSigning::makeSigningKey(), and QGC::secureZero().

◆ addRawKey()

bool MAVLinkSigningKeys::addRawKey ( const QString &  name,
const QString &  hexKey 
)

Add a key from raw 32-byte hex string (e.g. from a key file or shared secret). Returns false on duplicate name, malformed hex, or capacity limit.

Definition at line 174 of file MAVLinkSigningKeys.cc.

References keysChanged(), and MAVLinkSigning::makeSigningKey().

◆ flushAllTimestamps()

void MAVLinkSigningKeys::flushAllTimestamps ( )

Walk every signing channel and persist its current timestamp under the active key's name.

Definition at line 317 of file MAVLinkSigningKeys.cc.

References recordTimestamps().

Referenced by MAVLinkSigningKeys().

◆ generateRandomHexKey()

QString MAVLinkSigningKeys::generateRandomHexKey ( )
static

Cryptographically random 64-char hex string (32 bytes).

Definition at line 197 of file MAVLinkSigningKeys.cc.

◆ instance()

◆ isKeyInUse()

bool MAVLinkSigningKeys::isKeyInUse ( const QString &  name) const

True if any connected vehicle is using the key with the given name.

Definition at line 75 of file MAVLinkSigningKeys.cc.

References MultiVehicleManager::instance().

◆ keyAt()

MAVLinkSigningKey * MAVLinkSigningKeys::keyAt ( int  index) const

Key entry at the given index, or nullptr if invalid.

Definition at line 105 of file MAVLinkSigningKeys.cc.

References QmlObjectListModel::value().

Referenced by tryDetectKey().

◆ keyBytesByName()

std::optional< MAVLinkSigning::SigningKey > MAVLinkSigningKeys::keyBytesByName ( const QString &  name) const

Key bytes for the key with the given name, or nullopt if not found.

Definition at line 113 of file MAVLinkSigningKeys.cc.

Referenced by VehicleSigningController::enable(), keyHexByName(), and tryDetectKey().

◆ keyHexByName()

QString MAVLinkSigningKeys::keyHexByName ( const QString &  name) const

Hex-encoded key bytes for export (empty if not found).

Definition at line 206 of file MAVLinkSigningKeys.cc.

References keyBytesByName(), and QGC::secureZero().

◆ keys()

QmlObjectListModel * MAVLinkSigningKeys::keys ( ) const
inline

Definition at line 109 of file MAVLinkSigningKeys.h.

◆ keysChanged

void MAVLinkSigningKeys::keysChanged ( )
signal

◆ keyUsageChanged

void MAVLinkSigningKeys::keyUsageChanged ( )
signal

◆ keyUsageRevision()

int MAVLinkSigningKeys::keyUsageRevision ( ) const
inline

Definition at line 111 of file MAVLinkSigningKeys.h.

◆ lastTimestamp()

uint64_t MAVLinkSigningKeys::lastTimestamp ( const QString &  name) const

Last persisted signing timestamp for name, or 0 if unknown / no entry.

Definition at line 279 of file MAVLinkSigningKeys.cc.

Referenced by SigningController::initSigningImmediate(), and SigningController::tryBeginEnable().

◆ recordTimestamp()

void MAVLinkSigningKeys::recordTimestamp ( const QString &  name,
uint64_t  ts 
)

Update in-memory + persisted last-timestamp for name. Monotonic — older values are dropped.

Definition at line 312 of file MAVLinkSigningKeys.cc.

References recordTimestamps().

Referenced by SigningController::clearSigning().

◆ recordTimestamps()

void MAVLinkSigningKeys::recordTimestamps ( const QHash< QString, uint64_t > &  batch)

Batch update with single QSettings + sync; per-entry monotonic guard still applies.

Definition at line 285 of file MAVLinkSigningKeys.cc.

Referenced by flushAllTimestamps(), and recordTimestamp().

◆ removeAllKeys()

void MAVLinkSigningKeys::removeAllKeys ( )

Used by tests and full reset.

Definition at line 236 of file MAVLinkSigningKeys.cc.

References QmlObjectListModel::clearAndDeleteContents(), QmlObjectListModel::count(), and keysChanged().

◆ removeKey()

void MAVLinkSigningKeys::removeKey ( const QString &  name)

Definition at line 221 of file MAVLinkSigningKeys.cc.

References keysChanged(), and QmlObjectListModel::removeOne().

◆ setPbkdf2IterationsForTesting()

static void MAVLinkSigningKeys::setPbkdf2IterationsForTesting ( int  iterations)
inlinestatic

Test-only override for PBKDF2 iteration count; 0 restores production default.

Definition at line 150 of file MAVLinkSigningKeys.h.

◆ tryDetectKey()

Friends And Related Symbol Documentation

◆ SigningTest

friend class SigningTest
friend

Definition at line 57 of file MAVLinkSigningKeys.h.


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