1 #include "incs.h"
2
3 #include <openssl/md5.h>
4
5 /*
6 * accounting request authenticator
7 */
8
test11(void)9 void test11(void)
10 {
11 RADIUS_PACKET *packet;
12 MD5_CTX ctx;
13
14 uint8_t packetdata[] = {
15 RADIUS_CODE_ACCOUNTING_REQUEST, 0x7f, 0, 31,
16 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* auth */
17 10, 11, 'f', 'o', 'o', 'b', 'a', 'r', 'b', 'a', 'z',
18 };
19
20 packet = radius_new_request_packet(RADIUS_CODE_ACCOUNTING_REQUEST);
21 radius_set_id(packet, 0x7f);
22 radius_put_string_attr(packet, 10, "foobarbaz");
23 radius_set_accounting_request_authenticator(packet, "sharedsecret");
24
25 MD5_Init(&ctx);
26 MD5_Update(&ctx, packetdata, sizeof(packetdata));
27 MD5_Update(&ctx, "sharedsecret", 12);
28 MD5_Final(packetdata + 4, &ctx);
29
30 CHECK(radius_get_length(packet) == sizeof(packetdata));
31 CHECK(memcmp(radius_get_data(packet), packetdata, sizeof(packetdata)) == 0);
32 CHECK(radius_check_accounting_request_authenticator(packet, "sharedsecret") == 0);
33
34 radius_set_raw_attr(packet, 10, "zapzapzap", 9);
35 CHECK(radius_check_accounting_request_authenticator(packet, "sharedsecret") != 0);
36 }
37
38 ADD_TEST(test11)
39