obu-firmware builds against vanetza-idf from microbu-esp32c5/external, but that tree was gitignored, so a clone of this repository could not build the firmware it ships. It is now committed here as ordinary files in its own folder, microbu-esp32c5/: the colleague's commit cf4b99f plus the V2X2MAP bridge's signature verification (--trust) used on the bench. Nothing is fetched from or pushed to the colleague's repository; this repository and its remotes carry everything. The folder's own .gitignore keeps build output, downloaded components and private key material out, as it did there; the committed file set is identical to that repository's tracked files. The ESP32-C5 is still flashed from obu-firmware/, which only takes vanetza-idf from microbu-esp32c5/, so the two stay separate folders. FLASHING.md says how to take a newer version of the colleague's tree (copy it over the folder, rebuild, test, commit).
138 lines
4.7 KiB
C++
138 lines
4.7 KiB
C++
#include "mock_credential_storage.hpp"
|
|
#include "openssl_security_module.hpp"
|
|
#include <gtest/gtest.h>
|
|
|
|
using vanetza::ByteBuffer;
|
|
using namespace vanetza::pki;
|
|
|
|
/**
|
|
* Test vectors from IEEE 1609.2-2017 (Annex D)
|
|
*/
|
|
|
|
class SecurityModuleTest : public ::testing::Test
|
|
{
|
|
public:
|
|
void SetUp() override
|
|
{
|
|
credentials = std::make_shared<MockCredentialStorage>();
|
|
security = std::make_shared<OpenSslSecurityModule>(credentials);
|
|
}
|
|
|
|
protected:
|
|
std::shared_ptr<CredentialStorage> credentials;
|
|
std::shared_ptr<SecurityModule> security;
|
|
};
|
|
|
|
TEST_F(SecurityModuleTest, mac_vector1)
|
|
{
|
|
const ByteBuffer key(20, 0x0B);
|
|
const ByteBuffer msg { 0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65 };
|
|
const ByteBuffer tag {
|
|
0xB0, 0x34, 0x4C, 0x61, 0xD8, 0xDB, 0x38, 0x53,
|
|
0x5C, 0xA8, 0xAF, 0xCE, 0xAF, 0x0B, 0xF1, 0x2B
|
|
};
|
|
EXPECT_EQ(tag, security->calculate_hmac_sha256(key, msg));
|
|
}
|
|
|
|
TEST_F(SecurityModuleTest, mac_vector2)
|
|
{
|
|
const ByteBuffer key { 0x4A, 0x65, 0x66, 0x65 };
|
|
const ByteBuffer msg {
|
|
0x77, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6F, 0x20,
|
|
0x79, 0x61, 0x20, 0x77, 0x61, 0x6E, 0x74, 0x20,
|
|
0x66, 0x6F, 0x72, 0x20, 0x6E, 0x6F, 0x74, 0x68,
|
|
0x69, 0x6E, 0x67, 0x3F };
|
|
const ByteBuffer tag {
|
|
0x5B, 0xDC, 0xC1, 0x46, 0xBF, 0x60, 0x75, 0x4E,
|
|
0x6A, 0x04, 0x24, 0x26, 0x08, 0x95, 0x75, 0xC7
|
|
};
|
|
EXPECT_EQ(tag, security->calculate_hmac_sha256(key, msg));
|
|
}
|
|
|
|
TEST_F(SecurityModuleTest, mac_vector3)
|
|
{
|
|
const ByteBuffer key(20, 0xAA);
|
|
const ByteBuffer msg(50, 0xDD);
|
|
const ByteBuffer tag {
|
|
0x77, 0x3E, 0xA9, 0x1E, 0x36, 0x80, 0x0E, 0x46,
|
|
0x85, 0x4D, 0xB8, 0xEB, 0xD0, 0x91, 0x81, 0xA7
|
|
};
|
|
EXPECT_EQ(tag, security->calculate_hmac_sha256(key, msg));
|
|
}
|
|
|
|
TEST_F(SecurityModuleTest, mac_vector4)
|
|
{
|
|
const ByteBuffer key {
|
|
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
|
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10,
|
|
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19 };
|
|
const ByteBuffer msg(50, 0xCD);
|
|
const ByteBuffer tag {
|
|
0x82, 0x55, 0x8A, 0x38, 0x9A, 0x44, 0x3C, 0x0E,
|
|
0xA4, 0xCC, 0x81, 0x98, 0x99, 0xF2, 0x08, 0x3A
|
|
};
|
|
EXPECT_EQ(tag, security->calculate_hmac_sha256(key, msg));
|
|
}
|
|
|
|
TEST_F(SecurityModuleTest, mac_vector5)
|
|
{
|
|
const ByteBuffer key(20, 0x0C);
|
|
const ByteBuffer msg {
|
|
0x54, 0x65, 0x73, 0x74, 0x20, 0x57, 0x69, 0x74,
|
|
0x68, 0x20, 0x54, 0x72, 0x75, 0x6E, 0x63, 0x61,
|
|
0x74, 0x69, 0x6F, 0x6E };
|
|
const ByteBuffer tag {
|
|
0xA3, 0xB6, 0x16, 0x74, 0x73, 0x10, 0x0E, 0xE0,
|
|
0x6E, 0x0C, 0x79, 0x6C, 0x29, 0x55, 0x55, 0x2B
|
|
};
|
|
EXPECT_EQ(tag, security->calculate_hmac_sha256(key, msg));
|
|
}
|
|
|
|
TEST_F(SecurityModuleTest, mac_vector6)
|
|
{
|
|
const ByteBuffer key(131, 0xAA);
|
|
const ByteBuffer msg {
|
|
0x54, 0x65, 0x73, 0x74, 0x20, 0x55, 0x73, 0x69,
|
|
0x6E, 0x67, 0x20, 0x4C, 0x61, 0x72, 0x67, 0x65,
|
|
0x72, 0x20, 0x54, 0x68, 0x61, 0x6E, 0x20, 0x42,
|
|
0x6C, 0x6F, 0x63, 0x6B, 0x2D, 0x53, 0x69, 0x7A,
|
|
0x65, 0x20, 0x4B, 0x65, 0x79, 0x20, 0x2D, 0x20,
|
|
0x48, 0x61, 0x73, 0x68, 0x20, 0x4B, 0x65, 0x79,
|
|
0x20, 0x46, 0x69, 0x72, 0x73, 0x74 };
|
|
const ByteBuffer tag {
|
|
0x60, 0xE4, 0x31, 0x59, 0x1E, 0xE0, 0xB6, 0x7F,
|
|
0x0D, 0x8A, 0x26, 0xAA, 0xCB, 0xF5, 0xB7, 0x7F
|
|
};
|
|
EXPECT_EQ(tag, security->calculate_hmac_sha256(key, msg));
|
|
}
|
|
|
|
TEST_F(SecurityModuleTest, mac_vector7)
|
|
{
|
|
const ByteBuffer key(131, 0xAA);
|
|
const ByteBuffer msg {
|
|
0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
|
|
0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x75,
|
|
0x73, 0x69, 0x6E, 0x67, 0x20, 0x61, 0x20, 0x6C,
|
|
0x61, 0x72, 0x67, 0x65, 0x72, 0x20, 0x74, 0x68,
|
|
0x61, 0x6E, 0x20, 0x62, 0x6C, 0x6F, 0x63, 0x6B,
|
|
0x2D, 0x73, 0x69, 0x7A, 0x65, 0x20, 0x6B, 0x65,
|
|
0x79, 0x20, 0x61, 0x6E, 0x64, 0x20, 0x61, 0x20,
|
|
0x6C, 0x61, 0x72, 0x67, 0x65, 0x72, 0x20, 0x74,
|
|
0x68, 0x61, 0x6E, 0x20, 0x62, 0x6C, 0x6F, 0x63,
|
|
0x6B, 0x2D, 0x73, 0x69, 0x7A, 0x65, 0x20, 0x64,
|
|
0x61, 0x74, 0x61, 0x2E, 0x20, 0x54, 0x68, 0x65,
|
|
0x20, 0x6B, 0x65, 0x79, 0x20, 0x6E, 0x65, 0x65,
|
|
0x64, 0x73, 0x20, 0x74, 0x6F, 0x20, 0x62, 0x65,
|
|
0x20, 0x68, 0x61, 0x73, 0x68, 0x65, 0x64, 0x20,
|
|
0x62, 0x65, 0x66, 0x6F, 0x72, 0x65, 0x20, 0x62,
|
|
0x65, 0x69, 0x6E, 0x67, 0x20, 0x75, 0x73, 0x65,
|
|
0x64, 0x20, 0x62, 0x79, 0x20, 0x74, 0x68, 0x65,
|
|
0x20, 0x48, 0x4D, 0x41, 0x43, 0x20, 0x61, 0x6C,
|
|
0x67, 0x6F, 0x72, 0x69, 0x74, 0x68, 0x6D, 0x2E };
|
|
const ByteBuffer tag {
|
|
0x9B, 0x09, 0xFF, 0xA7, 0x1B, 0x94, 0x2F, 0xCB,
|
|
0x27, 0x63, 0x5F, 0xBC, 0xD5, 0xB0, 0xE9, 0x44
|
|
};
|
|
EXPECT_EQ(tag, security->calculate_hmac_sha256(key, msg));
|
|
}
|