2 * Copyright (c) 2008 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of KTH nor the names of its contributors may be
18 * used to endorse or promote products derived from this software without
19 * specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
33 #include "krb5_locl.h"
34 #include <pkinit_asn1.h>
41 const heim_oid
*(*oid
)(void);
54 oid_id_pkinit_kdf_ah_sha1
, /* AlgorithmIdentifier */
57 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
58 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
59 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
60 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
61 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
62 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
63 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
64 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
65 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
66 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
67 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
68 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
69 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
70 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
71 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
72 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
74 "lha@SU.SE", /* client, partyUInfo */
75 "krbtgt/SU.SE@SU.SE", /* server, partyVInfo */
76 ETYPE_AES256_CTS_HMAC_SHA1_96
, /* enctype */
79 "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
83 "\xBB\xBB\xBB\xBB\xBB\xBB\xBB\xBB\xBB"
87 "\x61\x35\x30\x33\xa0\x03\x02\x01\x05\xa1\x07\x1b\x05\x53\x55\x2e"
88 "\x53\x45\xa2\x10\x30\x0e\xa0\x03\x02\x01\x01\xa1\x07\x30\x05\x1b"
89 "\x03\x6c\x68\x61\xa3\x11\x30\x0f\xa0\x03\x02\x01\x12\xa2\x08\x04"
90 "\x06\x68\x65\x6a\x68\x65\x6a"
94 "\xc7\x62\x89\xec\x4b\x28\xa6\x91\xff\xce\x80\xbb\xb7\xec\x82\x41"
95 "\x52\x3f\x99\xb1\x90\xcf\x2d\x34\x8f\x54\xa8\x65\x81\x2c\x32\x73"
111 t
.sname
.name_type
= KRB5_NT_PRINCIPAL
;
112 t
.sname
.name_string
.len
= 1;
113 t
.sname
.name_string
.val
= ecalloc(1, sizeof(t
.sname
.name_string
.val
[0]));
114 t
.sname
.name_string
.val
[0] = estrdup("lha");
115 t
.enc_part
.etype
= ETYPE_AES256_CTS_HMAC_SHA1_96
;
116 t
.enc_part
.kvno
= NULL
;
117 t
.enc_part
.cipher
.length
= 6;
118 t
.enc_part
.cipher
.data
= "hejhej";
120 ASN1_MALLOC_ENCODE(Ticket
, data
.data
, data
.length
, &t
, &size
, ret
);
122 errx(1, "ASN1_MALLOC_ENCODE(Ticket)");
124 rk_dumpdata("foo", data
.data
, data
.length
);
130 test_dh2key(krb5_context context
, int i
, struct testcase
*c
)
134 krb5_principal client
, server
;
136 AlgorithmIdentifier ai
;
139 memset(&ticket
, 0, sizeof(&ticket
));
141 ai
.algorithm
= *(*c
->oid
)();
142 ai
.parameters
= NULL
;
144 ret
= decode_Ticket(c
->ticket
.data
, c
->ticket
.length
, &ticket
, &size
);
146 krb5_errx(context
, 1, "decode ticket: %d", ret
);
148 ret
= krb5_parse_name(context
, c
->client
, &client
);
150 krb5_err(context
, 1, ret
, "parse_name: %s", c
->client
);
151 ret
= krb5_parse_name(context
, c
->server
, &server
);
153 krb5_err(context
, 1, ret
, "parse_name: %s", c
->server
);
155 ret
= _krb5_pk_kdf(context
,
166 krb5_free_principal(context
, client
);
167 krb5_free_principal(context
, server
);
169 krb5_err(context
, 1, ret
, "_krb5_pk_kdf: %d", i
);
171 if (key
.keyvalue
.length
!= c
->key
.length
||
172 memcmp(key
.keyvalue
.data
, c
->key
.data
, c
->key
.length
) != 0)
173 krb5_errx(context
, 1, "resulting key wrong: %d", i
);
175 krb5_free_keyblock_contents(context
, &key
);
181 static int version_flag
= 0;
182 static int help_flag
= 0;
184 static struct getargs args
[] = {
185 {"version", 0, arg_flag
, &version_flag
,
186 "print version", NULL
},
187 {"help", 0, arg_flag
, &help_flag
,
194 arg_printusage (args
,
195 sizeof(args
)/sizeof(*args
),
203 main(int argc
, char **argv
)
205 krb5_context context
;
209 setprogname(argv
[0]);
211 if(getarg(args
, sizeof(args
) / sizeof(args
[0]), argc
, argv
, &optidx
))
229 ret
= krb5_init_context(&context
);
231 errx (1, "krb5_init_context failed: %d", ret
);
233 for (i
= 0; i
< sizeof(tests
)/sizeof(tests
[0]); i
++)
234 test_dh2key(context
, i
, &tests
[i
]);
236 krb5_free_context(context
);