Commit a85d6a6b authored by garciay's avatar garciay
Browse files

STF545: Start ATS development

        Provide ssp in lower layer parameters
parent 03999107
......@@ -102,10 +102,10 @@ void cam_layer::receive_data(OCTETSTRING& data, params& params)
p.btpInfo().set_to_omit();
}
// ssp
it = params.find(params::ssp);
it = params.find(_params[params::its_aid]);
if (it != params.cend()) {
OCTETSTRING os(it->second.length(), (const unsigned char *)(it->second.c_str()));
p.ssp() = oct2bit(os);
loggers::get_instance().log("cam_layer::receive_data: ssp=%s", it->second.c_str());
p.ssp() = oct2bit(str2oct(CHARSTRING(it->second.c_str())));
} else {
p.ssp().set_to_omit();
}
......
......@@ -101,10 +101,10 @@ void denm_layer::receive_data(OCTETSTRING& data, params& params)
p.btpInfo().set_to_omit();
}
// ssp
it = params.find(params::ssp);
it = params.find(_params[params::its_aid]);
if (it != params.cend()) {
OCTETSTRING os(it->second.length(), (const unsigned char *)(it->second.c_str()));
p.ssp() = oct2bit(os);
loggers::get_instance().log("denm_layer::receive_data: ssp=%s", it->second.c_str());
p.ssp() = oct2bit(str2oct(CHARSTRING(it->second.c_str())));
} else {
p.ssp().set_to_omit();
}
......
......@@ -4,6 +4,8 @@
#include "geonetworking_codec.hh"
#include "loggers.hh"
#include "etsi_ts103097_data_codec.hh"
#include "LibItsGeoNetworking_TypesAndValues.hh"
template <typename T_type> class OPTIONAL;
......@@ -66,6 +68,10 @@ int geonetworking_codec::encode_ (const Base_Type& type, const TTCN_Typedescript
for(int i = 0; i < r.get_count(); i++) {
loggers::get_instance().log("geonetworking_codec::encode_: processing %s/%s/%s - %d (1 ==> use dynamic_cast<const OPTIONAL<...>) - %d", r.fld_name(i), r.fld_descr(i)->name, r.get_at(i)->get_descriptor()->name, r.get_at(i)->is_optional(), r.get_at(i)->is_present());
if (r.get_at(i)->is_present()) {
if ((_ec.basic_header == 0x02) && (std::string(r.fld_descr(i)->name).compare("@LibItsGeoNetworking_TypesAndValues.GeoNetworkingPacket.packet") == 0)) { // Encoding secured GeoNetworking packet, unsecured GN message was already encoded using encvalue
loggers::get_instance().log("geonetworking_codec::encode_: Skip it");
continue;
}
if (encode_(*r.get_at(i), *r.fld_descr(i), encoding_buffer) == -1) {
loggers::get_instance().warning("geonetworking_codec::encode_: -1 result code returned");
return -1;
......@@ -95,9 +101,25 @@ int geonetworking_codec::encode_ (const Base_Type& type, const TTCN_Typedescript
loggers::get_instance().log("geonetworking_codec::encode_: Storing payload length %d for %s", _ec.length, p.get_descriptor()->name);
}
}
} else if (std::string(field_descriptor.name).compare("@EtsiTs103097Module.EtsiTs103097Data") == 0) {
const EtsiTs103097Module::EtsiTs103097Data& ieee_1609dot2_data = static_cast<const EtsiTs103097Module::EtsiTs103097Data&>(type);
loggers::get_instance().log_msg("geonetworking_codec::encode_: Encode secured message = ", ieee_1609dot2_data);
etsi_ts103097_data_codec codec;
OCTETSTRING os;
codec.encode(ieee_1609dot2_data, os);
if (os.lengthof() == 0) {
loggers::get_instance().warning("geonetworking_codec::encode_: Failed to encode EtsiTs103097Data");
return -1;
}
loggers::get_instance().log_msg("geonetworking_codec::encode_: ", os);
encoding_buffer.put_string(os);
} else {
loggers::get_instance().log("geonetworking_codec::encode_ (else): processing type %s/%s", type.get_descriptor()->name, field_descriptor.name);
if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.CommonHeader.nextHeader") == 0) {
if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.BasicHeader.nextHeader") == 0) {
// Store NextHeader field value and continue encoding
_ec.basic_header = (unsigned int)dynamic_cast<const Enum_Type &>(type).as_int();
loggers::get_instance().log("geonetworking_codec::encode_: Storing basic_header %d for %s", _ec.next_header, field_descriptor.name);
} else if (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.CommonHeader.nextHeader") == 0) {
// Store NextHeader field value and continue encoding
_ec.next_header = (unsigned int)dynamic_cast<const Enum_Type &>(type).as_int();
loggers::get_instance().log("geonetworking_codec::encode_: Storing next_header %d for %s", _ec.next_header, field_descriptor.name);
......@@ -113,7 +135,7 @@ int geonetworking_codec::encode_ (const Base_Type& type, const TTCN_Typedescript
type.encode(field_descriptor, encoding_buffer, TTCN_EncDec::CT_RAW);
}
loggers::get_instance().log_to_hexa("<<<geonetworking_codec::encode_: ", encoding_buffer);
loggers::get_instance().log_to_hexa("<<< geonetworking_codec::encode_: ", encoding_buffer);
return 0;
}
......
......@@ -20,12 +20,13 @@ namespace LibItsSecurity__TypesAndValues {
};
struct encoding_context {
unsigned char basic_header;
unsigned char next_header;
unsigned char header_type;
unsigned int length_position;
unsigned int length;
encoding_context() { next_header = 0xff; header_type = 0xff; length_position = -1; length = -1; }
encoding_context() { basic_header = 0xff; next_header = 0xff; header_type = 0xff; length_position = -1; length = -1; }
};
//typedef struct encoding_context encoding_context;
......
......@@ -362,10 +362,10 @@ void geonetworking_layer::receive_data(OCTETSTRING& data, params& params) {
ind.macDestinationAddress() = str2oct(CHARSTRING(_params["mac_bc"].c_str()));
}
// 2. ssp
it = params.find(params::ssp);
it = params.find(_params[params::its_aid]);
if (it != params.cend()) {
loggers::get_instance().log("geonetworking_layer::receive_data: ssp=%s", it->second.c_str());
ind.ssp() = str2bit(CHARSTRING(it->second.c_str()));
ind.ssp() = oct2bit(str2oct(CHARSTRING(it->second.c_str())));
} else {
ind.ssp().set_to_omit();
}
......
......@@ -76,14 +76,14 @@ int certificates_loader::retrieve_certificates_list(std::set<std::experimental::
// Walk through directories
std::set<std::experimental::filesystem::path> folders;
for (const std::experimental::filesystem::directory_entry it : std::experimental::filesystem::recursive_directory_iterator(_full_path.string())) {
loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Processing directory '%s'", it.path().string().c_str());
//loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Processing directory '%s'", it.path().string().c_str());
if (std::experimental::filesystem::is_directory(it)) {
std::set<std::string>::const_iterator i = _directory_filter.find(it.path().filename());
if (i != _directory_filter.cend()) {
loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Exclude directory '%s'", it.path().string().c_str());
//loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Exclude directory '%s'", it.path().string().c_str());
continue;
}
loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Add directory '%s'", it.path().string().c_str());
//loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Add directory '%s'", it.path().string().c_str());
folders.insert(it.path());
}
} // End of 'for' statement
......@@ -96,20 +96,20 @@ int certificates_loader::retrieve_certificates_list(std::set<std::experimental::
p_files.clear();
std::set<std::string> extensions_filter{ _certificateExt, _privateKeyExt, _publicKeysExt, _publicCompKeysExt, _privateEncKeyExt, _publicEncKeysExt, _hashedidDigestExt, _issuerDigestExt };
for (std::set<std::experimental::filesystem::path>::const_reverse_iterator f = folders.crbegin(); f != folders.crend(); ++f) {
loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Processing directory '%s'", f->string().c_str());
//loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Processing directory '%s'", f->string().c_str());
for(const std::experimental::filesystem::directory_entry it : std::experimental::filesystem::recursive_directory_iterator(*f)) {
loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Processing file '%s'", it.path().filename().string().c_str());
//loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Processing file '%s'", it.path().filename().string().c_str());
if (std::experimental::filesystem::is_regular_file(it)) {
loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Check extension '%s'", it.path().extension().string().c_str());
//loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Check extension '%s'", it.path().extension().string().c_str());
std::set<std::string>::const_iterator i = extensions_filter.find(it.path().extension().string());
if (i != extensions_filter.cend()) {
loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Add file '%s'", it.path().filename().string().c_str());
//loggers::get_instance().log("certificates_loader::retrieve_certificates_list: Add file '%s'", it.path().filename().string().c_str());
p_files.insert(it);
}
}
} // End of 'for' statement
} // End of 'for' statement
loggers::get_instance().log("certificates_loader::retrieve_certificates_list: # of files to cache: %d", p_files.size());
//loggers::get_instance().log("certificates_loader::retrieve_certificates_list: # of files to cache: %d", p_files.size());
if (p_files.size() == 0) {
loggers::get_instance().warning("certificates_loader::retrieve_certificates_list: No certificate found");
return -1;
......@@ -123,10 +123,10 @@ int certificates_loader::build_certificates_cache(std::set<std::experimental::fi
std::set<std::experimental::filesystem::path>::const_iterator it = p_files.cbegin();
do {
loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching '%s'", it->string().c_str());
//loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching '%s'", it->string().c_str());
std::experimental::filesystem::path p = *it;
const std::string& key = p.stem();
loggers::get_instance().log("certificates_loader::build_certificates_cache: Key = '%s'", key.c_str());
//loggers::get_instance().log("certificates_loader::build_certificates_cache: Key = '%s'", key.c_str());
// Load certificate file
it = p_files.find(p.replace_extension(_certificateExt));
......@@ -134,7 +134,7 @@ int certificates_loader::build_certificates_cache(std::set<std::experimental::fi
loggers::get_instance().warning("certificates_loader::build_certificates_cache: Certificate file not found for '%s'", key.c_str());
return -1;
}
loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching certificate '%s'", it->string().c_str());
//loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching certificate '%s'", it->string().c_str());
std::ifstream is(it->string(), ios::in | ios::binary);
std::vector<unsigned char> certificate(std::experimental::filesystem::file_size(*it), 0x00);
is.read(reinterpret_cast<char *>(certificate.data()), certificate.size());
......@@ -148,7 +148,7 @@ int certificates_loader::build_certificates_cache(std::set<std::experimental::fi
loggers::get_instance().warning("certificates_loader::build_certificates_cache: Private keys file not found for '%s'", key.c_str());
return -1;
}
loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching private keys '%s'", it->string().c_str());
//loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching private keys '%s'", it->string().c_str());
is.open(it->string(), ios::in | ios::binary);
int size = std::experimental::filesystem::file_size(*it);
if ((size != 32) && (size != 48)) {
......@@ -167,7 +167,7 @@ int certificates_loader::build_certificates_cache(std::set<std::experimental::fi
loggers::get_instance().warning("certificates_loader::build_certificates_cache: Public keys file not found for '%s'", key.c_str());
return -1;
}
loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching public keys '%s'", it->string().c_str());
//loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching public keys '%s'", it->string().c_str());
is.open(it->string(), ios::in | ios::binary);
size = std::experimental::filesystem::file_size(*it);
if ((size != 64) && (size != 96)) {
......@@ -188,7 +188,7 @@ int certificates_loader::build_certificates_cache(std::set<std::experimental::fi
loggers::get_instance().warning("certificates_loader::build_certificates_cache: Public compress key file not found for '%s'", key.c_str());
return -1;
}
loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching public compressed ke '%s'", it->string().c_str());
//loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching public compressed ke '%s'", it->string().c_str());
is.open(it->string(), ios::in | ios::binary);
size = std::experimental::filesystem::file_size(*it);
if ((size != 33) && (size != 49)) {
......@@ -205,7 +205,7 @@ int certificates_loader::build_certificates_cache(std::set<std::experimental::fi
std::vector<unsigned char> private_enc_key;
it = p_files.find(p.replace_extension(_privateEncKeyExt));
if (it != p_files.cend()) {
loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching private encryption keys '%s'", it->string().c_str());
//loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching private encryption keys '%s'", it->string().c_str());
is.open(it->string(), ios::in | ios::binary);
int size = std::experimental::filesystem::file_size(*it);
if (size != 32) { // IEEE Std 1609.2 2017: NistP256 or BrainpoolP256r1
......@@ -224,7 +224,7 @@ int certificates_loader::build_certificates_cache(std::set<std::experimental::fi
std::vector<unsigned char> public_enc_key_y;
it = p_files.find(p.replace_extension(_publicEncKeysExt));
if (it != p_files.cend()) {
loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching public encryption keys '%s'", it->string().c_str());
//loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching public encryption keys '%s'", it->string().c_str());
is.open(it->string(), ios::in | ios::binary);
size = std::experimental::filesystem::file_size(*it);
if (size != 64) { // IEEE Std 1609.2 2017: NistP256 or BrainpoolP256r1
......@@ -246,7 +246,7 @@ int certificates_loader::build_certificates_cache(std::set<std::experimental::fi
loggers::get_instance().warning("certificates_loader::build_certificates_cache: Issuer keys file not found for '%s'", key.c_str());
return -1;
}
loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching issuer keys '%s'", it->string().c_str());
//loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching issuer keys '%s'", it->string().c_str());
is.open(it->string(), ios::in | ios::binary);
size = std::experimental::filesystem::file_size(*it);
if (size != 8) {
......@@ -265,7 +265,7 @@ int certificates_loader::build_certificates_cache(std::set<std::experimental::fi
loggers::get_instance().warning("certificates_loader::build_certificates_cache: Hashed_Id keys file not found for '%s'", key.c_str());
return -1;
}
loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching hashed_id keys '%s'", it->string().c_str());
//loggers::get_instance().log("certificates_loader::build_certificates_cache: Caching hashed_id keys '%s'", it->string().c_str());
is.open(it->string(), ios::in | ios::binary);
size = std::experimental::filesystem::file_size(*it);
if (size != 8) {
......@@ -283,7 +283,7 @@ int certificates_loader::build_certificates_cache(std::set<std::experimental::fi
IEEE1609dot2::CertificateBase decoded_certificate;
OCTETSTRING os(certificate.size(), certificate.data());
codec.decode(os, decoded_certificate);
loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: Decoded certificate: ", decoded_certificate);
//loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: Decoded certificate: ", decoded_certificate);
p_certificates.insert(std::pair<const std::string, std::unique_ptr<security_db_record> >(key, std::unique_ptr<security_db_record>(
new security_db_record(
key,
......
......@@ -259,6 +259,32 @@ int security_services::process_ieee_1609_dot2_signed_data(const IEEE1609dot2::Si
std::vector<std::string> certificate_ids;
for (int i = 0; i < p_signed_data.signer().certificate().size_of(); i++) {
IEEE1609dot2::CertificateBase cert = p_signed_data.signer().certificate()[i];
// Retrieve ssps
OPTIONAL<IEEE1609dot2BaseTypes::SequenceOfPsidSsp>& v = cert.toBeSigned().appPermissions();
if (v.is_present()) {
IEEE1609dot2BaseTypes::SequenceOfPsidSsp psid_ssps = static_cast<const IEEE1609dot2BaseTypes::SequenceOfPsidSsp&>(*v.get_opt_value());
loggers::get_instance().log("security_services::process_ieee_1609_dot2_signed_data: psid_ssps size: %d", psid_ssps.lengthof());
for (int i = 0; i < psid_ssps.lengthof(); i++) {
const IEEE1609dot2BaseTypes::PsidSsp& psid_ssp = psid_ssps[i];
loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_signed_data: Processing psid_ssp ", psid_ssp);
const OPTIONAL<IEEE1609dot2BaseTypes::ServiceSpecificPermissions>& s = psid_ssp.ssp();
if (s.is_present()) {
const IEEE1609dot2BaseTypes::ServiceSpecificPermissions& ssp = static_cast<const IEEE1609dot2BaseTypes::ServiceSpecificPermissions>(s);
loggers::get_instance().log_msg("security_services::process_ieee_1609_dot2_signed_data: Processing ssp ", ssp);
params::const_iterator it = p_params.find(std::to_string(psid_ssp.psid()));
if (it == p_params.cend()) {
OCTETSTRING os;
if (ssp.ischosen(IEEE1609dot2BaseTypes::ServiceSpecificPermissions::ALT_opaque)) {
os = ssp.opaque();
} else {
os = ssp.bitmapSsp();
}
p_params[std::to_string(psid_ssp.psid())] = std::string(static_cast<const char *>(oct2str(os)));
}
}
} // End of 'for' statement
}
std::string certificate_id;
if (extract_and_store_certificate(cert, certificate_id) != 0) {
loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: Failed to store certificate");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment