Files
MicrOBU/microbu-esp32c5/external/vanetza-idf/vanetza/security/v2/verification.cpp
T
Ashin Walpola 0e9525162d Keep the colleague's microbu-esp32c5 tree in this repository
obu-firmware builds against vanetza-idf from microbu-esp32c5/external, but
that tree was gitignored, so a clone of this repository could not build the
firmware it ships. It is now committed here as ordinary files in its own
folder, microbu-esp32c5/: the colleague's commit cf4b99f plus the V2X2MAP
bridge's signature verification (--trust) used on the bench. Nothing is
fetched from or pushed to the colleague's repository; this repository and
its remotes carry everything. The folder's own .gitignore keeps build output,
downloaded components and private key material out, as it did there; the
committed file set is identical to that repository's tracked files.

The ESP32-C5 is still flashed from obu-firmware/, which only takes
vanetza-idf from microbu-esp32c5/, so the two stay separate folders.
FLASHING.md says how to take a newer version of the colleague's tree (copy
it over the folder, rebuild, test, commit).
2026-09-23 17:46:40 +02:00

95 lines
2.9 KiB
C++

#include <vanetza/security/v2/verification.hpp>
namespace vanetza
{
namespace security
{
namespace v2
{
bool check_generation_time(const SecuredMessage& message, Clock::time_point now)
{
using namespace std::chrono;
bool valid = false;
const Time64* generation_time = message.header_field<HeaderFieldType::Generation_Time>();
if (generation_time) {
// Values are picked from C2C-CC Basic System Profile v1.1.0, see RS_BSP_168
static const auto generation_time_future = milliseconds(40);
static const Clock::duration generation_time_past_default = minutes(10);
static const Clock::duration generation_time_past_ca = seconds(2);
auto generation_time_past = generation_time_past_default;
const IntX* its_aid = message.header_field<HeaderFieldType::Its_Aid>();
if (its_aid && aid::CA == *its_aid) {
generation_time_past = generation_time_past_ca;
}
if (*generation_time > convert_time64(now + generation_time_future)) {
valid = false;
} else if (*generation_time < convert_time64(now - generation_time_past)) {
valid = false;
} else {
valid = true;
}
}
return valid;
}
bool check_generation_location(const SecuredMessage& message, const Certificate& cert)
{
const IntX* its_aid = message.header_field<HeaderFieldType::Its_Aid>();
if (its_aid && aid::CA == *its_aid) {
return true; // no check required for CAMs, field not even allowed
}
const ThreeDLocation* generation_location = message.header_field<HeaderFieldType::Generation_Location>();
if (generation_location) {
auto region = cert.get_restriction<ValidityRestrictionType::Region>();
if (!region || get_type(*region) == RegionType::None) {
return true;
}
return is_within(TwoDLocation(*generation_location), *region);
}
return false;
}
bool check_certificate_time(const Certificate& certificate, Clock::time_point now)
{
auto time = certificate.get_restriction<ValidityRestrictionType::Time_Start_And_End>();
auto time_now = convert_time32(now);
if (!time) {
return false; // must be present
}
if (time->start_validity > time_now || time->end_validity < time_now) {
return false; // premature or outdated
}
return true;
}
bool check_certificate_region(const Certificate& certificate, const PositionFix& position)
{
auto region = certificate.get_restriction<ValidityRestrictionType::Region>();
if (!region || get_type(*region) == RegionType::None) {
return true;
}
if (!position.confidence) {
return false; // cannot check region restrictions without good position fix
}
return is_within(TwoDLocation(position.latitude, position.longitude), *region);
}
} // namespace v2
} // namespace security
} // namespace vanetza