Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / kauth / decode_ticket.c
blob15082e5794cceb12f7d4a72e63b9898c2043753a
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
10 #include <afsconfig.h>
11 #include <afs/param.h>
14 #include <des.h>
15 #include <afs/com_err.h>
16 #include <afs/auth.h>
17 #include <rx/rxkad.h>
18 #include "kautils.h"
20 static char *whoami;
22 int
23 main(int argc, char *argv[])
25 struct ktc_principal client;
26 struct ktc_encryptionKey sessionkey;
27 Date start, end;
28 afs_int32 host;
29 char key[8];
30 char ticket[MAXKTCTICKETLEN];
31 afs_int32 ticketLen;
32 afs_int32 code;
33 char bob[KA_TIMESTR_LEN];
35 whoami = argv[0];
36 initialize_RXK_error_table();
37 initialize_KA_error_table();
39 if (argc != 3) {
40 printf("Usage is %s key ticket\n", whoami);
41 exit(1);
43 if (ka_ReadBytes(argv[1], key, sizeof(key)) != 8)
44 printf("Key must be 8 bytes long\n");
45 if (!des_check_key_parity(key) || des_is_weak_key(key)) {
46 afs_com_err(whoami, KABADKEY, "server's key for decoding ticket is bad");
47 exit(1);
49 ticketLen = ka_ReadBytes(argv[2], ticket, sizeof(ticket));
50 printf("Ticket length is %d\n", ticketLen);
52 code =
53 tkt_DecodeTicket(ticket, ticketLen, key, client.name, client.instance,
54 client.cell, &sessionkey, &host, &start, &end);
55 if (code) {
56 afs_com_err(whoami, code, "decoding ticket");
57 if (code = tkt_CheckTimes(start, end, time(0)) <= 0)
58 afs_com_err(whoami, 0, "because of start or end times");
59 exit(1);
62 if (!des_check_key_parity(&sessionkey) || des_is_weak_key(&sessionkey)) {
63 afs_com_err(whoami, KABADKEY, "checking ticket's session key");
64 exit(1);
67 ka_PrintUserID("Client is ", client.name, client.instance, 0);
68 if (strlen(client.cell))
69 printf("@%s", client.cell);
70 printf("\nSession key is ");
71 ka_PrintBytes(&sessionkey, 8);
72 ka_timestr(start, bob, KA_TIMESTR_LEN);
73 printf("\nGood from %s", bob);
74 ka_timestr(end, bob, KA_TIMESTR_LEN);
75 printf(" till %s\n", bob);