aboutsummaryrefslogtreecommitdiffstats
path: root/packet-kerberos.c
blob: 76a9ccff54ecf26f10c05a9a6af4f88c8d0e80ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
/* packet-kerberos.c
 * Routines for Kerberos
 * Wes Hardaker (c) 2000
 * wjhardaker@ucdavis.edu
 *
 * $Id: packet-kerberos.c,v 1.8 2000/12/24 09:10:11 guy Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@zing.org>
 * Copyright 1998 Didier Jorand
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif

#include <glib.h>

#include "packet.h"

#include "strutil.h"

#include "asn1.h"

#define UDP_PORT_KERBEROS		88
#define TCP_PORT_KERBEROS		88

static gint ett_kerberos   = -1;
static gint ett_preauth    = -1;
static gint ett_addresses  = -1;
static gint ett_request    = -1;
static gint ett_princ      = -1;
static gint ett_ticket     = -1;
static gint ett_encrypted  = -1;
static gint ett_etype      = -1;
static gint proto_kerberos = -1;

#define KRB5_MSG_AS_REQ   10	/* AS-REQ type */
#define KRB5_MSG_AS_REP   11	/* AS-REP type */
#define KRB5_MSG_TGS_REQ  12	/* TGS-REQ type */
#define KRB5_MSG_TGS_REP  13	/* TGS-REP type */
#define KRB5_MSG_AP_REQ   14	/* AP-REQ type */
#define KRB5_MSG_AP_REP   15	/* AP-REP type */

#define KRB5_MSG_SAFE     20	/* KRB-SAFE type */
#define KRB5_MSG_PRIV     21	/* KRB-PRIV type */
#define KRB5_MSG_CRED     22	/* KRB-CRED type */
#define KRB5_MSG_ERROR    30	/* KRB-ERROR type */

/* Type tags within KDC-REQ */
#define KRB5_KDC_REQ_PVNO     1
#define KRB5_KDC_REQ_MSG_TYPE 2
#define KRB5_KDC_REQ_PADATA   3
#define KRB5_KDC_REQ_REQBODY  4

/* Type tags within KDC-REP */
#define KRB5_KDC_REP_PVNO     0
#define KRB5_KDC_REP_MSG_TYPE 1
#define KRB5_KDC_REP_PADATA   2
#define KRB5_KDC_REP_CREALM   3
#define KRB5_KDC_REP_CNAME    4
#define KRB5_KDC_REP_TICKET   5
#define KRB5_KDC_REP_ENC_PART 6

/* Type tags within KDC-REQ-BODY */
#define KRB5_BODY_KDC_OPTIONS            0
#define KRB5_BODY_CNAME                  1
#define KRB5_BODY_REALM                  2
#define KRB5_BODY_SNAME                  3
#define KRB5_BODY_FROM                   4
#define KRB5_BODY_TILL                   5
#define KRB5_BODY_RTIME                  6
#define KRB5_BODY_NONCE                  7
#define KRB5_BODY_ETYPE                  8
#define KRB5_BODY_ADDRESSES              9
#define KRB5_BODY_ENC_AUTHORIZATION_DATA 10
#define KRB5_BODY_ADDITIONAL_TICKETS     11

#define KRB5_ADDR_IPv4       0x02
#define KRB5_ADDR_CHAOS      0x05
#define KRB5_ADDR_XEROX      0x06
#define KRB5_ADDR_ISO        0x07
#define KRB5_ADDR_DECNET     0x0c
#define KRB5_ADDR_APPLETALK  0x10

#define KRB5_ETYPE_NULL                0
#define KRB5_ETYPE_DES_CBC_CRC         1
#define KRB5_ETYPE_DES_CBC_MD4         2
#define KRB5_ETYPE_DES_CBC_MD5         3

#define KRB5_PA_TGS_REQ       0x01
#define KRB5_PA_ENC_TIMESTAMP 0x02
#define KRB5_PA_PW_SALT       0x03

/* Type tags within Ticket */
#define KRB5_TKT_TKT_VNO  0
#define KRB5_TKT_REALM    1
#define KRB5_TKT_SNAME    2
#define KRB5_TKT_ENC_PART 3

static const value_string krb5_preauthentication_types[] = {
    { KRB5_PA_TGS_REQ      , "PA-TGS-REQ" },
    { KRB5_PA_ENC_TIMESTAMP, "PA-ENC-TIMESTAMP" },
    { KRB5_PA_PW_SALT      , "PA-PW-SALT" },
};

static const value_string krb5_encryption_types[] = {
    { KRB5_ETYPE_NULL           , "NULL" },
    { KRB5_ETYPE_DES_CBC_CRC    , "des-cbc-crc" },
    { KRB5_ETYPE_DES_CBC_MD4    , "des-cbc-md4" },
    { KRB5_ETYPE_DES_CBC_MD5    , "des-cbc-md5" },
};

static const value_string krb5_address_types[] = {
    { KRB5_ADDR_IPv4,		"IPv4"},
    { KRB5_ADDR_CHAOS,		"CHAOS"},
    { KRB5_ADDR_XEROX,		"XEROX"},
    { KRB5_ADDR_ISO,		"ISO"},
    { KRB5_ADDR_DECNET,		"DECNET"},
    { KRB5_ADDR_APPLETALK,	"APPLETALK"}
};

static const value_string krb5_msg_types[] = {
	{ KRB5_MSG_TGS_REQ,	"TGS-REQ" },
	{ KRB5_MSG_TGS_REP,	"TGS-REP" },
	{ KRB5_MSG_AS_REQ,	"AS-REQ" },
	{ KRB5_MSG_AS_REP,	"AS-REP" },
	{ KRB5_MSG_AP_REQ,	"AP-REQ" },
	{ KRB5_MSG_AP_REP,	"AP-REP" },
	{ KRB5_MSG_SAFE,	"KRB-SAFE" },
	{ KRB5_MSG_PRIV,	"KRB-PRIV" },
	{ KRB5_MSG_CRED,	"KRB-CRED" },
	{ KRB5_MSG_ERROR,	"KRB-ERROR" }
};

static int dissect_PrincipalName(char *title, ASN1_SCK *asn1p,
                                 frame_data *fd, proto_tree *tree,
                                 int start_offset);
static int dissect_Ticket(char *title, ASN1_SCK *asn1p, frame_data *fd,
                          proto_tree *tree, int start_offset);
static int dissect_EncryptedData(char *title, ASN1_SCK *asn1p, frame_data *fd,
                                 proto_tree *tree, int start_offset);
static int dissect_Addresses(char *title, ASN1_SCK *asn1p, frame_data *fd,
                             proto_tree *tree, int start_offset);

static const char *
to_error_str(int ret) {
    switch (ret) {

        case ASN1_ERR_EMPTY:
            return("Ran out of data");

        case ASN1_ERR_EOC_MISMATCH:
            return("EOC mismatch");

        case ASN1_ERR_WRONG_TYPE:
            return("Wrong type for that item");

        case ASN1_ERR_LENGTH_NOT_DEFINITE:
            return("Length was indefinite");

        case ASN1_ERR_LENGTH_MISMATCH:
            return("Length mismatch");

        case ASN1_ERR_WRONG_LENGTH_FOR_TYPE:
            return("Wrong length for that item's type");

    }
    return("Unknown error");
}

static void
krb_proto_tree_add_time(proto_tree *tree, int offset, int str_len,
                        char *name, guchar *str) {
    if (tree)
        proto_tree_add_text(tree, NullTVB, offset, str_len,
                            "%s: %.4s-%.2s-%.2s %.2s:%.2s:%.2s (%.1s)",
                            name, str, str+4, str+6,
                            str+8, str+10, str+12,
                            str+14);
}


/*
 * You must be kidding.  I'm going to actually use a macro to do something?
 *   bad me.  Bad me.
 */

#define KRB_HEAD_DECODE_OR_DIE(token) \
   start = asn1p->pointer; \
   ret = asn1_header_decode (asn1p, &cls, &con, &tag, &def, &item_len); \
   if (ret != ASN1_ERR_NOERROR && ret != ASN1_ERR_EMPTY) {\
       if (check_col(fd, COL_INFO)) \
           col_add_fstr(fd, COL_INFO, "ERROR: Problem at %s: %s", \
                    token, to_error_str(ret)); \
       return -1; \
   } \
   if (!def) {\
       if (check_col(fd, COL_INFO)) \
           col_add_fstr(fd, COL_INFO, "not definite: %s", token); \
       fprintf(stderr,"not definite: %s\n", token); \
       return -1; \
   } \
   offset += (asn1p->pointer - start);

#define CHECK_APPLICATION_TYPE(expected_tag) \
    (cls == ASN1_APL && con == ASN1_CON && tag == expected_tag)

#define DIE_IF_NOT_APPLICATION_TYPE(token, expected_tag) \
    if (!CHECK_APPLICATION_TYPE(expected_tag)) \
        DIE_WITH_BAD_TYPE(token);

#define CHECK_CONTEXT_TYPE(expected_tag) \
    (cls == ASN1_CTX && con == ASN1_CON && tag == expected_tag)

#define DIE_IF_NOT_CONTEXT_TYPE(token, expected_tag) \
    if (!CHECK_CONTEXT_TYPE(expected_tag)) \
        DIE_WITH_BAD_TYPE(token);

#define DIE_WITH_BAD_TYPE(token) \
    { \
      if (check_col(fd, COL_INFO)) \
         col_add_fstr(fd, COL_INFO, "ERROR: Problem at %s: %s", \
                      token, to_error_str(ASN1_ERR_WRONG_TYPE)); \
      return -1; \
    }

#define KRB_DECODE_APPLICATION_TAGGED_HEAD_OR_DIE(token, expected_tag) \
    KRB_HEAD_DECODE_OR_DIE(token); \
    DIE_IF_NOT_APPLICATION_TYPE(token, expected_tag);

#define KRB_DECODE_CONTEXT_HEAD_OR_DIE(token, expected_tag) \
    KRB_HEAD_DECODE_OR_DIE(token); \
    DIE_IF_NOT_CONTEXT_TYPE(token, expected_tag);

#define KRB_SEQ_HEAD_DECODE_OR_DIE(token) \
   ret = asn1_sequence_decode (asn1p, &item_len, &header_len); \
   if (ret != ASN1_ERR_NOERROR && ret != ASN1_ERR_EMPTY) {\
       if (check_col(fd, COL_INFO)) \
           col_add_fstr(fd, COL_INFO, "ERROR: Problem at %s: %s", \
                    token, to_error_str(ret)); \
       return -1; \
   } \
   offset += header_len;

#define KRB_DECODE_OR_DIE(token, fn, val) \
    ret = fn (asn1p, &val, &length); \
    if (ret != ASN1_ERR_NOERROR) { \
       if (check_col(fd, COL_INFO)) \
         col_add_fstr(fd, COL_INFO, "ERROR: Problem at %s: %s", \
                     token, to_error_str(ret)); \
        return -1; \
    } \

#define KRB_DECODE_UINT32_OR_DIE(token, val) \
    KRB_DECODE_OR_DIE(token, asn1_uint32_decode, val);

#define KRB_DECODE_STRING_OR_DIE(token, expected_tag, val, val_len, item_len) \
    ret = asn1_string_decode (asn1p, &val, &val_len, &item_len, expected_tag); \
    if (ret != ASN1_ERR_NOERROR) { \
       if (check_col(fd, COL_INFO)) \
         col_add_fstr(fd, COL_INFO, "ERROR: Problem at %s: %s", \
                     token, to_error_str(ret)); \
        return -1; \
    }

#define KRB_DECODE_OCTET_STRING_OR_DIE(token, val, val_len, item_len) \
    KRB_DECODE_STRING_OR_DIE(token, ASN1_OTS, val, val_len, item_len)

#define KRB_DECODE_GENERAL_STRING_OR_DIE(token, val, val_len, item_len) \
    KRB_DECODE_STRING_OR_DIE(token, ASN1_GENSTR, val, val_len, item_len)

#define KRB_DECODE_GENERAL_TIME_OR_DIE(token, val, val_len, item_len) \
    KRB_DECODE_STRING_OR_DIE(token, ASN1_GENTIM, val, val_len, item_len)

/* dissect_type_value_pair decodes (roughly) this:

    SEQUENCE  {
                        INTEGER,
                        OCTET STRING
    }

    which is all over the place in krb5 */

static void
dissect_type_value_pair(ASN1_SCK *asn1p, int *inoff,
                        guint32 *type, int *type_len, int *type_off,
                        guchar **val, int *val_len, int *val_off) {
    int offset = *inoff;
    guint cls, con, tag;
    gboolean def;
    const guchar *start;
    guint tmp_len;
    int ret;

    /* SEQUENCE */
    start = asn1p->pointer;
    asn1_header_decode (asn1p, &cls, &con, &tag, &def, &tmp_len);
    offset += (asn1p->pointer - start);

    /* INT */
    /* wrapper */
    start = asn1p->pointer;
    asn1_header_decode (asn1p, &cls, &con, &tag, &def, &tmp_len);
    offset += (asn1p->pointer - start);

    if (type_off)
        *type_off = offset;

    /* value */
    ret =  asn1_uint32_decode(asn1p, type, type_len);
    if (ret != ASN1_ERR_NOERROR) {
        fprintf(stderr,"die: type_value_pair: type, %s\n", to_error_str(ret));
        return;
    }
    offset += tmp_len;

    /* OCTET STRING (or generic data) */
    /* wrapper */
    start = asn1p->pointer;
    asn1_header_decode (asn1p, &cls, &con, &tag, &def, val_len);
    asn1_header_decode (asn1p, &cls, &con, &tag, &def, val_len);
    offset += asn1p->pointer - start;
    
    if (val_off)
        *val_off = offset;

    /* value */
    asn1_string_value_decode (asn1p, *val_len, val);

    *inoff = offset + *val_len;
}

static gboolean
dissect_kerberos_main(const u_char *pd, int offset, frame_data *fd,
                      proto_tree *tree)
{
    proto_tree *kerberos_tree = NULL;
    proto_tree *etype_tree = NULL;
    proto_tree *preauth_tree = NULL;
    proto_tree *request_tree = NULL;
    ASN1_SCK asn1, *asn1p = &asn1;
    proto_item *item = NULL;

    guint length;
    guint cls, con, tag;
    gboolean def;
    guint item_len, total_len;
    const guchar *start;

    int ret;

    guint protocol_message_type;
    
    guint32 version;
    guint32 msg_type;
    guint32 preauth_type;
    guint32 tmp_int;

    /* simple holders */
    int str_len;
    guchar *str;
    int tmp_pos1, tmp_pos2;

    if (tree) {
        item = proto_tree_add_item(tree, proto_kerberos, NullTVB, offset,
                                   END_OF_FRAME, FALSE);
        kerberos_tree = proto_item_add_subtree(item, ett_kerberos);
    }

    asn1_open(&asn1, &pd[offset], END_OF_FRAME);

    /* top header */
    KRB_HEAD_DECODE_OR_DIE("top");
    protocol_message_type = tag;
    
    /* second header */
    KRB_HEAD_DECODE_OR_DIE("top2");

    /* version number */
    KRB_HEAD_DECODE_OR_DIE("version-wrap");
    KRB_DECODE_UINT32_OR_DIE("version", version);

    if (kerberos_tree) {
        proto_tree_add_text(kerberos_tree, NullTVB, offset, length,
                            "Version: %d",
                            version);
    }
    offset += length;

    /* message type */
    KRB_HEAD_DECODE_OR_DIE("message-type-wrap");
    KRB_DECODE_UINT32_OR_DIE("message-type", msg_type);

    if (kerberos_tree) {
        proto_tree_add_text(kerberos_tree, NullTVB, offset, length,
                            "MSG Type: %s",
                            val_to_str(msg_type, krb5_msg_types,
                                       "Unknown msg type %#x"));
    }
    offset += length;

    if (check_col(fd, COL_INFO))
        col_add_str(fd, COL_INFO, val_to_str(msg_type, krb5_msg_types,
                                             "Unknown msg type %#x"));

        /* is preauthentication present? */
    KRB_HEAD_DECODE_OR_DIE("padata-or-body");
    if (((protocol_message_type == KRB5_MSG_AS_REQ ||
          protocol_message_type == KRB5_MSG_TGS_REQ) &&
         tag == KRB5_KDC_REQ_PADATA) ||
        ((protocol_message_type == KRB5_MSG_AS_REP ||
          protocol_message_type == KRB5_MSG_TGS_REP) &&
         tag == KRB5_KDC_REP_PADATA)) {
        /* pre-authentication supplied */

        if (tree) {
            item = proto_tree_add_text(kerberos_tree, NullTVB, offset,
                                       item_len, "Pre-Authentication");
            preauth_tree = proto_item_add_subtree(item, ett_preauth);
        }

        KRB_HEAD_DECODE_OR_DIE("sequence of pa-data");
        start = asn1p->pointer + item_len;

        while(start > asn1p->pointer) {
            dissect_type_value_pair(asn1p, &offset,
                                    &preauth_type, &item_len, &tmp_pos1,
                                    &str, &str_len, &tmp_pos2);

            if (preauth_tree) {
                proto_tree_add_text(preauth_tree, NullTVB, tmp_pos1,
                                    item_len, "Type: %s",
                                    val_to_str(preauth_type,
                                               krb5_preauthentication_types,
                                               "Unknown preauth type %#x"));
                proto_tree_add_text(preauth_tree, NullTVB, tmp_pos2,
                                    str_len, "Value: %s",
                                    bytes_to_str(str, str_len));
            }
        }
        KRB_HEAD_DECODE_OR_DIE("message-body");
    }

    switch (protocol_message_type) {

    case KRB5_MSG_AS_REQ:
    case KRB5_MSG_TGS_REQ:
/*
  AS-REQ ::=         [APPLICATION 10] KDC-REQ
  TGS-REQ ::=        [APPLICATION 12] KDC-REQ
    
  KDC-REQ ::=        SEQUENCE {
           pvno[1]               INTEGER,
           msg-type[2]           INTEGER,
           padata[3]             SEQUENCE OF PA-DATA OPTIONAL,
           req-body[4]           KDC-REQ-BODY
  }

  KDC-REQ-BODY ::=   SEQUENCE {
            kdc-options[0]       KDCOptions,
            cname[1]             PrincipalName OPTIONAL,
                         -- Used only in AS-REQ
            realm[2]             Realm, -- Server's realm
                         -- Also client's in AS-REQ
            sname[3]             PrincipalName OPTIONAL,
            from[4]              KerberosTime OPTIONAL,
            till[5]              KerberosTime,
            rtime[6]             KerberosTime OPTIONAL,
            nonce[7]             INTEGER,
            etype[8]             SEQUENCE OF INTEGER, -- EncryptionType,
                         -- in preference order
            addresses[9]         HostAddresses OPTIONAL,
            enc-authorization-data[10]   EncryptedData OPTIONAL,
                         -- Encrypted AuthorizationData encoding
            additional-tickets[11]       SEQUENCE OF Ticket OPTIONAL
  }

*/
        /* request body */
        KRB_HEAD_DECODE_OR_DIE("body-sequence");
        if (tree) {
            item = proto_tree_add_text(kerberos_tree, NullTVB, offset,
                                       item_len, "Request");
            request_tree = proto_item_add_subtree(item, ett_request);
        }

        /* kdc options */
        KRB_HEAD_DECODE_OR_DIE("kdc options");

        KRB_HEAD_DECODE_OR_DIE("kdc options:bits");

        if (request_tree) {
                proto_tree_add_text(request_tree, NullTVB, offset, item_len,
                                    "Options: %s",
                                    bytes_to_str(asn1.pointer, item_len));
        }
        offset += item_len;
        asn1.pointer += item_len;

        KRB_HEAD_DECODE_OR_DIE("Client Name or Realm");

        if (CHECK_CONTEXT_TYPE(KRB5_BODY_CNAME)) {
            item_len = dissect_PrincipalName("Client Name", asn1p, fd,
                                             request_tree, offset);
            if (item_len == -1)
                return -1;
            offset += item_len;
            KRB_HEAD_DECODE_OR_DIE("Realm");
        }

        DIE_IF_NOT_CONTEXT_TYPE("Realm", KRB5_BODY_REALM);
        KRB_DECODE_GENERAL_STRING_OR_DIE("Realm", str, str_len, item_len);
        if (request_tree) {
            proto_tree_add_text(request_tree, NullTVB, offset, item_len,
                                "Realm: %.*s", str_len, str);
        }
        offset += item_len;

        KRB_HEAD_DECODE_OR_DIE("Server Name");
        if (CHECK_CONTEXT_TYPE(KRB5_BODY_SNAME)) {
            item_len = dissect_PrincipalName("Server Name", asn1p, fd,
                                             request_tree, offset);
            if (item_len == -1)
                return -1;
            offset += item_len;
            KRB_HEAD_DECODE_OR_DIE("From or Till");
        }

        if (CHECK_CONTEXT_TYPE(KRB5_BODY_FROM)) {
            KRB_DECODE_GENERAL_TIME_OR_DIE("From", str, str_len, item_len);
            krb_proto_tree_add_time(request_tree, offset, item_len,
                                    "Start Time", str);
            offset += item_len;
            KRB_HEAD_DECODE_OR_DIE("Till");
        }

        DIE_IF_NOT_CONTEXT_TYPE("Till", KRB5_BODY_TILL);
        KRB_DECODE_GENERAL_TIME_OR_DIE("Till", str, str_len, item_len);
        krb_proto_tree_add_time(request_tree, offset, item_len,
                                "End Time", str);
        offset += item_len;

        KRB_HEAD_DECODE_OR_DIE("Renewable Until or Nonce");
        if (CHECK_CONTEXT_TYPE(KRB5_BODY_RTIME)) {
            KRB_DECODE_GENERAL_TIME_OR_DIE("Renewable Until", str, str_len, item_len);
            krb_proto_tree_add_time(request_tree, offset, item_len,
                                    "Renewable Until", str);
            offset += item_len;
            KRB_HEAD_DECODE_OR_DIE("Nonce");
        }
            
        DIE_IF_NOT_CONTEXT_TYPE("Nonce", KRB5_BODY_NONCE);
        KRB_DECODE_UINT32_OR_DIE("Nonce", tmp_int);
        if (request_tree) {
            proto_tree_add_text(request_tree, NullTVB, offset, length,
                                "Random Number: %u",
                                tmp_int);
        }
        offset += length;
        
        KRB_DECODE_CONTEXT_HEAD_OR_DIE("encryption type spot",
                                              KRB5_BODY_ETYPE);
        KRB_HEAD_DECODE_OR_DIE("encryption type list");
        if (kerberos_tree) {
            item = proto_tree_add_text(request_tree, NullTVB, offset,
                                       item_len, "Encryption Types");
            etype_tree = proto_item_add_subtree(item, ett_etype);
        }
        total_len = item_len;
        while(total_len > 0) {
            KRB_DECODE_UINT32_OR_DIE("encryption type", tmp_int);
            if (etype_tree) {
                proto_tree_add_text(etype_tree, NullTVB, offset, length,
                                    "Type: %s",
                                    val_to_str(tmp_int,
                                               krb5_encryption_types,
                                               "Unknown encryption type %#x"));
            }
            offset += length;
            total_len -= length;
        }

        KRB_HEAD_DECODE_OR_DIE("addresses");
        if (CHECK_CONTEXT_TYPE(KRB5_BODY_ADDRESSES)) {
            /* pre-authentication supplied */

            offset = dissect_Addresses("Addresses", asn1p, fd, kerberos_tree,
                                       offset);
            if (offset == -1)
                return -1;
            KRB_HEAD_DECODE_OR_DIE("auth-data");
        }
        break;

    case KRB5_MSG_AS_REP:
    case KRB5_MSG_TGS_REP:
/*
   AS-REP ::=    [APPLICATION 11] KDC-REP
   TGS-REP ::=   [APPLICATION 13] KDC-REP

   KDC-REP ::=   SEQUENCE {
                 pvno[0]                    INTEGER,
                 msg-type[1]                INTEGER,
                 padata[2]                  SEQUENCE OF PA-DATA OPTIONAL,
                 crealm[3]                  Realm,
                 cname[4]                   PrincipalName,
                 ticket[5]                  Ticket,
                 enc-part[6]                EncryptedData
   }
*/

        if (tag == KRB5_KDC_REP_CREALM) {
            KRB_DECODE_GENERAL_STRING_OR_DIE("realm name", str, str_len, item_len);
            if (kerberos_tree) {
                proto_tree_add_text(kerberos_tree, NullTVB, offset, item_len,
                                    "Realm: %.*s", str_len, str);
            }
            offset += item_len;
        } else {
            DIE_WITH_BAD_TYPE("crealm");
        }

        KRB_DECODE_CONTEXT_HEAD_OR_DIE("cname", KRB5_KDC_REP_CNAME);
        item_len = dissect_PrincipalName("Client Name", asn1p, fd,
                                         kerberos_tree, offset);
        if (item_len == -1)
            return -1;
        offset += item_len;
        
        KRB_DECODE_CONTEXT_HEAD_OR_DIE("ticket", KRB5_KDC_REP_TICKET);
        offset = dissect_Ticket("ticket", asn1p, fd, kerberos_tree, offset);
        if (offset == -1)
            return -1;

        KRB_DECODE_CONTEXT_HEAD_OR_DIE("enc-msg-part",
                                              KRB5_KDC_REP_ENC_PART);
        offset = dissect_EncryptedData("Encrypted Payload", asn1p, fd,
                                       kerberos_tree, offset);
        if (offset == -1)
            return -1;
        break;
    }
    return offset;
}

static void
dissect_kerberos(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
{
    OLD_CHECK_DISPLAY_AS_DATA(proto_kerberos, pd, offset, fd, tree);

    if (check_col(fd, COL_PROTOCOL))
        col_set_str(fd, COL_PROTOCOL, "KRB5");

    dissect_kerberos_main(pd, offset, fd, tree);
}

static int
dissect_PrincipalName(char *title, ASN1_SCK *asn1p, frame_data *fd,
                       proto_tree *tree, int start_offset)
{
/*
   PrincipalName ::=   SEQUENCE {
                       name-type[0]     INTEGER,
                       name-string[1]   SEQUENCE OF GeneralString
   }
*/
    proto_tree *princ_tree = NULL;
    int offset = start_offset;

    guint32 princ_type;

    const guchar *start;
    guint cls, con, tag;
    guint header_len, item_len, total_len, type_len;
    int ret;

    proto_item *item = NULL;
    guint length;
    gboolean def;

    int type_offset;

    guchar *name;
    guint name_len;

    /* principal name */
    KRB_SEQ_HEAD_DECODE_OR_DIE("principal section");

    if (tree) {
      item = proto_tree_add_text(tree, NullTVB, start_offset,
                                 (offset - start_offset) + item_len, "%s",
                                 title);
      princ_tree = proto_item_add_subtree(item, ett_princ);
    } else {
      item = NULL;
      princ_tree = NULL;
    }

    KRB_DECODE_CONTEXT_HEAD_OR_DIE("principal type", 0);
    KRB_DECODE_UINT32_OR_DIE("princ-type", princ_type);
    type_offset = offset;
    type_len = item_len;
    offset += length;

    if (princ_tree) {
      proto_tree_add_text(princ_tree, NullTVB, type_offset, type_len,
                          "Type: %u", princ_type);
    }

    KRB_DECODE_CONTEXT_HEAD_OR_DIE("principal name-string", 1);
    KRB_SEQ_HEAD_DECODE_OR_DIE("principal name-string sequence-of");
    total_len = item_len;
    while (total_len > 0) {
        KRB_DECODE_GENERAL_STRING_OR_DIE("principal name", name, name_len, item_len);
        if (princ_tree) {
            proto_tree_add_text(princ_tree, NullTVB, offset, item_len,
                                "Name: %.*s", (int) name_len, name);
        }
        total_len -= item_len;
        offset += item_len;
    }
    return offset - start_offset;
}

static int
dissect_Addresses(char *title, ASN1_SCK *asn1p, frame_data *fd,
                  proto_tree *tree, int start_offset) {
    proto_tree *address_tree = NULL;
    int offset = start_offset;

    const guchar *start;
    guint cls, con, tag;
    guint item_len;
    int ret;

    proto_item *item = NULL;
    gboolean def;

    int tmp_pos1, tmp_pos2;
    guint32 address_type;

    int str_len;
    guchar *str;

    KRB_HEAD_DECODE_OR_DIE("sequence of addresses");
    if (tree) {
        item = proto_tree_add_text(tree, NullTVB, offset,
                                   item_len, "Addresses");
        address_tree = proto_item_add_subtree(item, ett_addresses);
    }

    start = asn1p->pointer + item_len;

    while(start > asn1p->pointer) {
        dissect_type_value_pair(asn1p, &offset,
                                &address_type, &item_len, &tmp_pos1,
                                &str, &str_len, &tmp_pos2);

        if (address_tree) {
            proto_tree_add_text(address_tree, NullTVB, tmp_pos1,
                                item_len, "Type: %s",
                                val_to_str(address_type, krb5_address_types,
                                           "Unknown address type %#x"));
            switch(address_type) {
                case KRB5_ADDR_IPv4:
                    proto_tree_add_text(address_tree, NullTVB, tmp_pos2,
                                        str_len, "Value: %d.%d.%d.%d",
                                        str[0], str[1], str[2], str[3]);
                    break;
                    
                default:
                    proto_tree_add_text(address_tree, NullTVB, tmp_pos2,
                                        str_len, "Value: %s",
                                        bytes_to_str(str, str_len));
            }
        }
    }
    
    return offset;
}

static int
dissect_EncryptedData(char *title, ASN1_SCK *asn1p, frame_data *fd,
                      proto_tree *tree, int start_offset)
{
/*
   EncryptedData ::=   SEQUENCE {
                       etype[0]     INTEGER, -- EncryptionType
                       kvno[1]      INTEGER OPTIONAL,
                       cipher[2]    OCTET STRING -- ciphertext
   }
*/
    proto_tree *encr_tree = NULL;
    int offset = start_offset;

    const guchar *start;
    guint cls, con, tag;
    guint header_len, item_len, data_len;
    int ret;

    proto_item *item = NULL;
    guint length;
    gboolean def;
    guint32 val;

    guchar *data;

    KRB_SEQ_HEAD_DECODE_OR_DIE("encrypted data section");

    if (tree) {
        item = proto_tree_add_text(tree, NullTVB, start_offset,
                                   (offset - start_offset) + item_len,
                                   "Encrypted Data: %s", title);
        encr_tree = proto_item_add_subtree(item, ett_princ);
    }

    /* type */
    KRB_DECODE_CONTEXT_HEAD_OR_DIE("encryption type", 0);
    KRB_DECODE_UINT32_OR_DIE("encr-type", val);
    if (encr_tree) {
        proto_tree_add_text(encr_tree, NullTVB, offset, length,
                            "Type: %s",
                            val_to_str(val, krb5_encryption_types,
                                       "Unknown encryption type %#x"));
    }
    offset += length;

    /* kvno */
    KRB_HEAD_DECODE_OR_DIE("kvno-wrap or cipher-wrap");
    if (CHECK_CONTEXT_TYPE(1)) {
      KRB_DECODE_UINT32_OR_DIE("kvno", val);
      if (encr_tree) {
          proto_tree_add_text(encr_tree, NullTVB, offset, length,
                              "KVNO: %d", val);
      }
      offset += length;
      KRB_HEAD_DECODE_OR_DIE("cipher-wrap");
    }

    DIE_IF_NOT_CONTEXT_TYPE("cipher-wrap", 2);
    KRB_DECODE_OCTET_STRING_OR_DIE("cipher", data, data_len, item_len);

    if (encr_tree) {
        proto_tree_add_text(encr_tree, NullTVB, offset, data_len,
                            "Cipher: %s", bytes_to_str(data, item_len));
    }
    offset += data_len;
    
    return offset;
}

static int
dissect_Ticket(char *title, ASN1_SCK *asn1p, frame_data *fd, proto_tree *tree,
               int start_offset)
{
/*
   Ticket ::=                    [APPLICATION 1] SEQUENCE {
                                 tkt-vno[0]                   INTEGER,
                                 realm[1]                     Realm,
                                 sname[2]                     PrincipalName,
                                 enc-part[3]                  EncryptedData
   }
*/
    proto_tree *ticket_tree = NULL;
    int offset = start_offset;

    const guchar *start;
    guint cls, con, tag;
    guint header_len, item_len, total_len;
    int ret;

    proto_item *item = NULL;
    guint length;
    gboolean def;
    guint32 val;

    int str_len;
    guchar *str;

    KRB_DECODE_APPLICATION_TAGGED_HEAD_OR_DIE("Ticket section", 1);
    KRB_SEQ_HEAD_DECODE_OR_DIE("Ticket sequence");
    total_len = item_len;

    if (tree) {
        item = proto_tree_add_text(tree, NullTVB, start_offset,
                                   (offset - start_offset) + item_len,
                                   "Ticket");
        ticket_tree = proto_item_add_subtree(item, ett_ticket);
    }

    /* type */
    KRB_DECODE_CONTEXT_HEAD_OR_DIE("Ticket tkt-vno", KRB5_TKT_TKT_VNO);
    KRB_DECODE_UINT32_OR_DIE("Ticket tkt-vno", val);
    if (ticket_tree) {
        proto_tree_add_text(ticket_tree, NullTVB, offset, length,
                            "Version: %u", val);
    }
    offset += length;
    total_len -= length;

    /* realm name */
    KRB_DECODE_CONTEXT_HEAD_OR_DIE("Ticket realm", KRB5_TKT_REALM);
    KRB_DECODE_GENERAL_STRING_OR_DIE("Ticket realm string", str, str_len, item_len);
    if (ticket_tree) {
        proto_tree_add_text(ticket_tree, NullTVB, offset, item_len,
                            "Realm: %.*s", str_len, str);
    }
    offset += item_len;
    total_len -= item_len;

    /* server name (sname) */
    KRB_DECODE_CONTEXT_HEAD_OR_DIE("Ticket sname", KRB5_TKT_SNAME);
    item_len = dissect_PrincipalName("Service Name", asn1p, fd, ticket_tree,
                                     offset);
    if (item_len == -1)
        return -1;
    offset += item_len;

    /* encrypted part */
    KRB_DECODE_CONTEXT_HEAD_OR_DIE("enc-part", KRB5_TKT_ENC_PART);
    offset = dissect_EncryptedData("Ticket data", asn1p, fd, ticket_tree,
                                   offset);
    if (offset == -1)
        return -1;

    return offset;
}


void
proto_register_kerberos(void) {
/*
    static hf_register_info hf[] = {
    };
*/
    static gint *ett[] = {
        &ett_kerberos,
        &ett_preauth,
        &ett_request,
        &ett_princ,
        &ett_encrypted,
        &ett_ticket,
        &ett_addresses,
        &ett_etype,
    };
    proto_kerberos = proto_register_protocol("Kerberos", "kerberos");
/*
    proto_register_field_array(proto_kerberos, hf, array_length(hf));
*/
    proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_kerberos(void)
{
	old_dissector_add("udp.port", UDP_PORT_KERBEROS, dissect_kerberos);
	old_dissector_add("tcp.port", TCP_PORT_KERBEROS, dissect_kerberos);
}

/*

  MISC definitions from RFC1510:
  
   Realm ::=           GeneralString

   KerberosTime ::=   GeneralizedTime

   HostAddress ::=    SEQUENCE  {
                      addr-type[0]             INTEGER,
                      address[1]               OCTET STRING
   }

   HostAddresses ::=   SEQUENCE OF SEQUENCE {
                       addr-type[0]             INTEGER,
                       address[1]               OCTET STRING
   }

   AuthorizationData ::=   SEQUENCE OF SEQUENCE {
                           ad-type[0]               INTEGER,
                           ad-data[1]               OCTET STRING
   }
                   APOptions ::=   BIT STRING {
                                   reserved(0),
                                   use-session-key(1),
                                   mutual-required(2)
                   }


                   TicketFlags ::=   BIT STRING {
                                     reserved(0),
                                     forwardable(1),
                                     forwarded(2),
                                     proxiable(3),
                                     proxy(4),
                                     may-postdate(5),
                                     postdated(6),
                                     invalid(7),
                                     renewable(8),
                                     initial(9),
                                     pre-authent(10),
                                     hw-authent(11)
                   }

                  KDCOptions ::=   BIT STRING {
                                   reserved(0),
                                   forwardable(1),
                                   forwarded(2),
                                   proxiable(3),
                                   proxy(4),
                                   allow-postdate(5),
                                   postdated(6),
                                   unused7(7),
                                   renewable(8),
                                   unused9(9),
                                   unused10(10),
                                   unused11(11),
                                   renewable-ok(27),
                                   enc-tkt-in-skey(28),
                                   renew(30),
                                   validate(31)
                  }


            LastReq ::=   SEQUENCE OF SEQUENCE {
                          lr-type[0]               INTEGER,
                          lr-value[1]              KerberosTime
            }

   Ticket ::=                    [APPLICATION 1] SEQUENCE {
                                 tkt-vno[0]                   INTEGER,
                                 realm[1]                     Realm,
                                 sname[2]                     PrincipalName,
                                 enc-part[3]                  EncryptedData
   }

  -- Encrypted part of ticket
  EncTicketPart ::=     [APPLICATION 3] SEQUENCE {
                        flags[0]             TicketFlags,
                        key[1]               EncryptionKey,
                        crealm[2]            Realm,
                        cname[3]             PrincipalName,
                        transited[4]         TransitedEncoding,
                        authtime[5]          KerberosTime,
                        starttime[6]         KerberosTime OPTIONAL,
                        endtime[7]           KerberosTime,
                        renew-till[8]        KerberosTime OPTIONAL,
                        caddr[9]             HostAddresses OPTIONAL,
                        authorization-data[10]   AuthorizationData OPTIONAL
  }

  -- encoded Transited field
  TransitedEncoding ::=         SEQUENCE {
                                tr-type[0]  INTEGER, -- must be registered
                                contents[1]          OCTET STRING
  }

  -- Unencrypted authenticator
  Authenticator ::=    [APPLICATION 2] SEQUENCE    {
                 authenticator-vno[0]          INTEGER,
                 crealm[1]                     Realm,
                 cname[2]                      PrincipalName,
                 cksum[3]                      Checksum OPTIONAL,
                 cusec[4]                      INTEGER,
                 ctime[5]                      KerberosTime,
                 subkey[6]                     EncryptionKey OPTIONAL,
                 seq-number[7]                 INTEGER OPTIONAL,
                 authorization-data[8]         AuthorizationData OPTIONAL
  }

  PA-DATA ::=        SEQUENCE {
           padata-type[1]        INTEGER,
           padata-value[2]       OCTET STRING,
                         -- might be encoded AP-REQ
  }

   padata-type     ::= PA-ENC-TIMESTAMP
   padata-value    ::= EncryptedData -- PA-ENC-TS-ENC

   PA-ENC-TS-ENC   ::= SEQUENCE {
           patimestamp[0]               KerberosTime, -- client's time
           pausec[1]                    INTEGER OPTIONAL
   }

   EncASRepPart ::=    [APPLICATION 25[25]] EncKDCRepPart
   EncTGSRepPart ::=   [APPLICATION 26] EncKDCRepPart

   EncKDCRepPart ::=   SEQUENCE {
               key[0]                       EncryptionKey,
               last-req[1]                  LastReq,
               nonce[2]                     INTEGER,
               key-expiration[3]            KerberosTime OPTIONAL,
               flags[4]                     TicketFlags,
               authtime[5]                  KerberosTime,
               starttime[6]                 KerberosTime OPTIONAL,
               endtime[7]                   KerberosTime,
               renew-till[8]                KerberosTime OPTIONAL,
               srealm[9]                    Realm,
               sname[10]                    PrincipalName,
               caddr[11]                    HostAddresses OPTIONAL
   }

   AP-REQ ::=      [APPLICATION 14] SEQUENCE {
                   pvno[0]                       INTEGER,
                   msg-type[1]                   INTEGER,
                   ap-options[2]                 APOptions,
                   ticket[3]                     Ticket,
                   authenticator[4]              EncryptedData
   }

   APOptions ::=   BIT STRING {
                   reserved(0),
                   use-session-key(1),
                   mutual-required(2)
   }

   AP-REP ::=         [APPLICATION 15] SEQUENCE {
              pvno[0]                   INTEGER,
              msg-type[1]               INTEGER,
              enc-part[2]               EncryptedData
   }

   EncAPRepPart ::=   [APPLICATION 27]     SEQUENCE {
              ctime[0]                  KerberosTime,
              cusec[1]                  INTEGER,
              subkey[2]                 EncryptionKey OPTIONAL,
              seq-number[3]             INTEGER OPTIONAL
   }

   KRB-SAFE ::=        [APPLICATION 20] SEQUENCE {
               pvno[0]               INTEGER,
               msg-type[1]           INTEGER,
               safe-body[2]          KRB-SAFE-BODY,
               cksum[3]              Checksum
   }

   KRB-SAFE-BODY ::=   SEQUENCE {
               user-data[0]          OCTET STRING,
               timestamp[1]          KerberosTime OPTIONAL,
               usec[2]               INTEGER OPTIONAL,
               seq-number[3]         INTEGER OPTIONAL,
               s-address[4]          HostAddress,
               r-address[5]          HostAddress OPTIONAL
   }

   KRB-PRIV ::=         [APPLICATION 21] SEQUENCE {
                pvno[0]                   INTEGER,
                msg-type[1]               INTEGER,
                enc-part[3]               EncryptedData
   }

   EncKrbPrivPart ::=   [APPLICATION 28] SEQUENCE {
                user-data[0]              OCTET STRING,
                timestamp[1]              KerberosTime OPTIONAL,
                usec[2]                   INTEGER OPTIONAL,
                seq-number[3]             INTEGER OPTIONAL,
                s-address[4]              HostAddress, -- sender's addr
                r-address[5]              HostAddress OPTIONAL
                                                      -- recip's addr
   }

   KRB-CRED         ::= [APPLICATION 22]   SEQUENCE {
                    pvno[0]                INTEGER,
                    msg-type[1]            INTEGER, -- KRB_CRED
                    tickets[2]             SEQUENCE OF Ticket,
                    enc-part[3]            EncryptedData
   }

   EncKrbCredPart   ::= [APPLICATION 29]   SEQUENCE {
                    ticket-info[0]         SEQUENCE OF KrbCredInfo,
                    nonce[1]               INTEGER OPTIONAL,
                    timestamp[2]           KerberosTime OPTIONAL,
                    usec[3]                INTEGER OPTIONAL,
                    s-address[4]           HostAddress OPTIONAL,
                    r-address[5]           HostAddress OPTIONAL
   }

   KrbCredInfo      ::=                    SEQUENCE {
                    key[0]                 EncryptionKey,
                    prealm[1]              Realm OPTIONAL,
                    pname[2]               PrincipalName OPTIONAL,
                    flags[3]               TicketFlags OPTIONAL,
                    authtime[4]            KerberosTime OPTIONAL,
                    starttime[5]           KerberosTime OPTIONAL,
                    endtime[6]             KerberosTime OPTIONAL
                    renew-till[7]          KerberosTime OPTIONAL,
                    srealm[8]              Realm OPTIONAL,
                    sname[9]               PrincipalName OPTIONAL,
                    caddr[10]              HostAddresses OPTIONAL
   }

   KRB-ERROR ::=   [APPLICATION 30] SEQUENCE {
                   pvno[0]               INTEGER,
                   msg-type[1]           INTEGER,
                   ctime[2]              KerberosTime OPTIONAL,
                   cusec[3]              INTEGER OPTIONAL,
                   stime[4]              KerberosTime,
                   susec[5]              INTEGER,
                   error-code[6]         INTEGER,
                   crealm[7]             Realm OPTIONAL,
                   cname[8]              PrincipalName OPTIONAL,
                   realm[9]              Realm, -- Correct realm
                   sname[10]             PrincipalName, -- Correct name
                   e-text[11]            GeneralString OPTIONAL,
                   e-data[12]            OCTET STRING OPTIONAL
   }

   e-data    This field contains additional data about the error for use
             by the application to help it recover from or handle the
             error.  If the errorcode is KDC_ERR_PREAUTH_REQUIRED, then
             the e-data field will contain an encoding of a sequence of
             padata fields, each corresponding to an acceptable pre-
             authentication method and optionally containing data for
             the method:

      METHOD-DATA ::=    SEQUENCE of PA-DATA

   If the error-code is KRB_AP_ERR_METHOD, then the e-data field will
   contain an encoding of the following sequence:

      METHOD-DATA ::=    SEQUENCE {
                         method-type[0]   INTEGER,
                         method-data[1]   OCTET STRING OPTIONAL
       }

          EncryptionKey ::=   SEQUENCE {
                              keytype[0]    INTEGER,
                              keyvalue[1]   OCTET STRING
          }

            Checksum ::=   SEQUENCE {
                           cksumtype[0]   INTEGER,
                           checksum[1]    OCTET STRING
            }

*/