Commit dd0fa58b authored by garciay's avatar garciay
Browse files

STF538: Start Encryption TPs implementation

        Start Certificate generation script
parent d0757f86
Loading
Loading
Loading
Loading
+28 −4
Original line number Diff line number Diff line
@@ -249,6 +249,24 @@ namespace LibItsSecurity__Functions
    return FALSE;
  }
  
  
  OCTETSTRING fx__encryptWithEciesNistp256WithSha256(const OCTETSTRING& p__toBeEncryptedSecuredMessage, const OCTETSTRING& p__peerPublicKeyX, const OCTETSTRING& p__peerPublicKeyY, OCTETSTRING& p__publicEncKeyX, OCTETSTRING& p__publicEncKeyY, OCTETSTRING& p__ephKey, OCTETSTRING& p__tag, OCTETSTRING& p__nonce) {
    OCTETSTRING os;

    os = OCTETSTRING();
    p__nonce = OCTETSTRING();
    p__tag = OCTETSTRING();
    return os;
  }
  
  OCTETSTRING fx__decryptWithEciesNistp256WithSha256(const OCTETSTRING& p__encryptedSecuredMessage, const OCTETSTRING& p__publicKeyX, const OCTETSTRING& p__publicKeyY, const OCTETSTRING& p__nonce, const OCTETSTRING& p__tag) {
    OCTETSTRING os;

    os = OCTETSTRING();
    
    return os;
}
  
  /**
   * @desc    Produce a new public/private key pair based on Elliptic Curve Digital Signature Algorithm (ECDSA) algorithm.
   *          This function should not be used by the ATS
@@ -365,14 +383,20 @@ namespace LibItsSecurity__Functions
    return TRUE;
  }

  BOOLEAN fx__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) {
  BOOLEAN fx__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, const OCTETSTRING_template& p__private__enc__key, const OCTETSTRING_template& p__public__enc__key__x, const OCTETSTRING_template& p__public__enc__key__y) {
    loggers::get_instance().log(">>> fx__store__certificate: '%s'", static_cast<const char*>(p__cert__id));

    if (security_services::get_instance().store_certificate(p__cert__id, p__cert, p__private__key, p__public__key__x, p__public__key__y, p__hashid8, p__issuer) == -1) {
      return FALSE;
    int result;
    if (!p__private__enc__key.is_omit()) {
      const OCTETSTRING private_enc_key = p__private__enc__key.valueof();
      const OCTETSTRING public_enc_key_x = p__public__enc__key__x.valueof();
      const OCTETSTRING public_enc_key_y = p__public__enc__key__y.valueof();
      result = security_services::get_instance().store_certificate(p__cert__id, p__cert, p__private__key, p__public__key__x, p__public__key__y, p__hashid8, p__issuer, private_enc_key, public_enc_key_x, public_enc_key_y);
    } else {
      result = security_services::get_instance().store_certificate(p__cert__id, p__cert, p__private__key, p__public__key__x, p__public__key__y, p__hashid8, p__issuer, OCTETSTRING(), OCTETSTRING(), OCTETSTRING());
    }
    
    return TRUE;
    return (result == 0);
  }
  
  /**
+20 −12
Original line number Diff line number Diff line
#ifndef ASN1RECODEPER_H
#define ASN1RECODEPER_H
/*!
 * \file      asn1_recode_per.hh
 * \brief     Header file ASN.1 PER codec based on asn1c external tool.
 * \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
 */
#pragma once

#include "Params.hh"

class OCTETSTRING;
class CHARSTRING;
class BITSTRING;
class TTCN_Buffer;
class TTCN_EncDec;
class TTCN_Typedescriptor_t;
class OCTETSTRING;           //! Forward declaration of TITAN class
class CHARSTRING;            //! Forward declaration of TITAN class
class BITSTRING;             //! Forward declaration of TITAN class
class TTCN_Buffer;           //! Forward declaration of TITAN class
class TTCN_EncDec;           //! Forward declaration of TITAN class
class TTCN_Typedescriptor_t; //! Forward declaration of TITAN class

struct asn_TYPE_descriptor_s;
struct asn_TYPE_descriptor_s; //! Forward declaration of asn1c class

class ASN1RecodePer // FIXME Move into file ASN1RecodePer.hh
class ASN1RecodePer
{
protected:
  int ber2per (const asn_TYPE_descriptor_s & td, TTCN_Buffer & buf);
  int per2ber (const asn_TYPE_descriptor_s & td, TTCN_Buffer & buf);
  int recode  (const asn_TYPE_descriptor_s & td, int from, int to, TTCN_Buffer & buf);
};
}; // End of class ASN1RecodePer
#endif
+7 −7
Original line number Diff line number Diff line
/*!
 * \file      Layer.hh
 * \file      layer.hh
 * \brief     Header file for ITS abstract protocol layer definition.
 * \author    ETSI STF525
 * \copyright ETSI Copyright Notification
@@ -17,10 +17,10 @@

#include "Params.hh"

class OCTETSTRING; //! Declare TITAN class
class BITSTRING;   //! Declare TITAN class
class CHARSTRING;  //! Declare TITAN class
class INTEGER;     //! Declare TITAN class
class OCTETSTRING; //! Forward declaration of TITAN class
class BITSTRING;   //! Forward declaration of TITAN class
class CHARSTRING;  //! Forward declaration of TITAN class
class INTEGER;     //! Forward declaration of TITAN class

/*!
 * \class Layer
@@ -64,7 +64,7 @@ public:
  /*!
   * \fn void deleteLayer();
   * \brief Delete this layer
   * \todo Remove logs
   * \todo To be done
   */
  void deleteLayer() { };

@@ -132,7 +132,7 @@ public: //! \publicsection
   */
  inline const std::string& to_string() const { return type; };

protected:
protected: //! \protectedsection
  inline void toAllLayers(std::vector<Layer*>&layers, OCTETSTRING& data, Params& params) {
    for (std::vector<Layer*>::const_iterator it = layers.cbegin(); it != layers.cend(); ++it) {
      Layer * p = *it;
+17 −8
Original line number Diff line number Diff line
/*!
 * \file      LayerFactory.hh
 * \file      layer_factory.hh
 * \brief     Header file for ITS abstract protocol layer definition.
 * \author    ETSI STF525
 * \copyright ETSI Copyright Notification
@@ -27,11 +27,10 @@ public: //! \publicsection
  /*!
   * \fn Codec();
   * \brief  Default constructor
   * \todo Remove logs
   */
  LayerFactory() {};
  /*!
   * \fn Layer * createLayer(const std::string & type, const std::string & param);
   * \fn Layer * create_layer(const std::string & type, const std::string & param);
   * \brief  Create the layers stack based on the provided layers stack description (cf. remark)
   * \param[in] p_type The provided layers stack description
   * \param[in] p_params Optional parameters
@@ -49,14 +48,24 @@ public: //! \publicsection
   *       destination port: dst_port
   *       source port     : src_port
   *       device_mode     : Set to 1 if the layer shall encapsulate upper layer PDU
   *       device_mode     : Set to 1 if the layer shall encapsulate upper layer PDU
   *     GN Layer
   *       its_aid                : ITS AID as defined by ETSI TS 102 965 V1.2.1. Default: 141
   *       ll_address             : GeoNetworking address of the Test System
   *       latitude               : latitude of the Test System
   *       longitude              : longitude of the Test System
   *       beaconing              : Set to 1 if GnLayer shall start beaconing
   *       Beaconning timer expiry: expiry (ms)
   *       Beaconing timer expiry : expiry (ms)
   *       device_mode            : Set to 1 if the layer shall encapsulate upper layer PDU
   *       secured_mode           : Set to 1 if message exchanges shall be secured
   *       certificate            : Certificate identifier the Test Adapter shall use
   *       secure_db_path         : Path to the certificates and keys storage location
   *       hash                   : Hash algorithm to be used when secured mode is set
   *                                Authorized values are SHA-256 or SHA-384
   *                                Default: SHA-256
   *       signature              : Signature algorithm to be used when secured mode is set
   *                                Authorized values are NISTP-256, BP-256 and BP-384
   *                                Default: NISTP-256
   *       cypher                 : Cyphering algorithm to be used when secured mode is set
   *     Ethernet layer
   *       mac_src  :Source MAC address
   *       mac_bc   :Broadcast address
@@ -89,15 +98,15 @@ public: //! \publicsection
   *         time_offset : Time offset, used to skip packets with time offset < time_offset
   *         save_mode   : 1 to save sent packet, 0 otherwise
   *     Here are some examples:
   *       Geonetworking multiple component case:
   *       GeoNetworking multiple component case:
   *         NodeB.geoNetworkingPort.params := "GN(ll_address=04e548000001,latitude=43551050,longitude=10298730,beaconing=0,expiry=1000,its_aid=141)/COMMSIGNIA(mac_src=04e548000001,mac_bc=FFFFFFFFFFFF,eth_type=8947,target_host=10.200.1.101,target_port=7942,source_port=7943,its_aid=141,interface_id=2,tx_power=-32)/UDP(dst_ip=192.168.56.1,dst_port=12346,src_ip=192.168.156.4,src_port=12345)/ETH(mac_src=04e548000001,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=04e548000001,file=/home/vagrant/TriesAndDelete/etsi_its/testdata/TC_AUTO_IOT_DENM_RWW_BV_01_short.pcap,filter=and (udp port 30000 or udp port 7943))"
NodeC.geoNetworkingPort.params := "GN(ll_address=70b3d5791b48,latitude=43551050,longitude=10298730,beaconing=0,expiry=1000,its_aid=141)/COMMSIGNIA(mac_src=70b3d5791b48,mac_bc=FFFFFFFFFFFF,eth_type=8947,target_host=10.200.1.101,target_port=7942,source_port=7943,its_aid=141,interface_id=2,tx_power=-32)/UDP(dst_ip=192.168.56.1,dst_port=12346,src_ip=192.168.156.4,src_port=12345)/ETH(mac_src=70b3d5791b48,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=70b3d5791b48,file=/home/vagrant/TriesAndDelete/etsi_its/testdata/TC_AUTO_IOT_DENM_RWW_BV_01_short.pcap,filter=and (udp port 30000 or udp port 7943))"
   *         NodeB.geoNetworkingPort.params := "GN(ll_address=04e548000001,latitude=43551050,longitude=10298730,beaconing=0,expiry=1000,its_aid=141)/ETH(mac_src=04e548000001,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=04e548000001,file=/home/vagrant/TriesAndDelete/etsi_its/testdata/TC_AUTO_IOT_DENM_RWW_BV_01.pcap,filter=and ether src 04e548000001)"
#NodeC.geoNetworkingPort.params := "GN(ll_address=70b3d5791b48,latitude=43551050,longitude=10298730,beaconing=0,expiry=1000,its_aid=141)/ETH(mac_src=70b3d5791b48,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=70b3d5791b48,file=/home/vagrant/TriesAndDelete/etsi_its/testdata/TC_AUTO_IOT_DENM_RWW_BV_01.pcap,filter=and  ether src 70b3d5791b48)"
   *       UpperTester port based on UDP 
   *         ystem.utPort.params := "UT_GN/UDP(dst_ip=192.168.1.1,dst_port=12346,src_ip=192.168.156.4,src_port=12345)/ETH(mac_src=026f8338c1e5,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=0800275c4959,nic=enp0s8,filter=and udp port 12346)"
   *         system.utPort.params := "UT_GN/UDP(dst_ip=192.168.1.1,dst_port=12346,src_ip=192.168.156.4,src_port=12345)/ETH(mac_src=026f8338c1e5,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=0800275c4959,nic=enp0s8,filter=and udp port 12346)"
   * \pure
   */
  virtual Layer * createLayer(const std::string & p_type, const std::string & p_params) = 0;
  virtual Layer* create_layer(const std::string & p_type, const std::string & p_params) = 0;
}; // End of class LayerFactory
+42 −9
Original line number Diff line number Diff line
@@ -17,18 +17,51 @@
 * \brief  This class provides a factory class to create Layer class instances
 */
class LayerStackBuilder {
private: //! \privatesection
  typedef std::map<std::string, LayerFactory*> LayerFactoryMap;

  static LayerStackBuilder * _instance;
  std::map<std::string, LayerFactory*> _fs;
private:
  static LayerStackBuilder * _instance;                        //! Smart pointer to the unique instance of the logger framework
  std::map<std::string, LayerFactory*> _layer_factories; //! The list of the registered \see TLayer factories

  /*!
   * \brief Default constructor
   *        Create a new instance of the LayerStackBuilder class
   * \private
   */
  LayerStackBuilder(); // can not be created manually
public:
  static LayerStackBuilder * GetInstance();
  static void RegisterLayerFactory(const std::string & type, LayerFactory * f);
public: //! \publicsection
  /*!
   * \fn LayerStackBuilder* get_instance();
   * \brief Accessor for the unique instance of the logger framework
   * \static
   */
  static LayerStackBuilder* get_instance();

public:
  void registerLayerFactory(const std::string & type, LayerFactory * f);
  Layer* createLayerStack(const char*);
  /*!
   * \fn void register_layer_factory(const std::string & p_type, LayerFactory* p_layer_factory);
   * \brief Add a new layer factory
   * \param[in] p_type          The layer identifier (e.g. GN for the GeoNetworking layer...)
   * \param[in] p_layer_factory A reference to the \see LayerFactory
   * \static
   */
  static void register_layer_factory(const std::string & p_type, LayerFactory* p_layer_factory);

private: //! \privatesection
  /*!
   * \fn void _register_layer_factory(const std::string & p_type, LayerFactory* p_layer_factory);
   * \brief Add a new layer factory
   * \param[in] p_type          The layer identifier (e.g. GN for the GeoNetworking layer...)
   * \param[in] p_layer_factory A reference to the \see LayerFactory
   */
  void _register_layer_factory(const std::string & p_type, LayerFactory* p_layer_factory);

public: //! \publicsection
  /*!
   * \fn Layer* create_layer_stack(const char* p_layer_stack_description);
   * \brief Add a new layer factory
   * \param[in] p_layer_stack_description A textual description of the layer to create
   * \return The created layer object on success, nullptr otherwise
   */
  Layer* create_layer_stack(const char* p_layer_stack_description);
}; // End of class LayerStackBuilder
Loading