Commit 01a9c9e2 authored by Denis Filatov's avatar Denis Filatov
Browse files

Merge branch 'STF525' of https://forge.etsi.org/gitlab/ITS/ITS into STF525

parents e1f2572e 5a2f8d34
......@@ -37,6 +37,8 @@ The ETSI ITS protocols project builds and tests regularly on the following platf
- Linux (Ubuntu)
Note: The [OpenSSL](https://www.openssl.org) version > 1.x is also required.
### Using Vagrant
Pre-requisites on your host machine:
......
......@@ -818,7 +818,7 @@ namespace LibItsSecurity__Functions
* \see http://digital.csic.es/bitstream/10261/32671/1/V2-I2-P7-13.pdf
*/
// TODO Use common function for both fx__encryptWithEciesxxx and fx__decryptWithEciesxxx function
OCTETSTRING fx__decryptWithEciesNistp256WithSha256(const OCTETSTRING& p__encryptedSecuredMessage, const OCTETSTRING& p__privateEncKey, const OCTETSTRING& p__publicEphemeralKeyCompressed, const INTEGER& p__ephemeralCompressedMode, const OCTETSTRING& p__encrypted__sym__key, const OCTETSTRING& p__authentication__vector, const OCTETSTRING& p__nonce, const OCTETSTRING& p__salt) {
OCTETSTRING fx__decryptWithEciesNistp256WithSha256(const OCTETSTRING& p__encryptedSecuredMessage, const OCTETSTRING& p__privateEncKey, const OCTETSTRING& p__publicEphemeralKeyCompressed, const INTEGER& p__ephemeralCompressedMode, const OCTETSTRING& p__encrypted__sym__key, const OCTETSTRING& p__authentication__vector, const OCTETSTRING& p__nonce, const OCTETSTRING& p__salt, OCTETSTRING& p__aes__sym__enc__key) {
loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__toBeEncryptedSecuredMessage: ", p__encryptedSecuredMessage);
loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__privateEncKey: ", p__privateEncKey);
loggers::get_instance().log_msg(">>> fx__decryptWithEciesNistp256WithSha256: p__publicEphemeralKeyCompressed: ", p__publicEphemeralKeyCompressed);
......@@ -849,6 +849,8 @@ namespace LibItsSecurity__Functions
return OCTETSTRING(0, nullptr);
}
loggers::get_instance().log_msg("fx__decryptWithEciesNistp256WithSha256: dec message: ", message);
p__aes__sym__enc__key = ec.symmetric_encryption_key();
loggers::get_instance().log_msg("fx__decryptWithEciesNistp256WithSha256: AES 128 encryption key: ", p__aes__sym__enc__key);
return message;
}
......@@ -960,7 +962,7 @@ namespace LibItsSecurity__Functions
return enc_message;
}
OCTETSTRING fx__decryptWithEciesBrainpoolp256WithSha256(const OCTETSTRING& p__encryptedSecuredMessage, const OCTETSTRING& p__privateEncKey, const OCTETSTRING& p__publicEphemeralKeyCompressed, const INTEGER& p__ephemeralCompressedMode, const OCTETSTRING& p__encrypted__sym__key, const OCTETSTRING& p__authentication__vector, const OCTETSTRING& p__nonce) {
OCTETSTRING fx__decryptWithEciesBrainpoolp256WithSha256(const OCTETSTRING& p__encryptedSecuredMessage, const OCTETSTRING& p__privateEncKey, const OCTETSTRING& p__publicEphemeralKeyCompressed, const INTEGER& p__ephemeralCompressedMode, const OCTETSTRING& p__encrypted__sym__key, const OCTETSTRING& p__authentication__vector, const OCTETSTRING& p__nonce, const OCTETSTRING& p__salt, OCTETSTRING& p__aes__sym__enc__key) {
loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256WithSha256: p__toBeEncryptedSecuredMessage: ", p__encryptedSecuredMessage);
loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256WithSha256: p__privateEncKey: ", p__privateEncKey);
loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256WithSha256: p__publicEphemeralKeyCompressed: ", p__publicEphemeralKeyCompressed);
......@@ -968,6 +970,7 @@ namespace LibItsSecurity__Functions
loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256WithSha256: p__nonce: ", p__nonce);
loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256WithSha256: p__authentication__vector: ", p__authentication__vector);
loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key);
loggers::get_instance().log_msg(">>> fx__decryptWithEciesBrainpoolp256WithSha256: p__salt", p__salt);
// 1. Create security_ecc instance based on public ephemeral keys
security_ecc ec(ec_elliptic_curves::brainpool_p_256_r1, p__privateEncKey);
......@@ -990,6 +993,8 @@ namespace LibItsSecurity__Functions
return OCTETSTRING(0, nullptr);
}
loggers::get_instance().log_msg("fx__decryptWithEciesBrainpoolp256WithSha256: dec message: ", message);
p__aes__sym__enc__key = ec.symmetric_encryption_key();
loggers::get_instance().log_msg("fx__decryptWithEciesBrainpoolp256WithSha256: AES 128 encryption key: ", p__aes__sym__enc__key);
return message;
}
......
......@@ -80,6 +80,10 @@ const std::string& params::uri = std::string("uri");
const std::string& params::host = std::string("host");
const std::string& params::content_type = std::string("content_type");
//const std::string& params::sip_url = std::string("sip_url");
//const std::string& params::sip_version = std::string("sip_version");
//const std::string& params::payload = std::string("payload");
const std::string& params::codecs = std::string("codecs");
void params::convert(params& p_param, const std::string p_parameters) {
......
......@@ -103,7 +103,7 @@ void ConfigRsuSimulatorLayer::sendMsg(const LibItsPki__TypesAndValues::UtPkiResu
encoding_buffer.put_c(0x01/*static_cast<const unsigned char>(uppertester_pki_codec::c_utPkiInitializeResult)*/);
encoding_buffer.put_c((unsigned char)static_cast<const boolean>(send_par.utPkiInitializeResult()));
} else if (send_par.ischosen(LibItsPki__TypesAndValues::UtPkiResults::ALT_utPkiTriggerResult)) {
encoding_buffer.put_c(0x11/*static_cast<const unsigned char>(uppertester_pki_codec::c_utPkiTriggerResult)*/);
encoding_buffer.put_c(0xBC/*static_cast<const unsigned char>(uppertester_pki_codec::c_utPkiTriggerResult)*/);
encoding_buffer.put_c((unsigned char)static_cast<const boolean>(send_par.utPkiTriggerResult()));
} else {
loggers::get_instance().warning("ConfigRsuSimulatorLayer::sendMsg: Unsupported UtPkiResults variant");
......@@ -135,6 +135,8 @@ void ConfigRsuSimulatorLayer::receive_data(OCTETSTRING& data, params& params)
process_ut_cam_changeheading_data(data, params);
} else if ((id >= 0x50) && (id <= 0x54)) { // Receive an UtGnTrigger
process_ut_geonetworking_trigger(data, params);
} else if ((id >= 0xBB) && (id <= 0xBF)) { // Receive an UtPkiTrigger
process_ut_pki_trigger(data, params);
} else {
loggers::get_instance().warning("ConfigRsuSimulatorLayer::receive_data: Unsupported tag %02x", id);
}
......@@ -165,6 +167,11 @@ int ConfigRsuSimulatorLayer::process_utinitialize_data(const OCTETSTRING& data,
LibItsDenm__TypesAndValues::UtDenmInitialize p(hashedId);
// Pass it to the ports if any
to_all_upper_ports(p, params);
} else if (_params[std::string("ut")].compare("pki") == 0) {
OCTETSTRING hashedId(data.lengthof() - 1, 1 + static_cast<const unsigned char*>(data));
LibItsPki__TypesAndValues::UtPkiInitialize p(hashedId);
// Pass it to the ports if any
to_all_upper_ports(p, params);
} else {
loggers::get_instance().warning("ConfigRsuSimulatorLayer::process_utinitialize_data: Unsupported protocol");
return -1;
......@@ -281,4 +288,29 @@ int ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger(const OCTETSTRING&
return 0;
}
int ConfigRsuSimulatorLayer::process_ut_pki_trigger(const OCTETSTRING& data, params& params) {
loggers::get_instance().log(">>> ConfigRsuSimulatorLayer::process_ut_pki_trigger");
params::const_iterator it = _params.find("ut");
if (it == _params.cend()) {
loggers::get_instance().warning("ConfigRsuSimulatorLayer::process_ut_pki_trigger: CF layer's ut parameter is missing");
return -1;
}
if (_params[std::string("ut")].compare("pki") == 0) {
LibItsPki__TypesAndValues::UtPkiTrigger p;
p.triggerEnrolmentRequest().cannonicalId() = OCTETSTRING(0, nullptr); // No parameter used
p.triggerEnrolmentRequest().encAlgorithm() = OCTETSTRING(0, nullptr); // No parameter used
p.triggerEnrolmentRequest().privateKey() = OCTETSTRING(0, nullptr); // No parameter used
p.triggerEnrolmentRequest().compressedPublickey() = OCTETSTRING(0, nullptr); // No parameter used
// Pass it to the ports if any
to_all_upper_ports(p, params);
} else {
loggers::get_instance().warning("ConfigRsuSimulatorLayer::process_ut_pki_trigger: Unsupported protocol");
return -1;
}
return 0;
}
ConfigRsuSimulatorLayerFactory ConfigRsuSimulatorLayerFactory::_f;
......@@ -48,5 +48,6 @@ private:
int process_ut_cam_changecurvature_data(const OCTETSTRING& data, params& params);
int process_ut_cam_changeheading_data(const OCTETSTRING& data, params& params);
int process_ut_geonetworking_trigger(const OCTETSTRING& data, params& params);
int process_ut_pki_trigger(const OCTETSTRING& data, params& params);
}; // End of class ConfigRsuSimulatorLayer
......@@ -211,6 +211,16 @@ namespace ItsRSUsSimulator__TestSystem {
incoming_message(p_ind);
}
void ConfigRsuSimulatorPort::receiveMsg (const LibItsPki__TypesAndValues::UtPkiInitialize& p_ind, const params& p_params) {
loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::receive_msg: ", p_ind);
// Sanity check
if (!p_ind.is_bound()) {
return;
}
incoming_message(p_ind);
}
void ConfigRsuSimulatorPort::receiveMsg (const LibItsPki__TypesAndValues::UtPkiTrigger& p_ind, const params& p_params) {
loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::receive_msg: ", p_ind);
// Sanity check
......
......@@ -8,6 +8,8 @@
#include "converter.hh"
unsigned char commsignia_layer::_fixed_header[12] = { 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, 0x0D, 0x00, 0x00 };
commsignia_layer::commsignia_layer(const std::string & p_type, const std::string & param) : layer(p_type), _params(), _c2p_recv{0}, _802_11p_hdr{0}, _c2p_llc_hdr{0}, _mac_src(), _eth_type() {
loggers::get_instance().log(">>> commsignia_layer::commsignia_layer: %s, %s", to_string().c_str(), param.c_str());
......@@ -31,12 +33,57 @@ commsignia_layer::commsignia_layer(const std::string & p_type, const std::string
if (it == _params.cend()) {
_params.insert(std::pair<std::string, std::string>(std::string("interface_id"), "1"));
}
it = _params.find(std::string("power_tx"));
if (it == _params.cend()) {
_params.insert(std::pair<std::string, std::string>(std::string("power_tx"), "20")); // 20db
}
it = _params.find(std::string("data_rate"));
if (it == _params.cend()) {
_params.insert(std::pair<std::string, std::string>(std::string("data_rate"), "12")); // 12 * 500Kbps = 6Mbps
}
//_params.log();
}
void commsignia_layer::send_data(OCTETSTRING& data, params& params) {
loggers::get_instance().log_msg(">>> commsignia_layer::send_data: ", data);
OCTETSTRING buffer(12, commsignia_layer::_fixed_header);
buffer += int2oct(std::stoi(_params[params::interface_id]), 4);
loggers::get_instance().log_msg("commsignia_layer::send_data: buffer: ", buffer);
buffer += int2oct(std::stoi(_params[std::string("data_rate")]), 4);
loggers::get_instance().log_msg("commsignia_layer::send_data: buffer: ", buffer);
buffer += int2oct(0x80000000 & std::stoi(_params[std::string("power_tx")]), 4); // Negative number
loggers::get_instance().log_msg("commsignia_layer::send_data: buffer: ", buffer);
buffer += int2oct(7, 1); // MAC user priority
// Destination MAC address
params::const_iterator it = params.find(params::mac_dst); // Find in provided parameters, params
if (it != params.cend()) {
buffer = str2oct(CHARSTRING(it->second.c_str()));
} else {
it = _params.find(params::mac_dst);
if (it != _params.cend()) {
buffer = str2oct(CHARSTRING(it->second.c_str()));
} else {
buffer = str2oct(CHARSTRING(_params[params::mac_bc].c_str()));
}
}
loggers::get_instance().log_msg("commsignia_layer::send_data: buffer: ", buffer);
// Source MAC address
it = params.find(params::mac_src); // Find in provided parameters, params
if (it != params.cend()) {
buffer += str2oct(CHARSTRING(it->second.c_str()));
} else {
buffer += str2oct(CHARSTRING(_params[params::mac_src].c_str()));
}
loggers::get_instance().log_msg("commsignia_layer::send_data: buffer: ", buffer);
buffer += int2oct(0, 2); // Fixed
loggers::get_instance().log_msg("commsignia_layer::send_data: buffer: ", buffer);
buffer += int2oct(data.lengthof(), 2);
loggers::get_instance().log_msg("commsignia_layer::send_data: buffer: ", buffer);
buffer += data;
loggers::get_instance().log_msg("commsignia_layer::send_data: ", buffer);
send_to_all_layers(buffer, params);
}
void commsignia_layer::receive_data(OCTETSTRING& data, params& params) {
......@@ -44,25 +91,25 @@ void commsignia_layer::receive_data(OCTETSTRING& data, params& params) {
const unsigned char* p = static_cast<const unsigned char *>(data);
const commsignia_layer::c2p_recv* r = (const commsignia_layer::c2p_recv*)p;
loggers::get_instance().log("commsignia_layer::receive_data: version=%02x", r->version);
loggers::get_instance().log("commsignia_layer::receive_data: timestamp1=%08x", ntohl(r->timestamp_sec));
loggers::get_instance().log("commsignia_layer::receive_data: timestamp2=%08x", ntohl(r->timestamp_msec));
loggers::get_instance().log("commsignia_layer::receive_data: timestamp2=%08x", ntohl(r->timestamp_msec));
loggers::get_instance().log("commsignia_layer::receive_data: antenna=%02x", r->antenna);
loggers::get_instance().log("commsignia_layer::receive_data: rssi_ant2=%02x", r->rssi_ant2);
loggers::get_instance().log("commsignia_layer::receive_data: noise_ant1=%02x", r->noise_ant1);
loggers::get_instance().log("commsignia_layer::receive_data: noise_ant2=%02x", r->noise_ant2);
const commsignia_layer::c2p_s_v1_tx_t* r = (const commsignia_layer::c2p_s_v1_tx_t*)p;
loggers::get_instance().log("commsignia_layer::receive_data: version=%02x", r->s_header.u8_ver_type);
loggers::get_instance().log("commsignia_layer::receive_data: timestamp1=%08x", ntohl(r->s_header.u32_tst_sec));
loggers::get_instance().log("commsignia_layer::receive_data: timestamp2=%08x", ntohl(r->s_header.u32_tst_msec));
loggers::get_instance().log("commsignia_layer::receive_data: primary_channel=%08x", ntohl(r->u8_primary_channel));
loggers::get_instance().log("commsignia_layer::receive_data: secondary_channel=%08x", ntohl(r->u8_secondary_channel));
loggers::get_instance().log("commsignia_layer::receive_data: antenna=%02x", r->u8_antenna);
loggers::get_instance().log("commsignia_layer::receive_data: s8_tssi_ant_1=%d", r->s8_tssi_ant_1);
loggers::get_instance().log("commsignia_layer::receive_data: s8_tssi_ant_2=%d", r->s8_tssi_ant_2);
// Filtering on antenna index
loggers::get_instance().log("commsignia_layer::receive_data: compare %02x with %02x", r->antenna, static_cast<unsigned char>(std::strtoul(_params[params::interface_id].c_str(), NULL, 10)));
if (r->antenna != static_cast<unsigned char>(std::strtoul(_params[params::interface_id].c_str(), NULL, 10))) {
loggers::get_instance().log("commsignia_layer::receive_data: compare %02x with %02x", r->u8_antenna, static_cast<unsigned char>(std::stoi(_params[params::interface_id])));
if (r->u8_antenna != std::stoi(_params[params::interface_id])) {
// Discard packet
loggers::get_instance().warning("commsignia_layer::receive_data: Discard packet due to wrong antenna id");
return;
} // else, continue
const commsignia_layer::c2p_802_11p_hdr* h = (const commsignia_layer::c2p_802_11p_hdr*)(p + sizeof(commsignia_layer::c2p_recv));
//loggers::get_instance().log("commsignia_layer::receive_data: frame_ctrl=%04x", ntohs(h->frame_ctrl));
const commsignia_layer::c2p_802_11p_hdr* h = (const commsignia_layer::c2p_802_11p_hdr*)(p + sizeof(commsignia_layer::c2p_s_v1_tx_t));
loggers::get_instance().log("commsignia_layer::receive_data: frame_ctrl=%04x", ntohs(h->frame_ctrl));
OCTETSTRING dst = OCTETSTRING(6, (const unsigned char*)&h->dst_addr);
loggers::get_instance().log_msg("commsignia_layer::receive_data: dst: ", dst);
OCTETSTRING src = OCTETSTRING(6, (const unsigned char*)&h->src_addr);
......@@ -77,15 +124,16 @@ void commsignia_layer::receive_data(OCTETSTRING& data, params& params) {
const commsignia_layer::c2p_llc_hdr* l;
int length;
if ((ntohs(h->frame_ctrl) & 0xf000) == 0x8000) {
l = (const commsignia_layer::c2p_llc_hdr*)(p + sizeof(commsignia_layer::c2p_recv) + sizeof(commsignia_layer::c2p_802_11p_hdr) + sizeof(commsignia_layer::c2p_qos_ctrl));
length = sizeof(commsignia_layer::c2p_recv) + sizeof(commsignia_layer::c2p_802_11p_hdr) + sizeof(commsignia_layer::c2p_qos_ctrl) + sizeof(commsignia_layer::c2p_llc_hdr);
l = (const commsignia_layer::c2p_llc_hdr*)(p + sizeof(commsignia_layer::c2p_s_v1_tx_t) + sizeof(commsignia_layer::c2p_802_11p_hdr) + sizeof(commsignia_layer::c2p_qos_ctrl));
length = sizeof(commsignia_layer::c2p_s_v1_tx_t) + sizeof(commsignia_layer::c2p_802_11p_hdr) + sizeof(commsignia_layer::c2p_qos_ctrl) + sizeof(commsignia_layer::c2p_llc_hdr);
} else {
l = (const commsignia_layer::c2p_llc_hdr*)(p + sizeof(commsignia_layer::c2p_recv) + sizeof(commsignia_layer::c2p_802_11p_hdr));
length = sizeof(commsignia_layer::c2p_recv) + sizeof(commsignia_layer::c2p_802_11p_hdr) + sizeof(commsignia_layer::c2p_llc_hdr);
l = (const commsignia_layer::c2p_llc_hdr*)(p + sizeof(commsignia_layer::c2p_s_v1_tx_t) + sizeof(commsignia_layer::c2p_802_11p_hdr));
length = sizeof(commsignia_layer::c2p_s_v1_tx_t) + sizeof(commsignia_layer::c2p_802_11p_hdr) + sizeof(commsignia_layer::c2p_llc_hdr);
}
//loggers::get_instance().log("commsignia_layer::receive_data: dsap=%02x", l->dsap);
//loggers::get_instance().log("commsignia_layer::receive_data: ssap=%02x", l->ssap);
//loggers::get_instance().log("commsignia_layer::receive_data: type=%04x", l->type);
loggers::get_instance().log("commsignia_layer::receive_data: dsap=%02x", l->dsap);
loggers::get_instance().log("commsignia_layer::receive_data: ssap=%02x", l->ssap);
loggers::get_instance().log("commsignia_layer::receive_data: type=%04x", l->type);
// Check ether type
if ((_eth_type[1] == (unsigned char)((l->type & 0xff00) >> 8)) && (_eth_type[0] == (unsigned char)(l->type & 0xff))) { // Warning: Network ordered bytes
// Extract payload
......
......@@ -24,28 +24,28 @@ class commsignia_layer : public layer {
static constexpr unsigned char LL_ORG_CODE_LENGTH = 3;
/**
* \struct C2P packet description: Version 1, packet type: RX
* \struct C2P packet description
*/
typedef struct {
unsigned char version;
unsigned int timestamp_sec;
unsigned int timestamp_msec;
unsigned char primary_channel;
unsigned char secondary_channel;
unsigned char used_iface;
unsigned char data_rate;
unsigned char antenna;
unsigned int latitude;
unsigned int longitude;
unsigned short speed;
unsigned short heading;
unsigned char rssi_ant1;
unsigned char rssi_ant2;
unsigned char noise_ant1;
unsigned char noise_ant2;
unsigned short cbr_ant1;
unsigned short cbr_ant2;
} __attribute__((__packed__)) c2p_recv;
unsigned char u8_ver_type;
unsigned int u32_tst_sec;
unsigned int u32_tst_msec;
} c2p_s_header_t;
typedef struct {
c2p_s_header_t s_header;
unsigned char u8_primary_channel;
unsigned char u8_secondary_channel;
unsigned char u8_used_interface;
unsigned char u8_data_rate;
unsigned char u8_antenna;
int s32_latitude;
int s32_longitude;
unsigned short u16_speed;
unsigned short u16_heading;
signed char s8_txp;
signed char s8_tssi_ant_1;
signed char s8_tssi_ant_2;
} c2p_s_v1_tx_t;
/**
* \struct Injected data header
......@@ -73,11 +73,14 @@ class commsignia_layer : public layer {
} __attribute__((__packed__)) c2p_llc_hdr;
params _params; //! Layer parameters
c2p_recv _c2p_recv; //! \todo
c2p_s_v1_tx_t _c2p_recv; //! \todo
c2p_802_11p_hdr _802_11p_hdr; //! \todo
c2p_llc_hdr _c2p_llc_hdr; //! \todo
std::vector<unsigned char> _mac_src; //! Used to optimize filtering on source mac address in \see commsignia_layer::receive_data method
std::vector<unsigned char> _eth_type; //! Used to optimize filtering on ethernet type in \see commsignia_layer::receive_data method
//! Fixed header for packet injection
static unsigned char _fixed_header[12];
public:
//! \publicsection
......
......@@ -80,11 +80,12 @@ int http_codec::decode (const OCTETSTRING& data, LibItsHttp__TypesAndValues::Htt
response.statuscode() = std::stoi(m[3].str().c_str());
response.statustext() = CHARSTRING(m[4].str().c_str());
LibItsHttp__TypesAndValues::HeaderLines headers;
decode_headers(decoding_buffer, headers);
std::string content_type;
decode_headers(decoding_buffer, headers, content_type);
response.header() = headers;
loggers::get_instance().log_to_hexa("Before decoding Body: ", decoding_buffer);
LibItsHttp__MessageBodyTypes::HttpMessageBody body;
if (decode_body(decoding_buffer, body, std::string("application/x-its-request"/*TODO Add Content-Type*/)) == -1) {
if (decode_body(decoding_buffer, body, content_type) == -1) {
response.body().set_to_omit();
} else {
response.body() = OPTIONAL<LibItsHttp__MessageBodyTypes::HttpMessageBody>(body);
......@@ -104,11 +105,12 @@ int http_codec::decode (const OCTETSTRING& data, LibItsHttp__TypesAndValues::Htt
request.version__major() = std::stoi(m[3].str().c_str());
request.version__minor() = std::stoi(m[4].str().c_str());
LibItsHttp__TypesAndValues::HeaderLines headers;
decode_headers(decoding_buffer, headers);
std::string content_type;
decode_headers(decoding_buffer, headers, content_type);
request.header() = headers;
OPTIONAL<LibItsHttp__MessageBodyTypes::HttpMessageBody> body;
body.set_to_omit();
if (decode_body(decoding_buffer, body, std::string("application/x-its-request"/*TODO Add Content-Type*/)) == -1) {
if (decode_body(decoding_buffer, body, content_type) == -1) {
request.body().set_to_omit();
} else {
request.body() = body;
......@@ -156,7 +158,7 @@ int http_codec::encode_request(const LibItsHttp__TypesAndValues::Request& p_requ
if (v.size_of() > 0) {
loggers::get_instance().log_msg("http_codec::encode_request: Processing value ", v[0]);
if (std::string(static_cast<const char*>(header.header__name())).compare("Content-Type") == 0) { // Store it for HTTP body payload encoding
loggers::get_instance().log("http_codec::encode_request: Storing Content-Yype");
loggers::get_instance().log("http_codec::encode_request: Storing Content-Type");
int j = 0;
while (j < v.size_of()) {
content_type += v[j++];
......@@ -213,7 +215,7 @@ int http_codec::encode_request(const LibItsHttp__TypesAndValues::Request& p_requ
if (_ec.is_content_length_present == 0x01) {
loggers::get_instance().log_msg("http_codec::encode_request: Add body ", os);
p_encoding_buffer.put_os(os);
p_encoding_buffer.put_cs("\r\n");
//FIXME For test With GEMALTO, comment to be removed, p_encoding_buffer.put_cs("\r\n");
}
loggers::get_instance().log_to_hexa("<<< http_codec::encode_request: ", p_encoding_buffer);
......@@ -312,7 +314,7 @@ int http_codec::encode_response (const LibItsHttp__TypesAndValues::Response& p_r
return 0;
}
int http_codec::decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAndValues::HeaderLines& headers) {
int http_codec::decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAndValues::HeaderLines& headers, std::string& p_content_type) {
loggers::get_instance().log(">>> http_codec::decode_headers");
loggers::get_instance().log_to_hexa("http_codec::decode_headers", decoding_buffer);
......@@ -328,6 +330,14 @@ int http_codec::decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAn
return -1;
}
headers[i++] = header;
if (std::string(static_cast<const char*>(header.header__name())).compare("Content-Type") == 0) {
if (header.header__value().is_present() != 0) {
const PreGenRecordOf::PREGEN__RECORD__OF__CHARSTRING& l = static_cast<const PreGenRecordOf::PREGEN__RECORD__OF__CHARSTRING&>(*header.header__value().get_opt_value());
p_content_type = static_cast<const char*>(l[0]);
} else {
p_content_type = "";
}
}
}
break;
case 1:
......@@ -403,16 +413,6 @@ int http_codec::encode_body(const LibItsHttp__MessageBodyTypes::HttpMessageBody&
if (it != _codecs.cend()) {
loggers::get_instance().log("http_codec::encode_body: Call '%s'", it->first.c_str());
_codecs["http_its"]->encode((Record_Type&)binary_body.ieee1609dot2__data(), p_encoding_buffer); // TODO Use params
#if defined(GEMALTO_FIX) // Temporary fix to be removed
// GEMALTO Encode in hex string
CHARSTRING buf = oct2str(p_encoding_buffer);
p_encoding_buffer = OCTETSTRING(buf.lengthof(), (const unsigned char*)(static_cast<const char*>(buf)));
loggers::get_instance().log_msg("http_codec::encode_body: Convert binary to string: ", p_encoding_buffer);
#endif
processed = true;
}
} // TODO Add new HTTP message codec here
......@@ -482,16 +482,7 @@ int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBod
OCTETSTRING s(decoding_buffer.get_len() - decoding_buffer.get_pos(), decoding_buffer.get_data() + decoding_buffer.get_pos());
loggers::get_instance().log_msg("http_codec::decode_body: raw body=", s);
#if defined(GEMALTO_FIX) // Temporary fix to be removed
// GEMALTO Encode in hex string
if ((s.lengthof() & 0x00000001) == 0x00000001) {
s = int2oct(0, 1) + s;
}
s = str2oct(CHARSTRING(s.lengthof(), (const char*)(static_cast<const unsigned char*>(s))));
loggers::get_instance().log_msg("http_codec::decode_body: Convert string to binary: ", s);
#endif
// Align the payload length with the specified Content-lenght value
// Align the payload length with the specified Content-Lenght value
loggers::get_instance().log("http_codec::decode_body: _dc.length=%d - body length=%d", _dc.length, s.lengthof());
OCTETSTRING body;
if (_dc.length != 0) {
......@@ -515,6 +506,7 @@ int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBod
}
}
loggers::get_instance().log("http_codec::decode_body: counter=%d", counter);
loggers::get_instance().log("http_codec::decode_body: body length=%d", body.lengthof());
body = OCTETSTRING(body.lengthof() - counter, static_cast<const unsigned char*>(body));
if (_dc.chunked){
counter = 0;
......@@ -612,7 +604,10 @@ int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBod
loggers::get_instance().log("http_codec::decode_body: Find xml message");
LibItsHttp__XmlMessageBodyTypes::XmlBody xml_body;
// TODO To be refined adding a string identifier to check which codec to use. E.g. held_code.id() returns "xmlns=\"urn:ietf:params:xml:ns:geopriv:held\">"
if (p["decode_str"].find("xmlns=\"urn:ietf:params:xml:ns:geopriv:held\"") != std::string::npos) {
if (
(p["decode_str"].find("=\"urn:ietf:params:xml:ns:geopriv:held\"") != std::string::npos) ||
(p["decode_str"].find("=\"urn:ietf:params:xml:ns:pidf\"") != std::string::npos)
) {
loggers::get_instance().log("http_codec::decode_body: Find 'urn:ietf:params:xml:ns:geopriv:held'");
if (_codecs["held"].get() != nullptr) {
loggers::get_instance().log("http_codec::decode_body: Call 'held_codec'");
......@@ -628,7 +623,7 @@ int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBod
xml_body.raw() = CHARSTRING(body.lengthof(), (char*)static_cast<const unsigned char*>(body));
}
message_body.xml__body() = xml_body;
} else if (p["decode_str"].find("xmlns=\"urn:ietf:params:xml:ns:lost1\"") != std::string::npos) {
} else if (p["decode_str"].find("=\"urn:ietf:params:xml:ns:lost1\"") != std::string::npos) {
loggers::get_instance().log("http_codec::decode_body: Find 'urn:ietf:params:xml:ns:lost1'");
if (_codecs["lost"].get() != nullptr) {
loggers::get_instance().log("http_codec::decode_body: Call 'lost_codec'");
......
......@@ -59,7 +59,7 @@ private:
int encode_response (const LibItsHttp__TypesAndValues::Response& p_response, TTCN_Buffer& p_encoding_buffer);
int encode_body(const LibItsHttp__MessageBodyTypes::HttpMessageBody& p_message_body, OCTETSTRING& p_encoding_buffer, const std::string& p_content_type);
int decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAndValues::HeaderLines& headers);
int decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAndValues::HeaderLines& headers, std::string& p_content_type);
int decode_header(CHARSTRING& header_line, LibItsHttp__TypesAndValues::HeaderLine& header);
int decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBodyTypes::HttpMessageBody& message_body, const std::string& p_content_type);
int get_line(TTCN_Buffer& buffer, CHARSTRING& to, const bool concatenate_header_lines = false);
......
......@@ -171,9 +171,9 @@ void* pcap_offline_layer::thread() {
if(lh.ts.tv_sec|lh.ts.tv_usec){
long diff = timeval_diff(pkt_header->ts, lh.ts);
if(diff > 0) {
// fprintf(stderr,"<<< pcap_offline_layer::run: Wait %d msec", diff);
loggers::get_instance().log("<<< pcap_offline_layer::run: Wait %d msec", diff);
std::this_thread::sleep_for(std::chrono::milliseconds(diff));
// fprintf(stderr,"<<< pcap_offline_layer::run: Wait done");
loggers::get_instance().log("<<< pcap_offline_layer::run: Wait done");
}
}
}
......
......@@ -17,11 +17,11 @@
certificates_loader * certificates_loader::instance = nullptr;
certificates_loader::certificates_loader(): _certificateExt{".oer"}, _privateKeyExt{".vkey"}, _privateEncKeyExt{".ekey"}, _full_path(), _is_cache_initialized{false}, _directory_filter{".svn", "._.DS_Store", ".DS_Store"} {
loggers::get_instance().log(">>> certificates_loader::certificates_loader");
//loggers::get_instance().log(">>> certificates_loader::certificates_loader");
} // End of ctor
int certificates_loader::build_path(const std::string& p_root_directory) {
loggers::get_instance().log(">>> certificates_loader::build_path: '%s'", p_root_directory.c_str());
//loggers::get_instance().log(">>> certificates_loader::build_path: '%s'", p_root_directory.c_str());
// Build full path
if (!p_root_directory.empty()) {
......@@ -38,7 +38,7 @@ int certificates_loader::build_path(const std::string& p_root_directory) {
_full_path = "./";
}
std::experimental::filesystem::canonical(_full_path);
loggers::get_instance().log("certificates_loader::build_path: full path: %s", _full_path.string().c_str());
//loggers::get_instance().log("certificates_loader::build_path: full path: %s", _full_path.string().c_str());
if (!std::experimental::filesystem::exists(_full_path)) {
loggers::get_instance().warning("certificates_loader::build_path: Invalid path");
_full_path.clear();
......@@ -49,7 +49,7 @@ int certificates_loader::build_path(const std::string& p_root_directory) {
} // End of method build_path
int certificates_loader::load_certificates(std::map<std::string, std::unique_ptr<security_db_record> >& p_certificates, std::map<OCTETSTRING/*std::vector<unsigned char>*/, std::string, security_cache_comp>& p_hashed_id8s) {
loggers::get_instance().log(">>> certificates_loader::load_certificates");
//loggers::get_instance().log(">>> certificates_loader::load_certificates");
// Sanity check
if (_is_cache_initialized) {
......@@ -74,7 +74,7 @@ int certificates_loader::load_certificates(std::map<std::string, std::unique_ptr
} // End of method load_certificates
int certificates_loader::retrieve_certificates_list(std::set<std::experimental::filesystem::path>& p_files) {
loggers::get_instance().log(">>> certificates_loader::retrieve_certificates_list");
//loggers::get_instance().log(">>> certificates_loader::retrieve_certificates_list");
// Walk through directories
std::set<std::experimental::filesystem::path> folders;
......@@ -104,13 +104,13 @@ int certificates_loader::retrieve_certificates_list(std::set<std::experimental::
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());
if (it.path().extension().string().compare(_certificateExt) == 0) {
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;
......@@ -120,7 +120,7 @@ int certificates_loader::retrieve_certificates_list(std::set<std::experimental::
} // End of method retrieve_certificates_list
int certificates_loader::build_certificates_cache(std::set<std::experimental::filesystem::path>& p_files, std::map<std::string, std::unique_ptr<security_db_record> >& p_certificates, std::map<OCTETSTRING/*std::vector<unsigned char>*/, std::string, security_cache_comp>& p_hashed_id8s) {
loggers::get_instance().log(">>> certificates_loader::build_certificates_cache");
//loggers::get_instance().log(">>> certificates_loader::build_cer