Package com.mcawful

Class PanelPasskeyHandler

java.lang.Object
com.mcawful.PanelPasskeyHandler

public final class PanelPasskeyHandler extends Object
Passkey registration, management and sign-in for panel users.

Registration and management run over the authenticated panel websocket, so a user can only ever touch their own passkeys. The exception is a setup link, made by someone who can manage panel users or in the console, which adds a passkey over HTTP. Sign-in runs over HTTP so the bot can set the session cookie of PanelSessionManager.

Author:
mcawful
  • Method Details

    • handleWs

      public static void handleWs(ChannelHandlerContext ctx, PanelUser user, JSONObject request, JSONStringer response)
      Handles a passkey query on the panel websocket
      Parameters:
      ctx - the ChannelHandlerContext of the websocket
      user - the authenticated PanelUser
      request - the passkey object of the query, which must have an action
      response - the JSONStringer to write the single result value to
    • handleHttp

      public static void handleHttp(ChannelHandlerContext ctx, FullHttpRequest req)
      Handles a request to /panel/login/passkey/, which the login page uses to sign in with a passkey or add one with a setup link. These requests are not authenticated
      Parameters:
      ctx - the ChannelHandlerContext of the request
      req - the FullHttpRequest
    • deletePasskeys

      public static void deletePasskeys(String username)
      Removes all passkeys and setup links of a panel user and ends their sessions. Must be called when the user is deleted, so a later user with the same name does not inherit them, and when their password is reset, so nobody who had access keeps it
      Parameters:
      username - the user's name
    • renamePasskeys

      public static void renamePasskeys(String username, String newUsername)
      Moves all passkeys of a panel user to a new username and ends their sessions. Must be called when the user is renamed. Passkeys and setup links that were left under the new name are removed first, so the user does not inherit them, and the user's setup links stop working
      Parameters:
      username - the user's current name
      newUsername - the user's new name
    • createSetupLink

      public static String createSetupLink(String username)
      Creates a one-time link that lets a panel user add a passkey without signing in, replacing any earlier link of the user. The link works for SETUP_LINK_LIFETIME_MILLIS
      Parameters:
      username - the user's name
      Returns:
      the token of the link, which goes after /panel/login/#setup=
      Throws:
      IllegalArgumentException - if the user does not exist or can not use passkeys
    • printSetupLink

      public static void printSetupLink(String token)
      Prints a setup link in the console. The console does not know the address the panel is opened on, so the link uses localhost and the bot's port
      Parameters:
      token - the token of the link
    • printStartupSetupLink

      public static void printStartupSetupLink(boolean newPassword)
      Prints a setup link for the main login from botlogin.txt while it has no passkey: at startup while panelpasswordless is on, since it has no other way to sign in to the panel, and next to a panel password the bot has just created, as the other way to sign in
      Parameters:
      newPassword - true if the bot has just created the panel password
    • isMainLoginSession

      public static boolean isMainLoginSession(HttpHeaders headers)
      Checks if a request carries a passkey session of the main login from botlogin.txt, which the Bot Setup and OAuth pages accept like its password
      Parameters:
      headers - the request headers
      Returns:
      true if the session is valid and belongs to the main login