Files
openfsd/handler/auth_challenge.go
Reese Norris 57d54d6705 v0.1.0-alpha
Changes:
- Implement bootstrapping library for managing several concurrent internal services
- Refactor concurrency model for connections/logical clients and their associated I/O
- Refactor server context singleton
- Refactor error handling
    - Most errors are now gracefully sent to the FSD client directly encoded as an $ER packet,
      enhancing visibility and debugging
    - Most errors are now rightfully treated as non-fatal
- Refactor package/dependency graph
- Refactor calling conventions/interfaces for many packages
- Refactor database package
- Refactor post office

Features:
- Add VATSIM-esque HTTP/JSON "data feed"
- Add ephemeral in-memory database option
- Add user management REST API
- Add improved web interface
- Add MySQL support (drop SQLite support)
2024-10-07 12:50:39 -07:00

50 lines
1.3 KiB
Go

package handler
import (
"github.com/renorris/openfsd/protocol"
"github.com/renorris/openfsd/protocol/vatsimauth"
)
func authChallengeHandler(invoker Invoker, packet string) (result Result, err error) {
// Parse packet
pdu := protocol.AuthChallengePDU{}
if err = pdu.Parse(packet); err != nil {
return
}
// Verify source callsign
if pdu.From != invoker.Callsign() {
return pduSourceInvalidResult()
}
// Generate response
challengeResponse := invoker.AuthSelf().GenerateResponse(pdu.Challenge)
invoker.AuthSelf().UpdateState(challengeResponse)
challengeResponsePDU := protocol.AuthChallengeResponsePDU{
From: protocol.ServerCallsign,
To: invoker.Callsign(),
ChallengeResponse: challengeResponse,
}
// Send a counter-challenge
var chal string
if chal, err = vatsimauth.GenerateChallenge(); err != nil {
err = protocol.NewGenericFSDError(protocol.SyntaxError, "", "internal server error: error generating counter-challenge string")
return
}
invoker.SetPendingChallenge(chal)
newChallengePDU := protocol.AuthChallengePDU{
From: protocol.ServerCallsign,
To: invoker.Callsign(),
Challenge: invoker.PendingChallenge(),
}
result.addReply(challengeResponsePDU.Serialize())
result.addReply(newChallengePDU.Serialize())
return
}