1.2 wip - psk work

This commit is contained in:
Kevin Hester 2021-02-22 10:26:11 +08:00
parent c6091338ab
commit 008187caa4
7 changed files with 61 additions and 26 deletions

View File

@ -6,19 +6,19 @@ You probably don't care about this section - skip to the next one.
* DONE call RouterPlugin for *all* packets - not just Router packets * DONE call RouterPlugin for *all* packets - not just Router packets
* generate channel hash from the name of the channel+the psk (not just one or the other) * generate channel hash from the name of the channel+the psk (not just one or the other)
* send a hint that can be used to select which channel to try and hash against with each message
* DONE remove deprecated * DONE remove deprecated
* DONE fix setchannel in phoneapi.cpp * DONE fix setchannel in phoneapi.cpp
* DONE set mynodeinfo.max_channels * DONE set mynodeinfo.max_channels
* DONE set mynodeinfo.num_bands (formerly num_channels) * DONE set mynodeinfo.num_bands (formerly num_channels)
* DONE fix sniffing of non Routing packets * DONE fix sniffing of non Routing packets
* enable remote setttings access by moving settings operations into a regular plugin (move settings ops out of PhoneAPI) * DONE enable remote setttings access by moving settings operations into a regular plugin (move settings ops out of PhoneAPI)
* DONE move portnum up? * DONE move portnum up?
* DONE remove region specific builds from the firmware * DONE remove region specific builds from the firmware
* restrict settings operations to the admin channel * restrict settings operations to the admin channel
* add gui in android app for setting region * add gui in android app for setting region
* "FIXME - move the radioconfig/user/channel READ operations into SettingsMessage as well" * "FIXME - move the radioconfig/user/channel READ operations into SettingsMessage as well"
* scrub protobufs to make sure they are absoloute minimum wiresize (in particular packets, ChannelSets and positions) * DONE scrub protobufs to make sure they are absoloute minimum wiresize (in particular Data, ChannelSets and positions)
* send a hint that can be used to select which channel to try and hash against with each message
* change syncword * change syncword
* allow chaning packets in single transmission - to increase airtime efficiency and amortize packet overhead * allow chaning packets in single transmission - to increase airtime efficiency and amortize packet overhead
* DONE move most parts of meshpacket into the Data packet, so that we can chain multiple Data for sending when they all have a common destination and key. * DONE move most parts of meshpacket into the Data packet, so that we can chain multiple Data for sending when they all have a common destination and key.

2
proto

@ -1 +1 @@
Subproject commit 649c3deb71d1780416fac5db33ad3c957c0278b6 Subproject commit 7db1c2edb2e62e90b1f297be2f11aff0df35330a

View File

@ -74,18 +74,23 @@ void initDefaultChannel(size_t chIndex)
/** Given a channel index, change to use the crypto key specified by that index /** Given a channel index, change to use the crypto key specified by that index
*/ */
void setCrypto(size_t chIndex) void Channels::setCrypto(size_t chIndex)
{ {
assert(chIndex < devicestate.channels_count); assert(chIndex < devicestate.channels_count);
Channel *ch = devicestate.channels + chIndex; Channel *ch = devicestate.channels + chIndex;
ChannelSettings &channelSettings = ch->settings; ChannelSettings &channelSettings = ch->settings;
assert(ch->has_settings);
memset(activePSK, 0, sizeof(activePSK)); // In case the user provided a short key, we want to pad the rest with zeros memset(activePSK, 0, sizeof(activePSK)); // In case the user provided a short key, we want to pad the rest with zeros
memcpy(activePSK, channelSettings.psk.bytes, channelSettings.psk.size); memcpy(activePSK, channelSettings.psk.bytes, channelSettings.psk.size);
activePSKSize = channelSettings.psk.size; activePSKSize = channelSettings.psk.size;
if (activePSKSize == 0) if (activePSKSize == 0) {
DEBUG_MSG("Warning: User disabled encryption\n"); if(ch->role == Channel_Role_SECONDARY) {
DEBUG_MSG("Unset PSK for secondary channel %s. using primary key\n", ch->settings.name);
setCrypto(primaryIndex);
} else
DEBUG_MSG("Warning: User disabled encryption\n");
}
else if (activePSKSize == 1) { else if (activePSKSize == 1) {
// Convert the short single byte variants of psk into variant that can be used more generally // Convert the short single byte variants of psk into variant that can be used more generally
@ -134,7 +139,7 @@ void Channels::onConfigChanged()
primaryIndex = i; primaryIndex = i;
} }
setCrypto(0); // FIXME: for the time being (still single channel - just use our only channel as the crypto key) setCrypto(primaryIndex); // FIXME: for the time being (still single channel - just use our only channel as the crypto key)
} }
Channel &Channels::getChannel(size_t chIndex) Channel &Channels::getChannel(size_t chIndex)

View File

@ -45,6 +45,35 @@ their nodes
/// called when the user has just changed our radio config and we might need to change channel keys /// called when the user has just changed our radio config and we might need to change channel keys
void onConfigChanged(); void onConfigChanged();
/** Given a channel hash setup crypto for decoding that channel (or the primary channel if that channel is unsecured)
*
* This method is called before decoding inbound packets
*
* @return false if no suitable channel could be found.
*/
bool setCryptoByHash(uint8_t channelHash);
/** Given a channel index setup crypto for encoding that channel (or the primary channel if that channel is unsecured)
*
* This method is called before encoding inbound packets
*
* @eturn the (0 to 255) hash for that channel - if no suitable channel could be found, return -1
*/
int16_t setCryptoByIndex(uint8_t channelIndex);
private:
/** Given a channel index, change to use the crypto key specified by that index
*/
void setCrypto(size_t chIndex);
/** Return the channel index for the specified channel hash, or -1 for not found */
int8_t getChannelIndexByHash(uint8_t channelHash);
/** Given a channel number, return the (0 to 255) hash for that channel
* If no suitable channel could be found, return -1
*/
int16_t getChannelHash(size_t channelNum);
}; };
/// Singleton channel table /// Singleton channel table

View File

@ -80,7 +80,7 @@ extern const pb_msgdesc_t DeviceState_msg;
#define DeviceState_fields &DeviceState_msg #define DeviceState_fields &DeviceState_msg
/* Maximum encoded size of messages (where known) */ /* Maximum encoded size of messages (where known) */
#define DeviceState_size 6225 #define DeviceState_size 6119
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View File

@ -119,20 +119,20 @@ typedef enum _LogRecord_Level {
/* Struct definitions */ /* Struct definitions */
typedef PB_BYTES_ARRAY_T(32) ChannelSettings_psk_t; typedef PB_BYTES_ARRAY_T(32) ChannelSettings_psk_t;
typedef struct _ChannelSettings { typedef struct _ChannelSettings {
int32_t tx_power; int8_t tx_power;
ChannelSettings_ModemConfig modem_config; ChannelSettings_ModemConfig modem_config;
ChannelSettings_psk_t psk; ChannelSettings_psk_t psk;
char name[12]; char name[12];
uint32_t bandwidth; uint16_t bandwidth;
uint32_t spread_factor; uint32_t spread_factor;
uint32_t coding_rate; uint8_t coding_rate;
uint32_t channel_num; uint8_t channel_num;
uint32_t id; uint32_t id;
bool uplink_enabled; bool uplink_enabled;
bool downlink_enabled; bool downlink_enabled;
} ChannelSettings; } ChannelSettings;
typedef PB_BYTES_ARRAY_T(240) Data_payload_t; typedef PB_BYTES_ARRAY_T(237) Data_payload_t;
typedef struct _Data { typedef struct _Data {
PortNum portnum; PortNum portnum;
Data_payload_t payload; Data_payload_t payload;
@ -230,7 +230,7 @@ typedef struct _User {
} User; } User;
typedef struct _Channel { typedef struct _Channel {
uint32_t index; uint8_t index;
bool has_settings; bool has_settings;
ChannelSettings settings; ChannelSettings settings;
Channel_Role role; Channel_Role role;
@ -240,7 +240,7 @@ typedef PB_BYTES_ARRAY_T(256) MeshPacket_encrypted_t;
typedef struct _MeshPacket { typedef struct _MeshPacket {
uint32_t from; uint32_t from;
uint32_t to; uint32_t to;
uint32_t channel_index; uint8_t channel_index;
pb_size_t which_payloadVariant; pb_size_t which_payloadVariant;
union { union {
Data decoded; Data decoded;
@ -249,7 +249,7 @@ typedef struct _MeshPacket {
uint32_t id; uint32_t id;
uint32_t rx_time; uint32_t rx_time;
float rx_snr; float rx_snr;
uint32_t hop_limit; uint8_t hop_limit;
bool want_ack; bool want_ack;
MeshPacket_Priority priority; MeshPacket_Priority priority;
} MeshPacket; } MeshPacket;
@ -770,17 +770,17 @@ extern const pb_msgdesc_t AdminMessage_msg;
#define User_size 72 #define User_size 72
#define RouteDiscovery_size 40 #define RouteDiscovery_size 40
#define Routing_size 47 #define Routing_size 47
#define Data_size 258 #define Data_size 255
#define MeshPacket_size 302 #define MeshPacket_size 294
#define ChannelSettings_size 95 #define ChannelSettings_size 87
#define Channel_size 105 #define Channel_size 94
#define RadioConfig_size 308 #define RadioConfig_size 308
#define RadioConfig_UserPreferences_size 305 #define RadioConfig_UserPreferences_size 305
#define NodeInfo_size 130 #define NodeInfo_size 130
#define MyNodeInfo_size 89 #define MyNodeInfo_size 89
#define LogRecord_size 81 #define LogRecord_size 81
#define FromRadio_size 317 #define FromRadio_size 317
#define ToRadio_size 305 #define ToRadio_size 297
#define AdminMessage_size 311 #define AdminMessage_size 311
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -24,13 +24,14 @@ typedef enum _PortNum {
PortNum_STORE_FORWARD_APP = 65, PortNum_STORE_FORWARD_APP = 65,
PortNum_RANGE_TEST_APP = 66, PortNum_RANGE_TEST_APP = 66,
PortNum_PRIVATE_APP = 256, PortNum_PRIVATE_APP = 256,
PortNum_ATAK_FORWARDER = 257 PortNum_ATAK_FORWARDER = 257,
PortNum_MAX = 511
} PortNum; } PortNum;
/* Helper constants for enums */ /* Helper constants for enums */
#define _PortNum_MIN PortNum_UNKNOWN_APP #define _PortNum_MIN PortNum_UNKNOWN_APP
#define _PortNum_MAX PortNum_ATAK_FORWARDER #define _PortNum_MAX PortNum_MAX
#define _PortNum_ARRAYSIZE ((PortNum)(PortNum_ATAK_FORWARDER+1)) #define _PortNum_ARRAYSIZE ((PortNum)(PortNum_MAX+1))
#ifdef __cplusplus #ifdef __cplusplus