Commit 35eab6d1 authored by Yann Garcia's avatar Yann Garcia
Browse files

AtsPki validation: minor bugs fixed

parent be8628d9
#include "LibItsPki_EncdecDeclarations.hh"
#include "etsi_ts102941_data.hh"
#include "etsi_ts102941_data_codec.hh"
#include "etsi_ts102941_data_content_codec.hh"
#include "etsi_ts102941_types_enrolment_inner_request.hh"
#include "etsi_ts102941_types_enrolment_inner_response.hh"
#include "etsi_ts102941_types_authorization_inner_request.hh"
......@@ -15,7 +16,7 @@ namespace LibItsPki__EncdecDeclarations {
BITSTRING fx__enc__EtsiTs102941Data(const EtsiTs102941MessagesCa::EtsiTs102941Data& p_etsi_ts_102941_data) {
loggers::get_instance().log_msg(">>> fx__enc__EtsiTs102941Data: ", p_etsi_ts_102941_data);
etsi_ts102941_data codec;
etsi_ts102941_data_codec codec;
OCTETSTRING os;
if (codec.encode(p_etsi_ts_102941_data, os) == -1) {
loggers::get_instance().warning("fx__enc__EtsiTs102941Data: -1 result code was returned");
......@@ -28,7 +29,7 @@ namespace LibItsPki__EncdecDeclarations {
INTEGER fx__dec__EtsiTs102941Data(BITSTRING& b, EtsiTs102941MessagesCa::EtsiTs102941Data& p_etsi_ts_102941_data) {
loggers::get_instance().log_msg(">>> fx__dec__EtsiTs102941Data: ", b);
etsi_ts102941_data codec;
etsi_ts102941_data_codec codec;
OCTETSTRING is = bit2oct(b);
if (codec.decode(is, p_etsi_ts_102941_data) == -1) {
loggers::get_instance().warning("fx__dec__EtsiTs102941Data: -1 result code was returned");
......@@ -38,6 +39,32 @@ namespace LibItsPki__EncdecDeclarations {
return 0;
}
BITSTRING fx__enc__EtsiTs102941DataContent(const EtsiTs102941MessagesCa::EtsiTs102941DataContent& p_etsi_ts_102941_data_content) {
loggers::get_instance().log_msg(">>> fx__enc__EtsiTs102941DataContent: ", p_etsi_ts_102941_data_content);
etsi_ts102941_data_content_codec codec;
OCTETSTRING os;
if (codec.encode(p_etsi_ts_102941_data_content, os) == -1) {
loggers::get_instance().warning("fx__enc__EtsiTs102941DataContent: -1 result code was returned");
return int2bit(0, 1);
}
return oct2bit(os);
}
INTEGER fx__dec__EtsiTs102941DataContent(BITSTRING& b, EtsiTs102941MessagesCa::EtsiTs102941DataContent& p_etsi_ts_102941_data_content) {
loggers::get_instance().log_msg(">>> fx__dec__EtsiTs102941DataContent: ", b);
etsi_ts102941_data_content_codec codec;
OCTETSTRING is = bit2oct(b);
if (codec.decode(is, p_etsi_ts_102941_data_content) == -1) {
loggers::get_instance().warning("fx__dec__EtsiTs102941DataContent: -1 result code was returned");
return -1;
}
return 0;
}
BITSTRING fx__enc__InnerEcRequest(const EtsiTs102941TypesEnrolment::InnerEcRequest& p_inner_request) {
loggers::get_instance().log_msg(">>> fx_enc_InnerEcRequest: ", p_inner_request);
......
......@@ -82,7 +82,7 @@ void pki_layer::sendMsg(const EtsiTs102941TypesEnrolment::InnerEcResponse& p_inn
// Encode it
OCTETSTRING etsi_ts_103097_data_enc;
_codec_etsi_ts102941_data.encode(etsi_ts_102941_data, etsi_ts_103097_data_enc);
_codec_etsi_ts102941_data_codec.encode(etsi_ts_102941_data, etsi_ts_103097_data_enc);
if (!etsi_ts_103097_data_enc.is_bound()) {
loggers::get_instance().warning("pki_layer::sendMsg: Failed to encode InnerEcResponse");
}
......@@ -115,7 +115,7 @@ void pki_layer::sendMsg(const EtsiTs102941TypesAuthorizationValidation::Authoriz
// Encode it
OCTETSTRING etsi_ts_103097_data_enc;
_codec_etsi_ts102941_data.encode(etsi_ts_102941_data, etsi_ts_103097_data_enc);
_codec_etsi_ts102941_data_codec.encode(etsi_ts_102941_data, etsi_ts_103097_data_enc);
if (!etsi_ts_103097_data_enc.is_bound()) {
loggers::get_instance().warning("pki_layer::sendMsg: Failed to encode AuthorizationValidationRequest");
}
......@@ -153,7 +153,7 @@ void pki_layer::receive_data(OCTETSTRING& data, params& params)
// Try to extract EtsiTs102941Data
EtsiTs102941MessagesCa::EtsiTs102941Data etsi_ts_102941_data;
if (_codec_etsi_ts102941_data.decode(unsecured_payload, etsi_ts_102941_data) == -1) {
if (_codec_etsi_ts102941_data_codec.decode(unsecured_payload, etsi_ts_102941_data) == -1) {
// Try with EtsiTs103097Data-Signed
IEEE1609dot2::Ieee1609Dot2Data etsi_ts_1609dot2_data;
if (_codec.decode(unsecured_payload, etsi_ts_1609dot2_data) == -1) {
......
......@@ -19,7 +19,7 @@
#include "etsi_ts102941_types_authorization_validation_request.hh"
#include "etsi_ts102941_types_authorization_validation_response.hh"
#include "etsi_ts103097_data_codec.hh"
#include "etsi_ts102941_data.hh"
#include "etsi_ts102941_data_codec.hh"
namespace LibItsPki__TestSystem {
class PkiPort; //! Forward declaration of TITAN class
......@@ -45,7 +45,7 @@ class pki_layer : public t_layer<LibItsPki__TestSystem::PkiPort> {
etsi_ts102941_types_authorization_validation_request _etsi_ts102941_types_authorization_validation_request; // TODO Rename _codec_etsi_ts102941_types_authorization_validation_request
etsi_ts102941_types_authorization_validation_response _etsi_ts102941_types_authorization_validation_response; // TODO Rename _codec_etsi_ts102941_types_authorization_validation_response
etsi_ts103097_data_codec _codec; // TODO Rename _codec_etsi_ts103097_data_codec
etsi_ts102941_data _codec_etsi_ts102941_data;
etsi_ts102941_data_codec _codec_etsi_ts102941_data_codec;
std::unique_ptr<LibItsPki__TypesAndValues::AcSetSecurityData> _ac_set_security_data;
......@@ -56,7 +56,7 @@ public: //! \publicsection
* \param[in] p_type \todo
* \param[in] p_param \todo
*/
pki_layer() : t_layer(), _params(), _etsi_ts102941_types_enrolment_inner_request(), _etsi_ts102941_types_enrolment_inner_response(), _etsi_ts102941_types_authorization_validation_request(), _etsi_ts102941_types_authorization_validation_response(), _codec(), _codec_etsi_ts102941_data(), _ac_set_security_data(nullptr) { };
pki_layer() : t_layer(), _params(), _etsi_ts102941_types_enrolment_inner_request(), _etsi_ts102941_types_enrolment_inner_response(), _etsi_ts102941_types_authorization_validation_request(), _etsi_ts102941_types_authorization_validation_response(), _codec(), _codec_etsi_ts102941_data_codec(), _ac_set_security_data(nullptr) { };
/*!
* \brief Specialised constructor
* Create a new instance of the pki_layer class
......
#include "etsi_ts102941_data_content_codec.hh"
#include "loggers.hh"
int etsi_ts102941_data_content_codec::encode (const EtsiTs102941MessagesCa::EtsiTs102941DataContent& p_etsi_ts_10291_data_content, OCTETSTRING& p_data)
{
loggers::get_instance().log(">>> etsi_ts102941_data_content_codec::encode: %s", p_etsi_ts_10291_data_content.get_descriptor()->name);
BITSTRING b;
TTCN_EncDec::clear_error();
TTCN_Buffer buffer;
p_etsi_ts_10291_data_content.encode(*p_etsi_ts_10291_data_content.get_descriptor(), buffer, TTCN_EncDec::CT_OER);
p_data = OCTETSTRING(buffer.get_len(), buffer.get_data());
loggers::get_instance().log_msg("etsi_ts102941_data_content_codec::encode: ", p_data);
return 0;
}
int etsi_ts102941_data_content_codec::decode (const OCTETSTRING& p_data, EtsiTs102941MessagesCa::EtsiTs102941DataContent& p_etsi_ts_10291_data_content, params* p_params)
{
loggers::get_instance().log_msg(">>> etsi_ts102941_data_content_codec::decode: ", p_data);
TTCN_EncDec::clear_error();
TTCN_Buffer decoding_buffer(p_data);
// _params = params;
p_etsi_ts_10291_data_content.decode(*p_etsi_ts_10291_data_content.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_OER);
loggers::get_instance().log_msg("<<< etsi_ts102941_data_content_codec::decode: ", (const Base_Type&)p_etsi_ts_10291_data_content);
return 0;
}
#pragma once
#include "codec.hh"
#include "params.hh"
#include "EtsiTs102941MessagesCa.hh"
class etsi_ts102941_data_content_codec : public codec<EtsiTs102941MessagesCa::EtsiTs102941DataContent, EtsiTs102941MessagesCa::EtsiTs102941DataContent>
{
public:
explicit etsi_ts102941_data_content_codec() : codec<EtsiTs102941MessagesCa::EtsiTs102941DataContent, EtsiTs102941MessagesCa::EtsiTs102941DataContent>() { };
virtual ~etsi_ts102941_data_content_codec() { };
virtual int encode (const EtsiTs102941MessagesCa::EtsiTs102941DataContent& p_etsi_ts_10291_data_content, OCTETSTRING& p_data);
virtual int decode (const OCTETSTRING& p_data, EtsiTs102941MessagesCa::EtsiTs102941DataContent& p_etsi_ts_10291_data_content, params* p_params = NULL);
}; // End of class etsi_ts102941_data_content_codec
......@@ -334,7 +334,7 @@ system.pkiPort.params := "PKI/HTTP(device_mode=1,uri=/its/inner_ec_request,host=
#TestCodec_SignedAndEncryptedMessages.tc_test_encrypt_aes_128_ccm_test_1
#TestCodec_SignedAndEncryptedMessages.tc_test_encrypt_aes_128_ccm_test_2
#TestCodec_SignedAndEncryptedMessages.tc_test_encrypt_aes_128_ccm_test_3
TestCodec_SignedAndEncryptedMessages.tc_test_decrypt_aes_128_ccm_test_1
#TestCodec_SignedAndEncryptedMessages.tc_test_decrypt_aes_128_ccm_test_1
#TestCodec_SignedAndEncryptedMessages.tc_test_encryptWithEciesNistp256WithSha256_1
#TestCodec_SignedAndEncryptedMessages.tc_test_encryptWithEciesNistp256WithSha256_2
#TestCodec_SignedAndEncryptedMessages.tc_test_encryptWithEciesNistp256WithSha256_3
......@@ -346,6 +346,8 @@ TestCodec_SignedAndEncryptedMessages.tc_test_decrypt_aes_128_ccm_test_1
# External functions
#TestCodec_ExternalFunctions.tc_f_computePositionUsingDistance
# Pki
TestCodec_Pki.tc_encode_inner_ec_response_1
#TestCodec_Pki.tc_decode_inner_ec_response_1
#TestCodec_Pki.tc_inner_ec_request_1
#TestCodec_Pki.tc_inner_ec_request_2
#TestCodec_Pki.tc_inner_ec_request_3
......
Subproject commit d7fb38fe273bdf9835b7ef676efb1b2b91b34af1
Subproject commit 419abe762498812e1d5c8eccc7d90a397153be88
......@@ -57,6 +57,27 @@ module TestCodec_Pki {
// TestCodec
import from TestCodec_TestAndSystem all;
testcase tc_encode_inner_ec_response_1() runs on TCType system TCType {
var EtsiTs102941Data v_data;
var bitstring v_response := oct2bit('01810059E6B6C01C2FE2DB06DA5263544D981D02'O);
var integer v_result;
v_data := valueof(m_etsiTs102941Data_inner_ec_response(m_innerEcResponse_ko('59E6B6C01C2FE2DB06DA5263544D981D'O, badcontenttype)));
log("v_data= ", v_data);
v_response := encvalue(v_data);
setverdict(pass);
}
testcase tc_decode_inner_ec_response_1() runs on TCType system TCType {
var bitstring v_response := oct2bit('01810059E6B6C01C2FE2DB06DA5263544D981D02'O);
var EtsiTs102941Data v_data;
var integer v_result;
v_result := decvalue(v_response, v_data);
log("v_data= ", v_data);
setverdict(pass);
}
testcase tc_inner_ec_request_1() runs on TCType system TCType {
var integer v_res := 0;
......
Supports Markdown
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