open-vault/vendor/layeh.com/radius
Jeff Mitchell 4e7ce6f42b
Update deps (#6580)
* Update deps

* Change azure dep to match plugin
2019-04-12 11:51:37 -04:00
..
rfc2865 Update Deps (#5454) 2018-10-03 09:55:26 -07:00
LICENSE RADIUS Authentication Backend (#2268) 2017-02-07 16:04:27 -05:00
README.md Update deps (#6580) 2019-04-12 11:51:37 -04:00
attribute.go Update deps (#6580) 2019-04-12 11:51:37 -04:00
attributes.go Update deps (#6580) 2019-04-12 11:51:37 -04:00
client.go Bump Deps (#4868) 2018-07-06 12:09:34 -04:00
code.go Bump deps 2017-09-05 18:06:47 -04:00
doc.go Bump deps 2017-09-05 18:06:47 -04:00
errors.go Bump deps 2018-02-10 19:29:52 -05:00
go.mod Update deps (#6580) 2019-04-12 11:51:37 -04:00
packet.go Update deps (#6580) 2019-04-12 11:51:37 -04:00
server-packet.go Minor dep sync 2018-07-11 16:04:02 -04:00
server.go Minor dep sync 2018-07-11 16:04:02 -04:00

README.md

radius

a Go (golang) RADIUS client and server implementation

GoDoc CircleCI

Installation

go get -u layeh.com/radius

Client example

package main

import (
	"context"
	"log"

	"layeh.com/radius"
	"layeh.com/radius/rfc2865"
)

func main() {
	packet := radius.New(radius.CodeAccessRequest, []byte(`secret`))
	rfc2865.UserName_SetString(packet, "tim")
	rfc2865.UserPassword_SetString(packet, "12345")
	response, err := radius.Exchange(context.Background(), packet, "localhost:1812")
	if err != nil {
		log.Fatal(err)
	}

	log.Println("Code:", response.Code)
}

Server example

package main

import (
	"log"

	"layeh.com/radius"
	"layeh.com/radius/rfc2865"
)

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

		var code radius.Code
		if username == "tim" && password == "12345" {
			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)
	}
}

RADIUS Dictionaries

Included in this package is the command line program radius-dict-gen. It can be installed with:

go get -u layeh.com/radius/cmd/radius-dict-gen

Given a FreeRADIUS dictionary, the program will generate helper functions and types for reading and manipulating RADIUS attributes in a packet. It is recommended that generated code be used for any RADIUS dictionary you would like to consume.

Included in this repository are sub-packages of generated helpers for commonly used RADIUS attributes, including rfc2865 and rfc2866.

License

MPL 2.0

Author

Tim Cooper (tim.cooper@layeh.com)