Documentation
¶
Overview ¶
Shared base for RADIUS Client & Server implementations
RADIUS Packet implementation
Index ¶
- Constants
- type Dictionary
- type DictionaryAttribute
- type DictionaryValue
- type DictionaryVendor
- type Host
- func (host *Host) CreateAttributeByID(attributeID uint8, value *[]uint8) (RadiusAttribute, error)
- func (host *Host) CreateAttributeByName(attributeName string, value *[]uint8) (RadiusAttribute, error)
- func (host *Host) Dictionary() Dictionary
- func (host *Host) DictionaryAttributeByID(packetAttrID uint8) (DictionaryAttribute, bool)
- func (host *Host) DictionaryAttributeByName(packetAttrName string) (DictionaryAttribute, bool)
- func (host *Host) DictionaryValueByAttrAndValueName(attrName, valueName string) (DictionaryValue, bool)
- func (host *Host) InitialiseRadiusPacketFromBytes(packet *[]uint8) (RadiusPacket, error)
- func (host *Host) Port(code TypeCode) (uint16, bool)
- func (host *Host) SetPort(port uint16, radMsgType RadiusMsgType) bool
- func (host *Host) VerifyMessageAuthenticator(secret string, packet *[]uint8) error
- func (host *Host) VerifyPacketAttributes(packet *[]uint8) error
- type RadiusAttribute
- func (radAttr *RadiusAttribute) ID() uint8
- func (radAttr *RadiusAttribute) Name() string
- func (radAttr *RadiusAttribute) OriginalIntegerValue(allowedType SupportedAttributeTypes) (uint32, bool)
- func (radAttr *RadiusAttribute) OriginalStringValue(allowedType SupportedAttributeTypes) (string, bool)
- func (radAttr *RadiusAttribute) OverrideValue(newValue []uint8)
- func (radAttr *RadiusAttribute) Value() []uint8
- func (radAttr *RadiusAttribute) VerifyOriginalValue(allowedType SupportedAttributeTypes) bool
- type RadiusMsgType
- type RadiusPacket
- func (radPacket *RadiusPacket) AttributeByID(attrID uint8) RadiusAttribute
- func (radPacket *RadiusPacket) AttributeByName(attrName string) RadiusAttribute
- func (radPacket *RadiusPacket) Attributes() []RadiusAttribute
- func (radPacket *RadiusPacket) Authenticator() []uint8
- func (radPacket *RadiusPacket) Code() TypeCode
- func (radPacket *RadiusPacket) GenerateMessageAuthenticator(secret string) error
- func (radPacket *RadiusPacket) ID() uint8
- func (radPacket *RadiusPacket) MessageAuthenticator() ([]uint8, error)
- func (radPacket *RadiusPacket) OverrideAuthenticator(authenticator []uint8)
- func (radPacket *RadiusPacket) OverrideID(id uint8)
- func (radPacket *RadiusPacket) OverrideMessageAuthenticator(newMessageAuth []uint8) error
- func (radPacket *RadiusPacket) SetAttributes(attr []RadiusAttribute)
- func (radPacket *RadiusPacket) ToBytes() ([]uint8, bool)
- type SupportedAttributeTypes
- type TypeCode
Constants ¶
const COMMENT_PREFIX = "#"
const IGNORE_VERIFY_ATTRIBUTE = "Message-Authenticator"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dictionary ¶
type Dictionary struct {
// contains filtered or unexported fields
}
============================= Represents RADIUS dictionary
func DictionaryFromFile ¶
func DictionaryFromFile(filePath string) (Dictionary, error)
func (*Dictionary) Attributes ¶
func (dict *Dictionary) Attributes() []DictionaryAttribute
func (*Dictionary) Values ¶
func (dict *Dictionary) Values() []DictionaryValue
func (*Dictionary) Vendors ¶
func (dict *Dictionary) Vendors() []DictionaryVendor
type DictionaryAttribute ¶
type DictionaryAttribute struct {
// contains filtered or unexported fields
}
============================= Represents an ATTRIBUTE from RADIUS dictionary file
func (DictionaryAttribute) Code ¶
func (da DictionaryAttribute) Code() uint8
func (DictionaryAttribute) CodeType ¶
func (da DictionaryAttribute) CodeType() SupportedAttributeTypes
func (DictionaryAttribute) Name ¶
func (da DictionaryAttribute) Name() string
type DictionaryValue ¶
type DictionaryValue struct {
// contains filtered or unexported fields
}
============================= Represents a VALUE from RADIUS dictionary file
func (*DictionaryValue) AttributeName ¶
func (dv *DictionaryValue) AttributeName() string
func (*DictionaryValue) Name ¶
func (dv *DictionaryValue) Name() string
func (*DictionaryValue) Value ¶
func (dv *DictionaryValue) Value() string
type DictionaryVendor ¶
type DictionaryVendor struct {
// contains filtered or unexported fields
}
============================= Represents a VENDOR from RADIUS dictionary file
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Generic struct that holds Server & Client common functions and attributes
func CreateHostWithDictionary ¶
func CreateHostWithDictionary(dictionary Dictionary) Host
CreateHostWithDictionary initialises host instance only with Dictionary; Ports should be set through *SetPort()*, otherwise default to 0
func InitialiseHost ¶
func InitialiseHost(authPort, acctPort, coaPort uint16, dictionary Dictionary) Host
Initialises host instance with all required fields
func (*Host) CreateAttributeByID ¶
func (host *Host) CreateAttributeByID(attributeID uint8, value *[]uint8) (RadiusAttribute, error)
CreateAttributeByID creates RadiusAttribute with given id (id is checked against Dictionary)
func (*Host) CreateAttributeByName ¶
func (host *Host) CreateAttributeByName(attributeName string, value *[]uint8) (RadiusAttribute, error)
CreateAttributeByName creates RadiusAttribute with given name (name is checked against Dictionary)
func (*Host) Dictionary ¶
func (host *Host) Dictionary() Dictionary
Dictionary returns host's dictionary instance
func (*Host) DictionaryAttributeByID ¶
func (host *Host) DictionaryAttributeByID(packetAttrID uint8) (DictionaryAttribute, bool)
DictionaryAttributeByID returns ATTRIBUTE from dictionary with given id
func (*Host) DictionaryAttributeByName ¶
func (host *Host) DictionaryAttributeByName(packetAttrName string) (DictionaryAttribute, bool)
DictionaryAttributeByName returns ATTRIBUTE from dictionary with given name
func (*Host) DictionaryValueByAttrAndValueName ¶
func (host *Host) DictionaryValueByAttrAndValueName(attrName, valueName string) (DictionaryValue, bool)
DictionaryValueByAttrAndValueName returns VALUE from dictionary with given attribute & value name
func (*Host) InitialiseRadiusPacketFromBytes ¶
func (host *Host) InitialiseRadiusPacketFromBytes(packet *[]uint8) (RadiusPacket, error)
InitialisePacketFromBytes initialises RadiusPacket from bytes
func (*Host) Port ¶
Port returns port of RADIUS server, that receives given type of RADIUS message/packet
func (*Host) SetPort ¶
func (host *Host) SetPort(port uint16, radMsgType RadiusMsgType) bool
SetPort sets remote port, that responsible for specific RADIUS Message Type
func (*Host) VerifyMessageAuthenticator ¶
VerifyMessageauthenticator verifies Message-Authenticator value
func (*Host) VerifyPacketAttributes ¶
VerifyPacketAttributes verifies that RadiusPacket attributes have valid values
Note: doesn't verify Message-Authenticator attribute, because it is HMAC-MD5 hash, not an ASCII string
type RadiusAttribute ¶
type RadiusAttribute struct {
// contains filtered or unexported fields
}
RadiusAttribute represents an attribute, which would be sent to RADIUS Server/client as a part of RadiusPacket
func CreateRadAttributeByID ¶
func CreateRadAttributeByID(dictionary *Dictionary, attributeID uint8, value *[]uint8) (RadiusAttribute, bool)
CreateRadAttributeByID creates RadiusAttribute with given id
Returns nil if ATTRIBUTE with such id is not found in Dictionary
func CreateRadAttributeByName ¶
func CreateRadAttributeByName(dictionary *Dictionary, attributeName string, value *[]uint8) (RadiusAttribute, bool)
CreateRadAttributeByName creates RadiusAttribute with given name
Returns nil if ATTRIBUTE with such name is not found in Dictionary
func (*RadiusAttribute) ID ¶
func (radAttr *RadiusAttribute) ID() uint8
ID returns RadiusAttribute id
func (*RadiusAttribute) Name ¶
func (radAttr *RadiusAttribute) Name() string
Name returns RadiusAttribute name
func (*RadiusAttribute) OriginalIntegerValue ¶
func (radAttr *RadiusAttribute) OriginalIntegerValue(allowedType SupportedAttributeTypes) (uint32, bool)
OriginalIntegerValue returns RadiusAttribute value, if the attribute is dictionary's ATTRIBUTE with code type integer or date
func (*RadiusAttribute) OriginalStringValue ¶
func (radAttr *RadiusAttribute) OriginalStringValue(allowedType SupportedAttributeTypes) (string, bool)
OriginalStringValue returns RadiusAttribute value, if the attribute is dictionary's ATTRIBUTE with code type string, ipaddr, ipv6addr or ipv6prefix
func (*RadiusAttribute) OverrideValue ¶
func (radAttr *RadiusAttribute) OverrideValue(newValue []uint8)
OverrideValue overriddes RadiusAttribute value
Mainly used when building Message-Authenticator
func (*RadiusAttribute) Value ¶
func (radAttr *RadiusAttribute) Value() []uint8
Value returns RadiusAttribute value
func (*RadiusAttribute) VerifyOriginalValue ¶
func (radAttr *RadiusAttribute) VerifyOriginalValue(allowedType SupportedAttributeTypes) bool
VerifyOriginalValue verifies RadiusAttribute value, based on the ATTRIBUTE code type
type RadiusMsgType ¶
type RadiusMsgType int
RadiusMsgType represents allowed types of RADIUS messages/packets
Mainly used in RADIUS Server implementation to distinguish between sockets and functions, that should process RADIUS packets
const ( // Authentication packet AUTH RadiusMsgType = iota // Accounting packet ACCT // Change of Authorisation packet COA )
type RadiusPacket ¶
type RadiusPacket struct {
// contains filtered or unexported fields
}
RadiusPacket represents RADIUS packet
func InitialiseRadiusPacket ¶
func InitialiseRadiusPacket(code TypeCode) RadiusPacket
InitialisePacket initialises RADIUS packet with random ID and authenticator
func InitialiseRadiusPacketFromBytes ¶
func InitialiseRadiusPacketFromBytes(dictionary *Dictionary, bytes *[]uint8) (RadiusPacket, error)
InitialisePacketFromBytes initialises RADIUS packet from raw bytes
func (*RadiusPacket) AttributeByID ¶
func (radPacket *RadiusPacket) AttributeByID(attrID uint8) RadiusAttribute
AttributeByID returns RadiusAttribute with given id
func (*RadiusPacket) AttributeByName ¶
func (radPacket *RadiusPacket) AttributeByName(attrName string) RadiusAttribute
AttributeByName returns RadiusAttribute with given name
func (*RadiusPacket) Attributes ¶
func (radPacket *RadiusPacket) Attributes() []RadiusAttribute
Attributes returns RadiusPacket attributes
func (*RadiusPacket) Authenticator ¶
func (radPacket *RadiusPacket) Authenticator() []uint8
Authenticator returns RadiusPacket authenticator
func (*RadiusPacket) Code ¶
func (radPacket *RadiusPacket) Code() TypeCode
Code returns RadiusPacket code
func (*RadiusPacket) GenerateMessageAuthenticator ¶
func (radPacket *RadiusPacket) GenerateMessageAuthenticator(secret string) error
Generates HMAC-MD5 hash for Message-Authenticator attribute
Note 1: this function assumes that RadiusAttribute Message-Authenticator already exists in RadiusPacket Note 2: Message-Authenticator in RadiusPacket would be overwritten when this function is called
func (*RadiusPacket) MessageAuthenticator ¶
func (radPacket *RadiusPacket) MessageAuthenticator() ([]uint8, error)
MessageAuthenticator returns Message-Authenticator value, if exists in RadiusPacket otherwise returns an error
func (*RadiusPacket) OverrideAuthenticator ¶
func (radPacket *RadiusPacket) OverrideAuthenticator(authenticator []uint8)
Overrides RadiusPacket authenticator
func (*RadiusPacket) OverrideID ¶
func (radPacket *RadiusPacket) OverrideID(id uint8)
Overrides RadiusPacket id
func (*RadiusPacket) OverrideMessageAuthenticator ¶
func (radPacket *RadiusPacket) OverrideMessageAuthenticator(newMessageAuth []uint8) error
Overrides RadiusPacket Message-Authenticator
Note: would fail if RadiusPacket has no Message-Authenticator attribute defined
func (*RadiusPacket) SetAttributes ¶
func (radPacket *RadiusPacket) SetAttributes(attr []RadiusAttribute)
SetAttributes sets attrbiutes for RadiusPacket
func (*RadiusPacket) ToBytes ¶
func (radPacket *RadiusPacket) ToBytes() ([]uint8, bool)
ToBytes converts RadiusPacket into ready-to-be-sent bytes slice
type SupportedAttributeTypes ¶
type SupportedAttributeTypes int
Represents a list of supported data types as defined in RFC 2865 & RFC 8044
const ( // Go's String; RFC 8044 calls this "text" - UTF-8 text AsciiString SupportedAttributeTypes = iota // Go's [u8]; RFC 8044 calls this "string" (FreeRADIUS calls this "octets") - binary data as a sequence of undistinguished octets ByteString // Go's u32 Integer // Go's u64 Integer64 // Go's u32; RFC 8044 calls this "time" Date // Go's \[u8;4\] IPv4Addr // Go's \[u8;5\] IPv4Prefix // Go's \[u8;16\] IPv6Addr // Go's \[u8;18\] IPv6Prefix // Go's \[u8;6\]; RFC 8044 calls this "ifid" InterfaceId )
type TypeCode ¶
type TypeCode int
TypeCode represents all supported Codes of RADIUS message/packet as defined in RFC 2865 & RFC 3576
const ( // AccessRequest = 1 AccessRequest TypeCode = iota // AccessAccept = 2 AccessAccept // AccessReject = 3 AccessReject // AccountingRequest = 4 AccountingRequest // AccountingResponse = 5 AccountingResponse // AccessChallenge = 11 AccessChallenge // StatusServer = 12 StatusServer // StatusClient = 13 StatusClient // DisconnectRequest = 40 DisconnectRequest // DisconnectACK = 41 DisconnectACK // DisconnectNAK = 42 DisconnectNAK // CoARequest = 43 CoARequest // CoAACK = 44 CoAACK // CoANAK = 45 CoANAK )