cookies

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package cookies provides Chrome cookie decryption and Netscape jar I/O.

Supports Chrome v10 (hardcoded "peanuts" key) and v11 (KWallet / user-supplied password) AES-128-CBC encryption on Linux.

Key derivation (both versions):

key = PBKDF2-HMAC-SHA1(password, "saltysalt", 1 iteration, 16 bytes)
IV  = 16 × 0x20 (space character)

v11 ciphertext starts with the 3-byte prefix "v11"; after decryption the first 32 bytes of plaintext are a per-scope header that must be stripped. v10 ciphertext starts with "v10"; no header strip required. Anything else is returned as plain UTF-8 text.

Index

Constants

This section is empty.

Variables

View Source
var GoogleDomains = []string{
	".google.com",
	".google.it",
	"accounts.google.com",
	"photos.google.com",
	"photos.fife.usercontent.google.com",
}

GoogleDomains is the default set of domains extracted for Google Photos auth.

Functions

func BuildHTTPJar

func BuildHTTPJar(rows []CookieRow) (http.CookieJar, error)

BuildHTTPJar converts CookieRows into a stdlib http.CookieJar.

func ChromeDefaultDBPath

func ChromeDefaultDBPath() string

ChromeDefaultDBPath returns the default Chrome cookies SQLite path on Linux.

func DefaultChromeDBPath

func DefaultChromeDBPath() (string, error)

DefaultChromeDBPath returns the default Chrome cookies database path for the current platform. Returns an error if the path does not exist.

func ExtractToJar

func ExtractToJar(chromeDBPath, v11Password, jarPath string) (int, error)

ExtractToJar extracts Google-domain cookies from Chrome's SQLite DB, decrypts them with the given v11 password, and writes a Netscape cookie jar to jarPath. Returns the number of cookies extracted.

func LoadNetscapeCookieJar

func LoadNetscapeCookieJar(path string) (http.CookieJar, error)

LoadNetscapeCookieJar reads a Netscape jar file and returns an http.CookieJar ready for use with http.Client.

func WriteNetscapeJar

func WriteNetscapeJar(path string, rows []CookieRow) error

WriteNetscapeJar writes a Netscape cookie jar file from CookieRows.

Types

type ChromeDecryptor

type ChromeDecryptor struct {
	// contains filtered or unexported fields
}

ChromeDecryptor can decrypt Chrome cookies using the v10/v11 scheme on Linux/macOS, and the v20 AES-256-GCM scheme on Windows (Chrome ≥ 127).

func NewChromeDecryptor

func NewChromeDecryptor(password string) *ChromeDecryptor

NewChromeDecryptor creates a decryptor for v10/v11 (PBKDF2-based) cookies. password is the v11 key material (e.g. from KWallet / macOS Keychain). Pass "" to use an empty password for v11 (Chrome default on many Linux setups).

func NewChromeDecryptorFromKey

func NewChromeDecryptorFromKey(aesKey []byte) *ChromeDecryptor

NewChromeDecryptorFromKey creates a decryptor with a raw AES key (Windows v20). The keyV10/keyV11 fields are populated with the peanuts / empty-password defaults as a fallback for any v10/v11 cookies that may still be present.

func (*ChromeDecryptor) Decrypt

func (d *ChromeDecryptor) Decrypt(enc []byte) (string, error)

Decrypt decrypts an encrypted_value blob from Chrome's cookies table. Handles v10, v11 (PBKDF2 AES-128-CBC) and v20 (App-Bound AES-256-GCM, Windows only).

type CookieRow

type CookieRow struct {
	Host      string
	Name      string
	Value     string // plaintext after decryption
	Path      string
	ExpiresAt time.Time
	Secure    bool
	HTTPOnly  bool
}

CookieRow holds one row from the Chrome cookies SQLite table.

func ReadChromeCookies

func ReadChromeCookies(dbPath string, domains []string, dec *ChromeDecryptor) ([]CookieRow, error)

ReadChromeCookies opens the Chrome SQLite cookies DB, decrypts the values for the specified domains, and returns the rows.

type NetscapeLine

type NetscapeLine struct {
	Domain   string
	Flag     bool // TRUE if domain-wide
	Path     string
	Secure   bool
	Expires  int64 // Unix timestamp, 0 = session
	Name     string
	Value    string
	HTTPOnly bool
}

NetscapeLine holds one parsed line from a Netscape cookie jar.

func ParseNetscapeJar

func ParseNetscapeJar(path string) ([]NetscapeLine, error)

ParseNetscapeJar reads a Netscape cookie file and returns parsed lines. Lines beginning with '#' (or #HttpOnly_) are handled correctly.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL