layeh / radius

a Go (golang) RADIUS client and server implementation
https://pkg.go.dev/layeh.com/radius
Mozilla Public License 2.0
567 stars 176 forks source link

userpassword string is empty #93

Open Gictorbit opened 3 years ago

Gictorbit commented 3 years ago

I'm using server example code on Linux and android client and EAP method is on PEAP when user tries to connect to ap and sends a request,the password is empty but username string is valid how can I solve the problem?

func Radius() {
    handler := func(w radius.ResponseWriter, r *radius.Request) {
        username := rfc2865.UserName_GetString(r.Packet)
        password := rfc2865.UserPassword_GetString(r.Packet) 

        fmt.Println(username,password)
        var code radius.Code
        if username == "admin" && password == "12345678" {  //this condition is false always because password is empty 
            code = radius.CodeAccessAccept
        } else {
            code = radius.CodeAccessReject
        }
        log.Printf("Writing %v to %v", code, r.RemoteAddr)
        w.Write(r.Response(code))
    }

    server := radius.PacketServer{
        Handler:      radius.HandlerFunc(handler),
        SecretSource: radius.StaticSecretSource([]byte(`secret`)),
    }

    log.Printf("Starting server on :1812")
    if err := server.ListenAndServe(); err != nil {
        log.Fatal(err)
    }
}
seanenck commented 3 years ago

When clients use EAP/PEAP the password string is never going to be filled out because the user's password is inside of the EAP section of a packet. You can see a bit more about using EAP with this library in #10 (I don't think anything has changed on this front).