Skip to content

Commit

Permalink
second part of gprocopciuc patch: enables CHAP
Browse files Browse the repository at this point in the history
(split patch by [email protected])
  • Loading branch information
Ghennadi Procopciuc authored and Nikos Mavrogiannopoulos committed Mar 3, 2015
1 parent 29fa57e commit bfa1ee4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
2 changes: 2 additions & 0 deletions include/freeradius-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@

#define MAX_SECRET_LENGTH (3 * 16) /* MUST be multiple of 16 */

#define MAX_STRING_LEN 254 /* RFC2138: string 0-253 octets */

#define VENDOR(x) (((x) >> 16) & 0xffff)
#define ATTRID(x) ((x) & 0xffff)

Expand Down
46 changes: 21 additions & 25 deletions lib/sendserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static int rc_pack_list (VALUE_PAIR *vp, char *secret, AUTH_HDR *auth)
unsigned char passbuf[MAX(AUTH_PASS_LEN, CHAP_VALUE_LENGTH)];
unsigned char md5buf[256];
unsigned char *buf, *vector, *vsa_length_ptr;
VALUE_PAIR *first_vp = vp;

buf = auth->data;

Expand Down Expand Up @@ -105,37 +106,32 @@ static int rc_pack_list (VALUE_PAIR *vp, char *secret, AUTH_HDR *auth)
total_length += padded_length + 2;

break;
#if 0
case PW_CHAP_PASSWORD:

*buf++ = CHAP_VALUE_LENGTH + 2;
if (vsa_length_ptr != NULL) *vsa_length_ptr += CHAP_VALUE_LENGTH + 2;

/* Encrypt the Password */
length = vp->lvalue;
if (length > CHAP_VALUE_LENGTH)
{
length = CHAP_VALUE_LENGTH;
int chap_attr_len = CHAP_VALUE_LENGTH + 3;
*buf++ = chap_attr_len;
char string[MAX_STRING_LEN * 2 + 1];
char *ptr = string;
int i = 0;
*ptr++ = auth->id;

i++;
memcpy(ptr, vp->strvalue, vp->lvalue);
ptr += vp->lvalue;
i += vp->lvalue;

/* TODO: use Chap-Challenge if available */
/* rc_avpair_get(); */
memcpy(ptr, auth->vector, AUTH_VECTOR_LEN);
i += AUTH_VECTOR_LEN;
*buf = auth->id;
rc_md5_calc((u_char *)buf + 1, (u_char *)string, i);
buf += chap_attr_len - 2;
total_length += chap_attr_len;
}
memset ((char *) passbuf, '\0', CHAP_VALUE_LENGTH);
memcpy ((char *) passbuf, vp->strvalue, (size_t) length);

/* Calculate the MD5 Digest */
secretlen = strlen (secret);
strcpy ((char *) md5buf, secret);
memcpy ((char *) md5buf + secretlen, (char *) auth->vector,
AUTH_VECTOR_LEN);
rc_md5_calc (buf, md5buf, secretlen + AUTH_VECTOR_LEN);

/* Xor the password into the MD5 digest */
for (i = 0; i < CHAP_VALUE_LENGTH; i++)
{
*buf++ ^= passbuf[i];
}
total_length += CHAP_VALUE_LENGTH + 2;

break;
#endif
default:
switch (vp->type)
{
Expand Down

0 comments on commit bfa1ee4

Please sign in to comment.