/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* lib/krad/t_attr.c - Attribute test program */2/*3* Copyright 2013 Red Hat, Inc. All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions are met:7*8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10*11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in13* the documentation and/or other materials provided with the14* distribution.15*16* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS17* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED18* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A19* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER20* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,21* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,22* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR23* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF24* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING25* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS26* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27*/2829#include "t_test.h"3031const static unsigned char encoded[] = {320xba, 0xfc, 0xed, 0x50, 0xe1, 0xeb, 0xa6, 0xc3,330xc1, 0x75, 0x20, 0xe9, 0x10, 0xce, 0xc2, 0xcb34};3536const static unsigned char auth[] = {370xac, 0x9d, 0xc1, 0x62, 0x08, 0xc4, 0xc7, 0x8b,380xa1, 0x2f, 0x25, 0x0a, 0xc4, 0x1d, 0x36, 0x4139};4041int42main(void)43{44unsigned char outbuf[MAX_ATTRSETSIZE];45const char *decoded = "accept";46const char *secret = "foo";47krb5_error_code retval;48krb5_context ctx;49const char *tmp;50krb5_data in;51size_t len;5253noerror(krb5_init_context(&ctx));5455/* Make sure User-Name is 1. */56insist(krad_attr_name2num("User-Name") == 1);5758/* Make sure 2 is User-Password. */59tmp = krad_attr_num2name(2);60insist(tmp != NULL);61insist(strcmp(tmp, "User-Password") == 0);6263/* Test decoding. */64in = make_data((void *)encoded, sizeof(encoded));65noerror(kr_attr_decode(ctx, secret, auth, KRAD_ATTR_USER_PASSWORD,66&in, outbuf, &len));67insist(len == strlen(decoded));68insist(memcmp(outbuf, decoded, len) == 0);6970/* Test encoding. */71in = string2data((char *)decoded);72retval = kr_attr_encode(ctx, secret, auth, KRAD_ATTR_USER_PASSWORD,73&in, outbuf, &len);74insist(retval == 0);75insist(len == sizeof(encoded));76insist(memcmp(outbuf, encoded, len) == 0);7778/* Test constraint. */79in.length = 100;80insist(kr_attr_valid(KRAD_ATTR_USER_PASSWORD, &in) == 0);81in.length = 200;82insist(kr_attr_valid(KRAD_ATTR_USER_PASSWORD, &in) != 0);8384krb5_free_context(ctx);85return 0;86}878889