Commit ecfbc410 authored by garciay's avatar garciay
Browse files

Validation of TD_AUTO_IOT_DENM_RWW_BV_01 done

parent b6a139f4
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
/*!
 * \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 "GeoNetworkingCodec.hh"
@@ -7,9 +17,9 @@
namespace LibItsGeoNetworking__EncdecDeclarations {
  
  /****************************************************
   * @desc    External function to encode a GeoNetworkingReq type
   * @param   value to encode
   * @return  encoded value
   * \brief External function to encode a GeoNetworkingReq type
   * \param[in] p_geoNetworkingReq The value to encode
   * \return  encoded value
   ****************************************************/
  BITSTRING fx__enc__GeoNetworkingReq(LibItsGeoNetworking__TestSystem::GeoNetworkingReq const& p_geoNetworkingReq)
  {
@@ -36,7 +46,7 @@ namespace LibItsGeoNetworking__EncdecDeclarations {
    loggers::get_instance().set_stop_time(tag, duration);
    
    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
+15 −11
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ void GeoNetworkingLayer::sendData(OCTETSTRING& data, Params& params) {
    }
  }
  if (_secured_mode) {
    if (build_secured_geonetworking_pdu(data, _params) != 0) {
    if (build_secured_pdu(data, _params) != 0) {
      return;
    }
  }
@@ -168,9 +168,12 @@ void GeoNetworkingLayer::receiveData(OCTETSTRING& data, Params& params) {
  LibItsGeoNetworking__TypesAndValues::BasicHeader 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
    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
    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");
      if (_enable_security_checks) {
        return;
@@ -178,7 +181,7 @@ void GeoNetworkingLayer::receiveData(OCTETSTRING& data, Params& params) {
    }
    // Update data
    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
@@ -228,7 +231,7 @@ void GeoNetworkingLayer::receiveData(OCTETSTRING& data, Params& params) {
              _codec.encode(*_ls_reply, os);
              // Apply security
              if (_secured_mode) {
                if (build_secured_geonetworking_pdu(data, _params) != 0) {
                if (build_secured_pdu(data, _params) != 0) {
                  return;
                }
              }
@@ -425,7 +428,7 @@ void GeoNetworkingLayer::send_beacon() {
  // Apply security
  Params params(_params);
  if (_secured_mode) {
    if (build_secured_geonetworking_pdu(data, _params) != 0) {
    if (build_secured_pdu(data, _params) != 0) {
      return;
    }
  }
@@ -828,24 +831,25 @@ int GeoNetworkingLayer::build_geonetworking_pdu(OCTETSTRING& data, Params& param
  return 0;
}

int GeoNetworkingLayer::build_secured_geonetworking_pdu(OCTETSTRING& data, Params& params) {
  loggers::get_instance().log_msg(">>> GeoNetworkingLayer::build_secured_geonetworking_pdu: ", data);
int GeoNetworkingLayer::build_secured_pdu(OCTETSTRING& data, Params& params) {
  loggers::get_instance().log_msg(">>> GeoNetworkingLayer::build_secured_pdu: ", data);
  
  LibItsGeoNetworking__TypesAndValues::BasicHeader basic_header;
  decode_basic_header(data, basic_header);
  // 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;
  OCTETSTRING unsecured_gn_payload = OCTETSTRING(data.lengthof() - basic_header_len, static_cast<const unsigned char*>(data) + basic_header_len);
  OCTETSTRING secured_gn_payload;
  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;
  }
  // TODO Add timer to check if certificate shall be sent

  // 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;
  rp.level=0;
  rp.pos=NULL;
@@ -857,7 +861,7 @@ int GeoNetworkingLayer::build_secured_geonetworking_pdu(OCTETSTRING& data, Param
  data =
    OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) +
    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;
}
+1 −1
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ public:
private:
  void send_beacon();
  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);
  
}; // End of class GeoNetworkingLayer
+2 −2
Original line number Diff line number Diff line
@@ -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);
    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)) {
      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;
    }
    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;
    }
  } else if (p_signed_data.tbsData().payload().extDataHash().is_present()) {