Commit b0371c51 authored by garciay's avatar garciay
Browse files

STF545: Execute tests TC_SEC_PKI_SND_EA_BV_01 & TC_SEC_PKI_SND_EA_BV_02

parent 8e68875c
......@@ -12,6 +12,8 @@
#include "LibItsHttp_MessageBodyTypes.hh"
#include "LibItsHttp_XmlMessageBodyTypes.hh"
#include "http_etsi_ieee1609dot2_codec.hh" // FIXME Work-around, to be removed
int http_codec::encode (const LibItsHttp__TypesAndValues::HttpMessage& msg, OCTETSTRING& data)
{
loggers::get_instance().log_msg(">>> http_codec::encode: ", (const Base_Type&)msg);
......@@ -375,7 +377,6 @@ int http_codec::decode_header(CHARSTRING& header_line, LibItsHttp__TypesAndValue
int http_codec::encode_body(const LibItsHttp__MessageBodyTypes::HttpMessageBody& p_message_body, OCTETSTRING& p_encoding_buffer, const std::string& p_content_type) {
loggers::get_instance().log_msg(">>> http_codec::encode_body: ", (const Base_Type&)p_message_body);
loggers::get_instance().log("http_codec::encode_body: # of codecs=%d - %p", _codecs.size(), this);
// Sanity check
if (p_content_type.empty()) {
......@@ -390,11 +391,13 @@ int http_codec::encode_body(const LibItsHttp__MessageBodyTypes::HttpMessageBody&
} else {
std::map<std::string, std::unique_ptr<codec<Record_Type, Record_Type> > >::const_iterator it;
bool processed = false;
loggers::get_instance().log("http_codec::encode_body: # of codecs=%d - %p", _codecs.size(), this);
if (p_content_type.find("x-its") != std::string::npos) {
loggers::get_instance().log("http_codec::encode_body: Find x-its");
it = _codecs.find("http_its"); // TODO Use params
if (it != _codecs.cend()) {
loggers::get_instance().log("http_codec::encode_body: Call 'http_etsi_ieee1609dot2_codec'");
_codecs["http_its"]->encode((Record_Type&)binary_body, p_encoding_buffer); // TODO Use params
_codecs["http_its"]->encode((Record_Type&)binary_body.ieee1609dot2__data(), p_encoding_buffer); // TODO Use params
processed = true;
}
} // TODO Add new HTTP message codec here
......@@ -451,7 +454,6 @@ int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBod
loggers::get_instance().log(">>> http_codec::decode_body");
loggers::get_instance().log_to_hexa("http_codec::decode_body", decoding_buffer);
loggers::get_instance().log("http_codec::decode_body: Content-Type=%s", p_content_type.c_str());
loggers::get_instance().log("http_codec::decode_body: # of codecs=%d - %p", _codecs.size(), this);
// Sanity checks
if (decoding_buffer.get_len() - decoding_buffer.get_pos() <= 0) {
......@@ -502,29 +504,34 @@ int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBod
loggers::get_instance().log("http_codec::decode_body: Binary mode: %x", _dc.is_binary);
LibItsHttp__MessageBodyTypes::HttpMessageBody v;
if (_dc.is_binary == 0x01) {
LibItsHttp__BinaryMessageBodyTypes::BinaryBody bb;
LibItsHttp__BinaryMessageBodyTypes::BinaryBody binary_body;
bool processed = false;
// 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_content_type.find("x-its") != std::string::npos) {
loggers::get_instance().log("http_codec::decode_body: Find 'x-its'");
/*std::for_each(
_codecs.cbegin(),
_codecs.cend(),
[](const std::pair<const std::string, std::unique_ptr<codec<Record_Type, Record_Type> > >& p)
{
loggers::get_instance().log("http_codec::decode_body: Key='%s', %p", p.first.c_str(), p.second.get());
}
);*/
if (_codecs["http_its"].get() != nullptr) { // TODO Use params
/***
FIXME:
This code generate a codedump, I don't undertsand the reason.
The same code works file for Ng112 HELD & LOST codec. Ununderstandable!!!!
==> Use a patch
if (_codecs["http_its"].get() != nullptr) {
loggers::get_instance().log("http_codec::decode_body: Call 'http_etsi_ieee1609dot2_codec'");
_codecs["http_its"]->decode(body, bb.ieee1609dot2__data());
if (_codecs["http_its"]->decode(body, (Record_Type&)binary_body) == 0) {
processed = true;
}
}*/
loggers::get_instance().log("http_codec::decode_body: Call 'http_etsi_ieee1609dot2_codec'");
http_etsi_ieee1609dot2_codec* codec = new http_etsi_ieee1609dot2_codec();
if (codec->decode(body, binary_body.ieee1609dot2__data()) == 0) {
message_body.binary__body() = binary_body;
processed = true;
}
delete codec;
} // TODO Add new HTTP message codec here
if (!processed) {
loggers::get_instance().warning("http_codec::decode_body: Unsupported HTTP codec, use raw field as default");
bb.raw() = body;
message_body.binary__body() = bb;
binary_body.raw() = body;
message_body.binary__body() = binary_body;
}
} else {
// Convert into string
......
......@@ -8,36 +8,31 @@
#include "loggers.hh"
int http_etsi_ieee1609dot2_codec::encode (const LibItsHttp__BinaryMessageBodyTypes::BinaryBody& p_binary_body, OCTETSTRING& p_data)
int http_etsi_ieee1609dot2_codec::encode (const IEEE1609dot2::Ieee1609Dot2Data& p_ieee_1609dot2_data, OCTETSTRING& p_data)
{
loggers::get_instance().log_msg(">>> http_etsi_ieee1609dot2_codec::encode: ", p_binary_body);
loggers::get_instance().log_msg(">>> http_etsi_ieee1609dot2_codec::encode: ", p_ieee_1609dot2_data);
if (p_binary_body.ischosen(LibItsHttp__BinaryMessageBodyTypes::BinaryBody::ALT_ieee1609dot2__data)) {
// Encode the Ieee1609Dot2Data
if (_codec.encode(p_binary_body.ieee1609dot2__data(), p_data) == -1) {
loggers::get_instance().warning("http_etsi_ieee1609dot2_codec::encode: Failed to encode InnerEcRequest");
return -1;
}
loggers::get_instance().log_msg("<<< http_etsi_ieee1609dot2_codec::encode: ", p_data);
return 0;
// Encode the Ieee1609Dot2Data
if (_codec.encode(p_ieee_1609dot2_data, p_data) == -1) {
loggers::get_instance().warning("http_etsi_ieee1609dot2_codec::encode: Failed to encode InnerEcRequest");
return -1;
}
loggers::get_instance().warning("http_etsi_ieee1609dot2_codec::encode: No codec found");
return -1;
loggers::get_instance().log_msg("<<< http_etsi_ieee1609dot2_codec::encode: ", p_data);
return 0;
}
int http_etsi_ieee1609dot2_codec::decode (const OCTETSTRING& p_data, LibItsHttp__BinaryMessageBodyTypes::BinaryBody& p_binary_body, params* p_params)
int http_etsi_ieee1609dot2_codec::decode (const OCTETSTRING& p_data, IEEE1609dot2::Ieee1609Dot2Data& p_ieee_1609dot2_data, params* p_params)
{
loggers::get_instance().log_msg(">>> http_etsi_ieee1609dot2_codec::decode: ", p_data);
/*if (p_binary_body.ischosen(LibItsHttp__BinaryMessageBodyTypes::BinaryBody::ALT_innerEcResponse)) {
return codec.decode(p_data, p_binary_body.innerEcResponse(), p_data);
}*/
loggers::get_instance().warning("http_etsi_ieee1609dot2_codec::decode: No codec found");
return -1;
if (_codec.decode(p_data, p_ieee_1609dot2_data, p_params) == -1) {
loggers::get_instance().warning("http_etsi_ieee1609dot2_codec::decode: Failed to decode data");
return -1;
}
loggers::get_instance().log_msg("<<< http_etsi_ieee1609dot2_codec::decode: ", p_ieee_1609dot2_data);
return 0;
}
http_etsi_ieee1609dot2_codec_factory http_etsi_ieee1609dot2_codec_factory::_f;
......@@ -8,13 +8,13 @@ namespace LibItsHttp__BinaryMessageBodyTypes {
class BinaryBody;
}
class http_etsi_ieee1609dot2_codec : public codec<LibItsHttp__BinaryMessageBodyTypes::BinaryBody, LibItsHttp__BinaryMessageBodyTypes::BinaryBody>
class http_etsi_ieee1609dot2_codec : public codec<IEEE1609dot2::Ieee1609Dot2Data, IEEE1609dot2::Ieee1609Dot2Data>
{
etsi_ts103097_data_codec _codec;
public:
explicit http_etsi_ieee1609dot2_codec() : codec<LibItsHttp__BinaryMessageBodyTypes::BinaryBody, LibItsHttp__BinaryMessageBodyTypes::BinaryBody>(), _codec() { };
explicit http_etsi_ieee1609dot2_codec() : codec<IEEE1609dot2::Ieee1609Dot2Data, IEEE1609dot2::Ieee1609Dot2Data>(), _codec() { };
virtual ~http_etsi_ieee1609dot2_codec() { };
virtual int encode (const LibItsHttp__BinaryMessageBodyTypes::BinaryBody& p_binary_body, OCTETSTRING& p_data);
virtual int decode (const OCTETSTRING& p_data, LibItsHttp__BinaryMessageBodyTypes::BinaryBody& p_binary_body, params* params = NULL);
virtual int encode (const IEEE1609dot2::Ieee1609Dot2Data& p_ieee_1609dot2_data, OCTETSTRING& p_data);
virtual int decode (const OCTETSTRING& p_data, IEEE1609dot2::Ieee1609Dot2Data& p_ieee_1609dot2_data, params* params = NULL);
};
......@@ -114,8 +114,8 @@ system.utPort.params := "UT_CAM/UDP(dst_ip=172.23.0.1,dst_port=8000)"
[EXECUTE]
#ItsPki_TestCases.TC_SEC_PKI_ITSS_ENR_BV_01
ItsPki_TestCases.TC_SEC_PKI_SND_EA_BV_01
#ItsPki_TestCases.TC_SEC_PKI_SND_EA_BV_02
#ItsPki_TestCases.TC_SEC_PKI_SND_EA_BV_01
ItsPki_TestCases.TC_SEC_PKI_SND_EA_BV_02
[MAIN_CONTROLLER]
# The options herein control the behavior of MC.
......
......@@ -252,7 +252,41 @@ module ItsPki_TestCases {
} // End of testcase f_TC_SEC_PKI_ITSS_ENR_BV_01_itss
function f_TC_SEC_PKI_ITSS_ENR_BV_01_pki(in charstring p_certificate_id) runs on ItsPki /*system ItsPkiItssSystem*/ {
LibItsPki_Functions.f_cfUp();
// Preamble
tc_ac.start;
alt {
[] pkiPort.receive(
mw_innerEcRequest
) {
log("*** " & testcasename() & ": INFO: InnerEcRequest received ***");
repeat;
}
[] pkiPort.receive(
mw_innerEcResponse_ok
) {
tc_ac.stop;
log("*** " & testcasename() & ": INFO: InnerEcResponse received ***");
f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
}
[] pkiPort.receive { // FIXME Use altstep
tc_ac.stop;
log("*** " & testcasename() & ": INCONC: Unexpected message received ***");
f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_timeout);
}
[] tc_ac.timeout {
log("*** " & testcasename() & ": INCONC: Expected message not received ***");
f_selfOrClientSyncAndVerdictTestBody(c_prDone, e_timeout);
}
} // End of 'alt' statement
// Test Body
log("*** " & testcasename() & ": PASS: Message triggered ***");
f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
// Postamble
LibItsPki_Functions.f_cfDown();
} // End of testcase f_TC_SEC_PKI_ITSS_ENR_BV_01_pki
} // End of f_TC_SEC_PKI_ITSS_ENR_BV_01
......@@ -326,7 +360,7 @@ module ItsPki_TestCases {
mw_innerEcResponse_ok
) {
tc_ac.stop;
log("*** " & testcasename() & ": PASS: InnerEcReponse received ***");
log("*** " & testcasename() & ": PASS: InnerEcResponse received ***");
f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
}
[] pkiPort.receive { // FIXME Use altstep
......@@ -387,11 +421,10 @@ module ItsPki_TestCases {
var Oct32 v_publicKeyY;
var Oct32 v_publicKeyCompressed;
var integer v_compressedMode;
var InnerEcRequest v_inner_ec_request;
var Ieee1609Dot2Data v_inner_ec_request_signed_for_pop;
var bitstring v_inner_ec_request_signed_for_pop_msg;
var Ieee1609Dot2Data v_ieee1609dot2_signed_and_encrypted_data;
var HeaderLines v_headers;
var HttpMessage v_response;
var EtsiTs102941Data v_etsi_ts_102941_data;
// Test control
if (not PICS_IUT_EA_ROLE) {
......@@ -406,27 +439,7 @@ module ItsPki_TestCases {
// Test adapter configuration
// Preamble
// Generate InnerEcRequest
// TODO f_build_enrolment_request(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode, v_ieee1609dot2_signed_and_encrypted_data);
if (f_generate_inner_ec_request(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode, v_inner_ec_request) == false) {
log("*** " & testcasename() & ": FAIL: Failed to setup InnerEcRequestPoP message ***")
f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_error);
stop;
}
// Generate InnerEcRequestSignedForPoP
if (f_generate_inner_ec_request_signed_for_pop(v_private_key, v_inner_ec_request, v_inner_ec_request_signed_for_pop) == false) {
log("*** " & testcasename() & ": FAIL: Failed to setup InnerEcRequestPoP message ***")
f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_error);
stop;
}
// Secure InnerEcRequestSignedForPoP message
v_inner_ec_request_signed_for_pop_msg := encvalue(m_etsiTs102941Data_inner_ec_request_signed_for_pop(v_inner_ec_request_signed_for_pop));
if (f_build_pki_secured_message(vc_eaPrivateKey, valueof(m_signerIdentifier_self), vc_eaHashedId8, v_publicKeyCompressed, v_compressedMode, bit2oct(v_inner_ec_request_signed_for_pop_msg), v_ieee1609dot2_signed_and_encrypted_data) == false) {
log("*** " & testcasename() & ": FAIL: Failed to seucure InnerEcRequestPoP message ***")
f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_error);
stop;
}
log("v_ieee1609dot2_signed_and_encrypted_data = ", v_ieee1609dot2_signed_and_encrypted_data);
f_http_build_enrolment_request(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode, v_ieee1609dot2_signed_and_encrypted_data);
f_init_default_headers_list(v_headers);
f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
......@@ -447,14 +460,26 @@ module ItsPki_TestCases {
mw_http_response_ok(
mw_http_message_body_binary(
mw_binary_body_ieee1609dot2_data(
mw_etsiTs103097Data_encrypted(
mw_encryptedData(
-,
mw_SymmetricCiphertext_aes128ccm
))))))) {
mw_enrolmentResponseMessage(
mw_encryptedData(
-,
mw_SymmetricCiphertext_aes128ccm
))))))) -> value v_response {
tc_ac.stop;
log("*** " & testcasename() & ": PASS: InnerEcReponse received ***");
f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
if (f_verify_pki_message(vc_eaPrivateEncKey, vc_eaPeerWholeHash, vc_eaCertificate, v_response.response.body.binary_body.ieee1609dot2_data, false, v_etsi_ts_102941_data) == false) {
log("*** " & testcasename() & ": FAIL: Failed to verify PKI message ***");
f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
} else {
log("*** " & testcasename() & ": LOG: Receive ", v_etsi_ts_102941_data, " ***");
if (not(match(v_etsi_ts_102941_data.content, mw_enrolmentResponse))) {
log("*** " & testcasename() & ": FAIL: Unexpected message received ***");
f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
} else {
log("*** " & testcasename() & ": PASS: InnerEcResponse received ***");
f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
}
}
}
[] httpPort.receive( // FIXME Use altstep
mw_http_response(
......
Subproject commit 2748f3acc66bbd563cb86df8d62b1bfab56e72d8
Subproject commit b8fe1ca2e826050cb7de7c354e5c15c27e0f68f0
......@@ -130,7 +130,7 @@ module TestCodec_Pki {
var bitstring v_dec_inner_ec_request_msg;
var bitstring v_tbs;
var Ieee1609Dot2Data v_ieee1609dot2_signed_and_encrypted_data;
var Ieee1609Dot2Data v_dec_ieee1609dot2_signed_and_encrypted_data;
var Ieee1609Dot2Data v_dec_ieee1609dot2_encrypted_and_signed_data;
var Ieee1609Dot2Data v_dec_ieee1609dot2_signed_data;
var bitstring v_ieee1609dot2_signed_and_encrypted_data_msg;
var integer v_result;
......@@ -165,11 +165,11 @@ module TestCodec_Pki {
setverdict(pass, "Encoded succeed");
// Decode encrypted InnerEcRequest
v_result := decvalue(v_ieee1609dot2_signed_and_encrypted_data_msg, v_dec_ieee1609dot2_signed_and_encrypted_data);
v_result := decvalue(v_ieee1609dot2_signed_and_encrypted_data_msg, v_dec_ieee1609dot2_encrypted_and_signed_data);
if (v_result == 0) {
log("Decoded message: ", v_dec_ieee1609dot2_signed_and_encrypted_data);
log("Decoded message: ", v_dec_ieee1609dot2_encrypted_and_signed_data);
setverdict(pass, "Decoded succeed");
if (match(v_dec_ieee1609dot2_signed_and_encrypted_data, v_ieee1609dot2_signed_and_encrypted_data)) {
if (match(v_dec_ieee1609dot2_encrypted_and_signed_data, v_ieee1609dot2_signed_and_encrypted_data)) {
setverdict(pass, "Decoded match succeed");
} else {
setverdict(fail, "Decoded match failed");
......@@ -181,7 +181,7 @@ module TestCodec_Pki {
}
// Decrypt InnerEcRequest
f_decrypt(v_private_key, v_dec_ieee1609dot2_signed_and_encrypted_data, v_dec_ieee1609dot2_signed_data);
f_decrypt(v_private_key, v_dec_ieee1609dot2_encrypted_and_signed_data, v_dec_ieee1609dot2_signed_data);
log("v_dec_ieee1609dot2_signed_data= ", v_dec_ieee1609dot2_signed_data);
// Verify signature
......@@ -400,7 +400,7 @@ module TestCodec_Pki {
var InnerEcResponse v_inner_ec_response;
var Ieee1609Dot2Data v_ieee1609dot2_signed_and_encrypted_data;
var bitstring v_ieee1609dot2_signed_and_encrypted_data_msg;
var Ieee1609Dot2Data v_dec_ieee1609dot2_signed_and_encrypted_data;
var Ieee1609Dot2Data v_dec_ieee1609dot2_encrypted_and_signed_data;
var Ieee1609Dot2Data v_dec_ieee1609dot2_signed_data;
var bitstring v_dec_inner_ec_response_msg;
var EtsiTs102941Data v_dec_inner_ec_response;
......@@ -490,11 +490,11 @@ module TestCodec_Pki {
setverdict(pass, "Encoded succeed");
// Decode encrypted InnerEcResponse
v_result := decvalue(v_ieee1609dot2_signed_and_encrypted_data_msg, v_dec_ieee1609dot2_signed_and_encrypted_data);
v_result := decvalue(v_ieee1609dot2_signed_and_encrypted_data_msg, v_dec_ieee1609dot2_encrypted_and_signed_data);
if (v_result == 0) {
log("Decoded message: ", v_dec_ieee1609dot2_signed_and_encrypted_data);
log("Decoded message: ", v_dec_ieee1609dot2_encrypted_and_signed_data);
setverdict(pass, "Decoded succeed");
if (match(v_dec_ieee1609dot2_signed_and_encrypted_data, v_ieee1609dot2_signed_and_encrypted_data)) {
if (match(v_dec_ieee1609dot2_encrypted_and_signed_data, v_ieee1609dot2_signed_and_encrypted_data)) {
setverdict(pass, "Decoded match succeed");
} else {
setverdict(fail, "Decoded match failed");
......@@ -506,7 +506,7 @@ module TestCodec_Pki {
}
// Decrypt InnerEcResponse
f_decrypt(v_private_enc_key_cert_ts_a_ea, v_dec_ieee1609dot2_signed_and_encrypted_data, v_dec_ieee1609dot2_signed_data);
f_decrypt(v_private_enc_key_cert_ts_a_ea, v_dec_ieee1609dot2_encrypted_and_signed_data, v_dec_ieee1609dot2_signed_data);
log("v_dec_ieee1609dot2_signed_data= ", v_dec_ieee1609dot2_signed_data);
// Verify signature
......
This diff is collapsed.
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