Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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.

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...
 

Function Documentation

void gec_add_to_whitelist ( struct gec_whitelist whitelist,
uint8_t  id 
)

Definition at line 791 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:

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 421 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:

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 ```ignore 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 ```ignore 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 524 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, 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:

void gec_dl_init ( void  )

Init function.

Definition at line 336 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:

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 362 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:

bool gec_is_in_the_whitelist ( struct gec_whitelist whitelist,
uint8_t  id 
)

Definition at line 805 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:

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 588 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:

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 735 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, 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 caller graph for this function:

void gec_transport_init ( struct gec_transport t)

Definition at line 316 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:

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

Simply insert byte to the message buffer.

Definition at line 85 of file gec_dl.c.

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

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

Definition at line 71 of file gec_dl.c.

References gec_sts_ctx::decrypt_err, 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

struct gec_transport gec_tp