1*0eaf192dSyasuoka #include "incs.h"
2*0eaf192dSyasuoka
3*0eaf192dSyasuoka #include <openssl/hmac.h>
4*0eaf192dSyasuoka
5*0eaf192dSyasuoka /*
6*0eaf192dSyasuoka * User-Password attribute
7*0eaf192dSyasuoka */
8*0eaf192dSyasuoka
test24(void)9*0eaf192dSyasuoka void test24(void)
10*0eaf192dSyasuoka {
11*0eaf192dSyasuoka uint8_t cipher[256],cipher1[256];
12*0eaf192dSyasuoka size_t clen;
13*0eaf192dSyasuoka char plain[256];
14*0eaf192dSyasuoka RADIUS_PACKET *packet;
15*0eaf192dSyasuoka
16*0eaf192dSyasuoka uint8_t ra[16] = {
17*0eaf192dSyasuoka 0xf3, 0xa4, 0x7a, 0x1f, 0x6a, 0x6d, 0x76, 0x71, 0x0b, 0x94, 0x7a, 0xb9, 0x30, 0x41, 0xa0, 0x39,
18*0eaf192dSyasuoka };
19*0eaf192dSyasuoka
20*0eaf192dSyasuoka uint8_t encryptedpass[16] = {
21*0eaf192dSyasuoka 0x33, 0x65, 0x75, 0x73, 0x77, 0x82, 0x89, 0xb5, 0x70, 0x88, 0x5e, 0x15, 0x08, 0x48, 0x25, 0xc5,
22*0eaf192dSyasuoka };
23*0eaf192dSyasuoka
24*0eaf192dSyasuoka clen = sizeof(cipher);
25*0eaf192dSyasuoka CHECK(radius_encrypt_user_password_attr(cipher, &clen, "challenge", ra, "xyzzy5461") == 0);
26*0eaf192dSyasuoka CHECK(clen == 16);
27*0eaf192dSyasuoka CHECK(memcmp(cipher, encryptedpass, 16) == 0);
28*0eaf192dSyasuoka
29*0eaf192dSyasuoka CHECK(radius_decrypt_user_password_attr(plain, sizeof(plain), cipher, clen, ra, "xyzzy5461") == 0);
30*0eaf192dSyasuoka CHECK(strcmp(plain, "challenge") == 0);
31*0eaf192dSyasuoka
32*0eaf192dSyasuoka clen = 15;
33*0eaf192dSyasuoka CHECK(radius_encrypt_user_password_attr(cipher, &clen, "challenge", ra, "xyzzy5461") != 0);
34*0eaf192dSyasuoka CHECK(radius_decrypt_user_password_attr(plain, 16, cipher, 16, ra, "xyzzy5461") != 0);
35*0eaf192dSyasuoka CHECK(radius_decrypt_user_password_attr(plain, 256, cipher, 17, ra, "xyzzy5461") != 0);
36*0eaf192dSyasuoka
37*0eaf192dSyasuoka packet = radius_new_request_packet(RADIUS_CODE_ACCESS_REQUEST);
38*0eaf192dSyasuoka
39*0eaf192dSyasuoka CHECK(radius_put_user_password_attr(packet, "foobarbaz", "sharedsecret") == 0);
40*0eaf192dSyasuoka clen = sizeof(cipher1);
41*0eaf192dSyasuoka CHECK(radius_get_raw_attr(packet, RADIUS_TYPE_USER_PASSWORD, cipher1, &clen) == 0);
42*0eaf192dSyasuoka CHECK(clen == 16);
43*0eaf192dSyasuoka radius_encrypt_user_password_attr(cipher, &clen, "foobarbaz", radius_get_authenticator_retval(packet), "sharedsecret");
44*0eaf192dSyasuoka CHECK(memcmp(cipher1, cipher, 16) == 0);
45*0eaf192dSyasuoka
46*0eaf192dSyasuoka CHECK(radius_get_user_password_attr(packet, plain, sizeof(plain), "sharedsecret") == 0);
47*0eaf192dSyasuoka CHECK(strcmp(plain, "foobarbaz") == 0);
48*0eaf192dSyasuoka }
49*0eaf192dSyasuoka
50*0eaf192dSyasuoka ADD_TEST(test24)
51