mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-08-24 23:25:58 +00:00
PPP, MPPE, reworked MPPE debug, using ppp_pcb metadata
This commit is contained in:
parent
fc7e327d19
commit
4c0af0f79e
@ -161,21 +161,19 @@ typedef struct ppp_mppe_state {
|
|||||||
*/
|
*/
|
||||||
u8_t bits; /* MPPE control bits */
|
u8_t bits; /* MPPE control bits */
|
||||||
u16_t ccount; /* 12-bit coherency count (seqno) */
|
u16_t ccount; /* 12-bit coherency count (seqno) */
|
||||||
|
u16_t sanity_errors; /* take down LCP if too many */
|
||||||
unsigned int stateful :1; /* stateful mode flag */
|
unsigned int stateful :1; /* stateful mode flag */
|
||||||
unsigned int discard :1; /* stateful mode packet loss flag */
|
unsigned int discard :1; /* stateful mode packet loss flag */
|
||||||
unsigned int debug :1; /* debug flag */
|
unsigned int :6; /* 6 bit of padding to round out to 8 bits */
|
||||||
unsigned int :5; /* 5 bit of padding to round out to 8 bits */
|
|
||||||
u16_t sanity_errors; /* take down LCP if too many */
|
|
||||||
u8_t unit;
|
|
||||||
} ppp_mppe_state;
|
} ppp_mppe_state;
|
||||||
|
|
||||||
void mppe_set_key(ppp_mppe_state *state, u8_t *key);
|
void mppe_set_key(ppp_pcb *pcb, ppp_mppe_state *state, u8_t *key);
|
||||||
void mppe_init(ppp_mppe_state *state, u8_t options, u8_t unit, u8_t debug, const char *debugstr);
|
void mppe_init(ppp_pcb *pcb, ppp_mppe_state *state, u8_t options);
|
||||||
void mppe_comp_reset(ppp_mppe_state *state);
|
void mppe_comp_reset(ppp_pcb *pcb, ppp_mppe_state *state);
|
||||||
err_t mppe_compress(ppp_mppe_state *state, struct pbuf **pb, u16_t protocol);
|
err_t mppe_compress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb, u16_t protocol);
|
||||||
void mppe_decomp_reset(ppp_mppe_state *state);
|
void mppe_decomp_reset(ppp_pcb *pcb, ppp_mppe_state *state);
|
||||||
err_t mppe_decompress(ppp_mppe_state *state, struct pbuf **pb);
|
err_t mppe_decompress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb);
|
||||||
void mppe_incomp(ppp_mppe_state *state, unsigned char *ibuf, int icnt);
|
void mppe_incomp(ppp_pcb *pcb, ppp_mppe_state *state, unsigned char *ibuf, int icnt);
|
||||||
|
|
||||||
#endif /* MPPE_H */
|
#endif /* MPPE_H */
|
||||||
#endif /* PPP_SUPPORT && MPPE_SUPPORT */
|
#endif /* PPP_SUPPORT && MPPE_SUPPORT */
|
||||||
|
@ -768,7 +768,7 @@ static void ccp_addci(fsm *f, u_char *p, int *lenp) {
|
|||||||
p[0] = CI_MPPE;
|
p[0] = CI_MPPE;
|
||||||
p[1] = CILEN_MPPE;
|
p[1] = CILEN_MPPE;
|
||||||
MPPE_OPTS_TO_CI(go->mppe, &p[2]);
|
MPPE_OPTS_TO_CI(go->mppe, &p[2]);
|
||||||
mppe_init(&pcb->mppe_decomp, go->mppe, pcb->netif->num, 1, "mppe_decomp_init");
|
mppe_init(pcb, &pcb->mppe_decomp, go->mppe);
|
||||||
p += CILEN_MPPE;
|
p += CILEN_MPPE;
|
||||||
}
|
}
|
||||||
#endif /* MPPE_SUPPORT */
|
#endif /* MPPE_SUPPORT */
|
||||||
@ -1196,7 +1196,7 @@ static int ccp_reqci(fsm *f, u_char *p, int *lenp, int dont_nak) {
|
|||||||
if (newret == CONFACK) {
|
if (newret == CONFACK) {
|
||||||
int mtu;
|
int mtu;
|
||||||
|
|
||||||
mppe_init(&pcb->mppe_comp, ho->mppe, pcb->netif->num, 1, "mppe_comp_init");
|
mppe_init(pcb, &pcb->mppe_comp, ho->mppe);
|
||||||
/*
|
/*
|
||||||
* We need to decrease the interface MTU by MPPE_PAD
|
* We need to decrease the interface MTU by MPPE_PAD
|
||||||
* because MPPE frames **grow**. The kernel [must]
|
* because MPPE frames **grow**. The kernel [must]
|
||||||
|
@ -730,8 +730,8 @@ static void Set_Start_Key(ppp_pcb *pcb, u_char *rchallenge, char *secret, int se
|
|||||||
sha1_finish(&sha1Context, Digest);
|
sha1_finish(&sha1Context, Digest);
|
||||||
|
|
||||||
/* Same key in both directions. */
|
/* Same key in both directions. */
|
||||||
mppe_set_key(&pcb->mppe_comp, Digest);
|
mppe_set_key(pcb, &pcb->mppe_comp, Digest);
|
||||||
mppe_set_key(&pcb->mppe_decomp, Digest);
|
mppe_set_key(pcb, &pcb->mppe_decomp, Digest);
|
||||||
|
|
||||||
pcb->mppe_keys_set = 1;
|
pcb->mppe_keys_set = 1;
|
||||||
}
|
}
|
||||||
@ -803,7 +803,7 @@ static void SetMasterKeys(ppp_pcb *pcb, char *secret, int secret_len, u_char NTR
|
|||||||
sha1_update(&sha1Context, (unsigned char *)mppe_sha1_pad2, SHA1_PAD_SIZE);
|
sha1_update(&sha1Context, (unsigned char *)mppe_sha1_pad2, SHA1_PAD_SIZE);
|
||||||
sha1_finish(&sha1Context, Digest);
|
sha1_finish(&sha1Context, Digest);
|
||||||
|
|
||||||
mppe_set_key(&pcb->mppe_comp, Digest);
|
mppe_set_key(pcb, &pcb->mppe_comp, Digest);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* generate recv key
|
* generate recv key
|
||||||
@ -819,7 +819,7 @@ static void SetMasterKeys(ppp_pcb *pcb, char *secret, int secret_len, u_char NTR
|
|||||||
sha1_update(&sha1Context, (unsigned char *)mppe_sha1_pad2, SHA1_PAD_SIZE);
|
sha1_update(&sha1Context, (unsigned char *)mppe_sha1_pad2, SHA1_PAD_SIZE);
|
||||||
sha1_finish(&sha1Context, Digest);
|
sha1_finish(&sha1Context, Digest);
|
||||||
|
|
||||||
mppe_set_key(&pcb->mppe_decomp, Digest);
|
mppe_set_key(pcb, &pcb->mppe_decomp, Digest);
|
||||||
|
|
||||||
pcb->mppe_keys_set = 1;
|
pcb->mppe_keys_set = 1;
|
||||||
}
|
}
|
||||||
|
@ -103,16 +103,24 @@ static void mppe_rekey(ppp_mppe_state * state, int initial_key)
|
|||||||
* Set key, used by MSCHAP before mppe_init() is actually called by CCP so we
|
* Set key, used by MSCHAP before mppe_init() is actually called by CCP so we
|
||||||
* don't have to keep multiple copies of keys.
|
* don't have to keep multiple copies of keys.
|
||||||
*/
|
*/
|
||||||
void mppe_set_key(ppp_mppe_state *state, u8_t *key) {
|
void mppe_set_key(ppp_pcb *pcb, ppp_mppe_state *state, u8_t *key) {
|
||||||
MEMCPY(state->master_key, key, MPPE_MAX_KEY_LEN);
|
LWIP_UNUSED_ARG(pcb);
|
||||||
|
MEMCPY(state->master_key, key, MPPE_MAX_KEY_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize (de)compressor state.
|
* Initialize (de)compressor state.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
mppe_init(ppp_mppe_state *state, u8_t options, u8_t unit, u8_t debug, const char *debugstr)
|
mppe_init(ppp_pcb *pcb, ppp_mppe_state *state, u8_t options)
|
||||||
{
|
{
|
||||||
|
#if PPP_DEBUG
|
||||||
|
const u8_t *debugstr = (u8_t*)"mppe_comp_init";
|
||||||
|
if (&pcb->mppe_decomp == state) {
|
||||||
|
debugstr = (u8_t*)"mppe_decomp_init";
|
||||||
|
}
|
||||||
|
#endif /* PPP_DEBUG */
|
||||||
|
|
||||||
/* Save keys. */
|
/* Save keys. */
|
||||||
MEMCPY(state->session_key, state->master_key, sizeof(state->master_key));
|
MEMCPY(state->session_key, state->master_key, sizeof(state->master_key));
|
||||||
|
|
||||||
@ -122,7 +130,7 @@ mppe_init(ppp_mppe_state *state, u8_t options, u8_t unit, u8_t debug, const char
|
|||||||
state->keylen = 8;
|
state->keylen = 8;
|
||||||
else {
|
else {
|
||||||
PPPDEBUG(LOG_DEBUG, ("%s[%d]: unknown key length\n", debugstr,
|
PPPDEBUG(LOG_DEBUG, ("%s[%d]: unknown key length\n", debugstr,
|
||||||
unit));
|
pcb->netif->num));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (options & MPPE_OPT_STATEFUL)
|
if (options & MPPE_OPT_STATEFUL)
|
||||||
@ -131,13 +139,14 @@ mppe_init(ppp_mppe_state *state, u8_t options, u8_t unit, u8_t debug, const char
|
|||||||
/* Generate the initial session key. */
|
/* Generate the initial session key. */
|
||||||
mppe_rekey(state, 1);
|
mppe_rekey(state, 1);
|
||||||
|
|
||||||
if (debug) {
|
#if PPP_DEBUG
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
char mkey[sizeof(state->master_key) * 2 + 1];
|
char mkey[sizeof(state->master_key) * 2 + 1];
|
||||||
char skey[sizeof(state->session_key) * 2 + 1];
|
char skey[sizeof(state->session_key) * 2 + 1];
|
||||||
|
|
||||||
PPPDEBUG(LOG_DEBUG, ("%s[%d]: initialized with %d-bit %s mode\n",
|
PPPDEBUG(LOG_DEBUG, ("%s[%d]: initialized with %d-bit %s mode\n",
|
||||||
debugstr, unit, (state->keylen == 16) ? 128 : 40,
|
debugstr, pcb->netif->num, (state->keylen == 16) ? 128 : 40,
|
||||||
(state->stateful) ? "stateful" : "stateless"));
|
(state->stateful) ? "stateful" : "stateless"));
|
||||||
|
|
||||||
for (i = 0; i < (int)sizeof(state->master_key); i++)
|
for (i = 0; i < (int)sizeof(state->master_key); i++)
|
||||||
@ -146,8 +155,9 @@ mppe_init(ppp_mppe_state *state, u8_t options, u8_t unit, u8_t debug, const char
|
|||||||
sprintf(skey + i * 2, "%02x", state->session_key[i]);
|
sprintf(skey + i * 2, "%02x", state->session_key[i]);
|
||||||
PPPDEBUG(LOG_DEBUG,
|
PPPDEBUG(LOG_DEBUG,
|
||||||
("%s[%d]: keys: master: %s initial session: %s\n",
|
("%s[%d]: keys: master: %s initial session: %s\n",
|
||||||
debugstr, unit, mkey, skey));
|
debugstr, pcb->netif->num, mkey, skey));
|
||||||
}
|
}
|
||||||
|
#endif /* PPP_DEBUG */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the coherency count. The initial value is not specified
|
* Initialize the coherency count. The initial value is not specified
|
||||||
@ -162,9 +172,6 @@ mppe_init(ppp_mppe_state *state, u8_t options, u8_t unit, u8_t debug, const char
|
|||||||
* set the FLUSHED bit. This is contrary to RFC 3078, sec. 3.1.
|
* set the FLUSHED bit. This is contrary to RFC 3078, sec. 3.1.
|
||||||
*/
|
*/
|
||||||
state->bits = MPPE_BIT_ENCRYPTED;
|
state->bits = MPPE_BIT_ENCRYPTED;
|
||||||
|
|
||||||
state->unit = unit;
|
|
||||||
state->debug = debug;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -176,8 +183,9 @@ mppe_init(ppp_mppe_state *state, u8_t options, u8_t unit, u8_t debug, const char
|
|||||||
* know how many times we've rekeyed. (If we rekey and THEN get another
|
* know how many times we've rekeyed. (If we rekey and THEN get another
|
||||||
* CCP Reset-Request, we must rekey again.)
|
* CCP Reset-Request, we must rekey again.)
|
||||||
*/
|
*/
|
||||||
void mppe_comp_reset(ppp_mppe_state *state)
|
void mppe_comp_reset(ppp_pcb *pcb, ppp_mppe_state *state)
|
||||||
{
|
{
|
||||||
|
LWIP_UNUSED_ARG(pcb);
|
||||||
state->bits |= MPPE_BIT_FLUSHED;
|
state->bits |= MPPE_BIT_FLUSHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +195,7 @@ void mppe_comp_reset(ppp_mppe_state *state)
|
|||||||
* MPPE_OVHD + 2 bytes larger than the input.
|
* MPPE_OVHD + 2 bytes larger than the input.
|
||||||
*/
|
*/
|
||||||
err_t
|
err_t
|
||||||
mppe_compress(ppp_mppe_state *state, struct pbuf **pb, u16_t protocol)
|
mppe_compress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb, u16_t protocol)
|
||||||
{
|
{
|
||||||
struct pbuf *np, *n;
|
struct pbuf *np, *n;
|
||||||
u8_t *pl;
|
u8_t *pl;
|
||||||
@ -201,9 +209,7 @@ mppe_compress(ppp_mppe_state *state, struct pbuf **pb, u16_t protocol)
|
|||||||
pl = (u8_t*)np->payload;
|
pl = (u8_t*)np->payload;
|
||||||
|
|
||||||
state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
|
state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
|
||||||
if (state->debug)
|
PPPDEBUG(LOG_DEBUG, ("mppe_compress[%d]: ccount %d\n", pcb->netif->num, state->ccount));
|
||||||
PPPDEBUG(LOG_DEBUG, ("mppe_compress[%d]: ccount %d\n", state->unit,
|
|
||||||
state->ccount));
|
|
||||||
/* FIXME: use PUT* macros */
|
/* FIXME: use PUT* macros */
|
||||||
pl[0] = state->ccount>>8;
|
pl[0] = state->ccount>>8;
|
||||||
pl[1] = state->ccount;
|
pl[1] = state->ccount;
|
||||||
@ -212,9 +218,9 @@ mppe_compress(ppp_mppe_state *state, struct pbuf **pb, u16_t protocol)
|
|||||||
((state->ccount & 0xff) == 0xff) || /* "flag" packet */
|
((state->ccount & 0xff) == 0xff) || /* "flag" packet */
|
||||||
(state->bits & MPPE_BIT_FLUSHED)) { /* CCP Reset-Request */
|
(state->bits & MPPE_BIT_FLUSHED)) { /* CCP Reset-Request */
|
||||||
/* We must rekey */
|
/* We must rekey */
|
||||||
if (state->debug && state->stateful)
|
if (state->stateful) {
|
||||||
PPPDEBUG(LOG_DEBUG, ("mppe_compress[%d]: rekeying\n",
|
PPPDEBUG(LOG_DEBUG, ("mppe_compress[%d]: rekeying\n", pcb->netif->num));
|
||||||
state->unit));
|
}
|
||||||
mppe_rekey(state, 0);
|
mppe_rekey(state, 0);
|
||||||
state->bits |= MPPE_BIT_FLUSHED;
|
state->bits |= MPPE_BIT_FLUSHED;
|
||||||
}
|
}
|
||||||
@ -243,8 +249,9 @@ mppe_compress(ppp_mppe_state *state, struct pbuf **pb, u16_t protocol)
|
|||||||
/*
|
/*
|
||||||
* We received a CCP Reset-Ack. Just ignore it.
|
* We received a CCP Reset-Ack. Just ignore it.
|
||||||
*/
|
*/
|
||||||
void mppe_decomp_reset(ppp_mppe_state *state)
|
void mppe_decomp_reset(ppp_pcb *pcb, ppp_mppe_state *state)
|
||||||
{
|
{
|
||||||
|
LWIP_UNUSED_ARG(pcb);
|
||||||
LWIP_UNUSED_ARG(state);
|
LWIP_UNUSED_ARG(state);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -253,7 +260,7 @@ void mppe_decomp_reset(ppp_mppe_state *state)
|
|||||||
* Decompress (decrypt) an MPPE packet.
|
* Decompress (decrypt) an MPPE packet.
|
||||||
*/
|
*/
|
||||||
err_t
|
err_t
|
||||||
mppe_decompress(ppp_mppe_state *state, struct pbuf **pb)
|
mppe_decompress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb)
|
||||||
{
|
{
|
||||||
struct pbuf *n0 = *pb, *n;
|
struct pbuf *n0 = *pb, *n;
|
||||||
u8_t *pl;
|
u8_t *pl;
|
||||||
@ -263,37 +270,35 @@ mppe_decompress(ppp_mppe_state *state, struct pbuf **pb)
|
|||||||
|
|
||||||
/* MPPE Header */
|
/* MPPE Header */
|
||||||
if (n0->len < MPPE_OVHD) {
|
if (n0->len < MPPE_OVHD) {
|
||||||
if (state->debug)
|
PPPDEBUG(LOG_DEBUG,
|
||||||
PPPDEBUG(LOG_DEBUG,
|
("mppe_decompress[%d]: short pkt (%d)\n",
|
||||||
("mppe_decompress[%d]: short pkt (%d)\n",
|
pcb->netif->num, n0->len));
|
||||||
state->unit, n0->len));
|
|
||||||
return ERR_BUF;
|
return ERR_BUF;
|
||||||
}
|
}
|
||||||
|
|
||||||
pl = (u8_t*)n0->payload;
|
pl = (u8_t*)n0->payload;
|
||||||
flushed = MPPE_BITS(pl) & MPPE_BIT_FLUSHED;
|
flushed = MPPE_BITS(pl) & MPPE_BIT_FLUSHED;
|
||||||
ccount = MPPE_CCOUNT(pl);
|
ccount = MPPE_CCOUNT(pl);
|
||||||
if (state->debug)
|
PPPDEBUG(LOG_DEBUG, ("mppe_decompress[%d]: ccount %d\n",
|
||||||
PPPDEBUG(LOG_DEBUG, ("mppe_decompress[%d]: ccount %d\n",
|
pcb->netif->num, ccount));
|
||||||
state->unit, ccount));
|
|
||||||
|
|
||||||
/* sanity checks -- terminate with extreme prejudice */
|
/* sanity checks -- terminate with extreme prejudice */
|
||||||
if (!(MPPE_BITS(pl) & MPPE_BIT_ENCRYPTED)) {
|
if (!(MPPE_BITS(pl) & MPPE_BIT_ENCRYPTED)) {
|
||||||
PPPDEBUG(LOG_DEBUG,
|
PPPDEBUG(LOG_DEBUG,
|
||||||
("mppe_decompress[%d]: ENCRYPTED bit not set!\n",
|
("mppe_decompress[%d]: ENCRYPTED bit not set!\n",
|
||||||
state->unit));
|
pcb->netif->num));
|
||||||
state->sanity_errors += 100;
|
state->sanity_errors += 100;
|
||||||
sanity = 1;
|
sanity = 1;
|
||||||
}
|
}
|
||||||
if (!state->stateful && !flushed) {
|
if (!state->stateful && !flushed) {
|
||||||
PPPDEBUG(LOG_DEBUG, ("mppe_decompress[%d]: FLUSHED bit not set in "
|
PPPDEBUG(LOG_DEBUG, ("mppe_decompress[%d]: FLUSHED bit not set in "
|
||||||
"stateless mode!\n", state->unit));
|
"stateless mode!\n", pcb->netif->num));
|
||||||
state->sanity_errors += 100;
|
state->sanity_errors += 100;
|
||||||
sanity = 1;
|
sanity = 1;
|
||||||
}
|
}
|
||||||
if (state->stateful && ((ccount & 0xff) == 0xff) && !flushed) {
|
if (state->stateful && ((ccount & 0xff) == 0xff) && !flushed) {
|
||||||
PPPDEBUG(LOG_DEBUG, ("mppe_decompress[%d]: FLUSHED bit not set on "
|
PPPDEBUG(LOG_DEBUG, ("mppe_decompress[%d]: FLUSHED bit not set on "
|
||||||
"flag packet!\n", state->unit));
|
"flag packet!\n", pcb->netif->num));
|
||||||
state->sanity_errors += 100;
|
state->sanity_errors += 100;
|
||||||
sanity = 1;
|
sanity = 1;
|
||||||
}
|
}
|
||||||
@ -389,15 +394,16 @@ mppe_decompress(ppp_mppe_state *state, struct pbuf **pb)
|
|||||||
* of what should be encrypted. At the least, we should drop this
|
* of what should be encrypted. At the least, we should drop this
|
||||||
* packet. (How to do this?)
|
* packet. (How to do this?)
|
||||||
*/
|
*/
|
||||||
void mppe_incomp(ppp_mppe_state *state, unsigned char *ibuf, int icnt)
|
void mppe_incomp(ppp_pcb *pcb, ppp_mppe_state *state, unsigned char *ibuf, int icnt)
|
||||||
{
|
{
|
||||||
|
LWIP_UNUSED_ARG(state);
|
||||||
LWIP_UNUSED_ARG(icnt);
|
LWIP_UNUSED_ARG(icnt);
|
||||||
|
|
||||||
if (state->debug &&
|
if (PPP_PROTOCOL(ibuf) >= 0x0021 && PPP_PROTOCOL(ibuf) <= 0x00fa) {
|
||||||
(PPP_PROTOCOL(ibuf) >= 0x0021 && PPP_PROTOCOL(ibuf) <= 0x00fa))
|
|
||||||
PPPDEBUG(LOG_DEBUG,
|
PPPDEBUG(LOG_DEBUG,
|
||||||
("mppe_incomp[%d]: incompressible (unencrypted) data! "
|
("mppe_incomp[%d]: incompressible (unencrypted) data! "
|
||||||
"(proto %04x)\n", state->unit, PPP_PROTOCOL(ibuf)));
|
"(proto %04x)\n", pcb->netif->num, PPP_PROTOCOL(ibuf)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* PPP_SUPPORT && MPPE_SUPPORT */
|
#endif /* PPP_SUPPORT && MPPE_SUPPORT */
|
||||||
|
Loading…
Reference in New Issue
Block a user