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).
87 lines
2.9 KiB
C++
87 lines
2.9 KiB
C++
#include <vanetza/common/position_fix.hpp>
|
|
#include <vanetza/geodesy/country_database.hpp>
|
|
#include <vanetza/geodesy/m49_code.hpp>
|
|
#include <vanetza/asn1/security_profile.hpp>
|
|
#include VANETZA_ASN1_SECURITY_HEADER(IdentifiedRegion.h)
|
|
#include VANETZA_ASN1_SECURITY_HEADER(SequenceOfIdentifiedRegion.h)
|
|
#include <vanetza/security/v3/asn1_types.hpp>
|
|
#include <vanetza/security/v3/distance.hpp>
|
|
#include <vanetza/security/v3/geometry.hpp>
|
|
#include <vanetza/security/v3/location_checker.hpp>
|
|
|
|
namespace vanetza
|
|
{
|
|
namespace security
|
|
{
|
|
namespace v3
|
|
{
|
|
|
|
bool AllowLocationChecker::valid_at_location(const asn1::EtsiTs103097Certificate&, const PositionFix&) const
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bool DenyLocationChecker::valid_at_location(const asn1::EtsiTs103097Certificate&, const PositionFix&) const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool DefaultLocationChecker::valid_at_location(const asn1::EtsiTs103097Certificate& cert, const PositionFix& location) const
|
|
{
|
|
const asn1::GeographicRegion* region = cert.toBeSigned.region;
|
|
if (region) {
|
|
switch (region->present) {
|
|
case Vanetza_Security_GeographicRegion_PR_circularRegion:
|
|
return is_inside(location, region->choice.circularRegion);
|
|
case Vanetza_Security_GeographicRegion_PR_rectangularRegion:
|
|
return is_inside(location, region->choice.rectangularRegion);
|
|
case Vanetza_Security_GeographicRegion_PR_polygonalRegion:
|
|
return is_inside(location, region->choice.polygonalRegion);
|
|
case Vanetza_Security_GeographicRegion_PR_identifiedRegion:
|
|
return check_identified_region(location, region->choice.identifiedRegion);
|
|
default:
|
|
// unknown or future region restriction type — reject conservatively
|
|
return false;
|
|
}
|
|
} else {
|
|
// no region restriction applies
|
|
return true;
|
|
}
|
|
}
|
|
|
|
bool DefaultLocationChecker::check_identified_region(const PositionFix& location, const Vanetza_Security_SequenceOfIdentifiedRegion& seq) const
|
|
{
|
|
if (!country_db_ || country_db_->empty())
|
|
{
|
|
// lacking database for country checks
|
|
return permissive_identified_region_;
|
|
}
|
|
|
|
// reject any region by default
|
|
bool accepted = false;
|
|
|
|
for (int i = 0; i < seq.list.count; ++i) {
|
|
const auto* entry = seq.list.array[i];
|
|
if (!entry) {
|
|
continue;
|
|
}
|
|
|
|
if (entry->present == Vanetza_Security_IdentifiedRegion_PR_countryOnly) {
|
|
geodesy::M49Code code(static_cast<uint16_t>(entry->choice.countryOnly));
|
|
geodesy::GeodeticPosition pos(location.latitude, location.longitude);
|
|
if (country_db_->is_inside(code, pos)) {
|
|
return true;
|
|
}
|
|
} else {
|
|
// may accept because of unsupported identified region
|
|
accepted = permissive_identified_region_;
|
|
}
|
|
}
|
|
|
|
return accepted;
|
|
}
|
|
|
|
} // namespace v3
|
|
} // namespace security
|
|
} // namespace vanetza
|