Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
gec_dl.c File Reference
#include "gec_dl.h"
#include "modules/datalink/gec/gec.h"
#include "subsystems/datalink/datalink.h"
#include "pprzlink/messages.h"
#include <string.h>
#include "subsystems/datalink/telemetry.h"
+ Include dependency graph for gec_dl.c:

Go to the source code of this file.

Macros

#define GEC_UPDATE_DL   TRUE
 

Functions

static void send_secure_link_info (struct transport_tx *trans, struct link_device *dev)
 
static void insert_byte (struct gec_transport *t, const uint8_t byte)
 Simply insert byte to the message buffer. More...
 
void gec_transport_init (struct gec_transport *t)
 
void gec_dl_init (void)
 Init function. More...
 
bool gec_encrypt_message (uint8_t *buf, uint8_t *payload_len)
 Attempts message encryption Adds crypto_byte, counter and tag Returns encrypted pprzlink message (crypto_byte . More...
 
bool gec_decrypt_message (uint8_t *buf, volatile uint8_t *payload_len)
 Attemp message decryption If a message is unencrypted, pass it through only if the MSG_ID is in the whitelist Returns Pprzlink message bytes (source_ID . More...
 
void gec_dl_event (void)
 Parse incoming message bytes (PPRZ_STX..CHCKSUM B) and returns a new decrypted message if it is available. More...
 
void gec_process_msg1 (uint8_t *buf)
 NOTE: for RESPONDER party only Process incoming message (expected MSG1) if the right (KEY_EXCHANGE) message received with the right data (P_AE) and the right P_AE.len=PPRZ_KEY_LEN, the internal state of Sts gets updated (key derivation etc), and msg2 is prepared to be sent. More...
 
bool gec_process_msg3 (uint8_t *buf)
 Process incoming message (expected MSG3) if the right (KEY_EXCHANGE) message received with the right data (SIG) and the right SIG.len=PPRZ_SIGN_LEN, and the signature is verified, Ok() is returned. More...
 
void gec_add_to_whitelist (struct gec_whitelist *whitelist, uint8_t id)
 
bool gec_is_in_the_whitelist (struct gec_whitelist *whitelist, uint8_t id)
 

Variables

struct gec_transport gec_tp
 PPRZ transport structure. More...
 

Macro Definition Documentation

◆ GEC_UPDATE_DL

#define GEC_UPDATE_DL   TRUE

Definition at line 67 of file gec_dl.c.

Function Documentation

◆ gec_add_to_whitelist()

void gec_add_to_whitelist ( struct gec_whitelist whitelist,
uint8_t  id 
)

Definition at line 800 of file gec_dl.c.

References gec_whitelist::idx, gec_whitelist::init, gec_whitelist::whitelist, and WHITELIST_LEN.

Referenced by gec_transport_init().

+ Here is the caller graph for this function:

◆ gec_decrypt_message()

bool gec_decrypt_message ( uint8_t buf,
volatile uint8_t payload_len 
)

Attemp message decryption If a message is unencrypted, pass it through only if the MSG_ID is in the whitelist Returns Pprzlink message bytes (source_ID .

. msg payload)

Input: expects (CRYPTO_BYTE .. MSG_DATA .. optional TAG) Output: returns stripped message (SENDER_ID .. MSG_PAYLOAD)

Definition at line 430 of file gec_dl.c.

References counter, gec_sym_key::counter, gec_sts_ctx::decrypt_err, gec_bytes_to_counter(), gec_is_in_the_whitelist(), gec_tp, gec_sym_key::key, gec_sym_key::nonce, PPRZ_AUTH_IDX, PPRZ_CNTR_IDX, PPRZ_CRYPTO_OVERHEAD, PPRZ_GEC_IDX, PPRZ_MAC_LEN, PPRZ_MSG_TYPE_ENCRYPTED, PPRZ_MSG_TYPE_PLAINTEXT, gec_sym_key::ready, gec_sts_ctx::rx_counter_err, gec_sts_ctx::rx_sym_key, gec_transport::sts, and gec_transport::whitelist.

Referenced by gec_dl_event().

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

◆ gec_dl_event()

void gec_dl_event ( void  )

Parse incoming message bytes (PPRZ_STX..CHCKSUM B) and returns a new decrypted message if it is available.

Datalink Event.

While the status != Crypto_OK no message is returned, and all logic is handled internally. Returned message has format of Pprzlink 2.0

payload[0] source SENDER_ID
payload[1] destination ID
payload[2] class/component
payload[3] MSG_ID
payload[4-end] MSG_PAYLOAD

or Pprzlink 1.0

payload[0] source SENDER_ID
payload[1] MSG_ID
payload[2-end] MSG_PAYLOAD

and can be directly processed by a parser

NOTE: the KEY_EXCHANGE messages are whitelisted and thus pass through the "decryption" even if they are in plaintext and after the key exchange is established. This is not a problem, because we don't act on them. It would be good to limit "sending" them from other processes, but for now lets assume nobody will want to send this message.

In the future, the KEY_EXCHANGE messages should be handled even in CRYPTO_OK mode and acted upon accordingly (i.e. the key renegotiation will be possible). For now, I am keeping this note here as a reminder.

Definition at line 533 of file gec_dl.c.

References CRYPTO_OK, DatalinkFillDlBuffer, dl_buffer, dl_msg_available, DlCheckAndParse(), DOWNLINK_DEVICE, gec_decrypt_message(), gec_process_msg1(), gec_process_msg3(), gec_tp, GEC_UPDATE_DL, LED_ON, gec_transport::pprz_tp, gec_sts_ctx::protocol_stage, gec_transport::sts, gec_transport::trans_rx, gec_transport::trans_tx, WAIT_MSG1, and WAIT_MSG3.

+ Here is the call graph for this function:

◆ gec_dl_init()

void gec_dl_init ( void  )

Init function.

Definition at line 345 of file gec_dl.c.

References DefaultPeriodic, gec_sts_init(), gec_tp, gec_transport_init(), LED_OFF, gec_transport::pprz_tp, register_periodic_telemetry(), send_secure_link_info(), and gec_transport::sts.

+ Here is the call graph for this function:

◆ gec_encrypt_message()

bool gec_encrypt_message ( uint8_t buf,
uint8_t payload_len 
)

Attempts message encryption Adds crypto_byte, counter and tag Returns encrypted pprzlink message (crypto_byte .

. tag) in the same buffer as was the incoming message

Definition at line 371 of file gec_dl.c.

References counter, gec_sym_key::counter, gec_sts_ctx::encrypt_err, gec_counter_to_bytes(), gec_tp, gec_sym_key::key, gec_sym_key::nonce, PPRZ_AUTH_IDX, PPRZ_CNTR_IDX, PPRZ_CRYPTO_OVERHEAD, PPRZ_GEC_IDX, PPRZ_MAC_LEN, PPRZ_MSG_TYPE_ENCRYPTED, gec_sym_key::ready, gec_transport::sts, and gec_sts_ctx::tx_sym_key.

+ Here is the call graph for this function:

◆ gec_is_in_the_whitelist()

bool gec_is_in_the_whitelist ( struct gec_whitelist whitelist,
uint8_t  id 
)

Definition at line 814 of file gec_dl.c.

References gec_whitelist::idx, gec_whitelist::init, and gec_whitelist::whitelist.

Referenced by gec_decrypt_message().

+ Here is the caller graph for this function:

◆ gec_process_msg1()

void gec_process_msg1 ( uint8_t buf)

NOTE: for RESPONDER party only Process incoming message (expected MSG1) if the right (KEY_EXCHANGE) message received with the right data (P_AE) and the right P_AE.len=PPRZ_KEY_LEN, the internal state of Sts gets updated (key derivation etc), and msg2 is prepared to be sent.

Input: decrypted message (source_ID .. msg payload) If all good, it sends response message

Definition at line 597 of file gec_dl.c.

References DOWNLINK_DEVICE, gec_derive_key_material(), gec_generate_ephemeral_keys(), gec_tp, gec_sym_key::key, gec_sts_ctx::last_error, MSG1_ENCRYPT_ERROR, gec_sts_ctx::my_private_ephemeral, gec_sts_ctx::my_private_key, gec_sym_key::nonce, P_AE, P_BE, PPRZ_GEC_IDX, PPRZ_KEY_LEN, PPRZ_MAC_LEN, PPRZ_MSG_TYPE_PLAINTEXT, PPRZ_SIGN_LEN, gec_transport::pprz_tp, gec_privkey::priv, gec_sts_ctx::protocol_stage, gec_privkey::pub, gec_pubkey::pub, gec_privkey::ready, gec_pubkey::ready, gec_transport::sts, gec_sts_ctx::their_public_ephemeral, gec_transport::tx_msg, gec_transport::tx_msg_idx, gec_sts_ctx::tx_sym_key, UNEXPECTED_MSG_DATA_ERROR, UNEXPECTED_MSG_ERROR, UNEXPECTED_MSG_TYPE_ERROR, and WAIT_MSG3.

Referenced by gec_dl_event().

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

◆ gec_process_msg3()

bool gec_process_msg3 ( uint8_t buf)

Process incoming message (expected MSG3) if the right (KEY_EXCHANGE) message received with the right data (SIG) and the right SIG.len=PPRZ_SIGN_LEN, and the signature is verified, Ok() is returned.

Input: decrypted message (source_ID .. msg payload) Returns true if this party is ready for communication

Definition at line 744 of file gec_dl.c.

References gec_tp, gec_sym_key::key, gec_sts_ctx::last_error, MSG3_DECRYPT_ERROR, MSG3_SIGNVERIFY_ERROR, gec_sts_ctx::my_private_ephemeral, gec_sym_key::nonce, PPRZ_KEY_LEN, PPRZ_MAC_LEN, PPRZ_SIGN_LEN, gec_privkey::pub, gec_pubkey::pub, gec_sts_ctx::rx_sym_key, SIG, sign(), gec_transport::sts, gec_sts_ctx::their_public_ephemeral, gec_sts_ctx::their_public_key, UNEXPECTED_MSG_DATA_ERROR, UNEXPECTED_MSG_ERROR, and UNEXPECTED_MSG_TYPE_ERROR.

Referenced by gec_dl_event().

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

◆ gec_transport_init()

void gec_transport_init ( struct gec_transport t)

Definition at line 325 of file gec_dl.c.

References gec_add_to_whitelist(), KEY_EXCHANGE_MSG_ID_GCS, KEY_EXCHANGE_MSG_ID_UAV, PPRZ_MUTEX_INIT, gec_transport::trans_rx, gec_transport::trans_tx, and gec_transport::whitelist.

Referenced by gec_dl_init().

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

◆ insert_byte()

static void insert_byte ( struct gec_transport t,
const uint8_t  byte 
)
inlinestatic

Simply insert byte to the message buffer.

Definition at line 89 of file gec_dl.c.

References byte, gec_transport::tx_msg, and gec_transport::tx_msg_idx.

◆ send_secure_link_info()

static void send_secure_link_info ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Definition at line 75 of file gec_dl.c.

References gec_sts_ctx::decrypt_err, dev, gec_sts_ctx::encrypt_err, gec_tp, gec_sts_ctx::last_error, gec_sts_ctx::protocol_stage, gec_sts_ctx::rx_counter_err, and gec_transport::sts.

Referenced by gec_dl_init().

+ Here is the caller graph for this function:

Variable Documentation

◆ gec_tp

struct gec_transport gec_tp