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
60
66 bool signOutgoing(mavlink_message_t& message);
67
69 bool isAutoDetectSuspended() const;
70
72 [[nodiscard]] QGC::AutoSuspendGuard suspendAutoDetect() { return QGC::AutoSuspendGuard(_autoDetectSuspended); }
73
75 bool isInDetectCooldown() const;
76 void recordDetectMiss();
78 static constexpr qint64 kDetectCooldownMs = 2000;
79
82
85
86private:
87 friend class SigningController;
88
90 bool setSignOutgoing(bool signOutgoing);
91
92 mavlink_signing_t _signing{};
94 mavlink_signing_streams_t _streams{};
95 QString _keyHint;
96 bool _enabled = false;
98 std::atomic<bool> _autoDetectSuspended{false};
99 QDeadlineTimer _detectCooldown; // default-constructed → expired (forever in the past)
100 mavlink_signing_status_t _lastTransitionStatus = MAVLINK_SIGNING_STATUS_NONE;
101 mutable QReadWriteLock _lock;
102};
mavlink_channel_t
struct __mavlink_message mavlink_message_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 refreshOutgoingTimestamp()
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
bool signOutgoing(mavlink_message_t &message)
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().