iPXE
Functions | Variables
eap_md5.c File Reference

EAP MD5-Challenge authentication method. More...

#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ipxe/md5.h>
#include <ipxe/chap.h>
#include <ipxe/eap.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int eap_rx_md5 (struct eap_supplicant *supplicant, const void *req, size_t req_len)
 Handle EAP MD5-Challenge. More...
 

Variables

struct eap_method eap_md5_method __eap_method
 EAP MD5-Challenge method. More...
 

Detailed Description

EAP MD5-Challenge authentication method.

Definition in file eap_md5.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ eap_rx_md5()

static int eap_rx_md5 ( struct eap_supplicant supplicant,
const void *  req,
size_t  req_len 
)
static

Handle EAP MD5-Challenge.

Parameters
supplicantEAP supplicant
reqRequest type data
req_lenLength of request type data
Return values
rcReturn status code

Definition at line 47 of file eap_md5.c.

48  {
49  struct net_device *netdev = supplicant->netdev;
50  const struct eap_md5 *md5req = req;
51  struct {
52  uint8_t len;
54  } __attribute__ (( packed )) md5rsp;
55  struct chap_response chap;
56  void *secret;
57  int secret_len;
58  int rc;
59 
60  /* Sanity checks */
61  if ( req_len < sizeof ( *md5req ) ) {
62  DBGC ( netdev, "EAP %s underlength MD5-Challenge:\n",
63  netdev->name );
64  DBGC_HDA ( netdev, 0, req, req_len );
65  rc = -EINVAL;
66  goto err_sanity;
67  }
68  if ( ( req_len - sizeof ( *md5req ) ) < md5req->len ) {
69  DBGC ( netdev, "EAP %s truncated MD5-Challenge:\n",
70  netdev->name );
71  DBGC_HDA ( netdev, 0, req, req_len );
72  rc = -EINVAL;
73  goto err_sanity;
74  }
75 
76  /* Construct response */
77  if ( ( rc = chap_init ( &chap, &md5_algorithm ) ) != 0 ) {
78  DBGC ( netdev, "EAP %s could not initialise CHAP: %s\n",
79  netdev->name, strerror ( rc ) );
80  goto err_chap;
81  }
82  chap_set_identifier ( &chap, supplicant->id );
84  &password_setting, &secret );
85  if ( secret_len < 0 ) {
86  rc = secret_len;
87  DBGC ( netdev, "EAP %s has no secret: %s\n",
88  netdev->name, strerror ( rc ) );
89  goto err_secret;
90  }
91  chap_update ( &chap, secret, secret_len );
92  chap_update ( &chap, md5req->value, md5req->len );
93  chap_respond ( &chap );
94  assert ( chap.response_len == sizeof ( md5rsp.value ) );
95  md5rsp.len = sizeof ( md5rsp.value );
96  memcpy ( md5rsp.value, chap.response, sizeof ( md5rsp.value ) );
97 
98  /* Transmit response */
99  if ( ( rc = eap_tx_response ( supplicant, &md5rsp,
100  sizeof ( md5rsp ) ) ) != 0 )
101  goto err_tx;
102 
103  err_tx:
104  free ( secret );
105  err_secret:
106  chap_finish ( &chap );
107  err_chap:
108  err_sanity:
109  return rc;
110 }
#define __attribute__(x)
Definition: compiler.h:10
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A CHAP response.
Definition: chap.h:18
int fetch_raw_setting_copy(struct settings *settings, const struct setting *setting, void **data)
Fetch value of setting.
Definition: settings.c:821
#define DBGC(...)
Definition: compiler.h:505
void chap_respond(struct chap_response *chap)
Respond to the CHAP challenge.
Definition: chap.c:104
EAP MD5 challenge request/response type data.
Definition: eap.h:56
uint8_t id
ID for current request/response.
Definition: eap.h:144
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:583
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int eap_tx_response(struct eap_supplicant *supplicant, const void *rsp, size_t rsp_len)
Transmit EAP response.
Definition: eap.c:47
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define DBGC_HDA(...)
Definition: compiler.h:506
int chap_init(struct chap_response *chap, struct digest_algorithm *digest)
Initialise CHAP challenge/response.
Definition: chap.c:51
static struct net_device * netdev
Definition: gdbudp.c:52
uint8_t len
Value length.
Definition: eap.h:58
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void chap_finish(struct chap_response *chap)
Free resources used by a CHAP response.
Definition: chap.c:122
A network device.
Definition: netdevice.h:352
unsigned char uint8_t
Definition: stdint.h:10
static void chap_set_identifier(struct chap_response *chap, unsigned int identifier)
Add identifier data to the CHAP challenge.
Definition: chap.h:46
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
uint8_t value[0]
Value.
Definition: eap.h:60
#define MD5_DIGEST_SIZE
MD5 digest size.
Definition: md5.h:72
struct net_device * netdev
Network device.
Definition: eap.h:140
void chap_update(struct chap_response *chap, const void *data, size_t len)
Add data to the CHAP challenge.
Definition: chap.c:85
struct digest_algorithm md5_algorithm
MD5 algorithm.
Definition: md5.c:286

References __attribute__, assert(), chap_finish(), chap_init(), chap_respond(), chap_set_identifier(), chap_update(), DBGC, DBGC_HDA, eap_tx_response(), EINVAL, fetch_raw_setting_copy(), free, eap_supplicant::id, eap_md5::len, md5_algorithm, MD5_DIGEST_SIZE, memcpy(), net_device::name, netdev, eap_supplicant::netdev, netdev_settings(), rc, chap_response::response, chap_response::response_len, strerror(), and eap_md5::value.

Variable Documentation

◆ __eap_method

struct eap_method eap_md5_method __eap_method
Initial value:
= {
.type = EAP_TYPE_MD5,
.rx = eap_rx_md5,
}
#define EAP_TYPE_MD5
EAP MD5 challenge request/response.
Definition: eap.h:53
static int eap_rx_md5(struct eap_supplicant *supplicant, const void *req, size_t req_len)
Handle EAP MD5-Challenge.
Definition: eap_md5.c:47

EAP MD5-Challenge method.

Definition at line 113 of file eap_md5.c.