JFLib

eapm#

EAP-MD5 and EAP-PWD as peer and server state machines without I/O -- crate root lib/eapm/lib.rs

eapm -- EAP methods as state machines without I/O: the peer and the server of EAP-MD5 and
EAP-PWD with the framing of netpkt::eap and the sums of crypto (RFC 3748, 5931).  They take the
packets they get and give the packets to send; whoever holds them carries the bytes (EAPOL,
RADIUS), keeps the timers and repeats a Request that got no answer.  Randomness comes from
the caller, so a run is the same byte for byte

  Method                         Md5 (wired ports, no keys) | Pwd (makes an MSK); word, parse,
                                 of_type, typ, makes_keys
  Peer::new(identity, password, method)
  Peer::on_packet(&b, rnd) -> PeerOut   Send(bytes) | Success | Failure | Silent
  Peer::msk() / emsk() / method_used()  after Success
  Server::new(server_id, methods)       methods in the order to offer them
  Server::on_packet(&b, lookup, rnd) -> ServerOut
                                 Send(bytes) | Success { eap, msk, emsk } | Failure { eap } |
                                 Silent; lookup: a user's password (None: no such user)
  Server::user() / method()      who is logging in, with which method now
  rand_scalar(rnd)               a scalar of P-256 from random bytes

The peer answers a Request again with the same bytes when its identifier repeats (RFC 3748
4.1) and takes a method it was not told to use with a Nak that names the one it knows.  A
Success before the method is over is ignored, for EAP-PWD unless its Confirm checked out
(RFC 3748 4.2 and 7.2); a Confirm that does not fit (another password) ends the method without
an answer, as RFC 5931 2.8.5.3 says, so the authenticator's retries run out.

The server starts when the first Response/Identity comes.  It offers its methods in order and
goes on to the one a Nak names if it has it; with none left, it answers with Failure.

eapm crate root#

  • type Rnd<'a> = &'a mut dyn FnMut(&mut [u8]) where random bytes come from

  • enum Method an EAP method

    • Md5
    • Pwd

impl Method

  • fn word(self) -> &'static str its word in a wpa_supplicant-style file ("MD5", "PWD")

  • fn parse(s: &str) -> Option<Method> by its word, in any case

  • fn typ(self) -> u8 the EAP type

  • fn of_type(t: u8) -> Option<Method>

  • fn makes_keys(self) -> bool it derives an MSK (WPA-Enterprise needs one)

  • fn rand_scalar(rnd: Rnd) -> [u8; 32] a scalar in [1, n - 1] of P-256 from random bytes

  • enum PeerOut what a peer does with a packet

    • Send(Vec<u8>) -- send this packet
    • Success -- EAP-Success after the method is over: msk() holds its keys
    • Failure -- EAP-Failure, or a method that ended here
    • Silent -- nothing to do
  • struct Peer the peer's side of EAP

    • identity: String

impl Peer

  • fn new(identity: &str, password: &str, method: Method) -> Peer

  • fn msk(&self) -> Option<&[u8; 64]>

  • fn emsk(&self) -> Option<&[u8; 64]>

  • fn method_used(&self) -> Option<Method> the method that ran

  • fn reset(&mut self) back to the start (a new authentication on the same port)

  • fn on_packet(&mut self, b: &[u8], rnd: Rnd) -> PeerOut a packet from the authenticator

  • enum ServerOut what a server does with a packet

    • Send(Vec<u8>) -- send this Request
    • Success { eap: Vec<u8>, msk: Option<[u8; 64]>, emsk: Option<[u8; 64]> } -- the peer is in: the EAP-Success, the keys of a method that makes them
    • Failure { eap: Vec<u8> } -- the peer is out: the EAP-Failure
    • Silent -- nothing to do
  • struct Server the server's side of EAP

impl Server

  • fn new(server_id: &str, methods: &[Method]) -> Server
  • fn user(&self) -> &str who is logging in (after the Response/Identity)
  • fn method(&self) -> Option<Method> the method it runs now
  • fn on_packet(&mut self, b: &[u8], lookup: &dyn Fn(&str) -> Option<String>, rnd: Rnd) -> ServerOut a Response; lookup gives a user's password, rnd the random bytes

Source: docs/API.md in the JFLib repository.