slightly better decoding
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
23
internal/outpost/radius/eap/protocol/eap/decode.go
Normal file
23
internal/outpost/radius/eap/protocol/eap/decode.go
Normal file
@ -0,0 +1,23 @@
|
||||
package eap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"goauthentik.io/internal/outpost/radius/eap/protocol"
|
||||
)
|
||||
|
||||
func EmptyPayload(settings protocol.Settings, t protocol.Type) (protocol.Payload, protocol.Type, error) {
|
||||
for _, cons := range settings.Protocols {
|
||||
np := cons()
|
||||
if np.Type() == t {
|
||||
return np, np.Type(), nil
|
||||
}
|
||||
// If the protocol has an inner protocol, return the original type but the code for the inner protocol
|
||||
if i, ok := np.(protocol.Inner); ok {
|
||||
if ii := i.HasInner(); ii != nil {
|
||||
return np, ii.Type(), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, protocol.Type(0), fmt.Errorf("unsupported EAP type %d", t)
|
||||
}
|
||||
@ -22,6 +22,8 @@ type Payload struct {
|
||||
MsgType protocol.Type
|
||||
Payload protocol.Payload
|
||||
RawPayload []byte
|
||||
|
||||
Settings protocol.Settings
|
||||
}
|
||||
|
||||
func (p *Payload) Type() protocol.Type {
|
||||
@ -44,10 +46,12 @@ func (p *Payload) Decode(raw []byte) error {
|
||||
}
|
||||
log.WithField("raw", debug.FormatBytes(raw)).WithField("payload", fmt.Sprintf("%T", p.Payload)).Trace("EAP: decode raw")
|
||||
p.RawPayload = raw[5:]
|
||||
if p.Payload == nil {
|
||||
return nil
|
||||
pp, _, err := EmptyPayload(p.Settings, p.MsgType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err := p.Payload.Decode(raw[5:])
|
||||
p.Payload = pp
|
||||
err = p.Payload.Decode(raw[5:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
package protocol
|
||||
|
||||
import "layeh.com/radius"
|
||||
|
||||
type EmptyPayload struct {
|
||||
ModifyPacket func(p *radius.Packet) *radius.Packet
|
||||
}
|
||||
|
||||
func (ep EmptyPayload) Decode(raw []byte) error {
|
||||
return nil
|
||||
}
|
||||
func (ep EmptyPayload) Encode() ([]byte, error) {
|
||||
return []byte{}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user