这是indexloc提供的服务,不要输入任何密码
Skip to content
19 changes: 5 additions & 14 deletions browser/edge/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ package edge

import (
"net/http"
"os"

"github.com/zellyn/kooky"
"github.com/zellyn/kooky/internal/chrome"
"github.com/zellyn/kooky/internal/cookies"
"github.com/zellyn/kooky/internal/ie"
)

func ReadCookies(filename string, filters ...kooky.Filter) ([]*kooky.Cookie, error) {
Expand All @@ -27,7 +25,6 @@ func ReadCookies(filename string, filters ...kooky.Filter) ([]*kooky.Cookie, err
// CookieJar returns an initiated http.CookieJar based on the cookies stored by
// the Edge browser. Set cookies are memory stored and do not modify any
// browser files.
//
func CookieJar(filename string, filters ...kooky.Filter) (http.CookieJar, error) {
j, err := cookieStore(filename, filters...)
if err != nil {
Expand All @@ -41,20 +38,14 @@ func CookieJar(filename string, filters ...kooky.Filter) (http.CookieJar, error)
}

// CookieStore has to be closed with CookieStore.Close() after use.
//
func CookieStore(filename string, filters ...kooky.Filter) (kooky.CookieStore, error) {
return cookieStore(filename, filters...)
}

func cookieStore(filename string, filters ...kooky.Filter) (*cookies.CookieJar, error) {
m := map[string]func(f *os.File, s *ie.CookieStore, browser string){
`sqlite`: func(f *os.File, s *ie.CookieStore, browser string) {
f.Close()
c := &chrome.CookieStore{}
c.FileNameStr = filename
c.BrowserStr = `edge`
s.CookieStore = c
},
}
return ie.GetCookieStore(filename, `edge`, m, filters...)
s := &chrome.CookieStore{}
s.FileNameStr = filename
s.BrowserStr = `edge`

return &cookies.CookieJar{CookieStore: s}, nil
}
50 changes: 14 additions & 36 deletions browser/edge/find.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
//go:build windows

package edge

import (
"errors"
"os"
"path/filepath"

"github.com/zellyn/kooky"
"github.com/zellyn/kooky/internal/chrome"
"github.com/zellyn/kooky/internal/chrome/find"
"github.com/zellyn/kooky/internal/cookies"
"github.com/zellyn/kooky/internal/ie"
_ "github.com/zellyn/kooky/internal/ie/find"
)

// TODO !windows platforms

type edgeFinder struct{}

var _ kooky.CookieStoreFinder = (*edgeFinder)(nil)
Expand All @@ -26,41 +16,29 @@ func init() {
}

func (f *edgeFinder) FindCookieStores() ([]kooky.CookieStore, error) {
locApp := os.Getenv(`LocalAppData`)
if len(locApp) == 0 {
return nil, errors.New(`%LocalAppData% is empty`)
}

var cookiesFiles []kooky.CookieStore

// Blink based
newRoot := func() ([]string, error) {
return []string{filepath.Join(locApp, `Microsoft`, `Edge`, `User Data`)}, nil
}
blinkCookiesFiles, err := find.FindCookieStoreFiles(newRoot, `edge`)
files, err := find.FindEdgeChookieStoreFiles()
if err != nil {
return nil, err
}
for _, cookiesFile := range blinkCookiesFiles {
cookiesFiles = append(
cookiesFiles,

var ret []kooky.CookieStore
for _, file := range files {
ret = append(
ret,
&cookies.CookieJar{
CookieStore: &ie.CookieStore{
CookieStore: &chrome.CookieStore{
DefaultCookieStore: cookies.DefaultCookieStore{
BrowserStr: cookiesFile.Browser,
ProfileStr: cookiesFile.Profile,
OSStr: cookiesFile.OS,
IsDefaultProfileBool: cookiesFile.IsDefaultProfile,
FileNameStr: cookiesFile.Path,
},
CookieStore: &chrome.CookieStore{
DefaultCookieStore: cookies.DefaultCookieStore{
BrowserStr: file.Browser,
ProfileStr: file.Profile,
OSStr: file.OS,
IsDefaultProfileBool: file.IsDefaultProfile,
FileNameStr: file.Path,
},
},
},
)
}

return cookiesFiles, nil
return ret, nil
}

/*
Expand Down
17 changes: 15 additions & 2 deletions internal/chrome/chrome_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,21 @@ func (s *CookieStore) getKeyringPassword(useSaved bool) ([]byte, error) {
}
}

// TODO: use s.browser
out, err := exec.Command(`/usr/bin/security`, `find-generic-password`, `-s`, `Chrome Safe Storage`, `-wa`, `Chrome`).Output()
var service, account string
switch s.BrowserStr {
case `chrome`:
service = `Chrome Safe Storage`
account = `Chrome`
case `chromium`:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried it, but I understand that they are all based on chromium and their principles should be the same.

service = `Chromium Safe Storage`
account = `Chromium`
case `edge`:
service = `Microsoft Edge Safe Storage`
account = `Microsoft Edge`
default:
return nil, fmt.Errorf(`unknown browser: %s`, s.BrowserStr)
}
out, err := exec.Command(`/usr/bin/security`, `find-generic-password`, `-s`, service,`-a`, account, `-w`, `Chrome`).Output()
if err != nil {
return nil, err
}
Expand Down
21 changes: 17 additions & 4 deletions internal/chrome/chrome_darwin_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"errors"
"fmt"

keychain "github.com/keybase/go-keychain"
"github.com/keybase/go-keychain"
)

// getKeyringPassword retrieves the Chrome Safe Storage password,
Expand All @@ -26,10 +26,23 @@ func (s *CookieStore) getKeyringPassword(useSaved bool) ([]byte, error) {
return kpw, nil
}
}

password, err := keychain.GetGenericPassword("Chrome Safe Storage", "Chrome", "", "")
var service, account string
switch s.BrowserStr {
case `chrome`:
service = `Chrome Safe Storage`
account = `Chrome`
case `chromium`:
service = `Chromium Safe Storage`
account = `Chromium`
case `edge`:
service = `Microsoft Edge Safe Storage`
account = `Microsoft Edge`
default:
return nil, fmt.Errorf(`unknown browser: %s`, s.BrowserStr)
}
password, err := keychain.GetGenericPassword(service, account, "", "")
if err != nil {
return nil, fmt.Errorf("error reading 'Chrome Safe Storage' keychain password: %w", err)
return nil, fmt.Errorf("error reading '%s' keychain password: %w", service, err)
}
s.KeyringPasswordBytes = password
keyringPasswordMap.set(kpmKey, password)
Expand Down
7 changes: 5 additions & 2 deletions internal/chrome/find/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ type chromeCookieStoreFile struct {
IsDefaultProfile bool
}

// chromeRoots and chromiumRoots could be put into the github.com/kooky/browser/{chrome,chromium} packages.
// It might be better though to keep those 2 together here as they are based on the same source.
// chromeRoots, chromiumRoots and edgeRoots could be put into the github.com/kooky/browser/{chrome,chromium,edge} packages.
// It might be better though to keep those 3 together here as they are based on the same source.
func FindChromeCookieStoreFiles() ([]*chromeCookieStoreFile, error) {
return FindCookieStoreFiles(chromeRoots, `chrome`)
}
func FindChromiumCookieStoreFiles() ([]*chromeCookieStoreFile, error) {
return FindCookieStoreFiles(chromiumRoots, `chromium`)
}
func FindEdgeChookieStoreFiles() ([]*chromeCookieStoreFile, error) {
return FindCookieStoreFiles(edgeRoots, `edge`)
}

func FindCookieStoreFiles(rootsFunc func() ([]string, error), browserName string) ([]*chromeCookieStoreFile, error) {
if rootsFunc == nil {
Expand Down
11 changes: 5 additions & 6 deletions internal/chrome/find/find_android.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

package find

import (
"os"
"path/filepath"
)

func chromeRoots() ([]string, error) {
// https://chromium.googlesource.com/chromium/src.git/+/62.0.3202.58/docs/user_data_dir.md#android
var ret = []string{
`/data/user/0/com.android.chrome/app_chrome` // TODO check
`/data/user/0/com.android.chrome/app_chrome`, // TODO check
}
return ret, nil
}

func chromiumRoots() ([]string, error) {
return ret, errors.New(`not implemented`)
}

func edgeRoots() ([]string, error) {
return nil, errors.New(`not implemented`)
}
9 changes: 9 additions & 0 deletions internal/chrome/find/find_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ func chromiumRoots() ([]string, error) {
}
return ret, nil
}

func edgeRoots() ([]string, error) {
// "$HOME/Library/Application Support"
cfgDir, err := os.UserConfigDir()
if err != nil {
return nil, err
}
return []string{filepath.Join(cfgDir, `Microsoft Edge`)}, nil
}
4 changes: 4 additions & 0 deletions internal/chrome/find/find_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ func chromeRoots() ([]string, error) {
func chromiumRoots() ([]string, error) {
return nil, errNotImplemented
}

func edgeRoots() ([]string, error) {
return nil, errNotImplemented
}
4 changes: 4 additions & 0 deletions internal/chrome/find/find_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ func chromiumRoots() ([]string, error) {
}
return ret, nil
}

func edgeRoots() ([]string, error) {
return nil, errors.New(`not implemented`)
}
14 changes: 14 additions & 0 deletions internal/chrome/find/find_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,17 @@ func chromiumRoots() ([]string, error) {
}
return []string{filepath.Join(cfgDir, `Chromium`, `User Data`)}, nil
}

func edgeRoots() ([]string, error) {
// AppData Local
locApp := os.Getenv(`LocalAppData`)
if len(locApp) == 0 {
return nil, errors.New(`%LocalAppData% is empty`)
}

var ret = []string{
filepath.Join(locApp, `Microsoft`, `Edge`, `User Data`),
}

return ret, nil
}