Commit f71e68d9 authored by garciay's avatar garciay
Browse files

STF545: Review first test

parent fa91e779
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ public: //! \publicsection
  static const std::string& enable_security_checks;//! To indicates if security check failures shall be treated as error or warning
  static const std::string& sec_db_path;           //! Path to the folder containing certificates
  static const std::string& certificate;           //! The certificate identifier the Test System shall use. E.g. CERT_TS_A
  static const std::string& peer_certificate;      //! The peer certificate identifier the Test System shall use for encryption. E.g. CERT_TS_A
  static const std::string& hash;                  //! The digest algorithm the Test System shall use, authorised values are SHA-256 or SHA-384. Default: SHA-256
  static const std::string& signature;             //! The signature algorithm the Test System shall use, authorised values are NISTP-256, BP-256 and BP-384. Default: NISTP-256
  static const std::string& cypher;                //! The encryption algorithm the Test System shall use, authorised values are NISTP-256 and BP-256. Default: NISTP-256
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ const std::string& params::secured_mode = std::string("secured_mode");
const std::string& params::encrypted_mode = std::string("encrypted_mode");
const std::string& params::enable_security_checks = std::string("enable_security_checks");
const std::string& params::certificate = std::string("certificate");
const std::string& params::peer_certificate = std::string("peer_certificate");
const std::string& params::sec_db_path = std::string("sec_db_path");
const std::string& params::hash = std::string("hash");
const std::string& params::signature = std::string("signature");
+14 −11
Original line number Diff line number Diff line
@@ -388,15 +388,16 @@ int http_codec::encode_body(const LibItsHttp__MessageBodyTypes::HttpMessageBody&
      std::map<std::string, std::unique_ptr<codec<Record_Type, Record_Type> > >::const_iterator it;
      bool processed = false;
      if (p_content_type.find_first_of("x-its") != std::string::npos) {
        it = _codecs.find("etsi_ieee1609dot2");
        it = _codecs.find("http_its"); // TODO Use params
        if (it != _codecs.cend()) {
          loggers::get_instance().log("http_codec::encode_body: Call 'etsi_ts103097_data_codec'");
          _codecs["etsi_ieee1609dot2"]->encode((Record_Type&)binary_body, p_encoding_buffer);
          loggers::get_instance().log("http_codec::encode_body: Call 'http_etsi_ieee1609dot2_codec'");
          _codecs["http_its"]->encode((Record_Type&)binary_body, p_encoding_buffer); // TODO Use params
          processed = true;
        }
      } // TODO Add new HTTP message codec here
      if (!processed) {
        loggers::get_instance().warning("http_codec::encode_body: Unsupported HTTP codec, use raw field as default");
        p_encoding_buffer = OCTETSTRING(binary_body.raw().lengthof(), (unsigned char*)static_cast<const unsigned char*>(binary_body.raw()));
        p_encoding_buffer = OCTETSTRING(0, nullptr);
      }
    }
  } else if (p_message_body.ischosen(LibItsHttp__MessageBodyTypes::HttpMessageBody::ALT_html__body)) {
@@ -411,21 +412,23 @@ int http_codec::encode_body(const LibItsHttp__MessageBodyTypes::HttpMessageBody&
      std::map<std::string, std::unique_ptr<codec<Record_Type, Record_Type> > >::const_iterator it;
      bool processed = false;
      if (p_content_type.find_first_of("held") != std::string::npos) {
        it = _codecs.find("held");
        it = _codecs.find("held"); // TODO Use params
        if (it != _codecs.cend()) {
          loggers::get_instance().log("http_codec::encode_body: Call 'held_codec'");
          _codecs["held"]->encode((Record_Type&)xml_body, p_encoding_buffer);
          _codecs["held"]->encode((Record_Type&)xml_body, p_encoding_buffer); // TODO Use params
          processed = true;
        }
      } else if (p_content_type.find_first_of("lost") != std::string::npos) {
        it = _codecs.find("lost");
        it = _codecs.find("lost"); // TODO Use params
        if (it != _codecs.cend()) {
          loggers::get_instance().log("http_codec::encode_body: Call 'lost_codec'");
          _codecs["lost"]->encode((Record_Type&)xml_body, p_encoding_buffer);
          _codecs["lost"]->encode((Record_Type&)xml_body, p_encoding_buffer); // TODO Use params
          processed = true;
        }
      } // TODO Add new HTTP message codec here
      if (!processed) {
        loggers::get_instance().warning("http_codec::encode_body: Unsupported HTTP codec, use raw field as default");
        p_encoding_buffer = OCTETSTRING(xml_body.raw().lengthof(), (unsigned char*)static_cast<const char*>(xml_body.raw()));
        p_encoding_buffer = OCTETSTRING(0, nullptr);
      }
    }
  } else {
@@ -536,8 +539,8 @@ int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBod
      }
    } else if (p["decode_str"].find("<html>") != std::string::npos) { // Try to identify HTML
      loggers::get_instance().log("http_codec::decode_body: Find html message");
      LibItsHttp__MessageBodyTypes::TextBody txt_body;
      loggers::get_instance().error("http_codec::decode_body: Not supported");
      LibItsHttp__MessageBodyTypes::HtmlBody html_body;
      message_body.html__body() = CHARSTRING(body.lengthof(), (char*)static_cast<const unsigned char*>(body));
    } else {
      loggers::get_instance().log("http_codec::decode_body: Use textBdy as default");
      LibItsHttp__MessageBodyTypes::TextBody text_body;
+77 −0
Original line number Diff line number Diff line
#include "EtsiTs103097Module.hh"

#include "http_etsi_ieee1609dot2_codec.hh"


#include "etsi_ts102941_types_enrolment_inner_request.hh"
#include "etsi_ts102941_types_enrolment_inner_response.hh"

#include "etsi_ts103097_data_codec.hh"

#include "http_etsi_ieee1609dot2_codec_factory.hh"

#include "LibItsHttp_MessageBodyTypes.hh"

#include "security_services.hh"

#include "loggers.hh"

int http_etsi_ieee1609dot2_codec::encode (const LibItsHttp__BinaryMessageBodyTypes::BinaryBody& p_binary_body, OCTETSTRING& p_data)
{
  loggers::get_instance().log_msg(">>> http_etsi_ieee1609dot2_codec::encode: ", p_binary_body);

  etsi_ts103097_data_codec codec;
  if (p_binary_body.ischosen(LibItsHttp__BinaryMessageBodyTypes::BinaryBody::ALT_innerEcRequest)) {

    params p; // TODO To be refined, PkiLayer parameters
    p[params::hash] = "SHA-256";
    p[params::its_aid] = "0";
    p[params::payload_type] = "";
    p[params::signature] = "NISTP-256";
    p[params::certificate] = "CERT_TS_A_AT";
    p[params::encrypted_mode] = "1";
    p[params::cypher] = "NISTP-256";
    p[params::peer_certificate] = "CERT_IUT_A_AT";
    
    // 1. Encode the InnerEcRequest
    OCTETSTRING os;
    etsi_ts102941_types_enrolment_inner_request c;
    if (c.encode(p_binary_body.innerEcRequest(), os) == -1) {
      loggers::get_instance().warning("http_etsi_ieee1609dot2_codec::encode: Failed to encode InnerEcRequest");
      return -1;
    }
    // 2. Signed the packet
    OCTETSTRING signed_os;
    if (security_services::get_instance().sign_gn_payload(os, signed_os, p) == -1) {
      loggers::get_instance().warning("http_etsi_ieee1609dot2_codec::encode: Failed to sign InnerEcRequest");
      return -1;
    }
    // 3. Encrypt the signed packet
    if (security_services::get_instance().encrypt_gn_payload(signed_os, p_data, p) == -1) {
      loggers::get_instance().warning("http_etsi_ieee1609dot2_codec::encode: Failed to encrypt InnerEcRequest");
      return -1;
    }

    loggers::get_instance().log_msg("<<< http_etsi_ieee1609dot2_codec::encode: ", p_data);
    return 0;
  }
  loggers::get_instance().warning("http_etsi_ieee1609dot2_codec::encode: No codec found");

  return -1;
}

int http_etsi_ieee1609dot2_codec::decode (const OCTETSTRING& p_data, LibItsHttp__BinaryMessageBodyTypes::BinaryBody& p_binary_body, params* p_params)
{
  loggers::get_instance().log_msg(">>> http_etsi_ieee1609dot2_codec::decode: ", p_data);

  etsi_ts103097_data_codec codec;
  /*if (p_binary_body.ischosen(LibItsHttp__BinaryMessageBodyTypes::BinaryBody::ALT_innerEcResponse)) {
    
    return codec.decode(p_data, p_binary_body.innerEcResponse(), p_data);
    }*/
  loggers::get_instance().warning("http_etsi_ieee1609dot2_codec::decode: No codec found");

  return -1;
}

http_etsi_ieee1609dot2_codec_factory http_etsi_ieee1609dot2_codec_factory::_f;
+19 −0
Original line number Diff line number Diff line
#pragma once

#include "codec.hh"
//#include "CodecOer.hh"
#include "params.hh"

namespace LibItsHttp__BinaryMessageBodyTypes {
  class BinaryBody;
}

class http_etsi_ieee1609dot2_codec : public codec<LibItsHttp__BinaryMessageBodyTypes::BinaryBody, LibItsHttp__BinaryMessageBodyTypes::BinaryBody>
{
public:
  explicit http_etsi_ieee1609dot2_codec() : codec<LibItsHttp__BinaryMessageBodyTypes::BinaryBody, LibItsHttp__BinaryMessageBodyTypes::BinaryBody>() { };
  virtual ~http_etsi_ieee1609dot2_codec() { };

  virtual int encode (const LibItsHttp__BinaryMessageBodyTypes::BinaryBody& p_binary_body, OCTETSTRING& p_data);
  virtual int decode (const OCTETSTRING& p_data, LibItsHttp__BinaryMessageBodyTypes::BinaryBody& p_binary_body, params* params = NULL);
};
Loading