1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-01-19 05:33:02 +00:00

[TAS-203] bug osnma_test_vector_config_1

adkd dependence on key selection
This commit is contained in:
cesaaargm 2024-05-22 21:01:24 +02:00
parent 163c915c72
commit b0eb958be0
2 changed files with 26 additions and 10 deletions

View File

@ -570,7 +570,7 @@ void osnma_msg_receiver::read_and_process_mack_block(const std::shared_ptr<OSNMA
// update the structure with newly coming NavData
d_osnma_data.d_nav_data.init(osnma_msg); // TODO refactor it
add_satellite_data(d_osnma_data.d_nav_data.PRNa,d_osnma_data.d_nav_data.TOW_sf0,d_osnma_data.d_nav_data); // TODO change place
add_satellite_data(osnma_msg->PRN,osnma_msg->TOW_sf0,d_osnma_data.d_nav_data); // TODO change place
// DEBUG PARSING MACK MESSAGES WHEN DSM-KROOT NOT YET AVAILABLE
// d_osnma_data.d_dsm_kroot_message.ts = 9;
// d_osnma_data.d_dsm_kroot_message.ks = 4;
@ -860,6 +860,7 @@ void osnma_msg_receiver::process_mack_message()
LOG(WARNING) << "But it will be processed for debugging purposes.";
}
// verify tesla key and add it to the container of verified keys if successful
// TODO not verify tesla key for each satellite if already verified.
bool retV = verify_tesla_key(d_osnma_data.d_mack_message.key, d_osnma_data.d_nav_data.TOW_sf0);
if(retV){
d_tesla_keys.insert(std::pair(d_osnma_data.d_nav_data.TOW_sf0, d_osnma_data.d_mack_message.key));
@ -1004,13 +1005,19 @@ bool osnma_msg_receiver::verify_tag(Tag& tag)
std::vector<uint8_t> m = build_message(tag);
std::vector<uint8_t> mac;
std::vector<uint8_t> applicable_key;
if (tag.ADKD == 0 || tag.ADKD == 4)
applicable_key = d_tesla_keys[tag.TOW + 30];
else // ADKD 12
applicable_key = d_tesla_keys[tag.TOW + 300];
if (d_osnma_data.d_dsm_kroot_message.mf == 0) // C: HMAC-SHA-256
{
mac = d_crypto->computeHMAC_SHA_256(d_tesla_keys[tag.TOW+30], m);
mac = d_crypto->computeHMAC_SHA_256(applicable_key, m);
}
else if (d_osnma_data.d_dsm_kroot_message.mf == 1) // C: CMAC-AES
{
mac = d_crypto->computeCMAC_AES(d_tesla_keys[tag.TOW+30], m);
mac = d_crypto->computeCMAC_AES(applicable_key, m);
}
// truncate the computed mac: trunc(l_t, mac(K,m)) Eq. 23 ICD
@ -1073,7 +1080,7 @@ std::vector<uint8_t> osnma_msg_receiver::build_message(const Tag& tag)
m.push_back(two_bits_nmas);
// convert std::string to vector<uint8_t>
std::string ephemeris_iono_vector_2 = d_satellite_nav_data[tag.PRNa][tag.TOW-30].ephemeris_iono_vector_2;
std::string ephemeris_iono_vector_2 = d_satellite_nav_data[tag.PRNa][tag.TOW - 30].ephemeris_iono_vector_2;
std::vector<uint8_t> ephemeris_iono_vector_2_bytes = d_helper->bytes(ephemeris_iono_vector_2);
// Convert and add ephemeris_iono_vector_2 into the vector

View File

@ -44,9 +44,6 @@ protected:
std::string merkleFilePath = "/home/cgm/CLionProjects/osnma/data/OSNMA_MerkleTree_20230803105953_newPKID_1.xml";
osnma = osnma_msg_receiver_make(pemFilePath, merkleFilePath);
}
void TearDown() override{
google::ShutdownGoogleLogging();
}
public:
static std::vector<uint8_t> parseNavBits(const std::string& hex);
@ -122,6 +119,7 @@ TEST_F(OsnmaMsgReceiverTest, OsnmaTestVectorsSimulation)
std::array<uint32_t, 15> mack{};
byte_index = offset_byte; // reset byte_index to the offset position for the next test vector. Offset is updated at the end of each Subframe (every 30 s or 450 Bytes)
std::map<uint8_t, std::bitset<128>> words;
for (int idx = 0; idx < SIZE_SUBFRAME_PAGES; ++idx) // extract all pages of a subframe
{
// extract bytes of complete page (odd+even) -- extract SIZE_PAGE from tv.navBits, starting from byte_index
@ -225,8 +223,6 @@ TEST_F(OsnmaMsgReceiverTest, OsnmaTestVectorsSimulation)
uint8_t length = param.second.second;
// Extract the required bits
std::bitset<128> word = words[wordKey];
osnmaMsg_sptr->EphemerisClockAndStatusData_2 += words[wordKey].
to_string().substr(
start, length);
@ -333,6 +329,19 @@ std::string OsnmaMsgReceiverTest::bytes_to_str(const std::vector<uint8_t>& bytes
}
return bit_string;
}
/**
* @brief Extracts a range of bytes from a TestVector's navBits vector.
*
* This function extracts a extracts the bytes of complete page (odd+even)
* from the navBits vector of a TestVector object.
*
*
* @param tv The TestVector object from which to extract bytes.
* @param byte_index The index of the first byte to extract.
* @param num_bytes The number of bytes to extract.
* @return A vector containing the extracted bytes, or an empty vector if extraction is not possible.
*/
std::vector<uint8_t> OsnmaMsgReceiverTest::extract_page_bytes(const TestVector& tv, const int byte_index, const int num_bytes)
{
// Ensure we don't go beyond the end of tv.navBits