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.
193 lines
4.5 KiB
C++
193 lines
4.5 KiB
C++
#ifndef SUBJECT_ATTRIBUTE_HPP_IRZLEB7C
|
|
#define SUBJECT_ATTRIBUTE_HPP_IRZLEB7C
|
|
|
|
#include <vanetza/security/v2/int_x.hpp>
|
|
#include <vanetza/security/v2/public_key.hpp>
|
|
#include <vanetza/security/v2/serialization.hpp>
|
|
#include <boost/variant/variant.hpp>
|
|
#include <cstdint>
|
|
#include <list>
|
|
|
|
namespace vanetza
|
|
{
|
|
namespace security
|
|
{
|
|
namespace v2
|
|
{
|
|
|
|
/// SubjectAssurance specified in TS 103 097 v1.2.1 in section 6.6 and 7.4.1
|
|
struct SubjectAssurance
|
|
{
|
|
SubjectAssurance(uint8_t _raw = 0) : raw(_raw) {}
|
|
|
|
static constexpr uint8_t assurance_mask = 0xE0;
|
|
static constexpr uint8_t confidence_mask = 0x03;
|
|
|
|
uint8_t raw;
|
|
|
|
uint8_t assurance() const
|
|
{
|
|
return (raw & assurance_mask) >> 5;
|
|
}
|
|
|
|
uint8_t confidence() const
|
|
{
|
|
return raw & confidence_mask;
|
|
}
|
|
};
|
|
|
|
/// ItsAidSsp specified in TS 103 097 v1.2.1, section 6.9
|
|
struct ItsAidSsp
|
|
{
|
|
IntX its_aid;
|
|
ByteBuffer service_specific_permissions;
|
|
};
|
|
|
|
/// SubjectAttributeType specified in TS 103 097 v1.2.1, section 6.5
|
|
enum class SubjectAttributeType : uint8_t {
|
|
Verification_Key = 0, //VerificationKey
|
|
Encryption_Key = 1, //EncryptionKey
|
|
Assurance_Level = 2, //SubjectAssurance
|
|
Reconstruction_Value = 3, //EccPoint
|
|
ITS_AID_List = 32, //std::list<IntX>
|
|
ITS_AID_SSP_List = 33, //std::list<ItsAidSsp>
|
|
};
|
|
|
|
/// VerificationKey specified in TS 103 097 v1.2.1, section 6.4
|
|
struct VerificationKey
|
|
{
|
|
PublicKey key;
|
|
};
|
|
|
|
/// EncryptionKey specified in TS 103 097 v1.2.1, section 6.4
|
|
struct EncryptionKey
|
|
{
|
|
PublicKey key;
|
|
};
|
|
|
|
/// SubjectAttribute specified in TS 103 097 v1.2.1, section 6.4
|
|
using SubjectAttribute = boost::variant<
|
|
VerificationKey,
|
|
EncryptionKey,
|
|
SubjectAssurance,
|
|
EccPoint,
|
|
std::list<IntX>,
|
|
std::list<ItsAidSsp>
|
|
>;
|
|
|
|
/**
|
|
* \brief Determines SubjectAttributeType to a given SubjectAttribute
|
|
* \param attribute
|
|
* \return type
|
|
*/
|
|
SubjectAttributeType get_type(const SubjectAttribute&);
|
|
|
|
/**
|
|
* \brief Calculates size of a SubjectAttribute
|
|
* \param sub
|
|
* \return number of octets needed to serialize the SubjectAttribute
|
|
*/
|
|
size_t get_size(const SubjectAttribute&);
|
|
|
|
/**
|
|
* \brief Calculates size of a SubjectAssurance
|
|
* \param sub
|
|
* \return number of octets needed to serialize the SubjectAssurance
|
|
*/
|
|
size_t get_size(const SubjectAssurance&);
|
|
|
|
/**
|
|
* \brief Calculates size of an ItsAidSsp
|
|
* \param its_aid_ssp
|
|
* \return number of octets needed to serialize the ItsAidSsp
|
|
*/
|
|
size_t get_size(const ItsAidSsp&);
|
|
|
|
/**
|
|
* \brief Deserializes a SubjectAttribute from a binary archive
|
|
* \param ar with a serialized SubjectAttribute at the beginning
|
|
* \param sub to deserialize
|
|
* \return size of the deserialized SubjectAttribute
|
|
*/
|
|
size_t deserialize(InputArchive&, SubjectAttribute&);
|
|
|
|
/**
|
|
* \brief Deserializes an ItsAidSsp from a binary archive
|
|
* \param ar with a serialized ItsAidSsp at the beginning
|
|
* \param its_aid_ssp to deserialize
|
|
* \return size of the deserialized ItsAidSsp
|
|
*/
|
|
size_t deserialize(InputArchive&, ItsAidSsp&);
|
|
|
|
/**
|
|
* \brief Serializes a SubjectAttribute into a binary archive
|
|
* \param ar to serialize in
|
|
* \param sub to serialize
|
|
*/
|
|
void serialize(OutputArchive&, const SubjectAttribute&);
|
|
|
|
/**
|
|
* \brief Serializes an ItsAidSsp into a binary archive
|
|
* \param ar to serialize in
|
|
* \param its_aid_ssp to serialize
|
|
*/
|
|
void serialize(OutputArchive&, const ItsAidSsp&);
|
|
|
|
namespace detail
|
|
{
|
|
|
|
template<SubjectAttributeType>
|
|
struct subject_attribute_type;
|
|
|
|
template<>
|
|
struct subject_attribute_type<SubjectAttributeType::Verification_Key>
|
|
{
|
|
using type = VerificationKey;
|
|
};
|
|
|
|
template<>
|
|
struct subject_attribute_type<SubjectAttributeType::Encryption_Key>
|
|
{
|
|
using type = EncryptionKey;
|
|
};
|
|
|
|
template<>
|
|
struct subject_attribute_type<SubjectAttributeType::Assurance_Level>
|
|
{
|
|
using type = SubjectAssurance;
|
|
};
|
|
|
|
template<>
|
|
struct subject_attribute_type<SubjectAttributeType::Reconstruction_Value>
|
|
{
|
|
using type = EccPoint;
|
|
};
|
|
|
|
template<>
|
|
struct subject_attribute_type<SubjectAttributeType::ITS_AID_List>
|
|
{
|
|
using type = std::list<IntX>;
|
|
};
|
|
|
|
template<>
|
|
struct subject_attribute_type<SubjectAttributeType::ITS_AID_SSP_List>
|
|
{
|
|
using type = std::list<ItsAidSsp>;
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
/**
|
|
* \brief resolve type for matching SubjectAttributeType
|
|
*
|
|
* This is kind of the reverse function of get_type(const SubjectAttribute&)
|
|
*/
|
|
template<SubjectAttributeType T>
|
|
using subject_attribute_type = typename detail::subject_attribute_type<T>::type;
|
|
|
|
} // namespace v2
|
|
} // namespace security
|
|
} // namespace vanetza
|
|
|
|
#endif /* SUBJECT_ATTRIBUTE_HPP_IRZLEB7C */
|