Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens Langhammer
2025-05-21 09:41:53 +02:00
parent 82c177b7eb
commit ee234ea3aa
9 changed files with 34 additions and 55 deletions

View File

@ -16,16 +16,14 @@ const (
type Context interface {
Packet() *radius.Request
RootPayload() Payload
ProtocolSettings() interface{}
ForInnerProtocol(p Type) Context
GetProtocolState(p Type) interface{}
SetProtocolState(p Type, s interface{})
IsProtocolStart(p Type) bool
StateForProtocol(p Type) interface{}
GetProtocolState() interface{}
SetProtocolState(interface{})
IsProtocolStart() bool
EndInnerProtocol(Status, func(p *radius.Packet) *radius.Packet)
Log() *log.Entry

View File

@ -76,8 +76,5 @@ func (p *Payload) Encode() ([]byte, error) {
func (ip *Payload) Handle(ctx protocol.Context) protocol.Payload {
ctx.Log().Debug("EAP: Handle")
ctx.SetProtocolState(&State{
PacketID: ip.ID,
})
return nil
}

View File

@ -26,7 +26,7 @@ func (ip *Payload) Encode() ([]byte, error) {
}
func (ip *Payload) Handle(ctx protocol.Context) protocol.Payload {
if ctx.IsProtocolStart() {
if ctx.IsProtocolStart(TypeIdentity) {
ctx.EndInnerProtocol(protocol.StatusNextProtocol, nil)
}
return nil

View File

@ -26,7 +26,7 @@ func (ln *Payload) Encode() ([]byte, error) {
}
func (ln *Payload) Handle(ctx protocol.Context) protocol.Payload {
if ctx.IsProtocolStart() {
if ctx.IsProtocolStart(TypeLegacyNAK) {
ctx.EndInnerProtocol(protocol.StatusError, nil)
}
return nil

View File

@ -47,22 +47,22 @@ func (p *Payload) Encode() ([]byte, error) {
func (p *Payload) Handle(ctx protocol.Context) protocol.Payload {
defer func() {
ctx.SetProtocolState(p.st)
ctx.SetProtocolState(TypePEAP, p.st)
}()
eapState := ctx.StateForProtocol(eap.TypeEAP).(*eap.State)
rootEap := ctx.RootPayload().(*eap.Payload)
if ctx.IsProtocolStart() {
if ctx.IsProtocolStart(TypePEAP) {
ctx.Log().Debug("PEAP: Protocol start")
p.st = &State{}
return &eap.Payload{
Code: protocol.CodeRequest,
ID: eapState.PacketID + 1,
ID: rootEap.ID + 1,
MsgType: identity.TypeIdentity,
Payload: &identity.Payload{},
}
}
p.st = ctx.GetProtocolState().(*State)
p.st = ctx.GetProtocolState(TypePEAP).(*State)
ep := &eap.Payload{}
err := ep.Decode(p.raw)

View File

@ -13,7 +13,7 @@ func (p *Payload) innerHandler(ctx protocol.Context) {
ctx.EndInnerProtocol(protocol.StatusError, nil)
return
}
pl := p.Inner.Handle(ctx.ForInnerProtocol(p.Inner.Type()))
pl := p.Inner.Handle(ctx)
enc, err := pl.Encode()
if err != nil {
ctx.Log().WithError(err).Warning("failed to encode inner protocol")

View File

@ -87,15 +87,15 @@ func (p *Payload) Encode() ([]byte, error) {
func (p *Payload) Handle(ctx protocol.Context) protocol.Payload {
defer func() {
ctx.SetProtocolState(p.st)
ctx.SetProtocolState(TypeTLS, p.st)
}()
if ctx.IsProtocolStart() {
if ctx.IsProtocolStart(TypeTLS) {
p.st = NewState(ctx).(*State)
return &Payload{
Flags: FlagTLSStart,
}
}
p.st = ctx.GetProtocolState().(*State)
p.st = ctx.GetProtocolState(TypeTLS).(*State)
if p.st.TLS == nil {
p.tlsInit(ctx)