Commit d3e90612 authored by YannGarcia's avatar YannGarcia
Browse files

Build AtsCAM Release.2

parent fddaf0a1
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -29,9 +29,9 @@ undefine sources
undefine modules
undefine includes
include $(1)/module.mk
$$(foreach S, $$(sources),  $$(eval all_sources +=  $$(if $$(filter /%, $$(S)), $$(TOPDIR)/$$(S), $(1)/$$(S))))
$$(foreach I, $$(includes), $$(eval all_includes += $$(if $$(filter /%, $$(I)), $$(TOPDIR)/$$(I), $(1)/$$(I))))
$$(foreach M, $$(modules),  $$(eval $$(call IncludeModule, $$(if $$(filter /%, $$(M)), $$(TOPDIR)/$$(M), $(1)/$$(M)))))
$$(foreach S, $$(sources),  $$(eval all_sources +=  $$(if $$(filter /%, $$(S)), $$(TOPDIR)$$(S), $(1)/$$(S))))
$$(foreach I, $$(includes), $$(eval all_includes += $$(if $$(filter /%, $$(I)), $$(TOPDIR)$$(I), $(1)/$$(I))))
$$(foreach M, $$(modules),  $$(eval $$(call IncludeModule, $$(if $$(filter /%, $$(M)), $$(TOPDIR)$$(M), $(1)/$$(M)))))
endef

all_includes := $(TTCN3_DIR)/include $(TTCN3_DIR)/src /usr/include/jsoncpp /usr/include/libxml2
@@ -57,9 +57,8 @@ $(eval $(call IncludeModule, $(TOPDIR)/ttcn/$(ATS)))
outdir := $(TOPDIR)/build/$(ATS)
bindir := $(TOPDIR)/bin

#sources     := $(sort $(all_sources))
sources     := $(all_sources)
includes    := $(outdir) $(outdir)/.. $(outdir)/../asn1 $(all_includes) $(NPCAP_INCLUDE)
includes    := $(outdir) $(outdir)/.. $(outdir)/asn1 $(all_includes) $(NPCAP_INCLUDE)

ifeq (Windows_NT,$(OS))
  EXE=.exe
@@ -142,7 +141,7 @@ $(cc_objects) : $(outdir)/%.o : %.cc
$(gen_sources): $(outdir)/.generate

$(outdir)/.generate: Makefile $(tt_sources)
	$(TTCN3_DIR)/bin/compiler -w -d -e -f -g -l -L -R -U none -x -X  -o  $(outdir) $(tt_sources)
	$(TTCN3_DIR)/bin/compiler $(TTCN3_COMPILER_OPTIONS) -o  $(outdir) $(tt_sources)
	touch $@

$(bindir)/libItsAsn.so: $(outdir)/asn1/libItsAsn.so
@@ -163,3 +162,6 @@ $(foreach S, $(ttcn_sources), $(eval $(outdir)/$(notdir $(patsubst %.ttcn, %.cc
$(foreach S, $(ttcn3_sources), $(eval $(outdir)/$(notdir $(patsubst %.ttcn3, %.cc, $(S))): $(S)))
$(foreach S, $(asn_sources),   $(eval $(outdir)/$(notdir $(patsubst %.asn, %.cc,   $(S))): $(S)))
$(foreach S, $(asn1_sources),  $(eval $(outdir)/$(notdir $(patsubst %.asn1, %.cc,  $(S))): $(S)))

$(asn_sources) $(asn1_sources):
+2 −2
Original line number Diff line number Diff line
@@ -42,10 +42,10 @@ int asn1_recoder::per2ber(const asn_TYPE_descriptor_s &td, TTCN_Buffer &buf)

int asn1_recoder::ber2oer(const asn_TYPE_descriptor_s & td, TTCN_Buffer & buf)
{
  return recode(td, (int)ATS_XER, (int)ATS_CANONICAL_OER, buf);
  return recode(td, (int)ATS_BER, (int)ATS_CANONICAL_OER, buf);
}

int asn1_recoder::oer2ber(const asn_TYPE_descriptor_s & td, TTCN_Buffer & buf)
{
  return recodeOer(td, (int)ATS_BASIC_OER, (int)ATS_XER, buf);
  return recode(td, (int)ATS_BASIC_OER, (int)ATS_BER, buf);
}
+13 −13
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@

#include "security_ecc.hh"

#include "security_services.hh"
#include "security_services_its.hh"

#include "geospacial.hh"

@@ -34,7 +34,7 @@ namespace LibItsSecurity__Functions {

  static std::unique_ptr<geospacial> g(new geospacial);

  // FIXME Unify code with security_services
  // FIXME Unify code with security_services_its

  /**
   * \fn OCTETSTRING fx_hashWithSha256(const OCTETSTRING& p__toBeHashedData);
@@ -1373,7 +1373,7 @@ namespace LibItsSecurity__Functions {
    }
    params_its params;
    params.insert(std::pair<std::string, std::string>(std::string("sec_db_path"), str));
    if (security_services::get_instance().setup(params) == -1) {
    if (security_services_its::get_instance().setup(params) == -1) {
      return FALSE;
    }

@@ -1393,12 +1393,12 @@ namespace LibItsSecurity__Functions {
      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(
      result                             = security_services_its::get_instance().store_certificate(
        p__cert__id, p__cert, p__private__key, p__public__key__x, p__public__key__y, p__public__key__compressed, p__public__key__compressed__mode, p__hash,
        p__hash__256, p__hashid8, p__issuer, p__private__enc__key.valueof(), p__public__enc__key__x.valueof(), p__public__enc__key__y.valueof(),
        p__public__enc__compressed__key.valueof(), p__public__enc__key__compressed__mode.valueof());
    } else {
      result = security_services::get_instance().store_certificate(
      result = security_services_its::get_instance().store_certificate(
        p__cert__id, p__cert, p__private__key, p__public__key__x, p__public__key__y, p__public__key__compressed, p__public__key__compressed__mode, p__hash,
        p__hash__256, p__hashid8, p__issuer, OCTETSTRING(0, nullptr), OCTETSTRING(0, nullptr), OCTETSTRING(0, nullptr), OCTETSTRING(0, nullptr), INTEGER(-1));
    }
@@ -1421,7 +1421,7 @@ namespace LibItsSecurity__Functions {
  BOOLEAN fx__readCertificate(const CHARSTRING &p__certificateId, OCTETSTRING &p__certificate) {
    loggers::get_instance().log(">>> fx__readCertificate: '%s'", static_cast<const char *>(p__certificateId));

    if (security_services::get_instance().read_certificate(p__certificateId, p__certificate) == -1) {
    if (security_services_its::get_instance().read_certificate(p__certificateId, p__certificate) == -1) {
      return FALSE;
    }

@@ -1431,7 +1431,7 @@ namespace LibItsSecurity__Functions {
  BOOLEAN fx__readCertificateFromDigest(const OCTETSTRING &p__digest, CHARSTRING &p__certificateId) {
    loggers::get_instance().log_msg(">>> fx__readCertificateFromDigest: ", p__digest);

    if (security_services::get_instance().read_certificate_from_digest(p__digest, p__certificateId) == -1) {
    if (security_services_its::get_instance().read_certificate_from_digest(p__digest, p__certificateId) == -1) {
      return FALSE;
    }
    loggers::get_instance().log_msg("fx__readCertificateFromDigest: ", p__certificateId);
@@ -1442,7 +1442,7 @@ namespace LibItsSecurity__Functions {
  BOOLEAN fx__readCertificateFromHashedId3(const OCTETSTRING &p__digest, CHARSTRING &p__certificateId) {
    loggers::get_instance().log_msg(">>> fx__readCertificateFromHashedId3: ", p__digest);

    if (security_services::get_instance().read_certificate_from_hashed_id3(p__digest, p__certificateId) == -1) {
    if (security_services_its::get_instance().read_certificate_from_hashed_id3(p__digest, p__certificateId) == -1) {
      return FALSE;
    }
    loggers::get_instance().log_msg("fx__readCertificateFromHashedId3: ", p__certificateId);
@@ -1459,7 +1459,7 @@ namespace LibItsSecurity__Functions {
  BOOLEAN fx__readCertificateDigest(const CHARSTRING &p__certificateId, OCTETSTRING &p__digest) {
    loggers::get_instance().log(">>> fx__readCertificateDigest: '%s'", static_cast<const char *>(p__certificateId));

    if (security_services::get_instance().read_certificate_digest(p__certificateId, p__digest) == -1) {
    if (security_services_its::get_instance().read_certificate_digest(p__certificateId, p__digest) == -1) {
      return FALSE;
    }

@@ -1475,7 +1475,7 @@ namespace LibItsSecurity__Functions {
  BOOLEAN fx__readCertificateHash(const CHARSTRING &p__certificateId, OCTETSTRING &p__hash) {
    loggers::get_instance().log(">>> fx__readCertificateHash: '%s'", static_cast<const char *>(p__certificateId));

    if (security_services::get_instance().read_certificate_hash(p__certificateId, p__hash) == -1) {
    if (security_services_its::get_instance().read_certificate_hash(p__certificateId, p__hash) == -1) {
      return FALSE;
    }

@@ -1491,7 +1491,7 @@ namespace LibItsSecurity__Functions {
  BOOLEAN fx__readCertificateHash256(const CHARSTRING &p__certificateId, OCTETSTRING &p__hash) {
    loggers::get_instance().log(">>> fx__readCertificateHash256: '%s'", static_cast<const char *>(p__certificateId));

    if (security_services::get_instance().read_certificate_hash_sha_256(p__certificateId, p__hash) == -1) {
    if (security_services_its::get_instance().read_certificate_hash_sha_256(p__certificateId, p__hash) == -1) {
      return FALSE;
    }

@@ -1507,7 +1507,7 @@ namespace LibItsSecurity__Functions {
  BOOLEAN fx__readSigningKey(const CHARSTRING &p__certificateId, OCTETSTRING &p__signingPrivateKey) {
    loggers::get_instance().log(">>> fx__readSigningKey: '%s'", static_cast<const char *>(p__certificateId));

    if (security_services::get_instance().read_private_key(p__certificateId, p__signingPrivateKey) == -1) {
    if (security_services_its::get_instance().read_private_key(p__certificateId, p__signingPrivateKey) == -1) {
      return FALSE;
    }

@@ -1524,7 +1524,7 @@ namespace LibItsSecurity__Functions {
  BOOLEAN fx__readEncryptingKey(const CHARSTRING &p__certificateId, OCTETSTRING &p__encryptingPrivateKey) {
    loggers::get_instance().log(">>> fx__readSigningKey: '%s'", static_cast<const char *>(p__certificateId));

    if (security_services::get_instance().read_private_enc_key(p__certificateId, p__encryptingPrivateKey) == -1) {
    if (security_services_its::get_instance().read_private_enc_key(p__certificateId, p__encryptingPrivateKey) == -1) {
      return FALSE;
    }

+5 −5
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@

#include "loggers.hh"

#include "security_services.hh"
#include "security_services_its.hh"

#include "base_time.hh"

@@ -253,7 +253,7 @@ void geonetworking_layer::receive_data(OCTETSTRING &data, params &p_params) {
      }
      return;
    } else {
      if (security_services::get_instance().verify_and_extract_gn_payload(secured_data, _enable_security_checks, ieee_1609dot2_data, unsecured_gn_payload,
      if (security_services_its::get_instance().verify_and_extract_gn_payload(secured_data, _enable_security_checks, ieee_1609dot2_data, unsecured_gn_payload,
                                                                          params) != 0) {
        loggers::get_instance().warning("geonetworking_layer::receive_data: Security error");
        if (_enable_security_checks) {
@@ -882,7 +882,7 @@ int geonetworking_layer::build_secured_pdu(OCTETSTRING &data, params_its &params
  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, secured_gn_payload, params) != 0) {
  if (security_services_its::get_instance().secure_gn_payload(unsecured_gn_payload, secured_gn_payload, params) != 0) {
    loggers::get_instance().warning("geonetworking_layer::build_secured_pdu: failed to build secured pdu");
    return -1;
  }
@@ -935,8 +935,8 @@ int geonetworking_layer::setup_secured_mode() {
    _params.insert(std::pair<std::string, std::string>(std::string("hash"), "SHA-256"));
  }
  // Set up security services even if secured_mode is set to 0. Later, we can receive an AcEnableSecurity request, the sertificate caching will be ready to go
  security_services::get_instance().setup(_params);
  security_services::get_instance().set_position(_latitude, _longitude);
  security_services_its::get_instance().setup(_params);
  security_services_its::get_instance().set_position(_latitude, _longitude);

  return 0;
}

ccsrc/Protocols/Security/hmac.cc

deleted100644 → 0
+0 −54
Original line number Diff line number Diff line
/*!
 * \file      hmac.cc
 * \brief     Source file for HMAC helper methods.
 * \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 <TTCN3.hh>

#include "hmac.hh"

#include "loggers.hh"

int hmac::generate(const OCTETSTRING p_buffer, const OCTETSTRING p_secret_key, OCTETSTRING &p_hmac) {
  // Sanity check
  if (p_buffer.lengthof() == 0) {
    return -1;
  }

  return generate(static_cast<const unsigned char *>(p_buffer), p_buffer.lengthof(), static_cast<const unsigned char *>(p_secret_key), p_secret_key.lengthof(),
                  p_hmac);
}

int hmac::generate(const unsigned char *p_buffer, const size_t p_buffer_length, const unsigned char *p_secret_key, const size_t p_secret_key_length,
                   OCTETSTRING &p_hmac) {
  // Sanity check
  if ((p_buffer == nullptr) || (p_secret_key == nullptr)) {
    return -1;
  }
  ::HMAC_CTX_reset(_ctx);

  p_hmac = int2oct(0, EVP_MAX_MD_SIZE);
  if (_hash_algorithms == hash_algorithms::sha_256) {
    ::HMAC_Init_ex(_ctx, (const void *)p_secret_key, (long unsigned int)p_secret_key_length, EVP_sha256(), NULL);
  } else if (_hash_algorithms == hash_algorithms::sha_384) {
    ::HMAC_Init_ex(_ctx, (const void *)p_secret_key, (long unsigned int)p_secret_key_length, EVP_sha384(), NULL);
  } else { // TODO To be continued
    return -1;
  }
  // Compute the hash value
  ::HMAC_Update(_ctx, p_buffer, p_buffer_length);
  unsigned int length = p_hmac.lengthof();
  ::HMAC_Final(_ctx, (unsigned char *)static_cast<const unsigned char *>(p_hmac), &length);
  loggers::get_instance().log_to_hexa("hmac::generate: ", (unsigned char *)static_cast<const unsigned char *>(p_hmac), length);
  // Resize the hmac
  if (_hash_algorithms == hash_algorithms::sha_256) {
    p_hmac = OCTETSTRING(16, static_cast<const unsigned char *>(p_hmac));
  } // FIXME Check length for the other hash algorithm

  return 0;
}
Loading