Commit 8bdd6a89 authored by juvancic's avatar juvancic
Browse files

added security functions and modules + titan framework

parent ecb9cb9e
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line


#include "NAS_EncdecDeclarations.hh"
#include "NAS_EncdecDeclarations.hh"
#include "NAS_CommonTypeDefs.hh" 
#include "NAS_CommonTypeDefs.hh" 
#include "SMS_TypeDefs.hh" 
//#include "SMS_TypeDefs.hh" 


namespace NAS__EncdecDeclarations {
namespace NAS__EncdecDeclarations {


@@ -15,7 +15,7 @@ namespace NAS__EncdecDeclarations {
  BITSTRING fx__enc__QoSParametersList(const NAS__CommonTypeDefs::QoSParametersList &p){return int2bit(0,0);}
  BITSTRING fx__enc__QoSParametersList(const NAS__CommonTypeDefs::QoSParametersList &p){return int2bit(0,0);}
  BITSTRING fx__enc__EPS__QualityOfService(const NAS__CommonTypeDefs::EPS__QualityOfService &p){return int2bit(0,0);}
  BITSTRING fx__enc__EPS__QualityOfService(const NAS__CommonTypeDefs::EPS__QualityOfService &p){return int2bit(0,0);}
  BITSTRING fx__enc__TrafficFlowTemplate(const NAS__CommonTypeDefs::TrafficFlowTemplate &p){return int2bit(0,0);}
  BITSTRING fx__enc__TrafficFlowTemplate(const NAS__CommonTypeDefs::TrafficFlowTemplate &p){return int2bit(0,0);}
  BITSTRING fx__enc__CP__PDU__Type(const SMS__TypeDefs::CP__PDU__Type &p){return int2bit(0,0);}
 // BITSTRING fx__enc__CP__PDU__Type(const SMS__TypeDefs::CP__PDU__Type &p){return int2bit(0,0);}


  /****************************************************
  /****************************************************
   * @desc    External function to decode a ... type
   * @desc    External function to decode a ... type
@@ -26,7 +26,7 @@ namespace NAS__EncdecDeclarations {
  INTEGER fx__dec__QoSParametersList (BITSTRING &b, NAS__CommonTypeDefs::QoSParametersList &p) {return -1;}
  INTEGER fx__dec__QoSParametersList (BITSTRING &b, NAS__CommonTypeDefs::QoSParametersList &p) {return -1;}
  INTEGER fx__dec__EPS__QualityOfService (BITSTRING &b, NAS__CommonTypeDefs::EPS__QualityOfService &p) {return -1;}
  INTEGER fx__dec__EPS__QualityOfService (BITSTRING &b, NAS__CommonTypeDefs::EPS__QualityOfService &p) {return -1;}
  INTEGER fx__dec__TrafficFlowTemplate (BITSTRING &b, NAS__CommonTypeDefs::TrafficFlowTemplate &p) {return -1;}
  INTEGER fx__dec__TrafficFlowTemplate (BITSTRING &b, NAS__CommonTypeDefs::TrafficFlowTemplate &p) {return -1;}
  INTEGER fx__dec__CP__PDU__Type (BITSTRING &b, SMS__TypeDefs::CP__PDU__Type &p) {return -1;}
 // INTEGER fx__dec__CP__PDU__Type (BITSTRING &b, SMS__TypeDefs::CP__PDU__Type &p) {return -1;}




} // namespace NAS__EncdecDeclarations
} // namespace NAS__EncdecDeclarations
+10 −7
Original line number Original line Diff line number Diff line
@@ -3,8 +3,9 @@
#include <iomanip>
#include <iomanip>
#include <random>
#include <random>


#include "NG_SecurityDefinitionsAndExternalFunctions.hh"
//#include "NG_SecurityDefinitionsAndExternalFunctions.hh"
#include "NR_RRC_ASN1_Definitions.hh"
#include "NG_NAS_SecurityFunctions.hh"
//#include "NR_RRC_ASN1_Definitions.hh"
#include "CommonDefs.hh"
#include "CommonDefs.hh"


#include "base_time.hh"
#include "base_time.hh"
@@ -13,7 +14,8 @@
//#include "xml_converters.hh"
//#include "xml_converters.hh"




namespace NG__SecurityDefinitionsAndExternalFunctions {
//namespace NG__SecurityDefinitionsAndExternalFunctions {
namespace NG__NAS__SecurityFunctions {


   /**
   /**
   * @desc    This external function ... 
   * @desc    This external function ... 
@@ -21,9 +23,9 @@ namespace NG__SecurityDefinitionsAndExternalFunctions {
   * @see     fx_get...() return ...
   * @see     fx_get...() return ...
   */
   */


BITSTRING fx__NR__AsIntegrityAlgorithm(const OCTETSTRING &a, const NR__RRC__ASN1__Definitions::IntegrityProtAlgorithm& b, const BITSTRING &c, const OCTETSTRING &d, const BITSTRING &e, const INTEGER &f){
//BITSTRING fx__NR__AsIntegrityAlgorithm(const OCTETSTRING &a, const NR__RRC__ASN1__Definitions::IntegrityProtAlgorithm& b, const BITSTRING &c, const OCTETSTRING &d, const BITSTRING &e, const INTEGER &f){
return int2bit(0, 0);
//return int2bit(0, 0);
}
//}


OCTETSTRING fx__NG__NasIntegrityAlgorithm(const OCTETSTRING& p_EncodedNasPdu, const BITSTRING& p_IntegrityAlgorithm, const BITSTRING& p_KNASint, const OCTETSTRING& p_NasCount, const BITSTRING& p_BearerId, const INTEGER& p_Direction){
OCTETSTRING fx__NG__NasIntegrityAlgorithm(const OCTETSTRING& p_EncodedNasPdu, const BITSTRING& p_IntegrityAlgorithm, const BITSTRING& p_KNASint, const OCTETSTRING& p_NasCount, const BITSTRING& p_BearerId, const INTEGER& p_Direction){
return int2oct(0, 0);
return int2oct(0, 0);
@@ -39,4 +41,5 @@ return int2oct(0, 0);






} // namespace NG__SecurityDefinitionsAndExternalFunctions 
} // namespace NG__NAS__SecurityFunctions 
 // namespace NG__SecurityDefinitionsAndExternalFunctions 
+73 −0
Original line number Original line Diff line number Diff line
/*!
 * \file      base_time.hh
 * \brief     Header file for base_time functionality.
 * \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 <chrono>

/**
 * \class base_time
 * \brief This class provides time tools such as getting current time
 */
class base_time {
  const unsigned long long its_base_time_ms = 1072915200000L; //! Base time 01/01/2004 12:00am in millseconds

  unsigned long long leap_delay;

  static base_time *_instance;

private:
  base_time() : leap_delay{0} {}; //! Can not be created manually
public:
  static inline base_time &get_instance();

  virtual ~base_time() {
    if (_instance != nullptr)
      delete _instance;
  };

public:
  inline const unsigned long long get_current_time_ms() const;
  inline const unsigned long long get_its_base_time_ms() const;
  inline const unsigned long long get_its_current_time_ms() const;
  inline const unsigned long long get_its_current_time_us() const;
  inline const unsigned long long get_its_current_time_mod_ms() const;
  inline void                     set_leap_delay_us(const unsigned long long p_leap_delay);
  inline const unsigned long long get_leap_delay_us() const;
}; // End of class base_time

// static functions
base_time &base_time::get_instance() { return (_instance != nullptr) ? *_instance : *(_instance = new base_time()); }

const unsigned long long base_time::get_current_time_ms() const {
  return (leap_delay / 1000) + std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}

const unsigned long long base_time::get_its_base_time_ms() const { return base_time::its_base_time_ms; }

const unsigned long long base_time::get_its_current_time_ms() const {
  return (leap_delay / 1000) + std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() -
         base_time::its_base_time_ms;
}

const unsigned long long base_time::get_its_current_time_us() const {
  return leap_delay + std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count() -
         base_time::its_base_time_ms * 1000;
}

const unsigned long long base_time::get_its_current_time_mod_ms() const {
  return ((leap_delay / 1000) + std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() -
          base_time::its_base_time_ms) %
         65536;
}

void base_time::set_leap_delay_us(const unsigned long long p_leap_delay) { leap_delay = p_leap_delay; }

inline const unsigned long long base_time::get_leap_delay_us() const { return leap_delay; }
+45 −0
Original line number Original line Diff line number Diff line
/*!
 * \file      codec_factory.hh
 * \brief     Header file for ITS abstract protocol codec definition.
 * \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 <algorithm>
#include <map>
#include <string>
#include <vector>

#include "codec_gen.hh"

class Record_Type; //! TITAN forward declaration

/*!
 * \class codec_factory
 * \brief  This class provides a factory class to create codec class instances
 * \abstract
 */
class codec_factory {
public: //! \publicsection
  /*!
   * \fn codec_factory();
   * \brief  Default constructor
   */
  codec_factory(){};
  /*!
   * \fn codec* create_codec(const std::string&  type, const std::string&  param);
   * \brief  Create the codecs stack based on the provided codecs stack description (cf. remark)
   * \param[in] p_type The provided codecs stack description
   * \param[in] p_params Optional parameters
   * \return 0 on success, -1 otherwise
   * \remark The description below introduces codecs stack in case of ITS project:
   *     HTTP(codecs=xml:held_codec;html:html_codec,json:json_codec)/TCP(debug=1,server=httpbin.org,port=80,use_ssl=0)
   * \pure
   */
  virtual codec_gen<Record_Type, Record_Type> *create_codec() = 0;
}; // End of class codec_factory
+61 −0
Original line number Original line Diff line number Diff line
/*!
 * \file      codec.hh
 * \brief     Header file for ITS abstract codec definition.
 * \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; //! Declare TITAN class
class CHARSTRING;  //! Declare TITAN class
class BITSTRING;   //! Declare TITAN class

/*!
 * \class codec
 * \brief  This class provides the interface for all ITS codecs, include UT and AC codecs
 * \abstract
 */
template <typename TPDUEnc, typename TPDUDec> class codec_gen {
protected:
  params *_params; //! Reference to params stack
                   // \todo Use smart pointer std::unique_ptr<params>

public: //! \publicsection
  /*!
   * \fn codec_gen();
   * \brief  Default constructor
   * \todo Remove logs
   */
  explicit codec_gen() : _params(nullptr){};
  /*!
   * \fn ~codec_gen();
   * \brief  Default destructor
   * \virtual
   * \todo Remove logs
   */
  virtual ~codec_gen(){};
  /*!
   * \fn int encode(const TPDUEnc& msg, OCTETSTRING& data);
   * \brief  Encode typed message into an octet string
   * \param[in] p_message The typed message to be encoded
   * \param[out] p_data The encoding result
   * \return 0 on success, -1 otherwise
   * \pure
   */
  virtual int encode(const TPDUEnc &p_message, OCTETSTRING &p_data) = 0;
  /*!
   * \fn int decode(const OCTETSTRING& p_, TPDUDec& p_message, params* p_params = NULL);
   * \brief  Encode typed message into an octet string format
   * \param[in] p_data The message in its octet string
   * \param[out] p_message The decoded typed message
   * \return 0 on success, -1 otherwise
   * \pure
   */
  virtual int decode(const OCTETSTRING &p_, TPDUDec &p_message, params *p_params = NULL) = 0;
}; // End of class codec_gen
Loading