From 656684e39630066c7ab2f1dae1391b2f340e3e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cesare=20G=2E=20Mart=C3=ADnez?= Date: Sun, 17 Dec 2023 21:01:01 +0100 Subject: [PATCH] DSM-PKR getter setter structure --- src/core/libs/osnma_msg_receiver.cc | 17 +++++++++++++---- src/core/system_parameters/gnss_crypto.cc | 23 +++++++++++++++++++++++ src/core/system_parameters/gnss_crypto.h | 3 ++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/core/libs/osnma_msg_receiver.cc b/src/core/libs/osnma_msg_receiver.cc index f7ab9e334..c08b669d3 100644 --- a/src/core/libs/osnma_msg_receiver.cc +++ b/src/core/libs/osnma_msg_receiver.cc @@ -341,7 +341,7 @@ void osnma_msg_receiver::process_dsm_message(const std::vector& dsm_msg { p_dk_truncated.push_back(hash[i]); } - // check DS signature + // Check that the padding bits received match the computed values if (d_osnma_data.d_dsm_kroot_message.p_dk == p_dk_truncated) { bool authenticated = d_crypto->verify_signature(message, d_osnma_data.d_dsm_kroot_message.ds); @@ -371,7 +371,7 @@ void osnma_msg_receiver::process_dsm_message(const std::vector& dsm_msg else if (d_osnma_data.d_dsm_header.dsm_id >= 12 && d_osnma_data.d_dsm_header.dsm_id < 16) { LOG(WARNING) << "OSNMA: DSM-PKR message received."; - // DSM-PKR message + // Save DSM-PKR message d_osnma_data.d_dsm_pkr_message.nb_dp = d_dsm_reader->get_number_blocks_index(dsm_msg[0]); d_osnma_data.d_dsm_pkr_message.mid = d_dsm_reader->get_mid(dsm_msg); for (int k = 0; k > 128; k++) @@ -424,7 +424,17 @@ void osnma_msg_receiver::process_dsm_message(const std::vector& dsm_msg << ", TOW=" << static_cast(d_osnma_data.d_dsm_kroot_message.towh_k) * 3600 << " received" << std::endl; // C: NPK verification against Merkle tree root. - d_public_key_verified = verify_dsm_pkr(d_osnma_data.d_dsm_pkr_message); + if (!d_public_key_verified) + { + bool verification = verify_dsm_pkr(d_osnma_data.d_dsm_pkr_message); + if (verification) + { + d_public_key_verified = true; + d_crypto->set_public_key(d_osnma_data.d_dsm_pkr_message.npk); + } + + } + } } else @@ -872,7 +882,6 @@ void osnma_msg_receiver::process_mack_message(const std::shared_ptr& bool osnma_msg_receiver::verify_dsm_pkr(DSM_PKR_message message) { - // TODO create leafe base message m_i // TODO create function for recursively apply hash // build base leaf m_i diff --git a/src/core/system_parameters/gnss_crypto.cc b/src/core/system_parameters/gnss_crypto.cc index eab8ab23e..eb9d38ca0 100644 --- a/src/core/system_parameters/gnss_crypto.cc +++ b/src/core/system_parameters/gnss_crypto.cc @@ -598,3 +598,26 @@ std::vector Gnss_Crypto::getMerkleRoot(const std::vector& publicKey) +{ +#if USE_OPENSSL_FALLBACK + // TODO - convert to OSSL PubKey format +#else +// GNU-TLS + // TODO - convert to gnutls_pubkey_st +#endif + +} + +std::vector Gnss_Crypto::get_public_key() +{ +#if USE_OPENSSL_FALLBACK + // TODO +#else +// GNU-TLS + // TODO +#endif + return {}; +} diff --git a/src/core/system_parameters/gnss_crypto.h b/src/core/system_parameters/gnss_crypto.h index 50047c440..6f405cc24 100644 --- a/src/core/system_parameters/gnss_crypto.h +++ b/src/core/system_parameters/gnss_crypto.h @@ -55,7 +55,8 @@ public: return d_x_4_0; } - // void set_public_key(const std::vector& publickey); + void set_public_key(const std::vector& publickey); + static std::vector get_public_key(); private: #if USE_OPENSSL_FALLBACK