From 8e01f42f6caa10a4df24d7c5f4da81187b07a3f7 Mon Sep 17 00:00:00 2001 From: Raphael Riebl Date: Mon, 12 Aug 2024 17:00:47 +0200 Subject: [PATCH] security: add SecuredMessageV3::sign_and_verify round-trip test case --- vanetza/security/tests/secured_message_v3.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/vanetza/security/tests/secured_message_v3.cpp b/vanetza/security/tests/secured_message_v3.cpp index ab928352c..73e103bee 100644 --- a/vanetza/security/tests/secured_message_v3.cpp +++ b/vanetza/security/tests/secured_message_v3.cpp @@ -3,7 +3,9 @@ #include #include #include +#include #include +#include using namespace vanetza; using namespace vanetza::security; @@ -84,3 +86,27 @@ TEST(SecuredMessageV3, verify) EXPECT_EQ(confirm.certificate_id, digest); // AT issuer digest = 56dfd6d627a362dc } + +TEST(SecuredMessageV3, sign_and_verify) +{ + StoredPositionProvider position_provider; + ManualRuntime runtime { Clock::at("2024-08-12 11:30") }; + auto backend = create_backend("default"); + + v3::NaiveCertificateProvider cert_provider { runtime }; + v3::DefaultSignHeaderPolicy sign_header_policy { runtime, position_provider}; + v3::StraightSignService sign_service { cert_provider, *backend, sign_header_policy }; + + SignRequest request; + ChunkPacket packet; + packet[OsiLayer::Application] = ByteBuffer {0x01, 0x02, 0x03}; + request.plain_message = std::move(packet); + request.its_aid = aid::DEN; + SignConfirm sign_confirm = sign_service.sign(std::move(request)); + + StraightVerifyService verify_service { runtime, *backend, position_provider }; + VerifyRequest verify_request { SecuredMessageView { sign_confirm.secured_message } }; + VerifyConfirm verify_confirm = verify_service.verify(verify_request); + EXPECT_EQ(verify_confirm.report, VerificationReport::Success); + EXPECT_TRUE(verify_confirm.certificate_validity.valid()); +} \ No newline at end of file