Commit ecfbc410 authored by garciay's avatar garciay
Browse files

Validation of TD_AUTO_IOT_DENM_RWW_BV_01 done

parent b6a139f4
/*!
* \file LibItsGeoNetworking_EncdecDeclarations.cc
* \brief Implementation file for GeoNetworking 'encvalue'/'decvalue'.
* \author ETSI STF525
* \copyright ETSI Copyright Notification
* No part may be reproduced except as authorized by written permission.
* The copyright and the foregoing restriction extend to reproduction in all media.
* All rights reserved.
* \version 0.1
*/
#include "LibItsGeoNetworking_EncdecDeclarations.hh" #include "LibItsGeoNetworking_EncdecDeclarations.hh"
#include "GeoNetworkingCodec.hh" #include "GeoNetworkingCodec.hh"
...@@ -7,9 +17,9 @@ ...@@ -7,9 +17,9 @@
namespace LibItsGeoNetworking__EncdecDeclarations { namespace LibItsGeoNetworking__EncdecDeclarations {
/**************************************************** /****************************************************
* @desc External function to encode a GeoNetworkingReq type * \brief External function to encode a GeoNetworkingReq type
* @param value to encode * \param[in] p_geoNetworkingReq The value to encode
* @return encoded value * \return encoded value
****************************************************/ ****************************************************/
BITSTRING fx__enc__GeoNetworkingReq(LibItsGeoNetworking__TestSystem::GeoNetworkingReq const& p_geoNetworkingReq) BITSTRING fx__enc__GeoNetworkingReq(LibItsGeoNetworking__TestSystem::GeoNetworkingReq const& p_geoNetworkingReq)
{ {
...@@ -36,7 +46,7 @@ namespace LibItsGeoNetworking__EncdecDeclarations { ...@@ -36,7 +46,7 @@ namespace LibItsGeoNetworking__EncdecDeclarations {
loggers::get_instance().set_stop_time(tag, duration); loggers::get_instance().set_stop_time(tag, duration);
return oct2bit(OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())); return oct2bit(OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()));
} } // End of function fx__enc__GeoNetworkingReq
/**************************************************** /****************************************************
* @desc External function to decode a GeoNetworkingReq type * @desc External function to decode a GeoNetworkingReq type
......
...@@ -146,7 +146,7 @@ void GeoNetworkingLayer::sendData(OCTETSTRING& data, Params& params) { ...@@ -146,7 +146,7 @@ void GeoNetworkingLayer::sendData(OCTETSTRING& data, Params& params) {
} }
} }
if (_secured_mode) { if (_secured_mode) {
if (build_secured_geonetworking_pdu(data, _params) != 0) { if (build_secured_pdu(data, _params) != 0) {
return; return;
} }
} }
...@@ -168,9 +168,12 @@ void GeoNetworkingLayer::receiveData(OCTETSTRING& data, Params& params) { ...@@ -168,9 +168,12 @@ void GeoNetworkingLayer::receiveData(OCTETSTRING& data, Params& params) {
LibItsGeoNetworking__TypesAndValues::BasicHeader basic_header; LibItsGeoNetworking__TypesAndValues::BasicHeader basic_header;
decode_basic_header(data, basic_header); decode_basic_header(data, basic_header);
if ((int)basic_header.nextHeader() == 2) { // Verify and extract the GeoNetworking Secured Packet as specified in ETSI EN 302 636-4-1 V1.3.1 (2017-08) Clause 9.6.1 Composition of the Basic Header if ((int)basic_header.nextHeader() == 2) { // Verify and extract the GeoNetworking Secured Packet as specified in ETSI EN 302 636-4-1 V1.3.1 (2017-08) Clause 9.6.1 Composition of the Basic Header
unsigned int basic_header_len = 4;// FIXME How to retrive the BasicHeader length basic_header.get_descriptor()->raw->fieldlength / 8;
loggers::get_instance().log("GeoNetworkingLayer::receiveData: basic_header_len = %d", basic_header_len);
// Verify and extract the GeoNetworking Secured Packet as specified in ETSI EN 302 636-4-1 V1.3.1 (2017-08) Clause 9.4 GeoNetworking Secured Packet // Verify and extract the GeoNetworking Secured Packet as specified in ETSI EN 302 636-4-1 V1.3.1 (2017-08) Clause 9.4 GeoNetworking Secured Packet
OCTETSTRING unsecured_gn_payload; OCTETSTRING unsecured_gn_payload;
if (security_services::get_instance().verify_and_extract_gn_payload(data, _enable_security_checks, unsecured_gn_payload, params) != 0) { OCTETSTRING secured_data = OCTETSTRING(data.lengthof() - basic_header_len, static_cast<const unsigned char*>(data) + basic_header_len);
if (security_services::get_instance().verify_and_extract_gn_payload(secured_data, _enable_security_checks, unsecured_gn_payload, params) != 0) {
loggers::get_instance().warning("GeoNetworkingLayer::receiveData: security error"); loggers::get_instance().warning("GeoNetworkingLayer::receiveData: security error");
if (_enable_security_checks) { if (_enable_security_checks) {
return; return;
...@@ -178,7 +181,7 @@ void GeoNetworkingLayer::receiveData(OCTETSTRING& data, Params& params) { ...@@ -178,7 +181,7 @@ void GeoNetworkingLayer::receiveData(OCTETSTRING& data, Params& params) {
} }
// Update data // Update data
loggers::get_instance().log_msg("GeoNetworkingLayer::receiveData: Unsecured payload: ", unsecured_gn_payload); loggers::get_instance().log_msg("GeoNetworkingLayer::receiveData: Unsecured payload: ", unsecured_gn_payload);
data = OCTETSTRING(4, static_cast<const unsigned char*>(data)) + unsecured_gn_payload; data = OCTETSTRING(basic_header_len, static_cast<const unsigned char*>(data)) + unsecured_gn_payload;
} }
// Decode the payload // Decode the payload
...@@ -228,7 +231,7 @@ void GeoNetworkingLayer::receiveData(OCTETSTRING& data, Params& params) { ...@@ -228,7 +231,7 @@ void GeoNetworkingLayer::receiveData(OCTETSTRING& data, Params& params) {
_codec.encode(*_ls_reply, os); _codec.encode(*_ls_reply, os);
// Apply security // Apply security
if (_secured_mode) { if (_secured_mode) {
if (build_secured_geonetworking_pdu(data, _params) != 0) { if (build_secured_pdu(data, _params) != 0) {
return; return;
} }
} }
...@@ -425,7 +428,7 @@ void GeoNetworkingLayer::send_beacon() { ...@@ -425,7 +428,7 @@ void GeoNetworkingLayer::send_beacon() {
// Apply security // Apply security
Params params(_params); Params params(_params);
if (_secured_mode) { if (_secured_mode) {
if (build_secured_geonetworking_pdu(data, _params) != 0) { if (build_secured_pdu(data, _params) != 0) {
return; return;
} }
} }
...@@ -828,24 +831,25 @@ int GeoNetworkingLayer::build_geonetworking_pdu(OCTETSTRING& data, Params& param ...@@ -828,24 +831,25 @@ int GeoNetworkingLayer::build_geonetworking_pdu(OCTETSTRING& data, Params& param
return 0; return 0;
} }
int GeoNetworkingLayer::build_secured_geonetworking_pdu(OCTETSTRING& data, Params& params) { int GeoNetworkingLayer::build_secured_pdu(OCTETSTRING& data, Params& params) {
loggers::get_instance().log_msg(">>> GeoNetworkingLayer::build_secured_geonetworking_pdu: ", data); loggers::get_instance().log_msg(">>> GeoNetworkingLayer::build_secured_pdu: ", data);
LibItsGeoNetworking__TypesAndValues::BasicHeader basic_header; LibItsGeoNetworking__TypesAndValues::BasicHeader basic_header;
decode_basic_header(data, basic_header); decode_basic_header(data, basic_header);
// Update security mode // Update security mode
unsigned int basic_header_len = basic_header.get_descriptor()->raw->fieldlength / 8; unsigned int basic_header_len = 4;// FIXME How to retrive the BasicHeader length basic_header.get_descriptor()->raw->fieldlength / 8;
loggers::get_instance().log("GeoNetworkingLayer::build_secured_pdu: basic_header_len = %d", basic_header_len);
basic_header.nextHeader() = BasicNextHeader::e__securedPacket; basic_header.nextHeader() = BasicNextHeader::e__securedPacket;
OCTETSTRING unsecured_gn_payload = OCTETSTRING(data.lengthof() - basic_header_len, static_cast<const unsigned char*>(data) + basic_header_len); OCTETSTRING unsecured_gn_payload = OCTETSTRING(data.lengthof() - basic_header_len, static_cast<const unsigned char*>(data) + basic_header_len);
OCTETSTRING secured_gn_payload; OCTETSTRING secured_gn_payload;
if (security_services::get_instance().secure_gn_payload(unsecured_gn_payload, false, secured_gn_payload, params) != 0) { if (security_services::get_instance().secure_gn_payload(unsecured_gn_payload, false, secured_gn_payload, params) != 0) {
loggers::get_instance().warning("GeoNetworkingLayer::build_secured_geonetworking_pdu: failed to build secured pdu"); loggers::get_instance().warning("GeoNetworkingLayer::build_secured_pdu: failed to build secured pdu");
return -1; return -1;
} }
// TODO Add timer to check if certificate shall be sent // TODO Add timer to check if certificate shall be sent
// Encode the basid header // Encode the basid header
//loggers::get_instance().log_msg("GeoNetworkingLayer::build_secured_geonetworking_pdu: New basic_header = ", basic_header); //loggers::get_instance().log_msg("GeoNetworkingLayer::build_secured_pdu: New basic_header = ", basic_header);
RAW_enc_tr_pos rp; RAW_enc_tr_pos rp;
rp.level=0; rp.level=0;
rp.pos=NULL; rp.pos=NULL;
...@@ -857,7 +861,7 @@ int GeoNetworkingLayer::build_secured_geonetworking_pdu(OCTETSTRING& data, Param ...@@ -857,7 +861,7 @@ int GeoNetworkingLayer::build_secured_geonetworking_pdu(OCTETSTRING& data, Param
data = data =
OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) +
secured_gn_payload; secured_gn_payload;
loggers::get_instance().log_msg("GeoNetworkingLayer::build_secured_geonetworking_pdu: Secured pdu = ", data); loggers::get_instance().log_msg("GeoNetworkingLayer::build_secured_pdu: Secured pdu = ", data);
return 0; return 0;
} }
......
...@@ -116,7 +116,7 @@ public: ...@@ -116,7 +116,7 @@ public:
private: private:
void send_beacon(); void send_beacon();
int build_geonetworking_pdu(OCTETSTRING& data, Params& params); int build_geonetworking_pdu(OCTETSTRING& data, Params& params);
int build_secured_geonetworking_pdu(OCTETSTRING& data, Params& params); int build_secured_pdu(OCTETSTRING& data, Params& params);
int decode_basic_header(const OCTETSTRING& p_data, LibItsGeoNetworking__TypesAndValues::BasicHeader& p_basic_header); int decode_basic_header(const OCTETSTRING& p_data, LibItsGeoNetworking__TypesAndValues::BasicHeader& p_basic_header);
}; // End of class GeoNetworkingLayer }; // End of class GeoNetworkingLayer
......
...@@ -97,11 +97,11 @@ int security_services::process_ieee_1609_dot2_signed_data(const IEEE1609dot2::Si ...@@ -97,11 +97,11 @@ int security_services::process_ieee_1609_dot2_signed_data(const IEEE1609dot2::Si
loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_signed_data: SignedDataPayload.data = ", v); loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_signed_data: SignedDataPayload.data = ", v);
const IEEE1609dot2::Ieee1609Dot2Data& ieee_1609dot2_data = static_cast<const IEEE1609dot2::Ieee1609Dot2Data&>(*v.get_opt_value()); const IEEE1609dot2::Ieee1609Dot2Data& ieee_1609dot2_data = static_cast<const IEEE1609dot2::Ieee1609Dot2Data&>(*v.get_opt_value());
if (p_verify && ((unsigned int)(int)ieee_1609dot2_data.protocolVersion() != security_services::ProtocolVersion)) { if (p_verify && ((unsigned int)(int)ieee_1609dot2_data.protocolVersion() != security_services::ProtocolVersion)) {
loggers::get_instance().warning("security_services::verify_and_extract_gn_payload: Wrong version protocol, discard it"); loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: Wrong version protocol, discard it");
return -1; return -1;
} }
if (process_ieee_1609_dot2_content(ieee_1609dot2_data.content(), p_verify, p_unsecured_payload, p_params) != 0) { if (process_ieee_1609_dot2_content(ieee_1609dot2_data.content(), p_verify, p_unsecured_payload, p_params) != 0) {
loggers::get_instance().warning("security_services::verify_and_extract_gn_payload: Failed to process SignedData, discard it"); loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: Failed to process SignedData, discard it");
return -1; return -1;
} }
} else if (p_signed_data.tbsData().payload().extDataHash().is_present()) { } else if (p_signed_data.tbsData().payload().extDataHash().is_present()) {
......
Supports Markdown
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