Documentation
¶
Overview ¶
Package radiusmfa is a RADIUS authentication client supporting PAP and MS-CHAP-V2, intended for verifying user credentials against a RADIUS server (e.g. NPS, FreeRADIUS, or an MFA gateway) from Go services.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrProofFailed = errors.New("radiusmfa: server failed MS-CHAP-V2 mutual authentication")
ErrProofFailed is returned when an Access-Accept carries an MS-CHAP2-Success authenticator response that does not match the locally computed value, meaning the server did not prove knowledge of the user's password.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client authenticates users against a RADIUS server. It is safe for concurrent use.
func (*Client) Authenticate ¶
Authenticate sends an Access-Request for username and password using the configured protocol. It returns nil on Access-Accept, a *RejectError on Access-Reject, ErrProofFailed if MS-CHAP-V2 mutual authentication fails, and a transport error if no valid response arrives within the configured timeout and retries.
username should be the bare account name (e.g. sAMAccountName) — for MS-CHAP-V2 the domain prefix must not be included, as it is excluded from the challenge hash.
type Config ¶
type Config struct {
// Addr is the RADIUS server address as host:port, e.g. "10.0.0.5:1812".
Addr string
// Secret is the RADIUS shared secret.
Secret string
// Protocol selects PAP or MSCHAPv2. Defaults to MSCHAPv2.
Protocol Protocol
// NASIdentifier, if non-empty, is sent as the NAS-Identifier attribute.
NASIdentifier string
// Timeout is the per-attempt wait for a server response. Defaults to 5s.
Timeout time.Duration
// Retries is the number of retransmissions after the first attempt, so
// the server is tried Retries+1 times in total. Defaults to 2.
Retries int
}
Config configures a Client. Addr and Secret are required.
type Option ¶
type Option func(*reqOptions)
Option adjusts a single Authenticate call.
func WithCallingStationID ¶
WithCallingStationID sets the Calling-Station-Id attribute for this request, typically the end user's source IP or phone number.
type Protocol ¶
type Protocol string
Protocol selects the authentication method used for Access-Requests.
const ( // MSCHAPv2 authenticates with MS-CHAP-Challenge and MS-CHAP2-Response // Microsoft vendor attributes (RFC 2548). The password never crosses the // wire; on Access-Accept the server's MS-CHAP2-Success proof is verified. MSCHAPv2 Protocol = "mschapv2" // PAP authenticates with the User-Password attribute, obfuscated with the // shared secret as defined by RFC 2865. Only use PAP over a trusted or // encrypted transport. PAP Protocol = "pap" )
type RejectError ¶
type RejectError struct {
// ReplyMessage holds the server's Reply-Message attribute, if any.
ReplyMessage string
}
RejectError is returned by Authenticate when the server answers with Access-Reject.
func (*RejectError) Error ¶
func (e *RejectError) Error() string