Commit b9cdc3ba authored by garciay's avatar garciay
Browse files

Major security bugs fixed for signature. Encryption to do.

parent f45b607e
Loading
Loading
Loading
Loading
+140 −112

File changed.

Preview size limit exceeded, changes collapsed.

+30 −24
Original line number Diff line number Diff line
@@ -17,11 +17,37 @@

using namespace LibItsGeoNetworking__TypesAndValues;

geonetworking_layer::geonetworking_layer(const std::string & p_type, const std::string & param) : t_layer<LibItsGeoNetworking__TestSystem::GeoNetworkingPort>(p_type), _params(), _codec(), _beacon(nullptr), _gbc_packet(nullptr), _shb_packet(nullptr), _tsb_packet(nullptr), _ls_reply(nullptr), _location_table(), _pass_beacon_table(), _device_mode{false}, _secured_mode{false}, _encrypted_mode{false}, _enable_security_checks{false}, _sendData(), _timerid{0}, _sev{0}, _its{0}, _freq_nanosecs(0), _mask{0}, _sa{0}, _sequence_number{0}, _latitude{0}, _longitude{0} {
  loggers::get_instance().log(">>> geonetworking_layer::geonetworking_layer: %s, %s", to_string().c_str(), param.c_str());
geonetworking_layer::geonetworking_layer(const std::string & p_type, const std::string & p_param) : t_layer<LibItsGeoNetworking__TestSystem::GeoNetworkingPort>(p_type), _params(), _codec(), _beacon(nullptr), _gbc_packet(nullptr), _shb_packet(nullptr), _tsb_packet(nullptr), _ls_reply(nullptr), _location_table(), _pass_beacon_table(), _device_mode{false}, _secured_mode{false}, _encrypted_mode{false}, _enable_security_checks{false}, _sendData(), _timerid{0}, _sev{0}, _its{0}, _freq_nanosecs(0), _mask{0}, _sa{0}, _sequence_number{0}, _latitude{0}, _longitude{0} {
  loggers::get_instance().log(">>> geonetworking_layer::geonetworking_layer: %s, %s", to_string().c_str(), p_param.c_str());

  init(p_type, p_param);
} // End of constructor

geonetworking_layer::~geonetworking_layer() {
  loggers::get_instance().log(">>> geonetworking_layer::~geonetworking_layer");

  if (_timerid != 0) {
    timer_delete(_timerid);
  }
  if (_beacon != nullptr) {
    delete _beacon;
  }
  if (_gbc_packet != nullptr) {
    delete _gbc_packet;
  }
  if (_shb_packet != nullptr) {
    delete _shb_packet;
  }
  if (_ls_reply != nullptr) {
    delete _ls_reply;
  }
} // End of destructor

void geonetworking_layer::init(const std::string & p_type, const std::string & p_param) {
  loggers::get_instance().log(">>> geonetworking_layer::init: %s, %s", to_string().c_str(), p_param.c_str());
  
  // Setup parameters
  params::convert(_params, param);
  params::convert(_params, p_param);
  // Sanity checks
  params::const_iterator it = _params.find(params::latitude);
  if (it != _params.cend()) {
@@ -121,27 +147,7 @@ geonetworking_layer::geonetworking_layer(const std::string & p_type, const std::
  // Register this object for AdapterControlPort
  loggers::get_instance().log("geonetworking_layer::geonetworking_layer: Register %s/%p", p_type.c_str(), this);
  registration<geonetworking_layer>::get_instance().add_item(p_type, this);
} // End of constructor

geonetworking_layer::~geonetworking_layer() {
  loggers::get_instance().log(">>> geonetworking_layer::~geonetworking_layer");

  if (_timerid != 0) {
    timer_delete(_timerid);
  }
  if (_beacon != nullptr) {
    delete _beacon;
  }
  if (_gbc_packet != nullptr) {
    delete _gbc_packet;
  }
  if (_shb_packet != nullptr) {
    delete _shb_packet;
  }
  if (_ls_reply != nullptr) {
    delete _ls_reply;
  }
} // End of destructor
} // End of init_params

void geonetworking_layer::sendMsg(const LibItsGeoNetworking__TestSystem::GeoNetworkingReq& p, params& params) {
  loggers::get_instance().log(">>> geonetworking_layer::sendMsg");
+2 −1
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ class geonetworking_layer : public t_layer<LibItsGeoNetworking__TestSystem::GeoN

public:
  explicit geonetworking_layer() : t_layer<LibItsGeoNetworking__TestSystem::GeoNetworkingPort>(), _params(), _codec(), _beacon(NULL), _gbc_packet(NULL), _shb_packet(nullptr), _ls_reply(nullptr), _location_table(), _pass_beacon_table(), _device_mode{false}, _sendData(), _timerid{0}, _sev{0}, _its{0}, _freq_nanosecs(0), _mask{0}, _sa{0}, _sequence_number{0} { };
  geonetworking_layer(const std::string& p_type, const std::string& param);
  geonetworking_layer(const std::string& p_type, const std::string& p_param);
  virtual ~geonetworking_layer();
  
  /*!
@@ -163,6 +163,7 @@ public:
  int disable_secured_mode();
  
private:
  void init(const std::string & p_type, const std::string & p_param);
  void send_beacon();
  int build_geonetworking_pdu(OCTETSTRING& data, params& params);
  int build_secured_pdu(OCTETSTRING& data, params& params);
+14 −0
Original line number Diff line number Diff line
@@ -96,6 +96,20 @@ int security_cache::get_hashed_id(const std::string& p_certificate_id, OCTETSTRI
  return 0;
}

int security_cache::get_hash(const std::string& p_certificate_id, OCTETSTRING& p_hash) const {
  loggers::get_instance().log(">>> security_cache::get_hash: '%s'", p_certificate_id.c_str());

  std::map<std::string, std::unique_ptr<security_db_record> >::const_iterator it = _certificates.find(p_certificate_id);
  if (it == _certificates.cend()) {
    loggers::get_instance().warning("security_cache::get_hash: record not found");
    return -1;
  }
  const std::vector<unsigned char> hash = it->second.get()->hash();
  p_hash = OCTETSTRING(hash.size(), hash.data());

  return 0;
}

int security_cache::get_private_key(const std::string& p_certificate_id, OCTETSTRING& p_private_key) const {
  loggers::get_instance().log(">>> security_cache::get_private_key: '%s'", p_certificate_id.c_str());

+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ public: /*! \publicsection */
  int get_certificate(const std::string& p_certificate_id, IEEE1609dot2::CertificateBase& p_certificate) const;
  int get_issuer(const std::string& p_certificate_id, OCTETSTRING& p_hashed_id_issuer) const;
  int get_hashed_id(const std::string& p_certificate_id, OCTETSTRING& p_hashed_id) const;
  int get_hash(const std::string& p_certificate_id, OCTETSTRING& p_hash) const;
  int get_private_key(const std::string& p_certificate_id, OCTETSTRING& p_private_key) const;
  int get_public_keys(const std::string& p_certificate_id, OCTETSTRING& p_public_key_x, OCTETSTRING& p_public_key_y) const;
  int get_public_comp_key(const std::string& p_certificate_id, OCTETSTRING& p_public_comp_key, INTEGER& p_comp_mode) const;
Loading