Commit 2c190cf6 authored by garciay's avatar garciay
Browse files

ATS security review

parent 98594485
......@@ -10,7 +10,6 @@ CAMLayer::CAMLayer(const std::string & p_type, const std::string & param) : TLay
Params::convert(_params, param);
_params.insert(std::make_pair<std::string, std::string>("its_aid", "36")); // ETSI TS 102 965 V1.2.1 (2015-06)
_params.insert(std::make_pair<std::string, std::string>("payload_type", "2")); // CA message id - See ETSI TS 102 894
//params.log();
}
void CAMLayer::sendMsg(const LibItsCam__TestSystem::CamReq& p, Params& params){
......
......@@ -21,7 +21,8 @@ void DENMLayer::sendMsg(const LibItsDenm__TestSystem::DenmReq& p, Params& params
loggers::get_instance().warning("DENMLayer::sendMsg: Encodeing failure");
return;
}
sendData(data, params);
sendData(data, _params);
}
void DENMLayer::sendData(OCTETSTRING& data, Params& params) {
......
......@@ -17,7 +17,7 @@
using namespace LibItsGeoNetworking__TypesAndValues;
GeoNetworkingLayer::GeoNetworkingLayer(const std::string & p_type, const std::string & param) : TLayer<LibItsGeoNetworking__TestSystem::GeoNetworkingPort>(p_type), _params(), _codec(), _beacon(nullptr), _gbc_packet(nullptr), _shb_packet(nullptr), _ls_reply(nullptr), _location_table(), _pass_beacon_table(), _device_mode{false}, _secured_mode{false}, _enable_security_checks{false}, _sendData(), _timerid{0}, _sev{0}, _its{0}, _freq_nanosecs(0), _mask{0}, _sa{0}, _sequence_number{0} {
GeoNetworkingLayer::GeoNetworkingLayer(const std::string & p_type, const std::string & param) : TLayer<LibItsGeoNetworking__TestSystem::GeoNetworkingPort>(p_type), _params(), _codec(), _beacon(nullptr), _gbc_packet(nullptr), _shb_packet(nullptr), _tsb_packet(nullptr), _ls_reply(nullptr), _location_table(), _pass_beacon_table(), _device_mode{false}, _secured_mode{false}, _enable_security_checks{false}, _sendData(), _timerid{0}, _sev{0}, _its{0}, _freq_nanosecs(0), _mask{0}, _sa{0}, _sequence_number{0} {
loggers::get_instance().log(">>> GeoNetworkingLayer::GeoNetworkingLayer: %s, %s", to_string().c_str(), param.c_str());
// Setup parameters
......@@ -69,7 +69,7 @@ GeoNetworkingLayer::GeoNetworkingLayer(const std::string & p_type, const std::st
// Add broadcast address if needed
it = _params.find(Params::its_aid);
if (it == _params.cend()) {
_params.insert(std::pair<std::string, std::string>(std::string("its_aid"), "38"));
_params.insert(std::pair<std::string, std::string>(std::string("its_aid"), "141"));
}
it = _params.find(Params::mac_bc);
if (it == _params.cend()) {
......@@ -101,6 +101,7 @@ GeoNetworkingLayer::GeoNetworkingLayer(const std::string & p_type, const std::st
}
// Set up security services even if secured_mode is set to 0. Later, we can receive an AcEnableSecurity request, the sertificate caching will be ready to go
security_services::get_instance().setup(_params);
security_services::get_instance().set_position(latitude, longitude);
}
// Automatic beaconing mode
......@@ -114,6 +115,7 @@ GeoNetworkingLayer::GeoNetworkingLayer(const std::string & p_type, const std::st
// Fill packet templates
fill_gbc_packet(latitude, longitude, ll_address, latitude, longitude, distanceA, distanceB, angle);// TODO Check if GeoBroadcastArea lat/lon are identical to lat/lon of the Test System
fill_shb_packet(latitude, longitude, ll_address);
fill_tsb_packet(latitude, longitude, ll_address);
fill_ls_reply(latitude, longitude, ll_address);
} // End of constructor
......@@ -685,6 +687,70 @@ void GeoNetworkingLayer::fill_shb_packet(const INTEGER& p_latitude, const INTEGE
//loggers::get_instance().log_msg("GeoNetworkingLayer::fill_shb_packet: packet value: ", *_shb_packet);
} // End of fill_shb_packet method
void GeoNetworkingLayer::fill_tsb_packet(const INTEGER& p_latitude, const INTEGER& p_longitude, const OCTETSTRING& p_ll_address, const int p_hop_number, const int p_max_hop_limit)
{
_tsb_packet = new GeoNetworkingPdu();
HeaderTST h;
h.tsbHdr() = TsbHeaderType(
HeaderType(HeaderType::e__topologicallyScopedBroadcast),
HeaderSubTypeTSB(HeaderSubTypeTSB::e__multiHop)
);
ExtendedHeader eh;
eh.tsbHeader() = TSBHeader(
0,
0,
LongPosVector(
GN__Address(
TypeOfAddress(TypeOfAddress::e__manual), // TODO Use Params
StationType(StationType::e__passengerCar), // TODO Use Params
33,
p_ll_address
),
0,
p_latitude,
p_longitude,
int2bit(1, 1), // PAI
0,
0
)
);
_tsb_packet->basicHeader() = BasicHeader(
0,
BasicNextHeader(
BasicNextHeader::e__commonHeader
),
0,
Lifetime(
4,
LtBase(LtBase::e__50ms)
),
p_hop_number
);
_tsb_packet->gnPacket().packet() = GnNonSecuredPacket(
CommonHeader(
NextHeader(
NextHeader::e__btpA
),
0,
h,
TrafficClass(
SCF(SCF::e__scfDisabled),
ChannelOffload(ChannelOffload::e__choffDisabled),
0
),
int2bit(128, 8), // Mobile stationnary flag set
0,
p_max_hop_limit,
0
),
OPTIONAL<ExtendedHeader>(eh),
OPTIONAL<GnRawPayload>()
);
_tsb_packet->gnPacket().packet().payload().set_to_omit();
_tsb_packet->gnPacket().securedMsg().set_to_omit();
//loggers::get_instance().log_msg("GeoNetworkingLayer::fill_tsb_packet: packet value: ", *_tsb_packet);
} // End of fill_tsb_packet method
void GeoNetworkingLayer::fill_ls_reply(const INTEGER& p_latitude, const INTEGER& p_longitude, const OCTETSTRING& p_ll_address)
{
_ls_reply = new GeoNetworkingPdu();
......@@ -808,18 +874,42 @@ int GeoNetworkingLayer::build_geonetworking_pdu(OCTETSTRING& data, Params& param
unsigned long long ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - 1072911600000L; // TODO Add method such as its_tme() & its_time_mod()
eh->shbHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(ms));
loggers::get_instance().log_msg("GeoNetworkingLayer::build_geonetworking_pdu: ", *_shb_packet);
loggers::get_instance().log_msg("GeoNetworkingLayer::build_geonetworking_pdu: shb: ", *_shb_packet);
// Encode GeoNetworking PDU
OCTETSTRING os;
_codec.encode(*_shb_packet, os);
data = os;
} else { // TODO Use TSB
loggers::get_instance().error("GeoNetworkingLayer::build_geonetworking_pdu: Not implemented");
return -2;
} else { // Use TSB
ExtendedHeader* eh = static_cast<ExtendedHeader *>(_tsb_packet->gnPacket().packet().extendedHeader().get_opt_value());
if (eh == nullptr) {
loggers::get_instance().error("GeoNetworkingLayer::build_geonetworking_pdu: Wrong cast");
return -1;
}
// Update sequence number
eh->tsbHeader().seqNumber() = _sequence_number++;
// Update NextHeader
it = params.find(Params::next_header);
if (next_header.compare("btpB") == 0) {
_tsb_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpB;
} else { // Default btp is btpA
_tsb_packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpA;
}
// Update payload
_tsb_packet->gnPacket().packet().commonHeader().plLength() = data.lengthof();
_tsb_packet->gnPacket().packet().payload() = OPTIONAL<OCTETSTRING>(data);
// Update timestamp
unsigned long long ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - 1072911600000L; // TODO Add method such as its_tme() & its_time_mod()
eh->tsbHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(ms));
loggers::get_instance().log_msg("GeoNetworkingLayer::build_geonetworking_pdu: tsb: ", *_tsb_packet);
// Encode GeoNetworking PDU
OCTETSTRING os;
_codec.encode(*_tsb_packet, os);
data = os;
}
} else { // TODO To be continued
// Default: Use GBC
ExtendedHeader* eh = static_cast<ExtendedHeader *>(_shb_packet->gnPacket().packet().extendedHeader().get_opt_value());
ExtendedHeader* eh = static_cast<ExtendedHeader *>(_gbc_packet->gnPacket().packet().extendedHeader().get_opt_value());
if (eh == nullptr) {
loggers::get_instance().error("GeoNetworkingLayer::build_geonetworking_pdu: Wrong cast");
return -1;
......@@ -840,7 +930,7 @@ int GeoNetworkingLayer::build_geonetworking_pdu(OCTETSTRING& data, Params& param
unsigned long long ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - 1072911600000L; // TODO Add method such as its_tme() & its_time_mod()
eh->geoBroadcastHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(ms));
loggers::get_instance().log_msg("GeoNetworkingLayer::build_geonetworking_pdu: ", *_gbc_packet);
loggers::get_instance().log_msg("GeoNetworkingLayer::build_geonetworking_pdu: gbc: ", *_gbc_packet);
// Encode GeoNetworking PDU
OCTETSTRING os;
......
......@@ -43,6 +43,7 @@ class GeoNetworkingLayer : public TLayer<LibItsGeoNetworking__TestSystem::GeoNet
LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu* _beacon; /*!< Data structure used for beaconing */
LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu* _gbc_packet; /*!< Data structure used to encapsulate upper layer PDU into a GeoNetworking packet as a Geobroadcast*/
LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu* _shb_packet; /*!< Data structure used to encapsulate upper layer PDU into a GeoNetworking packet as a SHB */
LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu* _tsb_packet; /*!< Data structure used to encapsulate upper layer PDU into a GeoNetworking packet as a TSB */
LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu* _ls_reply; /*!< Data structure used to reply to an incoming LS_REQUEST */
LocationTable _location_table;
LocationTable _pass_beacon_table;
......@@ -82,6 +83,16 @@ class GeoNetworkingLayer : public TLayer<LibItsGeoNetworking__TestSystem::GeoNet
* \param[in] p_address
*/
void fill_shb_packet(const INTEGER& p_latitude, const INTEGER& p_longitude, const OCTETSTRING& p_ll_address);
/*!
* \brief Initialize a GeoNetworking packet to send GeoNetworking Facility messages
* This object shall be updated before to be sent
* \param[in] p_latitude
* \param[in] p_longitude
* \param[in] p_address
* \param[in] p_hop_number
* \param[in] p_max_hop_number
*/
void fill_tsb_packet(const INTEGER& p_latitude, const INTEGER& p_longitude, const OCTETSTRING& p_ll_address, const int p_hop_number = 3, const int p_max_hop_limit = 5);
/*!
* \brief Initialize an LS_REPLY GeoNetworking packet to reply to an LS_REQUEST
* This object shall be updated before to be sent
......
......@@ -20,7 +20,7 @@
security_services * security_services::instance = nullptr;
security_services::security_services() : _ec_keys(nullptr), _security_cache(new security_cache), _security_db(nullptr), _last_generation_time(0), _unknown_certificate() {
security_services::security_services() : _ec_keys(nullptr), _security_cache(new security_cache), _security_db(nullptr), _last_generation_time(0), _unknown_certificate(), _latitude(0), _longitude(0), _elevation(0) {
loggers::get_instance().log(">>> security_services::security_services");
} // End of ctor
......@@ -278,14 +278,19 @@ int security_services::secure_gn_payload(const OCTETSTRING& p_unsecured_gn_paylo
header_info.encryptionKey().set_to_omit();
Params::const_iterator it = p_params.find(Params::payload_type);
if (it != p_params.cend()) {
loggers::get_instance().log("security_services::secure_gn_payload: Payload type: %s", it->second.c_str());
if (it->second.compare("1") == 0) { // DENM
loggers::get_instance().error("security_services::secure_gn_payload: TODO");
OPTIONAL<IEEE1609dot2BaseTypes::ThreeDLocation> location(IEEE1609dot2BaseTypes::ThreeDLocation(_latitude, _longitude, _elevation));
loggers::get_instance().log_msg("security_services::secure_gn_payload: generationLocation: ", location);
header_info.generationLocation() = location;
loggers::get_instance().log_msg("security_services::secure_gn_payload: generationLocation: ", header_info.generationLocation());
} else if (it->second.compare("2") == 0) { // CAM
// Noting to do
} else {
// Noting to do
}
} else {
} else { // Process it as a GeoNetworking payload
loggers::get_instance().log("security_services::secure_gn_payload: Payload type not set");
// Noting to do
}
unsigned long long ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - 1072911600000L; // TODO Add method such as its_tme() & its_time_mod() beacuse it is used also in LibItsCommon_externals
......
......@@ -41,6 +41,9 @@ class security_services {
std::unique_ptr<security_db> _security_db;
unsigned long long _last_generation_time;
std::vector<unsigned char> _unknown_certificate;
int _latitude;
int _longitude;
int _elevation;
/*!
* \brief Default private ctor
......@@ -76,13 +79,14 @@ public: /*! \publicsection */
* \return 0 on success, negative value otherwise
*/
int verify_and_extract_gn_payload(const OCTETSTRING& p_secured_gn_payload, const bool p_verify, OCTETSTRING& p_unsecured_gn_payload, Params& p_params);
int secure_gn_payload(const OCTETSTRING& p_unsecured_gn_payload, OCTETSTRING& p_secured_gn_payload, Params& p_params);
int setup(Params &p_params);
int store_certificate(const CHARSTRING& p_cert_id, const OCTETSTRING& p_cert, const OCTETSTRING& p_private_key, const OCTETSTRING& p_public_key_x, const OCTETSTRING& p_public_key_y, const OCTETSTRING& p_hashid8, const OCTETSTRING& p_issuer);
inline void set_position(const int p_latitude, const int p_longitude, const int p_elevation = 0) { _latitude = p_latitude; _longitude = p_longitude; _elevation = p_elevation; };
private:
/*!
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment