55b47bc24b2303e5dd00ac0b38a38dc15a4c04ac
[openafs.git] / src / kauth / decode_ticket.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13
14 #include <hcrypto/des.h>
15 #include <afs/com_err.h>
16 #include <afs/auth.h>
17 #include <rx/rxkad.h>
18 #include "kautils.h"
19
20 static char *whoami;
21
22 int
23 main(int argc, char *argv[])
24 {
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];
34
35     whoami = argv[0];
36     initialize_RXK_error_table();
37     initialize_KA_error_table();
38
39     if (argc != 3) {
40         printf("Usage is %s key ticket\n", whoami);
41         exit(1);
42     }
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(charptr_to_cblock(key)) || DES_is_weak_key(charptr_to_cblock(key))) {
46         afs_com_err(whoami, KABADKEY, "server's key for decoding ticket is bad");
47         exit(1);
48     }
49     ticketLen = ka_ReadBytes(argv[2], ticket, sizeof(ticket));
50     printf("Ticket length is %d\n", ticketLen);
51
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);
60     }
61
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);
65     }
66
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);
76 }