chap
struct chap *
struct chap *chap;
chap = calloc(1, sizeof(*chap));
if (chap == NULL)
arc4random_buf(chap->chap_challenge, sizeof(chap->chap_challenge));
arc4random_buf(&chap->chap_id, sizeof(chap->chap_id));
return (chap);
chap_get_id(const struct chap *chap)
ret = asprintf(&chap_i, "%d", chap->chap_id);
chap_get_challenge(const struct chap *chap)
chap_c = chap_bin2hex(chap->chap_challenge,
sizeof(chap->chap_challenge));
chap_receive_bin(struct chap *chap, void *response, size_t response_len)
if (response_len != sizeof(chap->chap_response)) {
response_len, sizeof(chap->chap_response));
memcpy(chap->chap_response, response, response_len);
chap_receive(struct chap *chap, const char *response)
error = chap_receive_bin(chap, response_bin, response_bin_len);
chap_authenticate(struct chap *chap, const char *secret)
chap_compute_md5(chap->chap_id, secret,
chap->chap_challenge, sizeof(chap->chap_challenge),
if (memcmp(chap->chap_response,
chap_delete(struct chap *chap)
free(chap);
struct chap *chap_new(void);
char *chap_get_id(const struct chap *chap);
char *chap_get_challenge(const struct chap *chap);
int chap_receive(struct chap *chap, const char *response);
int chap_authenticate(struct chap *chap,
void chap_delete(struct chap *chap);
} chap;
struct chap *conn_chap = nullptr;
login_send_chap_c(struct pdu *request, struct chap *chap)
chap_c = chap_get_challenge(chap);
chap_i = chap_get_id(chap);
struct chap *chap, const struct auth **authp, std::string &user)
error = chap_receive(chap, chap_r);
error = chap_authenticate(chap, auth->secret());
struct chap *chap;
chap = chap_new();
sizeof(chap->chap_challenge));
login_send_chap_c(request, chap);
request = login_receive_chap_r(&conn, ag, chap, &auth, user);
conn_chap = chap;
struct chap *conn_mutual_chap;
static char chap[10];
snprintf(chap, sizeof chap, "CHAP 0x%02x", type);
return chap;
chap_StartChild(struct chap *chap, char *prog, const char *name)
if (chap->child.fd != -1) {
switch ((chap->child.pid = fork())) {
chap->child.pid = 0;
chap->auth.physical->dl->bundle, 0, pid);
chap->child.fd = out[0];
chap->child.buf.len = 0;
write(in[1], chap->auth.in.name, strlen(chap->auth.in.name));
write(in[1], chap->challenge.peer + 1, *chap->challenge.peer);
chap_Cleanup(struct chap *chap, int sig)
if (chap->child.pid) {
close(chap->child.fd);
chap->child.fd = -1;
kill(chap->child.pid, SIGTERM);
chap->child.pid = 0;
chap->child.buf.len = 0;
*chap->challenge.local = *chap->challenge.peer = '\0';
chap->peertries = 0;
chap_Respond(struct chap *chap, char *name, char *key
ans = chap_BuildAnswer(name, key, chap->auth.id, chap->challenge.peer
, type, chap->challenge.local, chap->authresponse, lm
ChapOutput(chap->auth.physical, CHAP_RESPONSE, chap->auth.id,
chap->NTRespSent = !lm;
ChapOutput(chap->auth.physical, CHAP_FAILURE, chap->auth.id,
struct chap *chap = descriptor2chap(d);
if (r && chap && chap->child.fd != -1) {
FD_SET(chap->child.fd, r);
if (*n < chap->child.fd + 1)
*n = chap->child.fd + 1;
log_Printf(LogTIMER, "Chap: fdset(r) %d\n", chap->child.fd);
struct chap *chap = descriptor2chap(d);
return chap && chap->child.fd != -1 && FD_ISSET(chap->child.fd, fdset);
struct chap *chap = descriptor2chap(d);
got = read(chap->child.fd, chap->child.buf.ptr + chap->child.buf.len,
sizeof chap->child.buf.ptr - chap->child.buf.len - 1);
chap_Cleanup(chap, SIGTERM);
chap_Cleanup(chap, SIGTERM);
chap->child.buf.len += got;
chap->child.buf.ptr[chap->child.buf.len] = '\0';
name = chap->child.buf.ptr;
if (chap->child.buf.len == sizeof chap->child.buf.ptr - 1) {
chap_Cleanup(chap, SIGTERM);
int lanman = chap->auth.physical->link.lcp.his_authtype == 0x80 &&
((chap->NTRespSent &&
IsAccepted(chap->auth.physical->link.lcp.cfg.chap80lm)) ||
!IsAccepted(chap->auth.physical->link.lcp.cfg.chap80nt));
chap_Respond(chap, name, key
, chap->auth.physical->link.lcp.his_authtype, lanman
chap_Cleanup(chap, 0);
struct chap *chap = auth2chap(authp);
if (!*chap->challenge.local) {
cp = chap->challenge.local;
for (i = 0; i < *chap->challenge.local; i++)
struct chap *chap = auth2chap(authp);
if (!*chap->challenge.local)
chap->challenge.local, 1 + *chap->challenge.local, NULL);
chap->challenge.local, 1 + *chap->challenge.local + len, NULL);
chap_HaveAnotherGo(struct chap *chap)
if (++chap->peertries < 3) {
*chap->challenge.local = '\0';
chap_Challenge(&chap->auth);
chap_Init(struct chap *chap, struct physical *p)
chap->desc.type = CHAP_DESCRIPTOR;
chap->desc.UpdateSet = chap_UpdateSet;
chap->desc.IsSet = chap_IsSet;
chap->desc.Read = chap_Read;
chap->desc.Write = chap_Write;
chap->child.pid = 0;
chap->child.fd = -1;
auth_Init(&chap->auth, p, chap_Challenge, chap_Success, chap_Failure);
*chap->challenge.local = *chap->challenge.peer = '\0';
chap->NTRespSent = 0;
chap->peertries = 0;
chap_ReInit(struct chap *chap)
chap_Cleanup(chap, SIGTERM);
struct chap *chap = &p->dl->chap;
if ((bp = auth_ReadHeader(&chap->auth, bp)) == NULL &&
ntohs(chap->auth.in.hdr.length) == 0)
else if (chap->auth.in.hdr.code == 0 || chap->auth.in.hdr.code > MAXCHAPCODE)
chap->auth.in.hdr.code);
if (chap->auth.in.hdr.code != CHAP_CHALLENGE &&
chap->auth.id != chap->auth.in.hdr.id &&
chapcodes[chap->auth.in.hdr.code], chap->auth.in.hdr.id,
chap->auth.id);
chap->auth.id = chap->auth.in.hdr.id; /* We respond with this id */
switch (chap->auth.in.hdr.code) {
*chap->challenge.peer = alen;
bp = mbuf_Read(bp, chap->challenge.peer + 1, alen);
bp = auth_ReadName(&chap->auth, bp, len);
((chap->NTRespSent && IsAccepted(p->link.lcp.cfg.chap80lm)) ||
chap_ChallengeInit(&chap->auth);
auth_StopTimer(&chap->auth);
*ans = chap->auth.id;
bp = auth_ReadName(&chap->auth, bp, len);
switch (chap->auth.in.hdr.code) {
if (*chap->auth.in.name)
chapcodes[chap->auth.in.hdr.code], alen,
chap->auth.in.name,
lanman && chap->auth.in.hdr.code == CHAP_RESPONSE ?
chapcodes[chap->auth.in.hdr.code], alen,
lanman && chap->auth.in.hdr.code == CHAP_RESPONSE ?
chapcodes[chap->auth.in.hdr.code], ans);
chapcodes[chap->auth.in.hdr.code]);
switch (chap->auth.in.hdr.code) {
chap_StartChild(chap, bundle->cfg.auth.key + 1,
chap_Respond(chap, bundle->cfg.auth.name, bundle->cfg.auth.key +
name = chap->auth.in.name;
chap->challenge.peer[0] = sizeof resp->PeerChallenge;
memcpy(chap->challenge.peer + 1, resp->PeerChallenge,
if (!radius_Authenticate(&bundle->radius, &chap->auth,
chap->auth.in.name, ans, alen + 1,
chap->challenge.local + 1,
*chap->challenge.local))
chap_Failure(&chap->auth);
if (chap_HaveAnotherGo(chap))
if (chap_HaveAnotherGo(chap))
char *myans = chap_BuildAnswer(name, key, chap->auth.id,
chap->challenge.local
chap->challenge.peer,
chap->authresponse, lanman);
chap_Success(&chap->auth);
chap_Failure(&chap->auth);
if (strncasecmp(ans, chap->authresponse, 42)) {
" != ans: (%.42s)\n", chap->authresponse, ans);
((d)->type == CHAP_DESCRIPTOR ? (struct chap *)(d) : NULL)
((struct chap *)((char *)a - (uintptr_t)&((struct chap *)0)->auth))
extern void chap_Init(struct chap *, struct physical *);
extern void chap_ReInit(struct chap *);
&cx->chap.auth.cfg.fsm.timeout,
&cx->chap.auth.cfg.fsm.maxreq, NULL, DEF_FSMAUTHTRIES);
copy = dl->chap.auth.cfg.fsm;
chap_Init(&dl->chap, dl->physical);
dl->chap.auth.cfg.fsm = copy;
timer_Stop(&dl->chap.auth.authtimer);
result = descriptor_UpdateSet(&dl->chap.desc, r, w, e, n) +
return descriptor_IsSet(&dl->chap.desc, fdset) ? 1 :
if (descriptor_IsSet(&dl->chap.desc, fdset))
descriptor_Read(&dl->chap.desc, bundle, fdset);
if (descriptor_IsSet(&dl->chap.desc, fdset))
switch (descriptor_Write(&dl->chap.desc, bundle, fdset)) {
auth_StartReq(&dl->chap.auth);
auth_StopTimer(&dl->chap.auth);
chap_ReInit(&dl->chap);
timer_Stop(&dl->chap.auth.authtimer);
chap_Init(&dl->chap, dl->physical);
chap_Init(&dl->chap, dl->physical);
dl->chap.auth.cfg = odl->chap.auth.cfg;
struct chap chap; /* Authentication using chap */