37 lines
1.2 KiB
C++
37 lines
1.2 KiB
C++
#include "sodium/crypto_sign.h"
|
|
#include <catch2/catch_test_macros.hpp>
|
|
#include <protocol/protocol.hxx>
|
|
#include <sodium.h>
|
|
|
|
TEST_CASE("SignedMessage", "[protocol]") {
|
|
REQUIRE(sodium_init() >= 0);
|
|
|
|
unsigned char pub_key[crypto_sign_PUBLICKEYBYTES];
|
|
unsigned char priv_key[crypto_sign_SECRETKEYBYTES];
|
|
crypto_sign_keypair(pub_key, priv_key);
|
|
|
|
auto msg = Protocol::SignedMessage(pub_key, priv_key, "Hello, world!");
|
|
|
|
SECTION("valid signed message") { REQUIRE(msg.valid(pub_key)); }
|
|
|
|
SECTION("tampered invalid signed message") {
|
|
SECTION("plaintext") {
|
|
msg.plaintext = "Hello, world111111";
|
|
REQUIRE_FALSE(msg.valid(pub_key));
|
|
}
|
|
|
|
SECTION("timestamp") {
|
|
msg.timestamp = std::chrono::system_clock::now()
|
|
.time_since_epoch()
|
|
.count();
|
|
REQUIRE_FALSE(msg.valid(pub_key));
|
|
}
|
|
|
|
SECTION("fingerprint") {
|
|
std::memset(msg.sender_key_fingerprint, 'H',
|
|
crypto_hash_sha256_BYTES);
|
|
REQUIRE_FALSE(msg.valid(pub_key));
|
|
}
|
|
}
|
|
}
|