1package repository
2
3import (
4 "os"
5 "path"
6
7 "github.com/99designs/keyring"
8)
9
10type Item = keyring.Item
11
12var ErrKeyringKeyNotFound = keyring.ErrKeyNotFound
13
14// Keyring provides the uniform interface over the underlying backends
15type Keyring interface {
16 // Returns an Item matching the key or ErrKeyringKeyNotFound
17 Get(key string) (Item, error)
18 // Stores an Item on the keyring
19 Set(item Item) error
20 // Removes the item with matching key
21 Remove(key string) error
22 // Provides a slice of all keys stored on the keyring
23 Keys() ([]string, error)
24}
25
26func defaultKeyring() (Keyring, error) {
27 ucd, err := os.UserConfigDir()
28 if err != nil {
29 return nil, err
30 }
31
32 backends := []keyring.BackendType{
33 keyring.WinCredBackend,
34 keyring.KeychainBackend,
35 keyring.PassBackend,
36 keyring.FileBackend,
37 }
38
39 return keyring.Open(keyring.Config{
40 // TODO: ideally this would not be there, it disable the freedesktop backend on linux
41 // due to https://github.com/99designs/keyring/issues/44
42 AllowedBackends: backends,
43
44 ServiceName: "git-bug",
45
46 // MacOS keychain
47 KeychainName: "git-bug",
48 KeychainTrustApplication: true,
49
50 // KDE Wallet
51 KWalletAppID: "git-bug",
52 KWalletFolder: "git-bug",
53
54 // Windows
55 WinCredPrefix: "git-bug",
56
57 // freedesktop.org's Secret Service
58 LibSecretCollectionName: "git-bug",
59
60 // Pass (https://www.passwordstore.org/)
61 PassPrefix: "git-bug",
62
63 // Fallback encrypted file
64 FileDir: path.Join(ucd, "git-bug", "keyring"),
65 // As we write the file in the user's config directory, this file should already be protected by the OS against
66 // other user's access. We actually don't terribly need to protect it further and a password prompt across all
67 // UI's would be a pain. Therefore we use here a constant password so the file will be unreadable by generic file
68 // scanners if the user's machine get compromised.
69 FilePasswordFunc: func(string) (string, error) {
70 return "git-bug", nil
71 },
72 })
73}