diff --git a/diag-client-lib/lib/boost-support/src/boost-support/server/tls/tls_server.cpp b/diag-client-lib/lib/boost-support/src/boost-support/server/tls/tls_server.cpp index ecd6c6c..afd1f5e 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/server/tls/tls_server.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/server/tls/tls_server.cpp @@ -26,7 +26,7 @@ class TlsServer::TlsServerImpl final { * @brief Type alias for secured tcp connection */ using TcpConnectionSecured = - connection::tcp::TcpConnection; + connection::tcp::TcpConnection; /** * @brief Constructs an instance of TcpServerImpl diff --git a/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_context.cpp b/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_context.cpp index bf0cc12..f7d2f5a 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_context.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_context.cpp @@ -118,8 +118,16 @@ auto ToOpenSslString(server::tls::Tls13CipherSuites cipher) noexcept -> std::str template auto ConvertCipherListToString(std::initializer_list ciphers) noexcept -> std::string { return std::accumulate(ciphers.begin(), ciphers.end(), std::string{}, - [](std::string const& result, CipherType const& cipher) { - return result + ':' + ToOpenSslString(cipher); + [](std::string const& result, CipherType const& cipher) -> std::string { + std::string calculated_ssl_string{}; + if (result.empty()) { + calculated_ssl_string.append(ToOpenSslString(cipher)); + } else { + calculated_ssl_string.append(result); + calculated_ssl_string.append(":"); + calculated_ssl_string.append(ToOpenSslString(cipher)); + } + return calculated_ssl_string; }); } } // namespace @@ -173,4 +181,4 @@ TlsContext::TlsContext(Tls13VersionServer server, std::string_view certificate_p } } // namespace tls } // namespace socket -} // namespace boost_support \ No newline at end of file +} // namespace boost_support diff --git a/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_socket.cpp b/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_socket.cpp index c99613c..7b7e687 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_socket.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_socket.cpp @@ -22,12 +22,33 @@ TlsSocket::TlsSocket(std::string_view local_ip_address, std::uint16_t local_port local_endpoint_{boost::asio::ip::make_address(local_ip_address), local_port_num} {} TlsSocket::TlsSocket(TlsSocket::TcpSocket tcp_socket, TlsContext &tls_context) noexcept - : ssl_stream_{std::move(tcp_socket), tls_context.GetContext()} {} + : ssl_stream_{std::move(tcp_socket), tls_context.GetContext()}, + local_endpoint_{} { + TcpErrorCodeType ec{}; + + // Perform TLS handshake + ssl_stream_.handshake(boost::asio::ssl::stream_base::server, ec); + + if (ec.value() == boost::system::errc::success) { + printf("Connected with %s encryption\n", SSL_get_cipher(ssl_stream_.native_handle())); + } else { + common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tls client handshake with host failed with error: " << ec.message(); + }); + } +} TlsSocket::TlsSocket(TlsSocket &&other) noexcept : ssl_stream_{std::move(other.ssl_stream_)}, local_endpoint_{std::move(other.local_endpoint_)} {} +TlsSocket &TlsSocket::operator=(TlsSocket &&other) noexcept { + ssl_stream_ = std::move(std::move(other.ssl_stream_)); + local_endpoint_ = std::move(other.local_endpoint_); + return *this; +} + TlsSocket::~TlsSocket() noexcept = default; core_type::Result TlsSocket::Open() noexcept { @@ -49,8 +70,8 @@ core_type::Result TlsSocket::Open() noexcept { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug( __FILE__, __LINE__, __func__, [this](std::stringstream &msg) { Tcp::endpoint const endpoint_{GetNativeTcpSocket().local_endpoint()}; - msg << "Tls Socket opened and bound to " - << "<" << endpoint_.address().to_string() << "," << endpoint_.port() << ">"; + msg << "Tls Socket opened and bound to " << "<" << endpoint_.address().to_string() + << "," << endpoint_.port() << ">"; }); result.EmplaceValue(); } else { @@ -83,8 +104,8 @@ core_type::Result TlsSocket::Connect( common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug( __FILE__, __LINE__, __func__, [this](std::stringstream &msg) { Tcp::endpoint const endpoint_{GetNativeTcpSocket().remote_endpoint()}; - msg << "Tls client socket connected to host " - << "<" << endpoint_.address().to_string() << "," << endpoint_.port() << ">"; + msg << "Tls socket connected to host " << "<" << endpoint_.address().to_string() << "," + << endpoint_.port() << ">"; }); // Perform TLS handshake ssl_stream_.handshake(boost::asio::ssl::stream_base::client, ec); @@ -140,8 +161,8 @@ core_type::Result TlsSocket::Transmit( common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug( __FILE__, __LINE__, __func__, [this](std::stringstream &msg) { Tcp::endpoint const endpoint_{GetNativeTcpSocket().remote_endpoint()}; - msg << "Tcp message sent to " - << "<" << endpoint_.address().to_string() << "," << endpoint_.port() << ">"; + msg << "Tcp message sent to " << "<" << endpoint_.address().to_string() << "," + << endpoint_.port() << ">"; }); result.EmplaceValue(); } else { @@ -194,8 +215,8 @@ core_type::Result TlsSocket::R endpoint_.address().to_string(), endpoint_.port(), std::move(rx_buffer))}; common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug( __FILE__, __LINE__, __func__, [endpoint_](std::stringstream &msg) { - msg << "Tcp Message received from " - << "<" << endpoint_.address().to_string() << "," << endpoint_.port() << ">"; + msg << "Tcp Message received from " << "<" << endpoint_.address().to_string() << "," + << endpoint_.port() << ">"; }); result.EmplaceValue(std::move(tcp_rx_message)); } else { diff --git a/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_socket.h b/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_socket.h index a4fda73..4ca598d 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_socket.h +++ b/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_socket.h @@ -87,9 +87,9 @@ class TlsSocket final { TlsSocket &operator=(const TlsSocket &other) noexcept = delete; /** - * @brief Deleted move assignment + * @brief Move assignment */ - TlsSocket &operator=(TlsSocket &&other) noexcept = delete; + TlsSocket &operator=(TlsSocket &&other) noexcept; /** * @brief Move constructor diff --git a/test/component/CMakeLists.txt b/test/component/CMakeLists.txt index cf943f7..0403873 100644 --- a/test/component/CMakeLists.txt +++ b/test/component/CMakeLists.txt @@ -11,12 +11,12 @@ add_executable(${PROJECT_NAME} ${MAIN} ${COMMON} ${TEST_SRCS} - ) +) # include directories target_include_directories(${PROJECT_NAME} PRIVATE "$" - ) +) target_link_libraries(${PROJECT_NAME} diag-client @@ -25,12 +25,16 @@ target_link_libraries(${PROJECT_NAME} utility-support GTest::gtest_main GTest::gmock_main - ) +) gtest_discover_tests(${PROJECT_NAME}) -# Copy the default config file -set(DEFAULT_CONFIG "etc/diag_client_config.json") +# Copy etc directory add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMENT "Copying file '${CMAKE_CURRENT_SOURCE_DIR}/${DEFAULT_CONFIG}' for '${PROJECT_BINARY_DIR}' to working directory..." - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/${DEFAULT_CONFIG} ${PROJECT_BINARY_DIR}/) + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_CURRENT_SOURCE_DIR}/etc $/etc) + +# Copy cert directory +add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_CURRENT_SOURCE_DIR}/cert $/cert) diff --git a/test/component/cert/.empty b/test/component/cert/.empty new file mode 100644 index 0000000..e69de29 diff --git a/test/component/cert/DiagClientLibRootCA.pem b/test/component/cert/DiagClientLibRootCA.pem new file mode 100644 index 0000000..91fe1db --- /dev/null +++ b/test/component/cert/DiagClientLibRootCA.pem @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDTzCCAjegAwIBAgIUazi2eSuhQxKyqFqooZwpjd63OGowDQYJKoZIhvcNAQEL +BQAwNzEWMBQGA1UEAwwNRGlhZ0NsaWVudExp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component/cert/DiagClientLibServer.key b/test/component/cert/DiagClientLibServer.key new file mode 100644 index 0000000..60bd1b3 --- /dev/null +++ b/test/component/cert/DiagClientLibServer.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC7bQbR/yFJPaOD +/SOjvM9BcXeAsDW+bcdDmZ26NytAMF3kAQitqDx9cfg9lt7ucatjEmkW1GwyK1wz +RyNtDYTfZSCatoV6SWsJ383PxgoguVuIK3vtvTo+qCw8T214xSDAVnxCeo5ZEu58 +hL2n/BuEHV9CgzCW3fN1Y35QkYJCxRj4PyjN+vgS+CGtvPznrJiMPCAgivU3vRKY +uIXZlPJ+1k8RksNZeBeG6QPvLZoMHr6Lrh4tAaIxC4YQkfHUOfXKDp/iElVbTs00 +mtZgYakc8Sqj40DDd/78GdwO4hME5TiorYjhPh/Wjre9h27NUcJsxPduU84DjPOG +HFGuttznAgMBAAECggEAXKnTKOjD+rN8T+nMAIx9RYRFSn0UHTGmRmBBEIttGT+w +c+Uk9sKKIZVC36RjVK0jSIiWJ2Dfm1A/teRyedyouFAFtigORv7calXZqeNmJ3as +795b15bqIIdB05GLdJ21ixJXPgDctuI6wZpZMB/fNMrWyYoV8EkMsJl/nnLKXZq9 +2ZDZ8wrmks9nyUcYGsue9/tp6kto7fykrqQugOJch+cul5dlj5k6jLrSxewbGSis +zWjpcMnz+EROWgaq9p3o2DdaBIrmr64RUegrPMdJaJDybUngMm246YLfZDQud86o +xcOQOesRCsbbLY6NQ2s1T8BIqveo/XekD2gVqux2FQKBgQD0AGJRIMdvWQG07uLC +yHIT8TasfM8nNnWNb9KedZ5FlMXjmyZ6OH85TDupDV8KigC1AeZwhktYC+zQlJ4n +AkS0+JI+V3aFwn9wgcntJ4rZ3n4r8W45RfuJlyHY27Z6iYwFSnbbSCaBCCTozL10 +LLsyE18Lg8T+WzRom4nTw/ZNvQKBgQDEpHCTpqMJwwFb3CNRo8me0d++4cG+kEXN +6KEoQpJVyAyZiMrnvyYxts0Cg0osZ9Q4QV/u5iIYTfkhpwEFuQsrpqBE1JzeKlyc +IX3UC05jQYsk2z83cCp6/INbYH44uC0c+T7oLd0CD+yWfVPr9KNHS01ex/IM5GxM +bY4+m3ZFcwKBgQDFUUIwpTdifjH5JW3PYtWN9vTlzBChf1LUy+chKbCSSFs3UpJt +KB8KMPHWJfADz9H+jsjRmmh3jT0299hlZ1o0lwd8zrIUPVNdojevRtjskxapZpZi +Tou5mrROcG9C7NSEutEfR1uL4RAoCtnyhvHi7vNflnHJ1+ur5Iwy6jfWaQKBgFfO +VbaYohSpzuGF2v+Jc25HqPFDPZAqPAFF7zBbCZzkRzwHqRLyd8ubJNAKcASEGG9G +QeAbQv43UxeDyyETD7neHZKena1WnSPakKUup0IK8mbyv7exjkZ8musimzoYg4x8 +f2qNkDJrielo7SBfjMk5BsNb5Ol81h8KjInIQXehAoGAYFfvtizkz3gybyOwkJaw +1GpVyeV9CwoHl5eOSOq/ihQwrRWgu5o8eleFMctmxriaBXjhvrx/S0mJqzxkNamY +m+Smp2l+p1CWcBhitBkXvZchkHqP9CffIM25uDuxQgv9MgLeLWkLsoa4a5gaBA/3 +G+CF9qI4OSvssvK1A/uHSRo= +-----END PRIVATE KEY----- diff --git a/test/component/cert/DiagClientLibServer.pem b/test/component/cert/DiagClientLibServer.pem new file mode 100644 index 0000000..75614cf --- /dev/null +++ b/test/component/cert/DiagClientLibServer.pem @@ -0,0 +1,22 @@ +-----BEGIN CERTIFICATE----- +MIIDrDCCApSgAwIBAgIUAbUEHaoKcAGrJC5pycdfw9V15MkwDQYJKoZIhvcNAQEL +BQAwNzEWMBQGA1UEAwwNRGlhZ0NsaWVudExpYjELMAkGA1UEBhMCREUxEDAOBgNV +BAcMB0JlcmxpbiAwHhcNMjQwODA4MTY0NjA0WhcNMjUwODA4MTY0NjA0WjBzMQsw +CQYDVQQGEwJERTELMAkGA1UECAwCQlcxDzANBgNVBAcMBk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nostic_message_test.cpp b/test/component/test_cases/diagnostic_message_test.cpp index 66d842f..8ae16b4 100644 --- a/test/component/test_cases/diagnostic_message_test.cpp +++ b/test/component/test_cases/diagnostic_message_test.cpp @@ -31,7 +31,7 @@ const std::uint16_t kDiagClientLogicalAddress{0x0001U}; // Diag Test Server logical address const std::uint16_t kDiagServerLogicalAddress{0xFA25U}; // Path to json file -constexpr std::string_view kDiagClientConfigPath{"diag_client_config.json"}; +constexpr std::string_view kDiagClientConfigPath{"./etc/diag_client_config.json"}; // Default routing activation type constexpr std::uint8_t kDoipRoutingActivationReqActTypeDefault{0x00U}; // Successful routing activation response code diff --git a/test/component/test_cases/routing_activation_test.cpp b/test/component/test_cases/routing_activation_test.cpp index 0bc504c..449f03a 100644 --- a/test/component/test_cases/routing_activation_test.cpp +++ b/test/component/test_cases/routing_activation_test.cpp @@ -31,7 +31,7 @@ const std::uint16_t kDiagClientLogicalAddress{0x0001U}; // Diag Test Server logical address const std::uint16_t kDiagServerLogicalAddress{0xFA25U}; // Path to json file -constexpr std::string_view kDiagClientConfigPath{"diag_client_config.json"}; +constexpr std::string_view kDiagClientConfigPath{"./etc/diag_client_config.json"}; // Default routing activation type constexpr std::uint8_t kDoipRoutingActivationReqActTypeDefault{0x00}; constexpr std::uint8_t kDoipRoutingActivationResCodeUnknownSa{0x00}; diff --git a/test/component/test_cases/tls_test.cpp b/test/component/test_cases/tls_test.cpp index 6044218..6af3ce3 100644 --- a/test/component/test_cases/tls_test.cpp +++ b/test/component/test_cases/tls_test.cpp @@ -34,11 +34,11 @@ constexpr std::string_view kTlsClientIpAddress{"172.16.25.127"}; // Tls client port number constexpr std::uint16_t kTlsClientTcpPortNum{3496U}; // Certificate path -constexpr std::string_view kCertificatePath{}; +constexpr std::string_view kServerCertificatePath{"./cert/DiagClientLibServer.pem"}; // Private key path -constexpr std::string_view kPrivateKeyPath{}; +constexpr std::string_view kServerPrivateKeyPath{"./cert/DiagClientLibServer.key"}; // CA certificate path -constexpr std::string_view kCACertificatePath{}; +constexpr std::string_view kCACertificatePath{"./cert/DiagClientLibRootCA.pem"}; /*! * @brief Test fixture to test tls 1.2 @@ -66,10 +66,10 @@ class Tls12Fixture : public component::ComponentTest { kTlsServerTcpPortNum, 1u, TlsServerVersion{ - {TlsServerCipherSuite::TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, - TlsServerCipherSuite ::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}}, - kCertificatePath, - kPrivateKeyPath}, + {TlsServerCipherSuite::TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, + TlsServerCipherSuite ::TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256}}, + kServerCertificatePath, + kServerPrivateKeyPath}, tls_server_{}, tls_client_{ kTlsClientIpAddress, kTlsClientTcpPortNum, kCACertificatePath, @@ -87,7 +87,74 @@ class Tls12Fixture : public component::ComponentTest { auto CreateServerWithExpectation(Functor expectation_functor) noexcept -> std::future { return std::async(std::launch::async, [this, expectation_functor = std::move(expectation_functor)]() { - std::optional server{tls_acceptor_.GetTlsServer()}; + std::optional server{ + tls_acceptor_.GetTlsServer()}; // blocks until client is connected + if (server.has_value()) { + tls_server_.emplace(std::move(server).value()); + tls_server_->Initialize(); + // Set Expectation + expectation_functor(); + } + return tls_server_.has_value(); + }); + } + + protected: + // Tls acceptor + TlsAcceptor tls_acceptor_; + // Tls Server + std::optional tls_server_; + // Tls client with Tls version 1.2 + TlsClient tls_client_; +}; + +/*! + * @brief Test fixture to test tls 1.3 + */ +class Tls13Fixture : public component::ComponentTest { + public: + // Type Alias of acceptor + using TlsAcceptor = boost_support::server::tls::TlsAcceptor13; + // Type Alias of server + using TlsServer = boost_support::server::tls::TlsServer; + // Type Alias of client + using TlsClient = boost_support::client::tls::TlsClient13; + // Type Alias of tls server cipher suites version 1.2 + using TlsServerCipherSuite = boost_support::server::tls::Tls13CipherSuites; + // Type Alias of tls server version + using TlsServerVersion = boost_support::server::tls::TlsVersion13; + // Type Alias of tls client cipher suites version 1.2 + using TlsClientCipherSuite = boost_support::client::tls::Tls13CipherSuites; + // Type Alias of tls client version + using TlsClientVersion = boost_support::client::tls::TlsVersion13; + + protected: + Tls13Fixture() + : tls_acceptor_{kTlsServerIpAddress, + kTlsServerTcpPortNum, + 1u, + TlsServerVersion{{TlsServerCipherSuite::TLS_AES_128_GCM_SHA256, + TlsServerCipherSuite ::TLS_AES_256_GCM_SHA384}}, + kServerCertificatePath, + kServerPrivateKeyPath}, + tls_server_{}, + tls_client_{kTlsClientIpAddress, kTlsClientTcpPortNum, kCACertificatePath, + TlsClientVersion{{TlsClientCipherSuite::TLS_AES_128_GCM_SHA256, + TlsClientCipherSuite::TLS_AES_256_GCM_SHA384}}} {} + + void SetUp() override { tls_client_.Initialize(); } + + void TearDown() override { + if (tls_server_.has_value()) { tls_server_->DeInitialize(); } + tls_client_.DeInitialize(); + } + + template + auto CreateServerWithExpectation(Functor expectation_functor) noexcept -> std::future { + return std::async(std::launch::async, + [this, expectation_functor = std::move(expectation_functor)]() { + std::optional server{ + tls_acceptor_.GetTlsServer()}; // blocks until client is connected if (server.has_value()) { tls_server_.emplace(std::move(server).value()); tls_server_->Initialize(); @@ -110,20 +177,22 @@ class Tls12Fixture : public component::ComponentTest { /** * @brief Verify that sending of data from tls client to server works. */ -TEST_F(Tls12Fixture, SendDataFromClientToServer) { +TEST_F(Tls13Fixture, SendDataFromClientToServer) { std::vector const kTestData{1u, 2u, 3u, 4u, 5u, 6u}; std::future is_server_created{CreateServerWithExpectation([this, &kTestData]() { + ASSERT_TRUE(tls_server_.has_value()); // Create expectation that Receive Handler is invoked with same data tls_server_->SetReadHandler([&kTestData](TlsServer::MessagePtr message) { EXPECT_THAT(kTestData, ::testing::ElementsAreArray(message->GetPayload())); }); })}; - ASSERT_TRUE(is_server_created.get()); // Try connecting to server and verify EXPECT_TRUE(tls_client_.ConnectToHost(kTlsServerIpAddress, kTlsServerTcpPortNum).HasValue()); EXPECT_TRUE(tls_client_.IsConnectedToHost()); + + ASSERT_TRUE(is_server_created.get()); // Send test data to tls server EXPECT_TRUE(tls_client_ .Transmit(std::make_unique(kTlsServerIpAddress, diff --git a/test/component/test_cases/vehicle_discovery_test.cpp b/test/component/test_cases/vehicle_discovery_test.cpp index 6bbdaef..ae8b6e5 100644 --- a/test/component/test_cases/vehicle_discovery_test.cpp +++ b/test/component/test_cases/vehicle_discovery_test.cpp @@ -29,7 +29,7 @@ constexpr std::string_view kDiagUdpAnotherUnicastIpAddress{"172.16.25.129"}; // Port number constexpr std::uint16_t kDiagUdpPortNum{13400u}; // Path to json file -constexpr std::string_view kDiagClientConfigPath{"diag_client_config.json"}; +constexpr std::string_view kDiagClientConfigPath{"./etc/diag_client_config.json"}; // Fixture to test Vehicle discovery functionality class VehicleDiscoveryFixture : public component::ComponentTest { diff --git a/tools/generate_tls_certificates.sh b/tools/generate_tls_certificates.sh index 1491bdf..5897373 100755 --- a/tools/generate_tls_certificates.sh +++ b/tools/generate_tls_certificates.sh @@ -9,16 +9,16 @@ DOMAIN=DiagClientLib mkdir openssl && cd openssl -# Create root CA & Private key +# Create root CA openssl req -x509 \ + -newkey rsa:2048 \ -sha256 -days 356 \ -nodes \ - -newkey rsa:2048 \ - -subj "/CN=${DOMAIN}/C=DE/L=San Fransisco" \ - -keyout rootCA.key -out rootCA.crt + -subj "/CN=${DOMAIN}/C=DE/L=Berlin " \ + -keyout ${DOMAIN}RootCAKey.key -out ${DOMAIN}RootCA.crt -# Create the Server Private Key -openssl genrsa -out ${DOMAIN}.key 2048 +# Create server private key +openssl genrsa -out ${DOMAIN}Server.key 2048 # Create Certificate Signing Request Configuration cat > csr.conf < cert.conf <