Skip to content

Commit

Permalink
Split out deauth event and failed event
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed Nov 29, 2024
1 parent f9761e9 commit 22f32b6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
12 changes: 10 additions & 2 deletions internal/mfaportal/resources/static/js/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const url = (httpsEnabled ? 'wss://' : 'ws://') + window.location.host + "/chall

let backoff = 200;
let attempts = 0;
let failed = false;
let challenge = getCookie("challenge");
if (challenge === null || challenge === "null" || challenge == "") {
challenge = null
Expand Down Expand Up @@ -37,15 +38,22 @@ function connect() {
JSON.stringify({challenge: challenge
}));
return
case "reset":
case "deauthed":
window.location.href = "/"
return
case "failed_challenge":
failed = true;
deleteCookie("challenge")
window.location.href = '/'
return
}

};

ws.onclose = function (e) {
if(failed) {
return
}

console.log(`Socket is closed. Reconnect will be attempted in ${backoff} ms.`, e.reason);
if(backoff < 1000) {
backoff += backoff*2
Expand Down
2 changes: 1 addition & 1 deletion internal/router/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (f *Firewall) Deauthenticate(address string) error {

err = f._deauthenticate(addr)

f.Verifier.Reset(address)
f.Verifier.NotifyDeauth(address)

return err
}
Expand Down
20 changes: 17 additions & 3 deletions internal/router/session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (c *Challenger) Challenge(address string) error {
return nil
}

func (c *Challenger) Reset(address string) {
func (c *Challenger) FailChallenge(address string) {
c.Lock()
defer c.Unlock()

Expand All @@ -138,7 +138,21 @@ func (c *Challenger) Reset(address string) {
return
}

conn.WriteJSON("reset")
conn.WriteJSON("failed_challenge")
conn.Close()
delete(c.connections, address)
}

func (c *Challenger) NotifyDeauth(address string) {
c.Lock()
defer c.Unlock()

conn, ok := c.connections[address]
if !ok {
return
}

conn.WriteJSON("deauthed")
conn.Close()
delete(c.connections, address)
}
Expand Down Expand Up @@ -182,7 +196,7 @@ func (c *Challenger) WS(w http.ResponseWriter, r *http.Request) {

err = c.Challenge(remoteAddress.String())
if err != nil {
c.Reset(remoteAddress.String())
c.FailChallenge(remoteAddress.String())
log.Printf("%s:%s client did not complete inital ws challenge: %s", user.Username, remoteAddress, err)
return
}
Expand Down

0 comments on commit 22f32b6

Please sign in to comment.