Skip to content

Commit

Permalink
Code cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
chessing committed Jun 16, 2009
1 parent ec8eda9 commit 85461a9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 46 deletions.
13 changes: 5 additions & 8 deletions xsupplicant/src/eap_types/peap/eappeap.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,16 +462,14 @@ void eappeap_set_key_const(struct tls_vars *mytls_vars, uint8_t ver)
case PEAP_VERSION0:
debug_printf(DEBUG_AUTHTYPES,
"Setting Key Constant for PEAP v0!\n");
mytls_vars->sessionkeyconst =
(uint8_t *) _strdup(PEAP_SESSION_KEY_CONST);
mytls_vars->sessionkeyconst = (uint8_t *) _strdup(PEAP_SESSION_KEY_CONST);
mytls_vars->sessionkeylen = PEAP_SESSION_KEY_CONST_SIZE;
break;

case PEAP_VERSION1:
debug_printf(DEBUG_AUTHTYPES,
"Setting Key Constant for PEAP v1!\n");
mytls_vars->sessionkeyconst =
(uint8_t *) _strdup(PEAPv1_SESSION_KEY_CONST);
mytls_vars->sessionkeyconst = (uint8_t *) _strdup(PEAPv1_SESSION_KEY_CONST);
mytls_vars->sessionkeylen = PEAPv1_SESSION_KEY_CONST_SIZE;
break;

Expand Down Expand Up @@ -543,14 +541,13 @@ uint8_t eappeap_isKeyAvailable(eap_type_data * eapdata)
************************************************************************/
uint8_t *eappeap_getKey(eap_type_data * eapdata)
{
struct tls_vars *mytls_vars;
uint8_t *keydata;
struct tls_vars *mytls_vars = NULL;
uint8_t *keydata = NULL;

if (!xsup_assert((eapdata != NULL), "eapdata != NULL", FALSE))
return NULL;

if (!xsup_assert
((eapdata->eap_data != NULL), "eapdata->eap_data != NULL", FALSE))
if (!xsup_assert((eapdata->eap_data != NULL), "eapdata->eap_data != NULL", FALSE))
return NULL;

mytls_vars = (struct tls_vars *)eapdata->eap_data;
Expand Down
57 changes: 27 additions & 30 deletions xsupplicant/src/eapol_key_type2.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ void eapol_key_type2_do_gtk(context * ctx)

// Build the response.
len = sizeof(struct wpa2_key_packet);
intdata->send_size = len + OFFSET_TO_EAPOL + 4;
ctx->send_size = len + OFFSET_TO_EAPOL + 4;

value16 = (version | WPA2_KEY_MIC_FLAG | WPA2_SECURE_FLAG);
value16 = htons(value16);
Expand Down Expand Up @@ -1029,59 +1029,56 @@ void eapol_key_type2_do_type1(context * ctx)

wctx = ctx->intTypeData;

inkeydata = (struct wpa2_key_packet *)&intdata->recvframe[OFFSET_TO_EAPOL + 4];
outkeydata = (struct wpa2_key_packet *)&intdata->sendframe[OFFSET_TO_EAPOL + 4];
inkeydata = (struct wpa2_key_packet *)&ctx->recvframe[OFFSET_TO_EAPOL + 4];
outkeydata = (struct wpa2_key_packet *)&ctx->sendframe[OFFSET_TO_EAPOL + 4];

if ((memcmp(inkeydata->key_replay_counter, wctx->replay_counter, 8) <=
0) && (memcmp(inkeydata->key_replay_counter, zeros, 8) != 0)) {
debug_printf(DEBUG_NORMAL,
"Invalid replay counter! Discarding!\n");
intdata->recv_size = 0;
ctx->recv_size = 0;
return;
}
// Clear everything out.
memset(&intdata->sendframe[OFFSET_TO_EAPOL + 4], 0x00,
memset(&ctx->sendframe[OFFSET_TO_EAPOL + 4], 0x00,
sizeof(struct wpa2_key_packet));

RAND_bytes((uint8_t *) & outkeydata->key_nonce[0], 32);

FREE(intdata->statemachine->SNonce);
FREE(ctx->statemachine->SNonce);

intdata->statemachine->SNonce = (uint8_t *) Malloc(32);
if (intdata->statemachine->SNonce == NULL) {
ctx->statemachine->SNonce = (uint8_t *) Malloc(32);
if (ctx->statemachine->SNonce == NULL) {
debug_printf(DEBUG_NORMAL,
"Couldn't allocate memory for SNonce in "
"%s at %d!\n", __FUNCTION__, __LINE__);
ipc_events_malloc_failed(intdata);
ipc_events_malloc_failed(ctx);
return;
}
memcpy(intdata->statemachine->SNonce, (char *)&outkeydata->key_nonce[0],
memcpy(ctx->statemachine->SNonce, (char *)&outkeydata->key_nonce[0],
32);

value16 = ntohs(inkeydata->key_material_len);

version =
ntohs((uint16_t) (*inkeydata->key_information)) | WPA2_KEYTYPE_MASK;
version = ntohs((uint16_t) (*inkeydata->key_information)) | WPA2_KEYTYPE_MASK;

// Check the IE field to see if we have any KDEs to parse.
// We can discard the result field because the only thing we can possibly expect is a PMKID KDE, and
// if it isn't there, then it is okay.
if (eapol_key_type2_process_keydata
(intdata, inkeydata->keydata, value16, ntohs(inkeydata->key_length),
if (eapol_key_type2_process_keydata(ctx, inkeydata->keydata, value16, ntohs(inkeydata->key_length),
inkeydata->key_rsc, version, FALSE) != XENONE) {
return;
}
// Calculate the PTK.
FREE(intdata->statemachine->PTK);
FREE(ctx->statemachine->PTK);

intdata->statemachine->PTK =
(uint8_t *) eapol_key_type2_gen_ptk(intdata,
ctx->statemachine->PTK = (uint8_t *) eapol_key_type2_gen_ptk(ctx,
(char *)&inkeydata->key_nonce);

if (intdata->statemachine->PTK == NULL) {
if (ctx->statemachine->PTK == NULL) {
debug_printf(DEBUG_NORMAL,
"Unable to generate the PTK for interface '%s'!\n",
intdata->desc);
ctx->desc);
return;
}

Expand All @@ -1100,43 +1097,43 @@ void eapol_key_type2_do_type1(context * ctx)
memcpy(&outkeydata->key_information, &keyflags, 2);

len = sizeof(struct wpa2_key_packet);
intdata->send_size = len + OFFSET_TO_EAPOL + 4;
ctx->send_size = len + OFFSET_TO_EAPOL + 4;

outkeydata->key_length = inkeydata->key_length;

memcpy(&outkeydata->key_replay_counter, &inkeydata->key_replay_counter,
8);

if (cardif_get_wpa2_ie(intdata, wpa_ie, &ielen) < 0) {
if (cardif_get_wpa2_ie(ctx, wpa_ie, &ielen) < 0) {
debug_printf(DEBUG_NORMAL,
"Couldn't locate WPA2 information element!\n");
intdata->send_size = 0;
ctx->send_size = 0;
return;
}

#ifdef LINUX
wctx->okc = 0;
#endif

memcpy(&intdata->sendframe
memcpy(&ctx->sendframe
[OFFSET_TO_EAPOL + 4 + sizeof(struct wpa2_key_packet)], &wpa_ie,
ielen);
value16 = ielen;
value16 = htons(value16);
intdata->send_size += ielen;
ctx->send_size += ielen;

outkeydata->key_material_len = value16;

eapol_build_header(intdata, EAPOL_KEY,
(intdata->send_size - OFFSET_TO_EAPOL - 4),
(char *)intdata->sendframe);
eapol_build_header(ctx, EAPOL_KEY,
(ctx->send_size - OFFSET_TO_EAPOL - 4),
(char *)ctx->sendframe);

memcpy(key, intdata->statemachine->PTK, 16);
mic_wpa_populate((char *)intdata->sendframe, intdata->send_size + 4,
memcpy(key, ctx->statemachine->PTK, 16);
mic_wpa_populate((char *)ctx->sendframe, ctx->send_size + 4,
key, 16);

// Dump what we built.
eapol_key_type2_dump(intdata, (char *)intdata->sendframe);
eapol_key_type2_dump(ctx, (char *)ctx->sendframe);
}

/**
Expand Down
15 changes: 7 additions & 8 deletions xsupplicant/src/ipc_callout.c
Original file line number Diff line number Diff line change
Expand Up @@ -2041,8 +2041,7 @@ int ipc_callout_get_connection_upw(xmlNodePtr innode, xmlNodePtr * outnode)
outnode);
}
} else if ((conn != NULL) && (conn->association.psk == NULL)) {
if (xmlNewChild
(n, NULL, (xmlChar *) "Password",
if (xmlNewChild(n, NULL, (xmlChar *) "Password",
(xmlChar *) conn->association.psk_hex) == NULL) {
xmlFreeNode(n);
return ipc_callout_create_error(NULL,
Expand All @@ -2051,8 +2050,7 @@ int ipc_callout_get_connection_upw(xmlNodePtr innode, xmlNodePtr * outnode)
outnode);
}
} else {
if (xmlNewChild
(n, NULL, (xmlChar *) "Password",
if (xmlNewChild(n, NULL, (xmlChar *) "Password",
(xmlChar *) conn->association.psk) == NULL) {
xmlFreeNode(n);
return ipc_callout_create_error(NULL,
Expand All @@ -2064,6 +2062,8 @@ int ipc_callout_get_connection_upw(xmlNodePtr innode, xmlNodePtr * outnode)
} else {
username = config_get_inner_user_from_profile(prof->method);
if (username == NULL) {
if (prof->identity != NULL)
{
username = _strdup(prof->identity);
if (username != NULL) {
xsup_common_upcase(username);
Expand All @@ -2076,10 +2076,10 @@ int ipc_callout_get_connection_upw(xmlNodePtr innode, xmlNodePtr * outnode)
username = prof->identity;
}
}
}
}

if (xmlNewChild
(n, NULL, (xmlChar *) "Username",
if (xmlNewChild(n, NULL, (xmlChar *) "Username",
(xmlChar *) username) == NULL) {
xmlFreeNode(n);
return ipc_callout_create_error(NULL,
Expand All @@ -2088,8 +2088,7 @@ int ipc_callout_get_connection_upw(xmlNodePtr innode, xmlNodePtr * outnode)
outnode);
}

if (xmlNewChild
(n, NULL, (xmlChar *) "Password",
if (xmlNewChild(n, NULL, (xmlChar *) "Password",
(xmlChar *) config_get_pwd_from_profile(prof->method)) ==
NULL) {
xmlFreeNode(n);
Expand Down

0 comments on commit 85461a9

Please sign in to comment.