Skip to content

rfc2865: add CHAP password verification helpers#143

Open
jamiesun wants to merge 1 commit into
layeh:masterfrom
talkincode:feature/chap-verify
Open

rfc2865: add CHAP password verification helpers#143
jamiesun wants to merge 1 commit into
layeh:masterfrom
talkincode:feature/chap-verify

Conversation

@jamiesun

@jamiesun jamiesun commented Jun 8, 2026

Copy link
Copy Markdown

Summary

rfc2865 exposed CHAPPassword and CHAPChallenge accessors but offered no way to actually verify a CHAP login (plain CHAP, not MS-CHAP). This adds the missing helper, mirroring the hand-written helper style already used by rfc2759 (MS-CHAPv2).

CHAP verification per RFC 2865 §2.2: CHAP-Password value is CHAP-Identifier || MD5(CHAP-Identifier || password || challenge), where the challenge is the CHAP-Challenge attribute if present, otherwise the Request Authenticator.

API

// Low level: compare a known password against a raw CHAP-Password value.
func CHAPMatch(password, chapPassword, challenge []byte) bool

// Convenience: pull CHAP-Password / CHAP-Challenge off a packet and verify.
func CHAPVerify(p *radius.Packet, password []byte) bool

Both use crypto/subtle.ConstantTimeCompare. CHAPVerify falls back to the packet Authenticator when no CHAP-Challenge attribute is present.

Changes

  • rfc2865/chap.go (new): CHAPMatch, CHAPVerify.
  • rfc2865/chap_test.go (new): match, with-challenge, authenticator-as-challenge, and missing-attribute cases.

The generated rfc2865/generated.go is untouched; go generate only rewrites that file.

Closes #96

rfc2865 exposed accessors for the CHAP-Password and CHAP-Challenge
attributes but no way to verify a CHAP (RFC 1994 / RFC 2865) response
against a known password. MS-CHAP and MS-CHAPv2 helpers already exist in
rfc2759, but plain CHAP did not, so servers handling equipment that uses
standard CHAP (for example some Huawei switches) had to implement the
MD5 check themselves.

Add CHAPMatch, which checks a raw CHAP-Password value against a password
and challenge in constant time, and CHAPVerify, a packet-level
convenience that pulls the CHAP-Password and CHAP-Challenge attributes
(falling back to the packet Authenticator as the challenge, per RFC
2865, Section 2.2).

Closes layeh#96

Co-authored-by: Copilot <[email protected]>
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.

can not verify password base on CHAPPassword and CHAPChallenge(not mschapv2)

1 participant