Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-peap.c
blob8fccb992f641b8712a799dbcc123e6c5dc8b336d
1 /* packet-peap.c
2 * Routines for PEAP (Protected Extensible Authentication Protocol)
3 * draft-kamath-pppext-peapv0
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <stdio.h>
16 #include <epan/packet.h>
17 #include <epan/eap.h>
18 #include <epan/expert.h>
19 #include <wsutil/pint.h>
20 #include <epan/proto_data.h>
22 void proto_register_peap(void);
23 void proto_reg_handoff_peap(void);
25 static int proto_peap;
26 static int proto_eap;
28 static dissector_handle_t peap_handle;
29 static dissector_handle_t eap_handle;
32 From draft-kamath-pppext-peapv0, sec 1.1
34 0 1 2 3
35 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
36 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 | Code | Identifier | Length | <-- NOT sent
38 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 | Type | Value...
40 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 This matches the format of an EAP header but...
43 * 'Code', 'Identifier' and 'Length' are NOT sent over the wire
44 * 'Code' and 'Identifier' are extracted from the *outer* EAP header
45 * 'Length' is derived from the PEAP packet (ie. TLS data frame)
46 * ...when 'Type' is 33, the full EAP header is sent
49 #define EAP_TLS_FLAGS_OFFSET 5
50 #define EAP_TLS_FLAGS_VERSION 0x07 /* mask */
52 static int
53 dissect_peap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
55 int version;
56 int len;
57 int offset = 0;
58 tvbuff_t *eap_tvb, *eap_len_tvb, *next_tvb;
59 unsigned char *eap_len_buf;
60 uint32_t tls_group = pinfo->curr_proto_layer_num << 16;
62 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PEAP");
63 col_clear(pinfo->cinfo, COL_INFO);
65 len = tvb_reported_length(tvb);
67 eap_tvb = (tvbuff_t *)p_get_proto_data(pinfo->pool, pinfo, proto_eap, PROTO_DATA_EAP_TVB | tls_group);
68 version = tvb_get_uint8(eap_tvb, EAP_TLS_FLAGS_OFFSET) & EAP_TLS_FLAGS_VERSION;
69 if (version > 0) { /* FIXME support v1 and v2 */
70 goto ret;
73 if (!( len >= 5
74 && tvb_get_bits(tvb, offset, 16, ENC_BIG_ENDIAN) == tvb_get_bits(eap_tvb, 0, 16, ENC_BIG_ENDIAN)
75 && tvb_get_uint16(tvb, offset + 2, ENC_BIG_ENDIAN) <= tvb_get_uint16(eap_tvb, 2, ENC_BIG_ENDIAN)
76 && (
77 (tvb_get_uint8(eap_tvb, 0) == EAP_REQUEST && tvb_get_uint8(tvb, offset + 4) == EAP_TYPE_ID)
78 || tvb_get_uint8(tvb, offset + 4) == EAP_TYPE_MSAUTH_TLV
79 ))) {
80 eap_len_buf = (unsigned char *)wmem_alloc(pinfo->pool, 2);
81 eap_len_tvb = tvb_new_child_real_data(tvb, eap_len_buf, 2, 2);
82 phton16(eap_len_buf, 4 + len);
84 next_tvb = tvb_new_composite();
85 tvb_composite_append(next_tvb, tvb_new_subset_length(eap_tvb, 0, 2));
86 tvb_composite_append(next_tvb, eap_len_tvb);
87 tvb_composite_append(next_tvb, tvb_new_subset_length(tvb, offset, 4 + len));
88 tvb_composite_finalize(next_tvb);
90 add_new_data_source(pinfo, next_tvb, "Pseudo EAP");
91 } else {
92 next_tvb = tvb;
95 call_dissector(eap_handle, next_tvb, pinfo, tree);
97 ret:
98 return len;
101 void
102 proto_register_peap(void)
104 proto_peap = proto_register_protocol("Protected Extensible Authentication Protocol",
105 "PEAP", "peap");
106 peap_handle = register_dissector("peap", dissect_peap, proto_peap);
109 void
110 proto_reg_handoff_peap(void)
112 proto_eap = proto_get_id_by_filter_name("eap");
113 eap_handle = find_dissector_add_dependency("eap", proto_peap);
116 * Editor modelines
118 * Local Variables:
119 * c-basic-offset: 2
120 * tab-width: 8
121 * indent-tabs-mode: nil
122 * End:
124 * ex: set shiftwidth=2 tabstop=8 expandtab:
125 * :indentSize=2:tabSize=8:noTabs=true: