All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions
eap_tls.c File Reference

Implements the EAP part of EAP-TLS. More...

#include "eap_tls.h"
+ Include dependency graph for eap_tls.c:

Go to the source code of this file.

Functions

static
USES_APPLE_DEPRECATED_API int 
eap_tls_compose (eap_session_t *eap_session, fr_tls_status_t status, uint8_t flags, tls_record_t *record, size_t record_len, size_t frag_len)
 Convert the EAP-TLS reply packet into an EAP packet. More...
 
fr_tls_server_conf_t * eap_tls_conf_parse (CONF_SECTION *cs, char const *attr)
 Parse TLS configuration. More...
 
int eap_tls_fail (eap_session_t *eap_session)
 Send an EAP-TLS failure. More...
 
static fr_tls_status_t eap_tls_handshake (eap_session_t *eap_session)
 Continue with the handshake. More...
 
fr_tls_status_t eap_tls_process (eap_session_t *eap_session)
 Process an EAP TLS request. More...
 
int eap_tls_request (eap_session_t *eap_session)
 Frames the OpenSSL data that needs to be sent to the client in an EAP-Request. More...
 
static int eap_tls_send_ack (eap_session_t *eap_session)
 ACK a fragment of the TLS record from the peer. More...
 
tls_session_t * eap_tls_session_init (eap_session_t *eap_session, fr_tls_server_conf_t *tls_conf, bool client_cert)
 Create a new tls_session_t associated with an eap_session_t. More...
 
int eap_tls_start (eap_session_t *eap_session)
 Send an initial EAP-TLS request to the peer. More...
 
int eap_tls_success (eap_session_t *eap_session)
 Send an EAP-TLS success. More...
 
static fr_tls_status_t eap_tls_verify (eap_session_t *eap_session)
 Check that this EAP-TLS packet is correct and the progression of EAP-TLS packets is sane. More...
 

Detailed Description

Implements the EAP part of EAP-TLS.

Id:
6602d0c38f4288e8d33c6f81aab75135ebb9fbf8

RFC 2716 Section 4.2. PPP EAP TLS Request Packet

   0               1               2               3
   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
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |     Code      |   Identifier  |        Length           |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |     Type      |     Flags     |      TLS Message Length
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |     TLS Message Length     |       TLS Data...
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Structure of an EAP-TLS packet

  code    = EAP-code
  id      = EAP-id
  length  = code + id + length + flags + tlsdata
           =  1   +  1 +   2    +  1    +  X
  length  = EAP-length - 1(EAP-Type = 1 octet)
  flags   = EAP-typedata[0] (1 octet)
  data_len    = EAP-typedata[1-4] (4 octets), if L flag set
           = length - 5(code+id+length+flags), otherwise
  data    = EAP-typedata[5-n], if L flag set
           = EAP-typedata[1-n], otherwise
  packet  = EAP-typedata (complete typedata)

The S flag is set only within the EAP-TLS start message sent from the EAP server to the peer.

Similarly, when the EAP server receives an EAP-Response with the M bit set, it MUST respond with an EAP-Request with EAP-Type = EAP-TLS and no data. This serves as a fragment ACK. The EAP peer MUST wait.

The Length field is two octets and indicates the length of the EAP packet including the Code, Identifier, Length, Type, and TLS data fields.

The TLS Message Length field is four octets and indicates the complete reassembled length of the TLS record fragment.

Definition in file eap_tls.c.

Function Documentation

static USES_APPLE_DEPRECATED_API int eap_tls_compose ( eap_session_t eap_session,
fr_tls_status_t  status,
uint8_t  flags,
tls_record_t *  record,
size_t  record_len,
size_t  frag_len 
)
static

Convert the EAP-TLS reply packet into an EAP packet.

The EAP packet will be written to eap_round->request, with the original reply being untouched.

Parameters
eap_sessionto continue.
statusWhat type of packet we're sending.
flagsto set. This is checked to determine if we need to include a length field.
recordThe record buffer to read from. This most only be set for FR_TLS_REQUEST packets.
record_lenthe length of the record we're sending.
frag_lenthe length of the fragment we're sending.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 91 of file eap_tls.c.

+ Here is the caller graph for this function:

fr_tls_server_conf_t* eap_tls_conf_parse ( CONF_SECTION cs,
char const *  attr 
)

Parse TLS configuration.

If the option given by 'attr' is set, we find the config section of that name and use that for the TLS configuration. If not, we fall back to compatibility mode and read the TLS options from the 'tls' section.

Parameters
csto derive the configuration from.
attridentifier for common TLS configuration.
Returns
  • NULL on error.
  • A new fr_tls_server_conf_t on success.

Definition at line 891 of file eap_tls.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int eap_tls_fail ( eap_session_t eap_session)

Send an EAP-TLS failure.

Composes an EAP-TLS-Failure. This is a message with code FR_TLS_FAILURE. It contains no cryptographic material, and is not protected.

In addition to sending the failure, will destroy any cached session data.

Parameters
eap_sessionthat failed.
Returns
  • 0 on success.
  • -1 on failure (to compose a valid packet).

Definition at line 254 of file eap_tls.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static fr_tls_status_t eap_tls_handshake ( eap_session_t eap_session)
static

Continue with the handshake.

Parameters
eap_sessionto continue.
Returns
  • FR_TLS_FAIL if the message is invalid.
  • FR_TLS_HANDLED if we need to send an additional request to the peer.
  • FR_TLS_SUCCESS if the handshake completed successfully, and there's no more data to send.

Definition at line 635 of file eap_tls.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

fr_tls_status_t eap_tls_process ( eap_session_t eap_session)

Process an EAP TLS request.

Here we implement a basic state machine. The state machine is implicit and is driven by the state of the TLS session and the flags sent. INCOMING DATA:

  1. EAP-TLS should get the compelete TLS data from the peer.
  2. Store that data in a data structure with any other required info
  3. Hand this data structure to the TLS module.
  4. TLS module will perform its operations on the data and hands back to EAP-TLS OUTGOING DATA:
  1. EAP-TLS if necessary will fragment it and send it to the destination.

During EAP-TLS initialization, TLS Context object will be initialised and stored. For every new authentication request, TLS will open a new session object and that session object SHOULD be maintained even after the session is completed, for session resumption.

Parameters
eap_sessionto continue.
Returns
  • FR_TLS_SUCCESS
  • FR_TLS_HANDLED

Definition at line 708 of file eap_tls.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int eap_tls_request ( eap_session_t eap_session)

Frames the OpenSSL data that needs to be sent to the client in an EAP-Request.

A single TLS record may be up to 16384 octets in length, but a TLS message may span multiple TLS records, and a TLS certificate message may theoretically, be as long as 16MB.

In EAP-TLS with no inner method, this is used primarily to send our certificate chain to the peer.

In other methods this function is also called to package up application data for the inner tunnel method.

The tls_session->length_included flag determines whether we include the extra four byte length field in the request and set the L flag.

If present, the tls_length field indicates the total length of the reassembled TLS record.

If tls_session->length_included this means we include L flag and the tls_length field in EVERY packet we send out.

If !tls_session->length_included this means we include L flag and tls_length field ONLY in First packet of a fragment series. We do not use it anywhere else.

Parameters
eap_sessionthat's continuing.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 299 of file eap_tls.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int eap_tls_send_ack ( eap_session_t eap_session)
static

ACK a fragment of the TLS record from the peer.

EAP server sends an ACK when it determines there are More fragments to receive to make the complete TLS-record.

When the EAP server receives an EAP-Response with the M bit set, it MUST respond with an EAP-Request with EAP-Type = EAP-TLS and no data. This serves as a fragment ACK.

In order to prevent errors in the processing of fragments, the EAP server MUST use increment the Identifier value for each fragment ACK contained within an EAP-Request, and the peer MUST include this Identifier value in the subsequent fragment contained within an EAP-Reponse.

Parameters
eap_sessionthat we're acking the fragment for.

Definition at line 368 of file eap_tls.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

tls_session_t* eap_tls_session_init ( eap_session_t eap_session,
fr_tls_server_conf_t *  tls_conf,
bool  client_cert 
)

Create a new tls_session_t associated with an eap_session_t.

Creates a new server tls_session_t and associates it with an eap_session_t adding EAP specific opaque data to the SSL session created during tls_session_t initialisation.

Parameters
eap_sessionto use as a context for the tls_session_t
tls_confto use to configure the tls_session_t.
client_certWhether we require the peer to prevent a certificate.
Returns
  • A new tls_session on success.
  • NULL on error.

Definition at line 844 of file eap_tls.c.

+ Here is the caller graph for this function:

int eap_tls_start ( eap_session_t eap_session)

Send an initial EAP-TLS request to the peer.

Once having received the peer's Identity, the EAP server MUST respond with an EAP-TLS/Start packet, which is an EAP-Request packet with EAP-Type = EAP-TLS, the Start (S) bit set, and no data.

The EAP-TLS conversation will then begin, with the peer sending an EAP-Response packet with EAP-Type = EAP-TLS. The data field of that packet will be the TLS data.

The S flag is set only within the EAP-TLS start message sent from the EAP server to the peer.

  • len = header + type + tls_typedata
  • tls_typedata = flags(Start (S) bit set, and no data)

Fragment length is Framed-MTU - 4.

Parameters
eap_sessionto initiate.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 192 of file eap_tls.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int eap_tls_success ( eap_session_t eap_session)

Send an EAP-TLS success.

Composes an EAP-TLS-Success. This is a message with code FR_TLS_SUCCESS. It contains no cryptographic material, and is not protected.

We add the MPPE keys here. These are used by the NAS. The supplicant will derive the same keys separately.

Parameters
eap_sessionthat completed successfully.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 211 of file eap_tls.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static fr_tls_status_t eap_tls_verify ( eap_session_t eap_session)
static

Check that this EAP-TLS packet is correct and the progression of EAP-TLS packets is sane.

Note
In the received packet, No data will be present incase of ACK or NAK in this case the packet->data pointer will be NULL.
Parameters
[in]eap_sessionthe current EAP session state.
Returns
  • FR_TLS_INVALID if the TLS record or progression is invalid.
  • FR_TLS_FAIL handshake failed.
  • FR_TLS_RECORD_FRAGMENT_INIT this is the start of a new sequence of record fragments.
  • FR_TLS_RECORD_FRAGMENT_MORE this is a continuation of a sequence of fragments.
  • FR_TLS_REQUEST send more data to peer.
  • FR_TLS_RECORD_COMPLETE we received a completed record.
  • FR_TLS_SUCCESS handshake is complete, TLS session has been established.

Definition at line 392 of file eap_tls.c.

+ Here is the caller graph for this function: