QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SigningChannel.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QByteArrayView>
4#include <QtCore/QDeadlineTimer>
5#include <QtCore/QReadWriteLock>
6#include <QtCore/QString>
7#include <atomic>
8#include <cstdint>
9
10#include "AutoSuspendGuard.h"
11#include "MAVLinkMessageType.h"
12#include "MAVLinkSigning.h"
13
15
19{
20public:
21 SigningChannel() = default;
22 ~SigningChannel() = default;
27
29 static constexpr uint64_t kPersistedTimestampSafetyBumpTicks = 6'000'000;
30
33 bool init(mavlink_channel_t channel, QByteArrayView key, mavlink_accept_unsigned_t callback,
34 uint64_t persistedTimestamp = 0, const QString& keyName = {}, bool signOutgoing = true);
35
37 bool setAcceptUnsignedCallback(mavlink_accept_unsigned_t callback);
38
39 bool isEnabled() const;
40 int streamCount() const;
41
42 QString keyHint() const;
43 void setKeyHint(const QString& name);
44 void clearKeyHint();
45
47 {
48 uint64_t timestamp;
49 QString keyName;
50 };
51
54
56 bool isAutoDetectSuspended() const;
57
59 [[nodiscard]] QGC::AutoSuspendGuard suspendAutoDetect() { return QGC::AutoSuspendGuard(_autoDetectSuspended); }
60
62 bool isInDetectCooldown() const;
63 void recordDetectMiss();
65 static constexpr qint64 kDetectCooldownMs = 2000;
66
69
72
73private:
74 friend class SigningController;
75
77 bool setSignOutgoing(bool signOutgoing);
78
79 mavlink_signing_t _signing{};
81 mavlink_signing_streams_t _streams{};
82 QString _keyHint;
83 bool _enabled = false;
85 std::atomic<bool> _autoDetectSuspended{false};
86 QDeadlineTimer _detectCooldown; // default-constructed → expired (forever in the past)
87 mavlink_signing_status_t _lastTransitionStatus = MAVLINK_SIGNING_STATUS_NONE;
88 mutable QReadWriteLock _lock;
89};
mavlink_channel_t
RAII guard for an atomic suspend flag: sets on construction, clears on destruction.
Owns MAVLink signing state for one channel: signing/streams structs, key hint, and RW lock.
bool init(mavlink_channel_t channel, QByteArrayView key, mavlink_accept_unsigned_t callback, uint64_t persistedTimestamp=0, const QString &keyName={}, bool signOutgoing=true)
SigningChannel(SigningChannel &&)=delete
QString keyHint() const
void setKeyHint(const QString &name)
bool setAcceptUnsignedCallback(mavlink_accept_unsigned_t callback)
Swap the accept-unsigned callback without resetting the key. Returns false if signing isn't enabled.
QGC::AutoSuspendGuard suspendAutoDetect()
RAII handle that suspends auto-detect for the guard's lifetime; release is automatic on destruction.
SigningChannel & operator=(const SigningChannel &)=delete
MAVLinkSigning::DetectSnapshot detectSnapshot() const
Single-lock snapshot; 3 separate reads have TOCTOU window vs MockLink's thread.
static constexpr uint64_t kPersistedTimestampSafetyBumpTicks
60s post-reboot timestamp bump (matches ArduPilot GCS_Signing.cpp); absorbs SIGKILL/suspend/NTP/clock...
int streamCount() const
bool isEnabled() const
bool isAutoDetectSuspended() const
While suspended, tryDetectKey is suppressed to block stale-key installs during pending enable.
SigningChannel()=default
bool consumeStatusTransition(mavlink_channel_t channel)
True if last_status changed since previous call; sole transition-detection source.
SigningChannel(const SigningChannel &)=delete
SigningChannel & operator=(SigningChannel &&)=delete
bool isInDetectCooldown() const
Throttles detect misses; HMAC per packet per key is expensive. Monotonic timer to avoid wall-clock sk...
static constexpr qint64 kDetectCooldownMs
TimestampSnapshot currentTimestampAndName() const
Returns current timestamp and active key name. Returns {0, ""} when signing is not enabled.
~SigningChannel()=default
Owns MAVLink signing state and the deferred-confirmation state machine for one LinkInterface.
Single-lock snapshot struct; fields populated by SigningChannel::detectSnapshot().