Loading ccsrc/Externals/LibItsSecurity_externals.cc +59 −31 Original line number Original line Diff line number Diff line Loading @@ -8,6 +8,8 @@ * All rights reserved. * All rights reserved. * \version 0.1 * \version 0.1 */ */ #include <memory> #include "LibItsSecurity_Functions.hh" #include "LibItsSecurity_Functions.hh" #include "sha256.hh" #include "sha256.hh" Loading Loading @@ -571,7 +573,9 @@ namespace LibItsSecurity__Functions * \return The original message * \return The original message */ */ OCTETSTRING fx__test__decrypt__aes__128__ccm__test(const OCTETSTRING& p__k, const OCTETSTRING& p__n, const OCTETSTRING& p__ct) { OCTETSTRING fx__test__decrypt__aes__128__ccm__test(const OCTETSTRING& p__k, const OCTETSTRING& p__n, const OCTETSTRING& p__ct) { loggers::get_instance().log(">>> fx__test__decrypt__aes__128__ccm__test"); loggers::get_instance().log_msg(">>> fx__test__decrypt__aes__128__ccm__test: p__k: ", p__k); loggers::get_instance().log_msg(">>> fx__test__decrypt__aes__128__ccm__test: p__n: ", p__n); loggers::get_instance().log_msg(">>> fx__test__decrypt__aes__128__ccm__test: p__ct: ", p__ct); security_ecc ec(ec_elliptic_curves::nist_p_256); security_ecc ec(ec_elliptic_curves::nist_p_256); // Extract the tag // Extract the tag Loading Loading @@ -608,46 +612,59 @@ namespace LibItsSecurity__Functions * \see http://digital.csic.es/bitstream/10261/32671/1/V2-I2-P7-13.pdf * \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 // TODO Use common function for both fx__encryptWithEciesxxx and fx__decryptWithEciesxxx function OCTETSTRING fx__encryptWithEciesNistp256WithSha256(const OCTETSTRING& p__toBeEncryptedSecuredMessage, const OCTETSTRING& p__recipientsPublicKeyCompressed, const INTEGER& p__compressedMode, const OCTETSTRING& p__salt, OCTETSTRING& p__publicEphemeralKeyCompressed, INTEGER& p__ephemeralCompressedMode, OCTETSTRING& p__encrypted__sym__key, OCTETSTRING& p__authentication__vector, OCTETSTRING& p__nonce) { OCTETSTRING fx__encryptWithEciesNistp256WithSha256(const OCTETSTRING& p__toBeEncryptedSecuredMessage, const OCTETSTRING& p__recipientsPublicKeyCompressed, const INTEGER& p__compressedMode, const OCTETSTRING& p__salt, OCTETSTRING& p__publicEphemeralKeyCompressed, INTEGER& p__ephemeralCompressedMode,OCTETSTRING& p__aes__sym__key, OCTETSTRING& p__encrypted__sym__key, OCTETSTRING& p__authentication__vector, OCTETSTRING& p__nonce, const BOOLEAN& p__use__hardcoded__values) { loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__toBeEncryptedSecuredMessage: ", p__toBeEncryptedSecuredMessage); loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__toBeEncryptedSecuredMessage: ", p__toBeEncryptedSecuredMessage); loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__recipientsPublicKeyCompressed", p__recipientsPublicKeyCompressed); loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__recipientsPublicKeyCompressed", p__recipientsPublicKeyCompressed); loggers::get_instance().log(">>> fx__encryptWithEciesNistp256WithSha256: p__compressedMode: %d", static_cast<int>(p__compressedMode)); loggers::get_instance().log(">>> fx__encryptWithEciesNistp256WithSha256: p__compressedMode: %d", static_cast<int>(p__compressedMode)); loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__salt", p__salt); loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__salt", p__salt); // 1. Generate new Private/Public Ephemeral key // 1. Generate new Private/Public Ephemeral key security_ecc ec(ec_elliptic_curves::nist_p_256); std::unique_ptr<security_ecc> ec; if (ec.generate() == -1) { if (!p__use__hardcoded__values) { ec.reset(new security_ecc(ec_elliptic_curves::nist_p_256)); if (ec->generate() == -1) { loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to generate ephemeral keys"); loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to generate ephemeral keys"); return OCTETSTRING(0, nullptr); return OCTETSTRING(0, nullptr); } } } else { ec.reset(new security_ecc(ec_elliptic_curves::nist_p_256, str2oct("EE9CC7FBD9EDECEA41F7C8BD258E8D2E988E75BD069ADDCA1E5A38E534AC6818"), str2oct("5AE3C8D9FE0B1FC7438F29417C240F8BF81C358EC1A4D0C6E98D8EDBCC714017"))); // Private/Public ephemeral keys } // 2. Generate and derive shared secret based on recipient's private keys // 2. Generate and derive shared secret based on recipient's private keys security_ecc ec_comp(ec_elliptic_curves::nist_p_256, p__recipientsPublicKeyCompressed, (static_cast<int>(p__compressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); security_ecc ec_comp(ec_elliptic_curves::nist_p_256, p__recipientsPublicKeyCompressed, (static_cast<int>(p__compressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__salt) == -1) { if (p__use__hardcoded__values) { ec_comp.symmetric_encryption_key(str2oct("A6342013D623AD6C5F6882469673AE33")); } if (ec->generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__salt) == -1) { loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to generate and derive secret key"); loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to generate and derive secret key"); return OCTETSTRING(0, nullptr); return OCTETSTRING(0, nullptr); } } // Set the AES symmetric key loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: AES symmetric key: ", ec->symmetric_encryption_key()); p__aes__sym__key = ec->symmetric_encryption_key(); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__aes__sym__key: ", p__aes__sym__key); // Set the encrypted symmetric key // Set the encrypted symmetric key loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: Symmetric encryption key: ", ec.symmetric_encryption_key()); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: Encrypted symmetric key: ", ec->encrypted_symmetric_key()); p__encrypted__sym__key = ec.encrypted_symmetric_key(); p__encrypted__sym__key = ec->encrypted_symmetric_key(); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); // Set the tag of the symmetric key encryption // Set the tag of the symmetric key encryption p__authentication__vector = ec.tag(); p__authentication__vector = ec->tag(); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__authentication__vector: ", p__authentication__vector); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__authentication__vector: ", p__authentication__vector); // Set ephemeral public keys // Set ephemeral public keys p__publicEphemeralKeyCompressed = ec.public_key_compressed(); p__publicEphemeralKeyCompressed = ec->public_key_compressed(); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__publicEphemeralKeyCompressed: ", p__publicEphemeralKeyCompressed); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: Ephemeral public compressed key: ", p__publicEphemeralKeyCompressed); p__ephemeralCompressedMode = (ec.public_key_compressed_mode() == ecc_compressed_mode::compressed_y_0) ? 0 : 1; p__ephemeralCompressedMode = (ec->public_key_compressed_mode() == ecc_compressed_mode::compressed_y_0) ? 0 : 1; loggers::get_instance().log("fx__encryptWithEciesNistp256WithSha256: p__ephemeralCompressedMode: %d", p__ephemeralCompressedMode); loggers::get_instance().log("fx__encryptWithEciesNistp256WithSha256: Ephemeral public compressed mode: %d: ", p__ephemeralCompressedMode); // 3. Retrieve AES 128 parameters // 3. Retrieve AES 128 parameters p__nonce = ec.nonce(); p__nonce = ec->nonce(); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__nonce: ", p__nonce); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__nonce: ", p__nonce); // 4. Encrypt the data using AES-128 CCM // 4. Encrypt the data using AES-128 CCM OCTETSTRING enc_message; OCTETSTRING enc_message; if (ec.encrypt(encryption_algotithm::aes_128_ccm, ec.symmetric_encryption_key(), ec.nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { if (ec->encrypt(encryption_algotithm::aes_128_ccm, ec->symmetric_encryption_key(), ec->nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to encrypt message"); loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to encrypt message"); return OCTETSTRING(0, nullptr); return OCTETSTRING(0, nullptr); } } enc_message += ec.tag(); enc_message += ec->tag(); loggers::get_instance().log_to_hexa("fx__encryptWithEciesNistp256WithSha256: enc message||Tag: ", enc_message); loggers::get_instance().log_to_hexa("fx__encryptWithEciesNistp256WithSha256: enc message||Tag: ", enc_message); return enc_message; return enc_message; Loading @@ -657,7 +674,7 @@ namespace LibItsSecurity__Functions * @desc Test function for ECIES NIST P-256 Encryption with SHA-256 * @desc Test function for ECIES NIST P-256 Encryption with SHA-256 * @remark For the purpose of testing, the content of p__toBeEncryptedSecuredMessage is the AES 128 symmetric key to be encrypted * @remark For the purpose of testing, the content of p__toBeEncryptedSecuredMessage is the AES 128 symmetric key to be encrypted */ */ OCTETSTRING fx__test__encryptWithEciesNistp256WithSha256(const OCTETSTRING& p__toBeEncryptedSecuredMessage, const OCTETSTRING& p__privateEphemeralKey, const OCTETSTRING& p__recipientPublicKeyX, const OCTETSTRING& p__recipientPublicKeyY, const OCTETSTRING& p__salt, OCTETSTRING& p__publicEphemeralKeyX, OCTETSTRING& p__publicEphemeralKeyY, OCTETSTRING& p__encrypted__sym__key, OCTETSTRING& p__authentication__vector, OCTETSTRING& p__nonce) { OCTETSTRING fx__test__encryptWithEciesNistp256WithSha256(const OCTETSTRING& p__toBeEncryptedSecuredMessage, const OCTETSTRING& p__privateEphemeralKey, const OCTETSTRING& p__recipientPublicKeyX, const OCTETSTRING& p__recipientPublicKeyY, const OCTETSTRING& p__salt, OCTETSTRING& p__publicEphemeralKeyX, OCTETSTRING& p__publicEphemeralKeyY, OCTETSTRING& p__aes__sym__key, OCTETSTRING& p__encrypted__sym__key, OCTETSTRING& p__authentication__vector, OCTETSTRING& p__nonce) { // 1. Generate new ephemeral Private/Public keys // 1. Generate new ephemeral Private/Public keys security_ecc ec(ec_elliptic_curves::nist_p_256, p__privateEphemeralKey); security_ecc ec(ec_elliptic_curves::nist_p_256, p__privateEphemeralKey); Loading @@ -674,8 +691,13 @@ namespace LibItsSecurity__Functions loggers::get_instance().warning("fx__test__encryptWithEciesNistp256WithSha256: Failed to generate and derive secret key"); loggers::get_instance().warning("fx__test__encryptWithEciesNistp256WithSha256: Failed to generate and derive secret key"); return OCTETSTRING(0, nullptr); return OCTETSTRING(0, nullptr); } } loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: symmetric_encryption_key: ", ec.symmetric_encryption_key()); // Set the AES symmetric key loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: AES symmetric key: ", ec.symmetric_encryption_key()); p__aes__sym__key = ec.symmetric_encryption_key(); loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: p__aes__sym__key: ", p__aes__sym__key); // Set the encrypted symmetric key // Set the encrypted symmetric key loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: Encrypted symmetric key: ", ec.encrypted_symmetric_key()); p__encrypted__sym__key = ec.encrypted_symmetric_key(); p__encrypted__sym__key = ec.encrypted_symmetric_key(); loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); // Set the tag of the symmetric key encryption // Set the tag of the symmetric key encryption Loading Loading @@ -747,7 +769,7 @@ namespace LibItsSecurity__Functions return message; return message; } } OCTETSTRING fx__encryptWithEciesBrainpoolp256WithSha256(const OCTETSTRING& p__toBeEncryptedSecuredMessage, const OCTETSTRING& p__recipientsPublicKeyCompressed, const INTEGER& p__compressedMode, OCTETSTRING& p__publicEphemeralKeyCompressed, INTEGER& p__ephemeralCompressedMode, OCTETSTRING& p__encrypted__sym__key, OCTETSTRING& p__authentication__vector, OCTETSTRING& p__nonce) { OCTETSTRING fx__encryptWithEciesBrainpoolp256WithSha256(const OCTETSTRING& p__toBeEncryptedSecuredMessage, const OCTETSTRING& p__recipientsPublicKeyCompressed, const INTEGER& p__compressedMode, OCTETSTRING& p__publicEphemeralKeyCompressed, INTEGER& p__ephemeralCompressedMode, OCTETSTRING& p__aes__sym__key, OCTETSTRING& p__encrypted__sym__key, OCTETSTRING& p__authentication__vector, OCTETSTRING& p__nonce) { loggers::get_instance().log_msg(">>> fx__encryptWithEciesBrainpoolp256WithSha256: p__toBeEncryptedSecuredMessage: ", p__toBeEncryptedSecuredMessage); loggers::get_instance().log_msg(">>> fx__encryptWithEciesBrainpoolp256WithSha256: p__toBeEncryptedSecuredMessage: ", p__toBeEncryptedSecuredMessage); loggers::get_instance().log_msg(">>> fx__encryptWithEciesBrainpoolp256WithSha256: p__recipientsPublicKeyCompressed: ", p__recipientsPublicKeyCompressed); loggers::get_instance().log_msg(">>> fx__encryptWithEciesBrainpoolp256WithSha256: p__recipientsPublicKeyCompressed: ", p__recipientsPublicKeyCompressed); loggers::get_instance().log(">>> fx__encryptWithEciesBrainpoolp256WithSha256: p__compressedMode: %d", static_cast<int>(p__compressedMode)); loggers::get_instance().log(">>> fx__encryptWithEciesBrainpoolp256WithSha256: p__compressedMode: %d", static_cast<int>(p__compressedMode)); Loading @@ -761,33 +783,39 @@ namespace LibItsSecurity__Functions // 2. Generate and derive shared secret // 2. Generate and derive shared secret security_ecc ec_comp(ec_elliptic_curves::brainpool_p_256_r1, p__recipientsPublicKeyCompressed, (static_cast<int>(p__compressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); security_ecc ec_comp(ec_elliptic_curves::brainpool_p_256_r1, p__recipientsPublicKeyCompressed, (static_cast<int>(p__compressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), OCTETSTRING(0, nullptr)) == -1) { if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), OCTETSTRING(0, nullptr)) == -1) { loggers::get_instance().warning(": Failed to generate and derive secret key"); loggers::get_instance().warning("fx__encryptWithEciesBrainpoolp256WithSha256: Failed to generate and derive secret key"); return OCTETSTRING(0, nullptr); return OCTETSTRING(0, nullptr); } } // Set the AES symmetric key loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256WithSha256: AES symmetric key: ", ec.symmetric_encryption_key()); p__aes__sym__key = ec.symmetric_encryption_key(); loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256WithSha256: p__aes__sym__key: ", p__aes__sym__key); // Set the encrypted symmetric key // Set the encrypted symmetric key loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256WithSha256: Symmetric encryption key: ", ec.symmetric_encryption_key()); p__encrypted__sym__key = ec.encrypted_symmetric_key(); p__encrypted__sym__key = ec.encrypted_symmetric_key(); loggers::get_instance().log_msg(": Encrypted symmetric key: ", p__encrypted__sym__key); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); // Set the tag of the symmetric key encryption // Set the tag of the symmetric key encryption p__authentication__vector = ec.tag(); p__authentication__vector = ec.tag(); loggers::get_instance().log_msg(": p__authentication__vector: ", p__authentication__vector); loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256WithSha256: p__authentication__vector: ", p__authentication__vector); // Set ephemeral public keys // Set ephemeral public keys p__publicEphemeralKeyCompressed = ec.public_key_compressed(); p__publicEphemeralKeyCompressed = ec.public_key_compressed(); loggers::get_instance().log_msg(": Ephemeral public compressed key: ", p__publicEphemeralKeyCompressed); loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256WithSha256: Ephemeral public compressed key: ", p__publicEphemeralKeyCompressed); p__ephemeralCompressedMode = (ec.public_key_compressed_mode() == ecc_compressed_mode::compressed_y_0) ? 0 : 1; p__ephemeralCompressedMode = (ec.public_key_compressed_mode() == ecc_compressed_mode::compressed_y_0) ? 0 : 1; loggers::get_instance().log(": Ephemeral public compressed mode: %d: ", p__ephemeralCompressedMode); loggers::get_instance().log("fx__encryptWithEciesBrainpoolp256WithSha256: Ephemeral public compressed mode: %d: ", p__ephemeralCompressedMode); // 3. Retrieve AES 128 parameters // 3. Retrieve AES 128 parameters p__nonce = ec.nonce(); p__nonce = ec.nonce(); loggers::get_instance().log_msg(": p__nonce: ", p__nonce); loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256WithSha256: p__nonce: ", p__nonce); OCTETSTRING enc_symm_key = ec.symmetric_encryption_key(); OCTETSTRING enc_symm_key = ec.symmetric_encryption_key(); loggers::get_instance().log_msg(": enc_symm_key: ", enc_symm_key); loggers::get_instance().log_msg(": enc_symm_key: ", enc_symm_key); // 4. Encrypt the data using AES-128 CCM // 4. Encrypt the data using AES-128 CCM OCTETSTRING enc_message; OCTETSTRING enc_message; if (ec.encrypt(encryption_algotithm::aes_128_ccm, ec.symmetric_encryption_key(), ec.nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { if (ec.encrypt(encryption_algotithm::aes_128_ccm, ec.symmetric_encryption_key(), ec.nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { loggers::get_instance().warning(": Failed to encrypt message"); loggers::get_instance().warning("fx__encryptWithEciesBrainpoolp256WithSha256: Failed to encrypt message"); return OCTETSTRING(0, nullptr); return OCTETSTRING(0, nullptr); } } enc_message += ec.tag(); enc_message += ec.tag(); loggers::get_instance().log_to_hexa(": enc message||Tag: ", enc_message); loggers::get_instance().log_to_hexa("fx__encryptWithEciesBrainpoolp256WithSha256: enc message||Tag: ", enc_message); return enc_message; return enc_message; } } Loading ccsrc/Framework/params.hh +1 −0 Original line number Original line Diff line number Diff line Loading @@ -79,6 +79,7 @@ public: //! \publicsection static const std::string& server; //! HTTP server address (e.g. www.etsi.org) static const std::string& server; //! HTTP server address (e.g. www.etsi.org) static const std::string& port; //! HTTP server port. Default: 80 static const std::string& port; //! HTTP server port. Default: 80 static const std::string& use_ssl; //! Set to 1 to use SSL to communicate with the HTTP server. Default: false static const std::string& use_ssl; //! Set to 1 to use SSL to communicate with the HTTP server. Default: false static const std::string& method; //! HTTP method type. Default: POST static const std::string& uri; //! HTTP URI value. Default: / static const std::string& uri; //! HTTP URI value. Default: / static const std::string& host; //! HTTP Host value. Default: 127.0.0.1 static const std::string& host; //! HTTP Host value. Default: 127.0.0.1 static const std::string& content_type; //! HTTP Content-type value. Default: application/text static const std::string& content_type; //! HTTP Content-type value. Default: application/text Loading ccsrc/Framework/src/params.cc +1 −0 Original line number Original line Diff line number Diff line Loading @@ -72,6 +72,7 @@ const std::string& params::interface_id = std::string("interface_id"); const std::string& params::server = std::string("server"); const std::string& params::server = std::string("server"); const std::string& params::port = std::string("port"); const std::string& params::port = std::string("port"); const std::string& params::use_ssl = std::string("use_ssl"); const std::string& params::use_ssl = std::string("use_ssl"); const std::string& params::method = std::string("method"); const std::string& params::uri = std::string("uri"); const std::string& params::uri = std::string("uri"); const std::string& params::host = std::string("host"); const std::string& params::host = std::string("host"); const std::string& params::content_type = std::string("content_type"); const std::string& params::content_type = std::string("content_type"); Loading ccsrc/Protocols/Http/http_codec.cc +3 −3 Original line number Original line Diff line number Diff line Loading @@ -477,15 +477,15 @@ 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()); 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); loggers::get_instance().log_msg("http_codec::decode_body: raw body=", s); #if !defined(GEMALTO_FIX) #if !defined(GEMALTO_FIX) // GEMALTO Encode in hex string // 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)))); 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); loggers::get_instance().log_msg("http_codec::decode_body: Convert string to binary: ", s); #endif #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()); loggers::get_instance().log("http_codec::decode_body: _dc.length=%d - body length=%d", _dc.length, s.lengthof()); OCTETSTRING body; OCTETSTRING body; Loading ccsrc/Protocols/Http/http_layer.cc +5 −1 Original line number Original line Diff line number Diff line Loading @@ -25,6 +25,10 @@ http_layer::http_layer(const std::string & p_type, const std::string & param) : if (it != _params.cend()) { if (it != _params.cend()) { _device_mode = (1 == converter::get_instance().string_to_int(it->second)); _device_mode = (1 == converter::get_instance().string_to_int(it->second)); } } it = _params.find(params::method); if (it == _params.cend()) { _params[params::method] = "POST"; } it = _params.find(params::uri); it = _params.find(params::uri); if (it == _params.cend()) { if (it == _params.cend()) { _params[params::uri] = "/"; _params[params::uri] = "/"; Loading Loading @@ -54,7 +58,7 @@ void http_layer::send_data(OCTETSTRING& data, params& params) { if (_device_mode) { // Need to build an HTTP packet if (_device_mode) { // Need to build an HTTP packet loggers::get_instance().log("http_layer::send_data: Build http layer"); loggers::get_instance().log("http_layer::send_data: Build http layer"); TTCN_Buffer buffer; TTCN_Buffer buffer; buffer.put_cs("GET"); buffer.put_cs(_params[params::method].c_str()); buffer.put_c(' '); buffer.put_c(' '); buffer.put_cs(_params[params::uri].c_str()); buffer.put_cs(_params[params::uri].c_str()); buffer.put_cs(" HTTP/1.1\r\n"); buffer.put_cs(" HTTP/1.1\r\n"); Loading Loading
ccsrc/Externals/LibItsSecurity_externals.cc +59 −31 Original line number Original line Diff line number Diff line Loading @@ -8,6 +8,8 @@ * All rights reserved. * All rights reserved. * \version 0.1 * \version 0.1 */ */ #include <memory> #include "LibItsSecurity_Functions.hh" #include "LibItsSecurity_Functions.hh" #include "sha256.hh" #include "sha256.hh" Loading Loading @@ -571,7 +573,9 @@ namespace LibItsSecurity__Functions * \return The original message * \return The original message */ */ OCTETSTRING fx__test__decrypt__aes__128__ccm__test(const OCTETSTRING& p__k, const OCTETSTRING& p__n, const OCTETSTRING& p__ct) { OCTETSTRING fx__test__decrypt__aes__128__ccm__test(const OCTETSTRING& p__k, const OCTETSTRING& p__n, const OCTETSTRING& p__ct) { loggers::get_instance().log(">>> fx__test__decrypt__aes__128__ccm__test"); loggers::get_instance().log_msg(">>> fx__test__decrypt__aes__128__ccm__test: p__k: ", p__k); loggers::get_instance().log_msg(">>> fx__test__decrypt__aes__128__ccm__test: p__n: ", p__n); loggers::get_instance().log_msg(">>> fx__test__decrypt__aes__128__ccm__test: p__ct: ", p__ct); security_ecc ec(ec_elliptic_curves::nist_p_256); security_ecc ec(ec_elliptic_curves::nist_p_256); // Extract the tag // Extract the tag Loading Loading @@ -608,46 +612,59 @@ namespace LibItsSecurity__Functions * \see http://digital.csic.es/bitstream/10261/32671/1/V2-I2-P7-13.pdf * \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 // TODO Use common function for both fx__encryptWithEciesxxx and fx__decryptWithEciesxxx function OCTETSTRING fx__encryptWithEciesNistp256WithSha256(const OCTETSTRING& p__toBeEncryptedSecuredMessage, const OCTETSTRING& p__recipientsPublicKeyCompressed, const INTEGER& p__compressedMode, const OCTETSTRING& p__salt, OCTETSTRING& p__publicEphemeralKeyCompressed, INTEGER& p__ephemeralCompressedMode, OCTETSTRING& p__encrypted__sym__key, OCTETSTRING& p__authentication__vector, OCTETSTRING& p__nonce) { OCTETSTRING fx__encryptWithEciesNistp256WithSha256(const OCTETSTRING& p__toBeEncryptedSecuredMessage, const OCTETSTRING& p__recipientsPublicKeyCompressed, const INTEGER& p__compressedMode, const OCTETSTRING& p__salt, OCTETSTRING& p__publicEphemeralKeyCompressed, INTEGER& p__ephemeralCompressedMode,OCTETSTRING& p__aes__sym__key, OCTETSTRING& p__encrypted__sym__key, OCTETSTRING& p__authentication__vector, OCTETSTRING& p__nonce, const BOOLEAN& p__use__hardcoded__values) { loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__toBeEncryptedSecuredMessage: ", p__toBeEncryptedSecuredMessage); loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__toBeEncryptedSecuredMessage: ", p__toBeEncryptedSecuredMessage); loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__recipientsPublicKeyCompressed", p__recipientsPublicKeyCompressed); loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__recipientsPublicKeyCompressed", p__recipientsPublicKeyCompressed); loggers::get_instance().log(">>> fx__encryptWithEciesNistp256WithSha256: p__compressedMode: %d", static_cast<int>(p__compressedMode)); loggers::get_instance().log(">>> fx__encryptWithEciesNistp256WithSha256: p__compressedMode: %d", static_cast<int>(p__compressedMode)); loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__salt", p__salt); loggers::get_instance().log_msg(">>> fx__encryptWithEciesNistp256WithSha256: p__salt", p__salt); // 1. Generate new Private/Public Ephemeral key // 1. Generate new Private/Public Ephemeral key security_ecc ec(ec_elliptic_curves::nist_p_256); std::unique_ptr<security_ecc> ec; if (ec.generate() == -1) { if (!p__use__hardcoded__values) { ec.reset(new security_ecc(ec_elliptic_curves::nist_p_256)); if (ec->generate() == -1) { loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to generate ephemeral keys"); loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to generate ephemeral keys"); return OCTETSTRING(0, nullptr); return OCTETSTRING(0, nullptr); } } } else { ec.reset(new security_ecc(ec_elliptic_curves::nist_p_256, str2oct("EE9CC7FBD9EDECEA41F7C8BD258E8D2E988E75BD069ADDCA1E5A38E534AC6818"), str2oct("5AE3C8D9FE0B1FC7438F29417C240F8BF81C358EC1A4D0C6E98D8EDBCC714017"))); // Private/Public ephemeral keys } // 2. Generate and derive shared secret based on recipient's private keys // 2. Generate and derive shared secret based on recipient's private keys security_ecc ec_comp(ec_elliptic_curves::nist_p_256, p__recipientsPublicKeyCompressed, (static_cast<int>(p__compressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); security_ecc ec_comp(ec_elliptic_curves::nist_p_256, p__recipientsPublicKeyCompressed, (static_cast<int>(p__compressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__salt) == -1) { if (p__use__hardcoded__values) { ec_comp.symmetric_encryption_key(str2oct("A6342013D623AD6C5F6882469673AE33")); } if (ec->generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), p__salt) == -1) { loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to generate and derive secret key"); loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to generate and derive secret key"); return OCTETSTRING(0, nullptr); return OCTETSTRING(0, nullptr); } } // Set the AES symmetric key loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: AES symmetric key: ", ec->symmetric_encryption_key()); p__aes__sym__key = ec->symmetric_encryption_key(); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__aes__sym__key: ", p__aes__sym__key); // Set the encrypted symmetric key // Set the encrypted symmetric key loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: Symmetric encryption key: ", ec.symmetric_encryption_key()); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: Encrypted symmetric key: ", ec->encrypted_symmetric_key()); p__encrypted__sym__key = ec.encrypted_symmetric_key(); p__encrypted__sym__key = ec->encrypted_symmetric_key(); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); // Set the tag of the symmetric key encryption // Set the tag of the symmetric key encryption p__authentication__vector = ec.tag(); p__authentication__vector = ec->tag(); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__authentication__vector: ", p__authentication__vector); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__authentication__vector: ", p__authentication__vector); // Set ephemeral public keys // Set ephemeral public keys p__publicEphemeralKeyCompressed = ec.public_key_compressed(); p__publicEphemeralKeyCompressed = ec->public_key_compressed(); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__publicEphemeralKeyCompressed: ", p__publicEphemeralKeyCompressed); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: Ephemeral public compressed key: ", p__publicEphemeralKeyCompressed); p__ephemeralCompressedMode = (ec.public_key_compressed_mode() == ecc_compressed_mode::compressed_y_0) ? 0 : 1; p__ephemeralCompressedMode = (ec->public_key_compressed_mode() == ecc_compressed_mode::compressed_y_0) ? 0 : 1; loggers::get_instance().log("fx__encryptWithEciesNistp256WithSha256: p__ephemeralCompressedMode: %d", p__ephemeralCompressedMode); loggers::get_instance().log("fx__encryptWithEciesNistp256WithSha256: Ephemeral public compressed mode: %d: ", p__ephemeralCompressedMode); // 3. Retrieve AES 128 parameters // 3. Retrieve AES 128 parameters p__nonce = ec.nonce(); p__nonce = ec->nonce(); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__nonce: ", p__nonce); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__nonce: ", p__nonce); // 4. Encrypt the data using AES-128 CCM // 4. Encrypt the data using AES-128 CCM OCTETSTRING enc_message; OCTETSTRING enc_message; if (ec.encrypt(encryption_algotithm::aes_128_ccm, ec.symmetric_encryption_key(), ec.nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { if (ec->encrypt(encryption_algotithm::aes_128_ccm, ec->symmetric_encryption_key(), ec->nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to encrypt message"); loggers::get_instance().warning("fx__encryptWithEciesNistp256WithSha256: Failed to encrypt message"); return OCTETSTRING(0, nullptr); return OCTETSTRING(0, nullptr); } } enc_message += ec.tag(); enc_message += ec->tag(); loggers::get_instance().log_to_hexa("fx__encryptWithEciesNistp256WithSha256: enc message||Tag: ", enc_message); loggers::get_instance().log_to_hexa("fx__encryptWithEciesNistp256WithSha256: enc message||Tag: ", enc_message); return enc_message; return enc_message; Loading @@ -657,7 +674,7 @@ namespace LibItsSecurity__Functions * @desc Test function for ECIES NIST P-256 Encryption with SHA-256 * @desc Test function for ECIES NIST P-256 Encryption with SHA-256 * @remark For the purpose of testing, the content of p__toBeEncryptedSecuredMessage is the AES 128 symmetric key to be encrypted * @remark For the purpose of testing, the content of p__toBeEncryptedSecuredMessage is the AES 128 symmetric key to be encrypted */ */ OCTETSTRING fx__test__encryptWithEciesNistp256WithSha256(const OCTETSTRING& p__toBeEncryptedSecuredMessage, const OCTETSTRING& p__privateEphemeralKey, const OCTETSTRING& p__recipientPublicKeyX, const OCTETSTRING& p__recipientPublicKeyY, const OCTETSTRING& p__salt, OCTETSTRING& p__publicEphemeralKeyX, OCTETSTRING& p__publicEphemeralKeyY, OCTETSTRING& p__encrypted__sym__key, OCTETSTRING& p__authentication__vector, OCTETSTRING& p__nonce) { OCTETSTRING fx__test__encryptWithEciesNistp256WithSha256(const OCTETSTRING& p__toBeEncryptedSecuredMessage, const OCTETSTRING& p__privateEphemeralKey, const OCTETSTRING& p__recipientPublicKeyX, const OCTETSTRING& p__recipientPublicKeyY, const OCTETSTRING& p__salt, OCTETSTRING& p__publicEphemeralKeyX, OCTETSTRING& p__publicEphemeralKeyY, OCTETSTRING& p__aes__sym__key, OCTETSTRING& p__encrypted__sym__key, OCTETSTRING& p__authentication__vector, OCTETSTRING& p__nonce) { // 1. Generate new ephemeral Private/Public keys // 1. Generate new ephemeral Private/Public keys security_ecc ec(ec_elliptic_curves::nist_p_256, p__privateEphemeralKey); security_ecc ec(ec_elliptic_curves::nist_p_256, p__privateEphemeralKey); Loading @@ -674,8 +691,13 @@ namespace LibItsSecurity__Functions loggers::get_instance().warning("fx__test__encryptWithEciesNistp256WithSha256: Failed to generate and derive secret key"); loggers::get_instance().warning("fx__test__encryptWithEciesNistp256WithSha256: Failed to generate and derive secret key"); return OCTETSTRING(0, nullptr); return OCTETSTRING(0, nullptr); } } loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: symmetric_encryption_key: ", ec.symmetric_encryption_key()); // Set the AES symmetric key loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: AES symmetric key: ", ec.symmetric_encryption_key()); p__aes__sym__key = ec.symmetric_encryption_key(); loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: p__aes__sym__key: ", p__aes__sym__key); // Set the encrypted symmetric key // Set the encrypted symmetric key loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: Encrypted symmetric key: ", ec.encrypted_symmetric_key()); p__encrypted__sym__key = ec.encrypted_symmetric_key(); p__encrypted__sym__key = ec.encrypted_symmetric_key(); loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); loggers::get_instance().log_msg("fx__test__encryptWithEciesNistp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); // Set the tag of the symmetric key encryption // Set the tag of the symmetric key encryption Loading Loading @@ -747,7 +769,7 @@ namespace LibItsSecurity__Functions return message; return message; } } OCTETSTRING fx__encryptWithEciesBrainpoolp256WithSha256(const OCTETSTRING& p__toBeEncryptedSecuredMessage, const OCTETSTRING& p__recipientsPublicKeyCompressed, const INTEGER& p__compressedMode, OCTETSTRING& p__publicEphemeralKeyCompressed, INTEGER& p__ephemeralCompressedMode, OCTETSTRING& p__encrypted__sym__key, OCTETSTRING& p__authentication__vector, OCTETSTRING& p__nonce) { OCTETSTRING fx__encryptWithEciesBrainpoolp256WithSha256(const OCTETSTRING& p__toBeEncryptedSecuredMessage, const OCTETSTRING& p__recipientsPublicKeyCompressed, const INTEGER& p__compressedMode, OCTETSTRING& p__publicEphemeralKeyCompressed, INTEGER& p__ephemeralCompressedMode, OCTETSTRING& p__aes__sym__key, OCTETSTRING& p__encrypted__sym__key, OCTETSTRING& p__authentication__vector, OCTETSTRING& p__nonce) { loggers::get_instance().log_msg(">>> fx__encryptWithEciesBrainpoolp256WithSha256: p__toBeEncryptedSecuredMessage: ", p__toBeEncryptedSecuredMessage); loggers::get_instance().log_msg(">>> fx__encryptWithEciesBrainpoolp256WithSha256: p__toBeEncryptedSecuredMessage: ", p__toBeEncryptedSecuredMessage); loggers::get_instance().log_msg(">>> fx__encryptWithEciesBrainpoolp256WithSha256: p__recipientsPublicKeyCompressed: ", p__recipientsPublicKeyCompressed); loggers::get_instance().log_msg(">>> fx__encryptWithEciesBrainpoolp256WithSha256: p__recipientsPublicKeyCompressed: ", p__recipientsPublicKeyCompressed); loggers::get_instance().log(">>> fx__encryptWithEciesBrainpoolp256WithSha256: p__compressedMode: %d", static_cast<int>(p__compressedMode)); loggers::get_instance().log(">>> fx__encryptWithEciesBrainpoolp256WithSha256: p__compressedMode: %d", static_cast<int>(p__compressedMode)); Loading @@ -761,33 +783,39 @@ namespace LibItsSecurity__Functions // 2. Generate and derive shared secret // 2. Generate and derive shared secret security_ecc ec_comp(ec_elliptic_curves::brainpool_p_256_r1, p__recipientsPublicKeyCompressed, (static_cast<int>(p__compressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); security_ecc ec_comp(ec_elliptic_curves::brainpool_p_256_r1, p__recipientsPublicKeyCompressed, (static_cast<int>(p__compressedMode) == 0) ? ecc_compressed_mode::compressed_y_0 : ecc_compressed_mode::compressed_y_1); if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), OCTETSTRING(0, nullptr)) == -1) { if (ec.generate_and_derive_ephemeral_key(encryption_algotithm::aes_128_ccm, ec_comp.public_key_x(), ec_comp.public_key_y(), OCTETSTRING(0, nullptr)) == -1) { loggers::get_instance().warning(": Failed to generate and derive secret key"); loggers::get_instance().warning("fx__encryptWithEciesBrainpoolp256WithSha256: Failed to generate and derive secret key"); return OCTETSTRING(0, nullptr); return OCTETSTRING(0, nullptr); } } // Set the AES symmetric key loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256WithSha256: AES symmetric key: ", ec.symmetric_encryption_key()); p__aes__sym__key = ec.symmetric_encryption_key(); loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256WithSha256: p__aes__sym__key: ", p__aes__sym__key); // Set the encrypted symmetric key // Set the encrypted symmetric key loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256WithSha256: Symmetric encryption key: ", ec.symmetric_encryption_key()); p__encrypted__sym__key = ec.encrypted_symmetric_key(); p__encrypted__sym__key = ec.encrypted_symmetric_key(); loggers::get_instance().log_msg(": Encrypted symmetric key: ", p__encrypted__sym__key); loggers::get_instance().log_msg("fx__encryptWithEciesNistp256WithSha256: p__encrypted__sym__key: ", p__encrypted__sym__key); // Set the tag of the symmetric key encryption // Set the tag of the symmetric key encryption p__authentication__vector = ec.tag(); p__authentication__vector = ec.tag(); loggers::get_instance().log_msg(": p__authentication__vector: ", p__authentication__vector); loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256WithSha256: p__authentication__vector: ", p__authentication__vector); // Set ephemeral public keys // Set ephemeral public keys p__publicEphemeralKeyCompressed = ec.public_key_compressed(); p__publicEphemeralKeyCompressed = ec.public_key_compressed(); loggers::get_instance().log_msg(": Ephemeral public compressed key: ", p__publicEphemeralKeyCompressed); loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256WithSha256: Ephemeral public compressed key: ", p__publicEphemeralKeyCompressed); p__ephemeralCompressedMode = (ec.public_key_compressed_mode() == ecc_compressed_mode::compressed_y_0) ? 0 : 1; p__ephemeralCompressedMode = (ec.public_key_compressed_mode() == ecc_compressed_mode::compressed_y_0) ? 0 : 1; loggers::get_instance().log(": Ephemeral public compressed mode: %d: ", p__ephemeralCompressedMode); loggers::get_instance().log("fx__encryptWithEciesBrainpoolp256WithSha256: Ephemeral public compressed mode: %d: ", p__ephemeralCompressedMode); // 3. Retrieve AES 128 parameters // 3. Retrieve AES 128 parameters p__nonce = ec.nonce(); p__nonce = ec.nonce(); loggers::get_instance().log_msg(": p__nonce: ", p__nonce); loggers::get_instance().log_msg("fx__encryptWithEciesBrainpoolp256WithSha256: p__nonce: ", p__nonce); OCTETSTRING enc_symm_key = ec.symmetric_encryption_key(); OCTETSTRING enc_symm_key = ec.symmetric_encryption_key(); loggers::get_instance().log_msg(": enc_symm_key: ", enc_symm_key); loggers::get_instance().log_msg(": enc_symm_key: ", enc_symm_key); // 4. Encrypt the data using AES-128 CCM // 4. Encrypt the data using AES-128 CCM OCTETSTRING enc_message; OCTETSTRING enc_message; if (ec.encrypt(encryption_algotithm::aes_128_ccm, ec.symmetric_encryption_key(), ec.nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { if (ec.encrypt(encryption_algotithm::aes_128_ccm, ec.symmetric_encryption_key(), ec.nonce(), p__toBeEncryptedSecuredMessage, enc_message) == -1) { loggers::get_instance().warning(": Failed to encrypt message"); loggers::get_instance().warning("fx__encryptWithEciesBrainpoolp256WithSha256: Failed to encrypt message"); return OCTETSTRING(0, nullptr); return OCTETSTRING(0, nullptr); } } enc_message += ec.tag(); enc_message += ec.tag(); loggers::get_instance().log_to_hexa(": enc message||Tag: ", enc_message); loggers::get_instance().log_to_hexa("fx__encryptWithEciesBrainpoolp256WithSha256: enc message||Tag: ", enc_message); return enc_message; return enc_message; } } Loading
ccsrc/Framework/params.hh +1 −0 Original line number Original line Diff line number Diff line Loading @@ -79,6 +79,7 @@ public: //! \publicsection static const std::string& server; //! HTTP server address (e.g. www.etsi.org) static const std::string& server; //! HTTP server address (e.g. www.etsi.org) static const std::string& port; //! HTTP server port. Default: 80 static const std::string& port; //! HTTP server port. Default: 80 static const std::string& use_ssl; //! Set to 1 to use SSL to communicate with the HTTP server. Default: false static const std::string& use_ssl; //! Set to 1 to use SSL to communicate with the HTTP server. Default: false static const std::string& method; //! HTTP method type. Default: POST static const std::string& uri; //! HTTP URI value. Default: / static const std::string& uri; //! HTTP URI value. Default: / static const std::string& host; //! HTTP Host value. Default: 127.0.0.1 static const std::string& host; //! HTTP Host value. Default: 127.0.0.1 static const std::string& content_type; //! HTTP Content-type value. Default: application/text static const std::string& content_type; //! HTTP Content-type value. Default: application/text Loading
ccsrc/Framework/src/params.cc +1 −0 Original line number Original line Diff line number Diff line Loading @@ -72,6 +72,7 @@ const std::string& params::interface_id = std::string("interface_id"); const std::string& params::server = std::string("server"); const std::string& params::server = std::string("server"); const std::string& params::port = std::string("port"); const std::string& params::port = std::string("port"); const std::string& params::use_ssl = std::string("use_ssl"); const std::string& params::use_ssl = std::string("use_ssl"); const std::string& params::method = std::string("method"); const std::string& params::uri = std::string("uri"); const std::string& params::uri = std::string("uri"); const std::string& params::host = std::string("host"); const std::string& params::host = std::string("host"); const std::string& params::content_type = std::string("content_type"); const std::string& params::content_type = std::string("content_type"); Loading
ccsrc/Protocols/Http/http_codec.cc +3 −3 Original line number Original line Diff line number Diff line Loading @@ -477,15 +477,15 @@ 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()); 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); loggers::get_instance().log_msg("http_codec::decode_body: raw body=", s); #if !defined(GEMALTO_FIX) #if !defined(GEMALTO_FIX) // GEMALTO Encode in hex string // 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)))); 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); loggers::get_instance().log_msg("http_codec::decode_body: Convert string to binary: ", s); #endif #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()); loggers::get_instance().log("http_codec::decode_body: _dc.length=%d - body length=%d", _dc.length, s.lengthof()); OCTETSTRING body; OCTETSTRING body; Loading
ccsrc/Protocols/Http/http_layer.cc +5 −1 Original line number Original line Diff line number Diff line Loading @@ -25,6 +25,10 @@ http_layer::http_layer(const std::string & p_type, const std::string & param) : if (it != _params.cend()) { if (it != _params.cend()) { _device_mode = (1 == converter::get_instance().string_to_int(it->second)); _device_mode = (1 == converter::get_instance().string_to_int(it->second)); } } it = _params.find(params::method); if (it == _params.cend()) { _params[params::method] = "POST"; } it = _params.find(params::uri); it = _params.find(params::uri); if (it == _params.cend()) { if (it == _params.cend()) { _params[params::uri] = "/"; _params[params::uri] = "/"; Loading Loading @@ -54,7 +58,7 @@ void http_layer::send_data(OCTETSTRING& data, params& params) { if (_device_mode) { // Need to build an HTTP packet if (_device_mode) { // Need to build an HTTP packet loggers::get_instance().log("http_layer::send_data: Build http layer"); loggers::get_instance().log("http_layer::send_data: Build http layer"); TTCN_Buffer buffer; TTCN_Buffer buffer; buffer.put_cs("GET"); buffer.put_cs(_params[params::method].c_str()); buffer.put_c(' '); buffer.put_c(' '); buffer.put_cs(_params[params::uri].c_str()); buffer.put_cs(_params[params::uri].c_str()); buffer.put_cs(" HTTP/1.1\r\n"); buffer.put_cs(" HTTP/1.1\r\n"); Loading