Class CookieFile

java.lang.Object
lol.trq.alts.auth.CookieFile

public final class CookieFile extends Object
Reads exported browser cookies off disk into the text CookieAuthUtil parses.

Cookie exports arrive as files far more often than as pasted text — every browser extension that produces them writes a cookies.txt, and the Netscape format they use is line-oriented, so a paste through a single-line input mangles it. The parsing itself already lives in this package and is format-tolerant; only getting the bytes to it was missing.

Decoding is byte-order-mark aware. A file redirected out of PowerShell is UTF-16LE, which decoded as UTF-8 yields text interleaved with NUL bytes — the parser then finds no cookie it recognises and the failure reads as "my cookies are bad" rather than "my file is in another encoding".

Since:
0.7.0
  • Field Details

    • MAX_BYTES

      public static final long MAX_BYTES
      Largest cookie export accepted. Netscape exports of a full browser profile run to tens of kilobytes; a megabyte is far past any real one and keeps a mistakenly picked archive or disk image from being read into memory.
      Since:
      0.7.0
      See Also:
    • EXTENSIONS

      public static final List<String> EXTENSIONS
      The extensions cookie exports normally carry, without a leading dot, for a host building a file picker's filter. Advisory only — read(Path) accepts any path, because a user who renamed their export is not wrong. Ordered most to least common.
      Since:
      0.7.0
  • Method Details

    • read

      public static String read(Path file)
      Reads file as cookie text.

      Every failure is reported against the file's name only. The JDK's own I/O messages are the absolute path, and this message travels into a LoginResult a host shows in its UI and writes to its log, so an access-denied on a file under a home directory would otherwise publish that directory.

      Parameters:
      file - the file to read
      Returns:
      the file's text content, byte-order mark stripped
      Throws:
      AltsException - of kind AltsFailure.Kind.INVALID_INPUT if the file is missing, is not a regular file, is larger than MAX_BYTES, holds no text, or cannot be read; the message names the file, never its path, and no exception carrying the path rides along
      Since:
      0.7.0