netpkt/eapol.rs#
Source: lib/netpkt/eapol.rs
eapol -- EAPOL frames (IEEE 802.1X-2004 clause 11) with the EAPOL-Key body of IEEE 802.11-2020
12.7.2: the four messages of the 4-way handshake, the RSN element a station and an access
point put into them, and the key data elements (KDEs) of message 3. No cryptography here:
the caller computes the MIC over mic_input() (HMAC-SHA1-128 or AES-128-CMAC by the key
descriptor version) and wraps the key data (the AES key wrap of RFC 3394)
ET_EAPOL (eth.rs) 0x888E
EapolView::parse(pdu) version, packet type, body length, body
Key { info, key_len, replay, nonce, iv, rsc, mic, data } the EAPOL-Key body
Key::parse(body) / Key::pdu(version) -> Vec<u8> read one, write the whole EAPOL PDU
Key::message() -> Option<u8> 1 .. 4 of the 4-way handshake by its Key Information bits
mic_input(pdu) -> Vec<u8> the PDU with the MIC field zero (what the MIC covers)
set_mic(pdu, mic) puts the MIC into a written PDU
Rsne { akm, caps } the RSN element (CCMP for group and pairwise, one AKM):
to_bytes / parse
kde_gtk(id, gtk) / kde_igtk(id, ipn, igtk) / kdes(data) KDEs and the elements of key
data (with the padding of 12.7.2 j: 0xdd 0x00 ...)
pad_key_data(data) the padding for the key wrap (a multiple of 8, at least 16)
KI_* (Key Information), AKM_* and CIPHER_CCMP (the suites of 00-0F-AC)
pdu(version, kind, body) any other EAPOL PDU; start(version), logoff(version) and
eap_pdu(version, eap) are the ones of port access control
PAE_GROUP the group address of the port access entities (802.1X-2004
7.8): bridges never forward it
The fields are big endian; the key replay counter is a 64-bit number. Lengths are checked
once by parse; a body shorter than the 95 fixed bytes is no Key.
/// EAPOL packet types (802.1X-2004 11.3.2)
T_EAP: u8 = 0
T_START: u8 = 1
T_LOGOFF: u8 = 2
T_KEY: u8 = 3
/// the version 802.1X-2004 writes
VERSION_2004: u8 = 2
/// the RSN key descriptor type (802.11-2020 12.7.2)
DESC_RSN: u8 = 2
/// Key Information bits (802.11-2020 Figure 12-33)
KI_VERSION: u16 = 0x0007
KI_PAIRWISE: u16 = 0x0008
KI_INSTALL: u16 = 0x0040
KI_ACK: u16 = 0x0080
KI_MIC: u16 = 0x0100
KI_SECURE: u16 = 0x0200
KI_ERROR: u16 = 0x0400
KI_REQUEST: u16 = 0x0800
KI_ENCRYPTED: u16 = 0x1000
/// key descriptor versions: 2 HMAC-SHA1-128 MIC with the AES key wrap (AKM 2, PSK), 3 AES-128-CMAC
/// (AKM 6), 0 what the AKM defines (AKM 8, SAE: AES-128-CMAC)
KDV_AKM: u16 = 0
KDV_SHA1: u16 = 2
KDV_CMAC: u16 = 3
/// the fixed part of an EAPOL-Key body with a 16-byte MIC
KEY_FIXED: usize = 95
/// where the MIC sits in the body, its length
MIC_OFF: usize = 77
MIC_LEN: usize = 16
/// the OUI of IEEE 802.11 suites and KDEs
OUI: [u8; 3] = [0x00, 0x0F, 0xAC]
/// cipher suite: CCMP-128
CIPHER_CCMP: u8 = 4
/// AKM suites: PSK (WPA2-Personal), PSK-SHA256, SAE (WPA3-Personal)
AKM_PSK: u8 = 2
AKM_PSK_SHA256: u8 = 6
AKM_SAE: u8 = 8
/// AKM suites of 802.1X: WPA2-Enterprise and, with SHA-256, WPA3-Enterprise
AKM_8021X: u8 = 1
AKM_8021X_SHA256: u8 = 5
/// the group address EAPOL goes to on a wired port (802.1X-2004 7.8)
PAE_GROUP: [u8; 6] = [0x01, 0x80, 0xC2, 0x00, 0x00, 0x03]
/// RSN capabilities: management frame protection capable / required
RSN_MFPR: u16 = 0x0040
RSN_MFPC: u16 = 0x0080
/// the element id of the RSN element, the id of a vendor element (KDEs)
EID_RSN: u8 = 48
EID_VENDOR: u8 = 0xDD
/// KDE types (802.11-2020 Table 12-10)
KDE_GTK: u8 = 1
KDE_PMKID: u8 = 4
KDE_IGTK: u8 = 9
struct EapolView<'a>the EAPOL header and body of a PDU
impl<'a> EapolView<'a>
fn parse(b: &'a [u8]) -> Option<EapolView<'a>>the 4-byte header and a body as long as it saysfn version(&self) -> u8fn kind(&self) -> u8fn body_len(&self) -> usizefn body(&self) -> &'a [u8]fn pdu(&self) -> &'a [u8]header and body without what follows (Ethernet padding)fn pdu(version: u8, kind: u8, body: &[u8]) -> Vec<u8>an EAPOL PDU: the header withversionandkind, the bodyfn start(version: u8) -> Vec<u8>EAPOL-Startfn logoff(version: u8) -> Vec<u8>EAPOL-Logofffn eap_pdu(version: u8, eap: &[u8]) -> Vec<u8>an EAP packet in an EAPOL PDUfn kind_name(t: u8) -> &'static strthe name of a packet type ("EAPOL-Key")struct Keyan EAPOL-Key body (RSN descriptor, a 16-byte MIC)info: u16key_len: u16replay: u64nonce: [u8; 32]iv: [u8; 16]rsc: [u8; 8]mic: [u8; 16]data: Vec<u8>
impl Key
fn parse(body: &[u8]) -> Option<Key>a key body; None when it is shorter than its fixed part or its key data, or is no RSN descriptorfn body(&self) -> Vec<u8>the body bytesfn pdu(&self, version: u8) -> Vec<u8>the whole EAPOL PDU (header withversion, packet type EAPOL-Key, the body)fn version(&self) -> u16the key descriptor version (KDV_*)fn has(&self, bits: u16) -> boolfn message(&self) -> Option<u8>which message of the 4-way handshake: 1 (Ack), 2 (MIC), 3 (Ack, MIC, Install), 4 (MIC, Secure); None for a group key message or a requestfn mic_input(pdu: &[u8]) -> Option<Vec<u8>>the PDU with the MIC field set to zero: what the MIC covers (None when it holds no key body)fn set_mic(pdu: &mut [u8], mic: &[u8; 16])writes the MIC into a PDU made by Key::pdustruct Rsnethe RSN element of a personal network: CCMP for group and pairwise traffic, one AKMakm: u8caps: u16
impl Rsne
fn to_bytes(&self) -> Vec<u8>the element with its id and length (22 bytes)fn parse(elems: &[u8]) -> Option<Rsne>the first RSN element of a list of elements (key data): the first AKM suite's type (of 00-0F-AC) and the capabilities after every AKM suite; the counts are little endian as in every elementfn elements(b: &[u8]) -> Vec<(u8, &[u8])>the elements of a list: (id, contents); stops at one that does not fitfn kde_gtk(id: u8, gtk: &[u8]) -> Vec<u8>the GTK KDE: key id (0..3), transmit bit clear, the keyfn kde_igtk(id: u16, ipn: u64, igtk: &[u8]) -> Vec<u8>the IGTK KDE (management frame protection): key id (4 or 5), its packet number, the keyfn kdes(data: &[u8]) -> Vec<(u8, &[u8])>the KDEs of key data: (type, contents after the type); other elements are left outfn pad_key_data(data: &[u8]) -> Vec<u8>key data padded for the key wrap: 0xdd and zeros up to a multiple of 8, at least 16 bytes