obu-firmware builds against the vanetza-idf C-ITS library, which until now came from the colleague's microbu-esp32c5 tree beside the repository and was not tracked here, so a clone of this repository could not build the firmware it ships. The library alone is now part of obu-firmware, as obu-firmware/external/vanetza-idf: their external/vanetza-idf at commit cf4b99f, unchanged (9775 files; see its PROVENANCE.md). CMake takes it from there by default; -DVANETZA_IDF_DIR still points the build elsewhere. The rest of the colleague's tree (their own VAM firmware, PKI tooling, station-link Python tools, the V2X2MAP bridge) stays out of this repository and gitignored; nothing is pushed to their repository. NOTES.md, docs/06, TODO.md and the pcap verifier's usage line point at the new location.
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
|