goradius

package module
v0.0.0-...-aba6c7c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2013 License: Apache-2.0 Imports: 11 Imported by: 0

README

GoRadius

GoRadius is a Go Library implementing the RADIUS protocol. It provides functions for Marshalling & Unmarshalling RADIUS packets. The packet processing logic resides with the application using the library.

NOTE: This is a Work-In-Progress. A lot of will change in the coming weeks, and I recommend against using this in production code as API might change. Patches are welcome!

Dictionaries

GoRadius requires two kinds of dictionaries to function: a RADIUS dictionary containing Attribute-Value-Pairs (AVP) that are assigned by various RFCs and a Vendor Dictionary, which documents Vendor-specific extensions to the protocol. GoRadius includes samples of these user-extensible dictionaries under the dict/ directory.

Locations of these dictionary files must be given during initialization of the library, as they are needed to parse & decode the data received.

API

The first API exposed by GoRadius is the Parser Registration API RegisterParser. This allows the developer to register a custom parser for a specific AVP, not supported by default by the library. A Parser has a name, for reference, which must match the parser name given in the dictionary file. If GoRadius encounters that specific AVP, it will callback the function registered with the raw bytes of content, expecting in return the parsed content in interface{} format.

When operating in UDP Server mode, the library must be provided with a Shared-Secret Callback function. This function is called when the RADIUS server must authenticate a NAS sending packets to RADIUS. The library will provide the IP address of the callee, expecting in return the shared-secret as a plain-text string.

An example of how the above API functions are used is in the goradius_test.go file.

LICENSE

This library is under Apache License, Version 2.0. For more details please see LICENSE file.

Copyright (C) 2013 Andreas Louca. All rights reserved.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcctStatusTypeParser

func AcctStatusTypeParser(b []byte, r *RadiusPacket) interface{}

Accounting Status Parser

func FallbackParser

func FallbackParser(content []byte, r *RadiusPacket) interface{}

func HelperParseUint16

func HelperParseUint16(content []byte) int

func IPParser

func IPParser(content []byte, r *RadiusPacket) interface{}

Parses IP Addresses

func ParseString

func ParseString(content []byte, r *RadiusPacket) interface{}

Parses Strings

func ParseUint16

func ParseUint16(content []byte, r *RadiusPacket) interface{}

Parses UINT16

func ParseUint32

func ParseUint32(content []byte, r *RadiusPacket) interface{}

Parses UINT32

func ParseUserPassword

func ParseUserPassword(content []byte, r *RadiusPacket) interface{}

func ParseUvarint

func ParseUvarint(buf []byte, r *RadiusPacket) interface{}

func RegisterParser

func RegisterParser(name string, parser ContentParser) error

Registers a new AVP Parser

func StringMarshaller

func StringMarshaller(a AttributeValuePair, p *RadiusPacket) []byte

func Uvarint

func Uvarint(buf []byte) (x uint64)

func VendorParser

func VendorParser(avpContent []byte, rp *RadiusPacket) interface{}

Parses vendor-specific attribute (VSA)

Types

type AttributeValuePair

type AttributeValuePair struct {
	Name    string
	Type    string
	Length  uint8
	Content interface{}
}

Attribute-Value Pair structure

type ContentParser

type ContentParser func([]byte, *RadiusPacket) interface{}

Radius Content Parser Function Signature

type GoRadius

type GoRadius struct {
	SharedSecret SharedSecretProvider
	// contains filtered or unexported fields
}

func NewGoRadius

func NewGoRadius(radDictFile, vendorDictFile string, debug, verbose bool) *GoRadius

* Create a new RADIUS parser, providing the RADIUS & Vendor-Specific TLV Dictionary JSON files. * Option to enable debug & verbose output to aid in troubleshooting

func (*GoRadius) ParseRadiusPacket

func (r *GoRadius) ParseRadiusPacket(source *net.UDPAddr, data []byte) *RadiusPacket

RADIUS Packet Parser Returns an array of parsed Attribute-Value Pairs

func (*GoRadius) SendPacket

func (r *GoRadius) SendPacket(p *RadiusPacket) error

func (*GoRadius) SendRawPacket

func (r *GoRadius) SendRawPacket(data []byte, dest *net.UDPAddr) error

func (*GoRadius) StartUDPServer

func (r *GoRadius) StartUDPServer(port int, ssp SharedSecretProvider) (chan *RadiusPacket, error)

type MarshalHelper

type MarshalHelper func(AttributeValuePair, *RadiusPacket) []byte

Marshaller signature

type RadiusDictionary

type RadiusDictionary struct {
	Attribute   int
	Name        string
	ContentType string
}

RADIUS Dictionary (RFC2865 + RFC2866)

type RadiusPacket

type RadiusPacket struct {
	Originator    *net.UDPAddr         // The origin IP address of the packet
	SharedSecret  string               // Shared Secret
	Code          uint                 // Packet Code
	PacketType    string               // Packet Type, based on Code
	PacketId      uint                 // Packet Identifier
	Authenticator []byte               // Authenticator Signature
	AVPS          []AttributeValuePair // A list of Attribute-value Pairs
	Raw           []byte               // A buffer with the original raw data
}

func (*RadiusPacket) Marshal

func (p *RadiusPacket) Marshal() []byte

func (*RadiusPacket) String

func (p *RadiusPacket) String() string

func (*RadiusPacket) VerifyAuthenticator

func (p *RadiusPacket) VerifyAuthenticator() bool

Verifies the Authenticator Field if it matches our shared-secret

type SharedSecretProvider

type SharedSecretProvider func(string) string

Radius Shared-Secret Provider Signature

type TLV

type TLV struct {
	Type        uint8
	Name        string
	ContentType string
}

Type-Length-Value Structure

type VSA

type VSA struct {
	Name  string
	Value interface{}
}

type VendorDictionary

type VendorDictionary struct {
	VendorID int
	Name     string
	TLVs     []TLV
	TLVMap   map[int]TLV
}

Vendor-Specific Attribute Dictionary

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL