netpkt/eap.rs#
Source: lib/netpkt/eap.rs
eap -- EAP packets (RFC 3748): Request, Response, Success and Failure with the types Identity,
Notification and Nak, the data of EAP-MD5 (RFC 3748 5.4 with the value of RFC 1994 4.1) and
the exchanges of EAP-PWD (RFC 5931 3.2). No cryptography here: EAP-MD5's digest is lent by the
caller (crypto::md5_parts); the sums of EAP-PWD are crypto::eappwd, and the state machines of
a peer and a server are the crate eapm. EAP travels in EAPOL frames (eapol.rs) on a port and
in the EAP-Message attributes of RADIUS (radius.rs) behind the authenticator
REQUEST, RESPONSE, SUCCESS, FAILURE the codes; code_name
T_IDENTITY, T_NOTIFICATION, T_NAK, T_MD5, T_PWD the types; type_name (these and the types a
dissector meets: TLS, TTLS, PEAP, MS-CHAPv2)
Packet { code, id, typ, data } parse(b) / to_bytes; the constructors
request / response / success / failure /
identity_request / identity_response / nak
Packet::identity() / nak_types() what such a packet says
Md5Data { value, name } the Type-Data of EAP-MD5: parse / to_bytes
md5_value(id, secret, challenge, md5) MD5(Identifier || secret || Challenge)
Pwd the Type-Data of EAP-PWD: Id, Commit, Confirm;
parse / to_bytes; exch_name
PwdId { group, rand_func, prf, token, prep, identity }
info(b) one line about a packet for the packet tab
A packet is its 4-byte header and, for a Request or a Response, a type byte; bytes after its
Length field are padding (Ethernet) and go. EAP-PWD's L and M bits (fragments) are read and
refused: all three exchanges fit a frame, and a peer that fragments them is no peer of ours.
REQUEST: u8 = 1
RESPONSE: u8 = 2
SUCCESS: u8 = 3
FAILURE: u8 = 4
T_IDENTITY: u8 = 1
T_NOTIFICATION: u8 = 2
T_NAK: u8 = 3
T_MD5: u8 = 4
T_TLS: u8 = 13
T_TTLS: u8 = 21
T_PEAP: u8 = 25
T_MSCHAPV2: u8 = 26
T_PWD: u8 = 52
/// what Nak says when the peer takes no other method (RFC 3748 5.3.1)
NAK_NONE: u8 = 0
/// the exchanges of EAP-PWD
PWD_ID: u8 = 1
PWD_COMMIT: u8 = 2
PWD_CONFIRM: u8 = 3
/// EAP-PWD with group 19 (P-256) and SHA-256: an element and a scalar
PWD_ELEMENT: usize = 64
PWD_SCALAR: usize = 32
type Md5Fn = fn(&[&[u8]]) -> [u8; 16]MD5 of the concatenation of the parts (what the caller lends: crypto::md5_parts)fn code_name(c: u8) -> &'static strthe name of a codefn type_name(t: u8) -> Stringthe name of a typestruct Packetan EAP packetcode: u8id: u8typ: u8-- the type of a Request or a Response (0: Success and Failure have none)data: Vec<u8>-- the Type-Data
impl Packet
fn parse(b: &[u8]) -> Option<Packet>the packet at the start ofb; None when its Length does not fit (shorter than its header or longer thanb, a Request or a Response without a type)fn to_bytes(&self) -> Vec<u8>the bytesfn request(id: u8, typ: u8, data: &[u8]) -> Packetfn response(id: u8, typ: u8, data: &[u8]) -> Packetfn success(id: u8) -> Packetfn failure(id: u8) -> Packetfn identity_request(id: u8, prompt: &str) -> PacketRequest/Identity, an optional text for a person in the datafn identity_response(id: u8, name: &str) -> PacketResponse/Identityfn nak(id: u8, types: &[u8]) -> PacketResponse/Nak: the methods the peer takes instead (none: NAK_NONE)fn is(&self, code: u8, typ: u8) -> boola Request or a Response of a typefn identity(&self) -> Stringthe text of an Identity (bytes that are no UTF-8 are replaced)fn nak_types(&self) -> Vec<u8>the methods a Nak wants (NAK_NONE left out)struct Md5Datathe Type-Data of EAP-MD5: Value-Size, the value (a challenge or a digest), a namevalue: Vec<u8>name: Vec<u8>
impl Md5Data
fn parse(d: &[u8]) -> Option<Md5Data>fn to_bytes(&self) -> Vec<u8>fn md5_value(id: u8, secret: &[u8], challenge: &[u8], md5: Md5Fn) -> [u8; 16]the value of a CHAP-style answer (RFC 1994 4.1): MD5(Identifier || secret || Challenge)struct PwdIdEAP-pwd-ID: what the server offers and the peer takes (RFC 5931 3.2.1)group: u16-- the group's number in IANA's registry (19: P-256)rand_func: u8-- the random function (1: HMAC-SHA-256)prf: u8-- the PRF (1: HMAC-SHA-256)token: [u8; 4]prep: u8-- how the password is prepared (0: none)identity: Vec<u8>
enum Pwdthe Type-Data of EAP-PWDId(PwdId)Commit { element: [u8; PWD_ELEMENT], scalar: [u8; PWD_SCALAR] }Confirm([u8; 32])
impl Pwd
fn parse(d: &[u8]) -> Option<Pwd>the data of a packet; None for other sizes (only group 19 is read), a fragment or an unknown exchangefn to_bytes(&self) -> Vec<u8>the data bytes (L and M clear)fn exch_name(x: u8) -> &'static strthe name of an EAP-PWD exchangefn info(b: &[u8]) -> Stringone line about a packet: "Request, Identity", "Response, Identity (anna)", "Success", "Request, PWD-Commit", "Response, Nak (PWD)"