Files
bongo/contrib/debian/libsrs2/tests/security-regression.c
T
2026-07-20 11:13:05 +02:00

54 lines
1.7 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "srs2.h"
int main(void)
{
srs_t *srs = srs_new();
char long_secret[129];
char encoded[512];
char decoded[512];
char tiny[8];
char *allocated = NULL;
srs_hmac_ctx_t hmac;
unsigned char hmac_key[20];
unsigned char digest[SHA_DIGESTSIZE];
static const unsigned char expected[SHA_DIGESTSIZE] = {
0xb6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64, 0xe2, 0x8b,
0xc0, 0xb6, 0xfb, 0x37, 0x8c, 0x8e, 0xf1, 0x46, 0xbe, 0x00
};
int rc;
memset(long_secret, 's', sizeof(long_secret) - 1);
long_secret[sizeof(long_secret) - 1] = '\0';
if (srs == NULL || srs_add_secret(srs, long_secret) != SRS_SUCCESS)
return 1;
rc = srs_forward(srs, encoded, sizeof(encoded),
"sender@example.net", "forward.example.org");
if (rc != SRS_SUCCESS)
return 2;
rc = srs_reverse(srs, decoded, sizeof(decoded), encoded);
if (rc != SRS_SUCCESS || strcmp(decoded, "sender@example.net") != 0)
return 3;
if (srs_forward(srs, tiny, sizeof(tiny),
"sender@example.net", "forward.example.org") !=
SRS_EBUFTOOSMALL)
return 4;
rc = srs_forward_alloc(srs, &allocated, "sender@example.net",
"forward.example.org");
if (rc != SRS_SUCCESS || allocated == NULL)
return 5;
free(allocated);
memset(hmac_key, 0x0b, sizeof(hmac_key));
srs_hmac_init(&hmac, (char *)hmac_key, sizeof(hmac_key));
srs_hmac_update(&hmac, "Hi There", 8);
srs_hmac_fini(&hmac, (char *)digest);
if (memcmp(digest, expected, sizeof(expected)) != 0)
return 6;
srs_free(srs);
puts("libsrs2 security regression test: PASS");
return 0;
}