iPXE
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)
 FILE_SECBOOT (PERMITTED)
static int eap_rx_md5 (struct eap_supplicant *supplicant, const void *req, size_t req_len)
 Handle EAP MD5-Challenge.

Variables

struct eap_method eap_md5_method __eap_method
 EAP MD5-Challenge method.

Detailed Description

EAP MD5-Challenge authentication method.

Definition in file eap_md5.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ eap_rx_md5()

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 48 of file eap_md5.c.

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

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, len, md5_algorithm, MD5_DIGEST_SIZE, memcpy(), eap_supplicant::netdev, netdev, netdev_settings(), rc, chap_response::response, chap_response::response_len, strerror(), eap_md5::value, and 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:54
static int eap_rx_md5(struct eap_supplicant *supplicant, const void *req, size_t req_len)
Handle EAP MD5-Challenge.
Definition eap_md5.c:48

EAP MD5-Challenge method.

Definition at line 114 of file eap_md5.c.

114 {
115 .type = EAP_TYPE_MD5,
116 .rx = eap_rx_md5,
117};