diff --git a/browser/edge/edge.go b/browser/edge/edge.go index ca5a40b..d099f84 100644 --- a/browser/edge/edge.go +++ b/browser/edge/edge.go @@ -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) { @@ -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 { @@ -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 } diff --git a/browser/edge/find.go b/browser/edge/find.go index 34c038e..3ffb908 100644 --- a/browser/edge/find.go +++ b/browser/edge/find.go @@ -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) @@ -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 } /* diff --git a/internal/chrome/chrome_darwin.go b/internal/chrome/chrome_darwin.go index 70d2445..21f91bb 100644 --- a/internal/chrome/chrome_darwin.go +++ b/internal/chrome/chrome_darwin.go @@ -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`: + 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 } diff --git a/internal/chrome/chrome_darwin_cgo.go b/internal/chrome/chrome_darwin_cgo.go index 7bc66bc..5817dbe 100644 --- a/internal/chrome/chrome_darwin_cgo.go +++ b/internal/chrome/chrome_darwin_cgo.go @@ -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, @@ -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) diff --git a/internal/chrome/find/find.go b/internal/chrome/find/find.go index 0ea130a..a623bca 100644 --- a/internal/chrome/find/find.go +++ b/internal/chrome/find/find.go @@ -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 { diff --git a/internal/chrome/find/find_android.go b/internal/chrome/find/find_android.go index dbae725..08d835c 100644 --- a/internal/chrome/find/find_android.go +++ b/internal/chrome/find/find_android.go @@ -2,15 +2,10 @@ 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 } @@ -18,3 +13,7 @@ func chromeRoots() ([]string, error) { func chromiumRoots() ([]string, error) { return ret, errors.New(`not implemented`) } + +func edgeRoots() ([]string, error) { + return nil, errors.New(`not implemented`) +} diff --git a/internal/chrome/find/find_darwin.go b/internal/chrome/find/find_darwin.go index c0ecb46..04cd851 100644 --- a/internal/chrome/find/find_darwin.go +++ b/internal/chrome/find/find_darwin.go @@ -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 +} diff --git a/internal/chrome/find/find_others.go b/internal/chrome/find/find_others.go index e2d731b..ba9febd 100644 --- a/internal/chrome/find/find_others.go +++ b/internal/chrome/find/find_others.go @@ -13,3 +13,7 @@ func chromeRoots() ([]string, error) { func chromiumRoots() ([]string, error) { return nil, errNotImplemented } + +func edgeRoots() ([]string, error) { + return nil, errNotImplemented +} diff --git a/internal/chrome/find/find_unix.go b/internal/chrome/find/find_unix.go index 842d671..1a31f70 100644 --- a/internal/chrome/find/find_unix.go +++ b/internal/chrome/find/find_unix.go @@ -56,3 +56,7 @@ func chromiumRoots() ([]string, error) { } return ret, nil } + +func edgeRoots() ([]string, error) { + return nil, errors.New(`not implemented`) +} diff --git a/internal/chrome/find/find_windows.go b/internal/chrome/find/find_windows.go index 4d4049d..18e6090 100644 --- a/internal/chrome/find/find_windows.go +++ b/internal/chrome/find/find_windows.go @@ -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 +}