Documentation ¶
Index ¶
- Constants
- Variables
- func AuthenticateCHAP(password, authenticator, chapChallenge []byte) bool
- func ChallengeHash(peerChallenge, authenticatorChallenge []byte, username string) []byte
- func ChallengeResponse(challenge, passwordHash []byte) []byte
- func DESCrypt(key, clear []byte) []byte
- func DecodeUserPassword(p *Packet, a *AVP) error
- func EncodeCHAPPassword(password, authenticator []byte) []byte
- func EncodeUserPassword(plaintext, secret, requestAuthenticator []byte) []byte
- func GenerateAuthenticatorResponse(authenticatorChallenge, peerChallenge, ntResponse []byte, ...) (string, error)
- func GenerateClientMSCHAPResponse(authenticator [16]byte, userName, password string) ([]byte, error)
- func GenerateNTResponse(authenticatorChallenge, peerChallenge []byte, username, password string) ([]byte, error)
- func HashPassword(password []byte) []byte
- func ToUTF16(in string) ([]byte, error)
- type AVP
- type Client
- type Coder
- type Dictionaries
- type Dictionary
- func (dict *Dictionary) AttributeWithName(attrName, VendorName string) *DictionaryAttribute
- func (dict *Dictionary) AttributeWithNumber(attrNr uint8, vendorCode uint32) *DictionaryAttribute
- func (dict *Dictionary) ParseFromFolder(dirPath string) (err error)
- func (dict *Dictionary) ParseFromReader(rdr io.Reader) (err error)
- func (dict *Dictionary) ValueWithName(attrName, valName, vendorName string) (dv *DictionaryValue)
- func (dict *Dictionary) ValueWithNumber(attrName string, valNr uint8, vendorCode uint32) (dv *DictionaryValue)
- func (dict *Dictionary) VendorWithCode(vendorCode uint32) *DictionaryVendor
- func (dict *Dictionary) VendorWithName(VendorName string) *DictionaryVendor
- type DictionaryAttribute
- type DictionaryValue
- type DictionaryVendor
- type Packet
- func (p *Packet) AddAVPWithName(attrName, strVal, vendorName string) (err error)
- func (p *Packet) AddAVPWithNumber(attrNr uint8, val interface{}, vendorCode uint32) (err error)
- func (p *Packet) AttributesWithName(attrName, vendorName string) (avps []*AVP)
- func (p *Packet) AttributesWithNumber(attrNr uint8, vendorCode uint32) (avps []*AVP)
- func (p *Packet) Decode(buf []byte) error
- func (p *Packet) Encode(b []byte) (n int, err error)
- func (p *Packet) Has(attrNr uint8) bool
- func (p *Packet) NegativeReply(errMsg string) *Packet
- func (pk *Packet) RemoteAddr() net.Addr
- func (p *Packet) Reply() *Packet
- func (p *Packet) SetAVPValues()
- func (p *Packet) SetCodeWithName(codeName string) (err error)
- type PacketCode
- type Secrets
- type Server
- type VSA
- type Validation
Constants ¶
const ( AttributeKeyword = "ATTRIBUTE" ValueKeyword = "VALUE" VendorKeyword = "VENDOR" BeginVendorKeyword = "BEGIN-VENDOR" EndVendorKeyword = "END-VENDOR" IncludeFileKeyword = "$INCLUDE" // rfc2865 value Formats TextValue = "text" StringValue = "string" AddressValue = "address" IntegerValue = "integer" TimeValue = "time" IPAddrValue = "ipaddr" UnknownValue = "unknown" // other value formats OctetsValue = "octets" )
const ( MetaDefault = "*default" // default client MaxPacketLen = 4095 )
const (
UNLIMITED = -1
)
Variables ¶
var (
ErrNotImplemented = errors.New("not implemented")
)
var ErrUnsupportedAttributeType = errors.New("unsupported attribute type")
var RFC2865Dict = `` /* 2264-byte string literal not displayed */
Functions ¶
func AuthenticateCHAP ¶
AuthenticateCHAP receive the password as plaintext and verify against the chap challenge
func ChallengeHash ¶
ChallengeHash - rfc2759, 8.2
func ChallengeResponse ¶
ChallengeResponse - rfc2759, 8.5
func DecodeUserPassword ¶
func EncodeCHAPPassword ¶
EncodeCHAPPassword is used in test to encode CHAP-Password raw value
func EncodeUserPassword ¶
EncodeUserPassword encodes the plaintext, where plaintext's length needs to be greater than 16 and a multiple of 16.
func GenerateAuthenticatorResponse ¶
func GenerateAuthenticatorResponse(authenticatorChallenge, peerChallenge, ntResponse []byte, username, password string) (string, error)
GenerateAuthenticatorResponse - rfc2759, 8.7
Types ¶
type AVP ¶
type AVP struct { Number uint8 // attribute number Name string // attribute name Type string // type of the value helping us to convert to concrete RawValue []byte // original value as byte Value interface{} // holds the concrete value defined in dictionary, extracted back with type (eg: avp.Value.(string) or avp.Value.(*VSA)) StringValue string // stores the string value for convenience and pretty print }
func (*AVP) GetStringValue ¶
StringValue returns the string value from either AVP of VSA
func (*AVP) SetRawValue ¶
func (a *AVP) SetRawValue(dict *Dictionary, cdr Coder) (err error)
SetRawValue will set the raw value (wire ready) from concrete one stored in interface
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a thread-safe RADIUS client
func NewClient ¶
func NewClient(net, address string, secret string, dict *Dictionary, connAttempts int, avpCoders map[string]codecs.AVPCoder, l logger) (*Client, error)
NewClient creates a new client and connects it to the address
func (*Client) NewRequest ¶
func (c *Client) NewRequest(code PacketCode, id uint8) (req *Packet)
NewRequest produces new client request with an random Authenticator
type Coder ¶
Coder puts together the available codecs Key represents the attribute type as defined in dictionary
func (Coder) Decode ¶
Decode converts raw value received over network into concrete value stored in AVP and it's string representation
type Dictionaries ¶
Dictionaries gathers together dictionaries to be safely accessed centralized in more than one server instance
func NewDictionaries ¶
func NewDictionaries(dicts map[string]*Dictionary) *Dictionaries
NewDictionaries instantiates Dictionary structure
func (*Dictionaries) GetInstance ¶
func (dts *Dictionaries) GetInstance(instanceID string) (dict *Dictionary)
GetInstance returns the Dictionary instance based on id or default one if not found
type Dictionary ¶
type Dictionary struct { sync.RWMutex // locks the Dictionary so we can update it on run-time // contains filtered or unexported fields }
Dictionary translates between types and human readable attributes provides per-client inFormation
func NewDictionaryFromFoldersWithRFC2865 ¶
func NewDictionaryFromFoldersWithRFC2865(dirPath []string) (*Dictionary, error)
NewDictionaryFromFoldersWithDefaults parses the folder and returns the Dictionary object Resulting dictionary contains RFC2865 elements
func NewEmptyDictionary ¶
func NewEmptyDictionary() *Dictionary
NewEmptyDictionary initializes properly the maps in the Dictionary struct
func RFC2865Dictionary ¶
func RFC2865Dictionary() (d *Dictionary)
Dictionary data required in RFC2865
func (*Dictionary) AttributeWithName ¶
func (dict *Dictionary) AttributeWithName(attrName, VendorName string) *DictionaryAttribute
DictionaryAttribute queries Dictionary for Attribute with specific name
func (*Dictionary) AttributeWithNumber ¶
func (dict *Dictionary) AttributeWithNumber(attrNr uint8, vendorCode uint32) *DictionaryAttribute
DictionaryAttribute queries Dictionary for Attribute having specific number
func (*Dictionary) ParseFromFolder ¶
func (dict *Dictionary) ParseFromFolder(dirPath string) (err error)
parseFromFolder walks through the folder/subfolders and loads all dictionary.* files it finds
func (*Dictionary) ParseFromReader ¶
func (dict *Dictionary) ParseFromReader(rdr io.Reader) (err error)
parseFromReader loops through the lines in the reader, adding info to the Dictionary overwrites previous data
func (*Dictionary) ValueWithName ¶
func (dict *Dictionary) ValueWithName(attrName, valName, vendorName string) (dv *DictionaryValue)
func (*Dictionary) ValueWithNumber ¶
func (dict *Dictionary) ValueWithNumber(attrName string, valNr uint8, vendorCode uint32) (dv *DictionaryValue)
func (*Dictionary) VendorWithCode ¶
func (dict *Dictionary) VendorWithCode(vendorCode uint32) *DictionaryVendor
func (*Dictionary) VendorWithName ¶
func (dict *Dictionary) VendorWithName(VendorName string) *DictionaryVendor
type DictionaryAttribute ¶
dictionaryAttribute defines a dictionary mapping and type for an attribute.
type DictionaryValue ¶
dictionaryValue defines an enumerated value for an attribute.
type DictionaryVendor ¶
DictionaryVendor defines a dictionary mapping for a vendor.
type Packet ¶
type Packet struct { sync.RWMutex Code PacketCode Identifier uint8 Authenticator [16]byte AVPs []*AVP // contains filtered or unexported fields }
func NewPacket ¶
func NewPacket(code PacketCode, id uint8, dict *Dictionary, coder Coder, secret string) *Packet
NewPacket creates a fresh packet, used mostly for testing
func (*Packet) AddAVPWithName ¶
AddAVPWithName adds an AVP based on it's attribute name and string value
func (*Packet) AddAVPWithNumber ¶
AddAVPWithNumber adds an AVP based on it's attribute number and value
func (*Packet) AttributesWithName ¶
Attributes queries AVPs matching the attrNr
func (*Packet) AttributesWithNumber ¶
AttributesWithNumber queries AVPs matching the attrNr if vendorCode is defined, AttributesWithNumber will query VSAs
func (*Packet) Encode ¶
Encode is used to encode the Packet into buffer b returning number of bytes written or error
func (*Packet) NegativeReply ¶
NegativeReply generates a response packet indicating a failure or rejection based on the original request.
func (*Packet) RemoteAddr ¶
func (*Packet) SetAVPValues ¶
func (p *Packet) SetAVPValues()
func (*Packet) SetCodeWithName ¶
SetCodeWithName sets the packet code based on predefined name
type PacketCode ¶
type PacketCode uint8
const ( AccessRequest PacketCode = 1 AccessAccept PacketCode = 2 AccessReject PacketCode = 3 AccountingRequest PacketCode = 4 AccountingResponse PacketCode = 5 AccessChallenge PacketCode = 11 StatusServer PacketCode = 12 //(experimental) StatusClient PacketCode = 13 //(experimental) DisconnectRequest PacketCode = 40 DisconnectACK PacketCode = 41 DisconnectNAK PacketCode = 42 CoARequest PacketCode = 43 CoAACK PacketCode = 44 CoANAK PacketCode = 45 Reserved PacketCode = 255 ReplyMessage = 18 VendorSpecificNumber = 26 // vendor specific AVP number VendorSpecificName = "Vendor-Specific" NoVendor = 0 )
func (PacketCode) String ¶
func (p PacketCode) String() string
type Secrets ¶
Secrets centralizes RADIUS secrets so it can be safely accessed over different server instances
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents a single listener on a port
func (*Server) ListenAndServe ¶
ListenAndServe binds to a port and serves requests
func (*Server) RegisterHandler ¶
func (s *Server) RegisterHandler(code PacketCode, hndlr func(*Packet) (*Packet, error))
RegisterHandler registers a new handler after the server was instantiated useful for live server reloads
type VSA ¶
type VSA struct { Vendor uint32 Number uint8 // attribute number VendorName string // populated by dictionary Name string // attribute name Type string // type of the value helping us to convert to concrete Value interface{} // holds the concrete value defined in dictionary, extracted back with type (eg: avp.Value.(string)) RawValue []byte // value as received over network StringValue string // stores the string value }
Vendor specific Attribute/Val originally ported from github.com/bronze1man/radius/avp_vendor.go
func NewVSAFromAVP ¶
func (*VSA) SetRawValue ¶
func (vsa *VSA) SetRawValue(dict *Dictionary, cdr Coder) (err error)
SetRawValue populates RawValue(wire data) based on concrete stored in vsa.Value