Skip to content

pppd: Add an mppe option with preferred and permitted states - #665

Open
strrs wants to merge 10 commits into
ppp-project:masterfrom
strrs:pppd-mppe-preferred
Open

strrs wants to merge 10 commits into
ppp-project:masterfrom
strrs:pppd-mppe-preferred

Conversation

@strrs

@strrs strrs commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

This adds the "preferred" MPPE state from #57: pppd uses MPPE when the peer agrees and brings the link up without it, with a warning, when the peer can't do MPPE. It also adds the "permitted" state from the same list in #57, which jkroonza asked for again below: pppd doesn't ask for MPPE but uses it when the peer asks for it. I wrote it from scratch, from the pppd source, RFC 3078 and the states jkroonza listed in #57.

The first two commits fix two problems in the existing code that the new states run into. They don't depend on the option.

  • ccp.c closes the link from inside its own fsm callbacks when required MPPE fails, and fsm.c then leaves CCP in REQSENT or ACKSENT. After a restart from OPENED its timer is still running as well. Nothing resets that at the end of the call. With persist or demand, the next call then sends no CCP request of its own, or only keeps resending the old one. The first commit takes CCP down when the link has terminated.
  • With require-mppe, a peer that never completes CCP leaves the link up with no network protocol, because nothing handles the CCP timeout. The second commit closes the link at that timeout.

The last three commits fix three more problems; the first two don't depend on the option.

  • With persist or demand, the call after a failed CHAP authentication stayed in the authentication phase, on 2.5.5 too: chap_handle_response() set AUTH_DONE after auth_peer_fail() had already closed the link. A close from ccp_open() in the CHAP Success path, when required MPPE can't be used, did the same, and could also open IPCP and IPV6CP for the next call. The eighth commit sets the CHAP state before reporting the result and stops start_networks() when CCP has closed the link.
  • The radius plugin applied the server's reply only for the first CHAP authentication of the process (done_chap_once is never cleared), so later calls got no MS-CHAP2-Success authenticator, which fails an MS-CHAPv2 client, and no MPPE keys. The ninth commit clears the flag, and the reply data the plugin keeps, when a new authentication phase starts.
  • MS-MPPE-Encryption-Policy 2 (encryption required, RFC 2548) only limited the strengths, so a server that requires encryption could still get an unencrypted link with mppe preferred or mppe permitted. The last commit makes that policy work as mppe required until the call ends when MPPE is enabled (it never turns MPPE on), and gives back the strengths a reply turned off when the call ends. The plugin reads the policy and the types correctly only when the dictionary declares them as integers; the shipped dictionary.microsoft declares them as strings, so with that dictionary this has no effect yet.

The option syntax is the one suggested in #57, with permitted for the state it writes optional: mppe required|preferred|permitted|disabled[,40][,128]. With no strength given it allows 40 and 128-bit, like require-mppe. required and disabled set the same state as require-mppe and nomppe; a require-mppe-40 or require-mppe-128 given later adds that strength and makes MPPE required, and nomppe still turns MPPE off after mppe preferred. A preferred link only falls back before MPPE has come up, and then it also drops the MPPE keys and the kernel's CCP state and uses no other compression. Once MPPE has been up it is required for the rest of the call, as with require-mppe, also after an LCP renegotiation: there is no fallback any more. MPPE is never left on in one direction only: the link is closed if pppd has already accepted the peer's MPPE when its own request fails, or if the peer has accepted pppd's MPPE and its own request has no MPPE that pppd can use.

A permitted pppd sends no CCP request until the peer has sent one, because a require-mppe peer closes the link on a request without MPPE. When the peer's request asks for MPPE at a strength we allow and pppd has MPPE keys, pppd asks for it too and goes on as with preferred, so that MPPE runs in both directions. The network protocols are not held back, so data can go out unencrypted until MPPE is up; a pppd peer with require-mppe or mppe preferred holds its own until then, so against it no data is sent before MPPE.

For the existing options and the default (MPPE off) four things change, the first two through the fix commits: the next call after such a close negotiates CCP again, a CCP timeout with required MPPE closes the link, CCP leaves silent mode again when a later session of the same pppd has a compressor to ask for, and a call or LCP session no longer leaves its MPPE keys, or the other compressors turned off, to the next one. With persist, a required-MPPE call that hung on 2.5.5 is now closed and redialled, and pppd exits after maxfail failed calls, as it does for any other link that keeps failing. With the last three commits, the call after a failed CHAP authentication, or after such a close, authenticates normally, the radius plugin applies the reply of every call, and the strengths a reply turned off come back when the call ends.

Tested with the new testsuite/mppe-preferred_test.py and testsuite/mppe-permitted_test.py, both roles, and the whole testsuite, which passes; it also builds with --disable-microsoft-extensions and with --enable-multilink. The rest was run outside the tree, in both roles (a few mppe permitted cases in one only):

  • Existing options against a pppd 2.5.5 peer: every case gave the same result as with 2.5.5 on our side.
  • mppe preferred: MPPE came up against every peer that asks for it at a strength we allow. Against peers without MPPE, or with PAP instead of MS-CHAP, the link came up unencrypted with the warning. The same happened against a test peer that never answers CCP, after our CCP timeout of about 30 s, as long as that peer's IPCP was still trying (with the default 10 tries it gives up at the same time and closes the link). A peer that requires a strength we had turned off closed the link. Against a test peer that renegotiates LCP once MPPE is up and then refuses MPPE, pppd closed the link, as require-mppe does on 2.5.5.
  • mppe permitted: against a pppd 2.5.5 peer with require-mppe, require-mppe-40 or require-mppe-128, pppd asked for MPPE too and it came up in both directions. A 2.5.5 peer that requires a strength we had turned off closed the link. Against 2.5.5 with its default options or noccp the link came up as with MPPE off, and two permitted peers negotiated no compression. Test peers that start asking for MPPE while our request without it is out, or that renegotiate CCP after Deflate is up, got MPPE in both directions. As with MPPE off, pppd refused an MPPE request that came after an LCP renegotiation without authentication, and a request for 40-bit only after MS-CHAPv1. When a test peer rejected our MPPE, pppd gave it up with the warning, and after an LCP renegotiation without MPPE it negotiated Deflate again, or BSD-Compress when the secrets entry used in that session has nodeflate. When a test peer took its network protocols down after pppd had asked for MPPE, pppd closed the link, whether MPPE was up or had been given up. With persist and with demand, pppd waited for the peer's request and asked again in every call.
  • First commit, with persist and with demand over a pty link (the testsuite's notty link can't redial): after a close from ccp_reqci(), 2.5.5 with require-mppe sent no CCP request in the next call and stayed up without a network protocol. With the commit it sends its request and closes again, and a preferred link falls back with the warning. When a CCP Terminate-Ack arrived in OPENED, 2.5.5 went on resending the old request after the link had terminated; with a 5 s holdoff the next call then got no MPPE and CCP timed out. With the commit MPPE came up again.
  • Second commit: against test peers that ignore CCP, or ack our request once and then stay silent, 2.5.5 with require-mppe stayed up without a network protocol. With the commit it logs "MPPE required but peer negotiation failed" and closes after the CCP timeout.
  • Eighth commit, pppd as the server with radius.so and persist against a pppd client, two calls: after a rejected first call (2.5.5 too), or one that closed for missing keys or no strength left, the series without the commit left the second call in the authentication phase until it timed out. With the commit the second call authenticates and comes up as its reply allows, without an IPCP or IPV6CP request before authentication.
  • Ninth commit, the same server: before, the second and later calls failed the client's mutual authentication and had no keys; now three calls in a row came up with 128-bit MPPE, and the second call's accounting does not carry the first reply's Class. With a test peer that renegotiates LCP, the second authentication gets its reply again.
  • Last commit, the same server with an integer dictionary: "mppe preferred,40" with policy 2 and a "128-bit only" reply now closes with "MPPE required, but both 40-bit and 128-bit disabled." where it came up unencrypted; a client without MPPE, or a reply without keys, gets a closed link too. Policy 1, no policy attribute, require-mppe and MPPE disabled behave as before. Over two calls a "required" or "40-bit only" reply does not carry into the second call.

With the radius plugin, MS-MPPE-Encryption-Policy 2 now makes a preferred or permitted link require MPPE for that call, when the dictionary declares the policy and types attributes as integers.

Closes #57

@Neustradamus

Copy link
Copy Markdown
Member

@jkroonza, @enaess, @jjkeijser, @paulusmack: What do you think about this new @strrs PR?

@strrs

strrs commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, I have been working on this for a few weeks. If there is anything specific you would like to see regarding the design, I can try to adjust the code accordingly.

@jkroonza

Copy link
Copy Markdown
Contributor

I'm not commenting on where hooks are going and general code - I've just scanned - but I like the general direction of this, essentially it looks like you're aiming towards different "levels":

required
preferred
disabled

May I recommend a fourth? permitted?

Essentially my understanding:

required - advertise and enforce.
preferred - advertise, but don't refuse if the peer NACKs (or responds empty).
permitted - don't advertise, but if the peer requests, enable.
disabled - don't advertise, and NACK (except ACK empty option set).

And we must remember that some remotes will advertise an empty option set, which I think there was a merge about recently to ACK that, but simply not enable MPPE in that case.

please keep in mind my background is primarily service provider side - so permitted is useful in that "we don't really want it, nor do we want to advertise it, but some arb peers are requesting and enforcing it, as such we don't want to disallow it". We do still prefer L2TP from this perspective, but there's always that one :).

@strrs strrs changed the title pppd: Add an mppe option with a preferred state pppd: Add an mppe option with preferred and permitted states Nov 13, 2026
@strrs
strrs force-pushed the pppd-mppe-preferred branch from ab5eb91 to 2985621 Compare November 13, 2026 03:04
Comment thread pppd/ccp.c
bool refuse_mppe_stateful = 1; /* Allow stateful mode? */
static bool require_mppe;
static bool prefer_mppe; /* Go on without MPPE if it fails */
static bool permit_mppe; /* Use MPPE only if the peer asks */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these three perhaps be a single enum value?

enum {
none,
permit,
prefer,
require
} mppe_level;

kind of thing? One could then NACK (or ACK empty) if mppe_level < permit, ACK if != none and advertise if >= prefer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept them as bools because require-mppe, +mppe and their -40/-128 forms are o_bool options on require_mppe (the form we settled on in #646), and an o_bool can't hold a level, so an enum would mean turning those six entries into o_special handlers. If you still prefer the enum, I can change it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For comparison, this is the enum version against the current code. I have it ready and tested; only ccp.c changes. The main parts:

@@ -71,7 +71,13 @@ static char deflate_value[8];
 bool refuse_mppe_stateful = 1;		/* Allow stateful mode? */
-static bool require_mppe;
-static bool prefer_mppe;		/* Go on without MPPE if it fails */
-static bool permit_mppe;		/* Use MPPE only if the peer asks */
+static enum {
+    MPPE_DISABLED,
+    MPPE_PERMITTED,		/* Use MPPE only if the peer asks */
+    MPPE_PREFERRED,		/* Go on without MPPE if it fails */
+    MPPE_REQUIRED
+} mppe_level;
 static int setmppe (char **);
 static int setnomppe (char **);
+static int setreqmppe (char **);
+static int setreqmppe40 (char **);
+static int setreqmppe128 (char **);
 static char mppe_value[20];
@@ -137,8 +139,6 @@ static struct option ccp_option_list[] = {
 
-    { "require-mppe-40", o_bool, &require_mppe,
-      "require MPPE 40-bit encryption", OPT_PRIO | OPT_A2OR | MPPE_OPT_40,
-      &ccp_wantoptions[0].mppe },
-    { "+mppe-40", o_bool, &require_mppe,
-      "require MPPE 40-bit encryption", OPT_PRIO | OPT_A2OR | MPPE_OPT_40,
-      &ccp_wantoptions[0].mppe },
+    { "require-mppe-40", o_special_noarg, (void *)setreqmppe40,
+      "require MPPE 40-bit encryption", OPT_PRIO },
+    { "+mppe-40", o_special_noarg, (void *)setreqmppe40,
+      "require MPPE 40-bit encryption", OPT_PRIO },
     /* We use ccp_allowoptions[0].mppe as a junk var ... it is reset later */
@@ -287,6 +284,6 @@ static int mppe_pref[NUM_PPP];
 /* With "mppe permitted": the peer hasn't asked for MPPE yet */
-#define MPPE_WAITING(unit)	(permit_mppe && !require_mppe \
+#define MPPE_WAITING(unit)	(mppe_level == MPPE_PERMITTED \
 				 && !(mppe_pref[unit] & (MPPE_SOFT \
 				      | MPPE_GAVE_UP | MPPE_WAS_UP)))
-#define MPPE_MODE		(permit_mppe? "permitted": "preferred")
+#define MPPE_MODE	(mppe_level == MPPE_PERMITTED? "permitted": "preferred")
 #endif
@@ -440,5 +435,3 @@ setnomppe(char **argv)
 {
-    require_mppe = 0;
-    prefer_mppe = 0;
-    permit_mppe = 0;
+    mppe_level = MPPE_DISABLED;
     ccp_wantoptions[0].mppe = 0;
@@ -520,3 +542,3 @@ ccp_open(int unit)
 #ifdef PPP_WITH_MPPE
-	if (!mppe_pref[unit] && prefer_mppe && !require_mppe)
+	if (!mppe_pref[unit] && mppe_level == MPPE_PREFERRED)
 	    mppe_pref[unit] = MPPE_SOFT;
@@ -831,4 +853,4 @@ ccp_resetci(fsm *f)
 	go->mppe = 0;		/* only ask for MPPE once the peer has */
-    if ((require_mppe || (mppe_pref[f->unit] & (MPPE_SOFT | MPPE_WAS_UP)))
-	&& !go->mppe) {
+    if ((mppe_level == MPPE_REQUIRED
+	 || (mppe_pref[f->unit] & (MPPE_SOFT | MPPE_WAS_UP))) && !go->mppe) {
 	mppe_unavailable(f, "both 40-bit and 128-bit disabled.");

Each form gets one small handler, for example:

static int
setreqmppe40(char **argv)
{
    mppe_level = MPPE_REQUIRED;
    ccp_wantoptions[0].mppe |= MPPE_OPT_40;
    return 1;
}

The other forms use setreqmppe() and setreqmppe128() the same way. The checks stay == rather than < and >=, since permitted also asks for MPPE once the peer has. The option dump also lists require-mppe, +mppe and the -128 forms by name again. If you prefer this, I'll push it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the concern.

I personally prefer the enum mechanism, but I think I need to defer to @paulusmack here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the o_bool form for now and will switch to the enum if that is the decision.

Comment thread pppd/ccp.c Resolved
@strrs
strrs force-pushed the pppd-mppe-preferred branch from 2985621 to 4a977b9 Compare November 13, 2026 04:05

@jkroonza jkroonza left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked more in-depth. I like this, but I've not tested any of this. Code looks reasonable. Other than still personally preferring the enum over a bunch of booleans.

Comment thread pppd/ccp.c Resolved
@strrs
strrs force-pushed the pppd-mppe-preferred branch from 4a977b9 to 1d8599d Compare November 13, 2026 20:27
strrs added 10 commits November 16, 2026 14:24
ccp.c calls lcp_close() from inside its fsm callbacks when required
MPPE fails, for example in ccp_reqci() ("MPPE required but peer
negotiation failed") and in ccp_down() ("MPPE disabled"). lcp_close()
takes CCP down before it returns, but the caller in fsm.c then
continues. fsm_rconfreq() sets the state to ACKSENT or REQSENT after
the reqci callback. After the down callback, fsm_rconfreq() and
fsm_rtermack() send a Configure-Request, start its timer and set
REQSENT.

Nothing resets that when the call ends. With persist or demand the
next call finds CCP still in that state, where fsm_lowerup() and
fsm_open() do nothing. After a close from ccp_reqci() pppd sends no
CCP Configure-Request in the next call. After a restart from OPENED
the timer is still running and keeps resending the old request,
between the calls and in the next one.

Add a phase notifier that takes CCP down again at PHASE_DISCONNECT,
the way upper_layers_down() does when LCP goes down. Like link_down(),
it leaves CCP alone when multilink is on, where the bundle keeps its
CCP.

Signed-off-by: Semih Baskan <[email protected]>
With require-mppe the network protocols are held until CCP has come up
with MPPE. If the peer never completes CCP, for example because it
acks our request and then stays silent, or ignores CCP without sending
a Protocol-Reject, the CCP Configure-Requests time out and CCP stops.
Nothing reacts to that, since ccp_callbacks has no "finished" handler:
the link stays up with no network protocol, and the log only has the
fsm warning "CCP: timeout sending Config-Requests".

Add ccp_finished(). When CCP stops while MPPE is still required and
LCP is up, it logs "MPPE required but peer negotiation failed" and
closes the link, like the other places where required MPPE fails.

Signed-off-by: Semih Baskan <[email protected]>
pppd can either require MPPE (require-mppe*) or not use it at all.
Issue ppp-project#57 asks for a setting in between: use MPPE when the peer agrees,
and keep the link up without it when the peer can't do MPPE, for
example on an SSTP client or on a PPTP server that also has clients
without MPPE.

Add "mppe required|preferred|disabled[,40][,128]", the syntax suggested
in ppp-project#57. "required" and "disabled" set the same state as require-mppe
and nomppe. With no strength given, both 40-bit and 128-bit are
allowed, as with require-mppe. The option sets the state and the
strengths together. A require-mppe-40 or require-mppe-128 given after
it adds that strength and makes MPPE required. nomppe and -mppe are
now handled by setnomppe(), which also clears the preferred state, so
they still turn MPPE off after "mppe preferred".

With "preferred", pppd negotiates MPPE as with require-mppe. If MPPE
fails before it has come up (the peer rejects it, Naks with something
we can't use, rejects CCP or never answers, no strength is left, or
there are no MPPE keys, for example after PAP or CHAP-MD5), pppd logs a
warning, stops asking for MPPE, drops the MPPE keys and the kernel's
CCP state, and starts the network protocols that were waiting for
MPPE. No other compression is used after that either, as with
require-mppe.

Once MPPE has been up it is required for the rest of the call, as with
require-mppe, also after an LCP renegotiation: there is no fallback
any more. ccp_link_terminated() clears this when the call has ended,
so the next call of the same pppd is preferred again.

MPPE is never left on in one direction only. If we have already
accepted the peer's MPPE request when our own fails, or the peer has
accepted ours and its own request has no MPPE we can take, the link is
closed. ccp_up checks the same before it brings CCP up. With the
existing options required MPPE has normally closed the link before CCP
gets that far.

In the preferred state a Configure-Reject is acted on only after the
whole packet has been checked, and at a CCP timeout ccp_finished()
gives MPPE up instead of closing the link. ccp_open now also clears
the silent flag when there is something to ask for, so a fallback in
one session can't keep CCP silent, and the network protocols held, in
the next one. It does that for every compression type.

The checks in ccp_resetci that log why MPPE is not available now go
through mppe_unavailable(). The existing options behave as before and
keep their log messages. In the new state the messages say "preferred"
instead of "required".

Signed-off-by: Semih Baskan <[email protected]>
Add "mppe permitted[,40][,128]": pppd doesn't ask for MPPE, but uses
it when the peer asks for it. This is the third of the four states
listed in ppp-project#57 (written "optional" in the syntax suggested there), for a
server that doesn't want MPPE but has to take peers that insist on it.

A CCP request only covers the direction its sender receives, so acking
the peer's MPPE request alone would encrypt one direction. When the
peer asks, pppd therefore asks for MPPE too and from then on behaves as
with "mppe preferred": MPPE comes up in both directions, or pppd gives
it up with the usual warning, or the link is closed if pppd has already
accepted the peer's MPPE.

pppd must not send a CCP request of its own before the peer's, because
a peer with require-mppe closes the link on any request without MPPE.
So with "permitted" CCP stays in silent mode until the peer has sent a
request in this LCP session, and two permitted peers negotiate no
compression at all; after that, SIGUSR2 restarts CCP as before. The
decision has to be made before fsm_input(): in the stopped and opened
states fsm_rconfreq() sends our request before it calls ccp_reqci().
While pppd waits, mppe_peer_asks() looks at each Configure-Request that
fsm_rconfreq() will negotiate on; one that the state machine drops or
answers with a Terminate-Ack, because CCP is closed or going down,
doesn't count. If the request's first MPPE option asks for a strength
we allow, is not stateful while stateful mode is refused, and pppd has
MPPE keys, mppe_ask_too() sets the preferred state. If our own request
is already out without MPPE, the CCP state machine is restarted, so
that a new request with MPPE goes out before the reply.

The network protocols are not held back for "permitted": they start
at once, as with MPPE off, so ccp_up() and mppe_failed() don't call
continue_networks() a second time when the peer asked. Until MPPE is
up, data can be sent unencrypted. Against a peer that holds its own
network protocols until MPPE is up, as pppd does with require-mppe and
"preferred", no data flows before that. In this state the warnings say
"permitted" instead of "preferred".

An MPPE request that doesn't ask for a strength pppd can use (40-bit
is dropped after MS-CHAPv1, as in ccp_resetci()), for example one with
no bits set or with only MPPC, is handled as with MPPE off, and so is
any MPPE request while pppd has no MPPE keys from the authentication
of this LCP session (after PAP, for example). For that, ccp_lowerup()
now drops the keys before the session authenticates, and
ccp_link_terminated() drops them, with the rest of the MPPE state, when
the call is over. It waits for the dead phase because a multilink
bundle can outlive the link that terminates, and the bundle's CCP may
still need the keys. A bundle that renegotiates LCP keeps its CCP and
with it the keys, since link_established() skips the upper layers'
lowerup there. Until now the keys of a session that ended before MPPE
came up were still there in the next one, and a session without keys
of its own (EAP without TLS, for example) passed the key check with
them, also with require-mppe.

When pppd asked for MPPE, ccp_resetci() turned the other compressors
off in ccp_allowoptions, and mppe_give_up() did the same; nothing in
the MPPE code turned them on again. A later call or LCP session
without MPPE, which is normal with "permitted" and also happens when
options from the secrets file turn MPPE off, then asked for Deflate
but refused the peer's. ccp_allowoptions now keeps what the options
say, and ccp_reqci() refuses the other compressors while the session
asks for MPPE or has given it up. The other states behave as before,
apart from the keys and that later session.

Signed-off-by: Semih Baskan <[email protected]>
Describe the four states, the default strengths and how they relate
to require-mppe and nomppe. Say when a preferred link falls back and
when it is still closed, when a permitted link starts to use MPPE,
that it doesn't hold the network protocols back and only uses other
compression when the peer starts CCP, that anyone who can block or
alter the CCP negotiation can make either run unencrypted (RFC 3078
says the link should be closed when MPPE fails), and that the option
does not keep pppd from authenticating with PAP. Add a note on the new
states to README.MPPE, which says MPPE is either required or off.

Signed-off-by: Semih Baskan <[email protected]>
Check both roles: MPPE comes up against require-mppe and preferred
peers, at 40-bit with "preferred,40", and pings go through. Against a
peer without MPPE, with noccp, with PAP instead of MS-CHAP on either
side, or with no strength left ("preferred,128 nomppe-128"), the link
comes up with no compression at all, IPCP comes up once, pings work and
only the preferred side logs the warning. A require-mppe-128 peer still
closes the link, and "mppe preferred require-mppe" is required again;
the side that closes exits with EXIT_NEGOTIATION_FAILED and the other
with EXIT_HANGUP. "mppe preferred nomppe" brings up a normal link with
Deflate and no warning. Also check the dryrun output and that bad
values are option errors.

Signed-off-by: Semih Baskan <[email protected]>
Check both roles. Against require-mppe and preferred peers the
permitted side sends its first CCP request only after the peer's, with
MPPE in it; MPPE comes up, also at 40-bit with "permitted,40", IPCP
comes up once and pings go through. Two permitted peers, and a
permitted peer against noccp, send no CCP packet at all. With PAP
instead of MS-CHAP, only a preferred peer warns. Against a peer
without MPPE, and with "require-mppe mppe permitted", Deflate comes up,
and so it does between "mppe permitted nomppe" and a permitted peer. A
require-mppe-40 peer closes the link against "permitted,128" without
the permitted side asking for MPPE, and "mppe permitted require-mppe"
is required again. Also check the dryrun output and that bad values are
option errors.

Signed-off-by: Semih Baskan <[email protected]>
chap_handle_response() reports the result with auth_peer_fail() or
auth_peer_success() and only then sets AUTH_DONE and, on success, arms
the chap-interval timer. Both calls can close the link before they
return: auth_peer_fail() always does, and auth_peer_success() does when
ccp_open(), reached through network_phase() and start_networks(), finds
that required MPPE can't be used (for example no strength left or no
keys). lcp_close() takes the protocols down at once and
chap_lowerdown() clears the CHAP state, so AUTH_DONE is set again on a
link that is down. In the next call of a pppd with persist or demand,
chap_handle_response() then answers the peer's response with Success
but never calls auth_peer_success(), and that call stays in the
authentication phase until the peer gives up. The failure case happens
with 2.5.5 as well.

After a close from ccp_open() with no strength left
(ccp_gotoptions.mppe is 0), start_networks() also goes on to
continue_networks() and opens IPCP and IPV6CP on the closing link. In
the next call they send their requests at LCP up, before the peer is
authenticated.

Set AUTH_DONE and arm the timer before reporting the result, so that
chap_lowerdown() clears them when the link goes down;
chap_server_timeout() and chap_handle_status() also set their state
before they report. Return from start_networks() when LCP is no longer
open after CCP and ECP have been started.

Signed-off-by: Semih Baskan <[email protected]>
radius_chap_verify() applies the server's reply only while
rstate.done_chap_once is clear, so that a CHAP re-authentication
(chap-interval) keeps the reply of the session. The flag is set after
the first successful CHAP authentication and never cleared, so in a
pppd that serves several calls (persist or demand on the
authenticating side) every later CHAP authentication is sent with the
first call's user name and its reply is ignored: the CHAP Success has
no MS-CHAP2-Success authenticator, so an MS-CHAPv2 client fails mutual
authentication, and there are no MPPE keys and no address, Class,
timeouts or MPPE policy of its own. The same happens after an LCP
renegotiation, where pppd authenticates the peer from scratch.

Clear the flag from a phase change notifier when a new authentication
phase starts. Clear there also the reply data the plugin keeps, as a
reply only sets the attributes it has: the Framed-IP-Address choice,
the Class, the interim accounting interval and the two script
variables. PAP replies, which were applied every time, no longer start
from what an earlier reply left either. Re-authentications within a
session are unchanged. Settings a reply writes into pppd itself, such
as the peer address that ipcp_resetci() stores through ip_choose_hook
or the connect and idle time limits, stay as they were.

radius_acct_stop() now cancels the interim timer whatever the interval
is, and radius_acct_interim() only schedules itself again for a
non-zero interval, so the timer no longer depends on the interval that
a new authentication phase clears.

Signed-off-by: Semih Baskan <[email protected]>
With the radius plugin, an MS-MPPE-Encryption-Policy of 2 (encryption
required, RFC 2548) does not make pppd require MPPE. The plugin hands
it to mppe_set_enc_types() only when the reply also has a types
attribute and MPPE keys, and that function only turns off the
strengths that MS-MPPE-Encryption-Types does not allow. So with
"mppe preferred" a server that requires encryption still gets a link
without it when its types leave no strength, when the peer refuses
MPPE, or when the reply has no keys: pppd gives MPPE up and brings the
link up unencrypted. With "mppe permitted" pppd does not ask for MPPE
unless the peer does.

Make a policy of 2 work as "mppe required" until the call ends, if MPPE
is enabled at all. "mppe preferred" already has that state for "MPPE
has been up on this call": it holds across an LCP renegotiation and is
reset when the call is over. The bit is renamed MPPE_HARD for the wider
use. A policy of 2 does not turn MPPE on when it is disabled, and a
policy of 1 only applies the types as before, so the server can only
make MPPE stricter than configured.

mppe_set_enc_types() also changed ccp_wantoptions[0].mppe for good: in
a pppd that serves several calls, the strengths that one reply turned
off stayed off in the calls after it. Record the bits it turns off and
give them back when the call ends, where the MPPE state is reset.

The function moves from mppe.c to ccp.c, next to the state it changes.
It was the only code in mppe.c that used ccp.h, and the reason for the
#ifndef UNIT_TEST there. The early return for policy 1 when MPPE is not
configured goes away, as turning bits off in an empty mask changes
nothing. The radius plugin now passes the policy whenever the reply has
one, also without a types attribute or keys.

The plugin reads the policy and the types correctly only when the
dictionary declares MS-MPPE-Encryption-Policy and
MS-MPPE-Encryption-Types as integers. The dictionary.microsoft that
comes with pppd declares them as strings, and with it the plugin takes
the length of each value, 4, as the value, so this change has no effect
there until the plugin also reads the string form.

Signed-off-by: Semih Baskan <[email protected]>
@strrs
strrs force-pushed the pppd-mppe-preferred branch from 1d8599d to 16e5c0d Compare November 16, 2026 14:40
@strrs

strrs commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

I added three commits at the end. The first fixes the call after a close during CHAP authentication with persist or demand: after a failed authentication (on 2.5.5 too), or after ccp_open() closed the link because required MPPE couldn't be used, that call stayed in the authentication phase.

The second makes the radius plugin apply the server's reply in every authentication phase; it only did so for the first CHAP authentication of the process, so later calls got no MS-CHAP2-Success authenticator and no MPPE keys.

The third makes an MS-MPPE-Encryption-Policy of 2 work as "mppe required" for the call when MPPE is enabled (with an integer dictionary), and gives back the strengths a reply turned off when the call ends.

@jkroonza

Copy link
Copy Markdown
Contributor

I am running about a bit, but willing to test if I can find the time, otherwise, on eyeball looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Add mppe-optional option

3 participants