Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/crypto/krb5/src/lib/krad/t_attr.c
39536 views
1
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
/* lib/krad/t_attr.c - Attribute test program */
3
/*
4
* Copyright 2013 Red Hat, Inc. All rights reserved.
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions are met:
8
*
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
*
12
* 2. Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in
14
* the documentation and/or other materials provided with the
15
* distribution.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
*/
29
30
#include "t_test.h"
31
32
const static unsigned char encoded[] = {
33
0xba, 0xfc, 0xed, 0x50, 0xe1, 0xeb, 0xa6, 0xc3,
34
0xc1, 0x75, 0x20, 0xe9, 0x10, 0xce, 0xc2, 0xcb
35
};
36
37
const static unsigned char auth[] = {
38
0xac, 0x9d, 0xc1, 0x62, 0x08, 0xc4, 0xc7, 0x8b,
39
0xa1, 0x2f, 0x25, 0x0a, 0xc4, 0x1d, 0x36, 0x41
40
};
41
42
int
43
main(void)
44
{
45
unsigned char outbuf[MAX_ATTRSETSIZE];
46
const char *decoded = "accept";
47
const char *secret = "foo";
48
krb5_error_code retval;
49
krb5_context ctx;
50
const char *tmp;
51
krb5_data in;
52
size_t len;
53
54
noerror(krb5_init_context(&ctx));
55
56
/* Make sure User-Name is 1. */
57
insist(krad_attr_name2num("User-Name") == 1);
58
59
/* Make sure 2 is User-Password. */
60
tmp = krad_attr_num2name(2);
61
insist(tmp != NULL);
62
insist(strcmp(tmp, "User-Password") == 0);
63
64
/* Test decoding. */
65
in = make_data((void *)encoded, sizeof(encoded));
66
noerror(kr_attr_decode(ctx, secret, auth, KRAD_ATTR_USER_PASSWORD,
67
&in, outbuf, &len));
68
insist(len == strlen(decoded));
69
insist(memcmp(outbuf, decoded, len) == 0);
70
71
/* Test encoding. */
72
in = string2data((char *)decoded);
73
retval = kr_attr_encode(ctx, secret, auth, KRAD_ATTR_USER_PASSWORD,
74
&in, outbuf, &len);
75
insist(retval == 0);
76
insist(len == sizeof(encoded));
77
insist(memcmp(outbuf, encoded, len) == 0);
78
79
/* Test constraint. */
80
in.length = 100;
81
insist(kr_attr_valid(KRAD_ATTR_USER_PASSWORD, &in) == 0);
82
in.length = 200;
83
insist(kr_attr_valid(KRAD_ATTR_USER_PASSWORD, &in) != 0);
84
85
krb5_free_context(ctx);
86
return 0;
87
}
88
89