Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecated TrustedApplicationAccess on Macos Catalina #59

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ type Config struct {
// MacOSKeychainNameKeychainName is the name of the macOS keychain that is used
KeychainName string

// KeychainTrustApplication is whether the calling application should be trusted by default by items
KeychainTrustApplication bool

// KeychainSynchronizable is whether the item can be synchronized to iCloud
KeychainSynchronizable bool

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/dvsekhvalnov/jose2go v0.0.0-20180829124132-7f401d37b68a
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c
github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d
github.com/keybase/go-keychain v0.0.0-20191220220820-f65a47cbe0b1
github.com/kr/pretty v0.1.0 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/stretchr/objx v0.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d h1:Z+RDyXzjKE0i2sTjZ/b1uxiGtPhFy34Ou/Tk0qwN0kM=
github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc=
github.com/keybase/go-keychain v0.0.0-20191220220820-f65a47cbe0b1 h1:Lk38J60jgB05LTkSEElUXe49VEzWMNrPyPFf2vhKM1k=
github.com/keybase/go-keychain v0.0.0-20191220220820-f65a47cbe0b1/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
25 changes: 1 addition & 24 deletions keychain.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type keychain struct {

isSynchronizable bool
isAccessibleWhenUnlocked bool
isTrusted bool
}

func init() {
Expand All @@ -34,9 +33,6 @@ func init() {
if cfg.KeychainName != "" {
kc.path = cfg.KeychainName + ".keychain"
}
if cfg.KeychainTrustApplication {
kc.isTrusted = true
}
return kc, nil
})
}
Expand Down Expand Up @@ -144,23 +140,7 @@ func (k *keychain) Set(item Item) error {
kcItem.SetAccessible(gokeychain.AccessibleWhenUnlocked)
}

isTrusted := k.isTrusted && !item.KeychainNotTrustApplication

if isTrusted {
debugf("Keychain item trusts keyring")
kcItem.SetAccess(&gokeychain.Access{
Label: item.Label,
TrustedApplications: nil,
})
} else {
debugf("Keychain item doesn't trust keyring")
kcItem.SetAccess(&gokeychain.Access{
Label: item.Label,
TrustedApplications: []string{},
})
}

debugf("Adding service=%q, label=%q, account=%q, trusted=%v to osx keychain %q", k.service, item.Label, item.Key, isTrusted, k.path)
debugf("Adding service=%q, label=%q, account=%q to osx keychain %q", k.service, item.Label, item.Key, k.path)

if err := gokeychain.AddItem(kcItem); err == gokeychain.ErrorDuplicateItem {
debugf("Item already exists, updating")
Expand All @@ -183,9 +163,6 @@ func (k *keychain) Set(item Item) error {
return errors.New("no results")
}

// Don't call SetAccess() as this will cause multiple prompts on update, even when we are not updating the AccessList
kcItem.SetAccess(nil)

if err := gokeychain.UpdateItem(queryItem, kcItem); err != nil {
return fmt.Errorf("Failed to update item in keychain: %v", err)
}
Expand Down
8 changes: 0 additions & 8 deletions keychain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func TestOSXKeychainKeyringSet(t *testing.T) {
path: path,
passwordFunc: fixedStringPrompt("test password"),
service: "test",
isTrusted: true,
}

item := Item{
Expand Down Expand Up @@ -59,7 +58,6 @@ func TestOSXKeychainKeyringOverwrite(t *testing.T) {
path: path,
passwordFunc: fixedStringPrompt("test password"),
service: "test",
isTrusted: true,
}

item1 := Item{
Expand Down Expand Up @@ -111,7 +109,6 @@ func TestOSXKeychainKeyringListKeysWhenEmpty(t *testing.T) {
path: path,
service: "test",
passwordFunc: fixedStringPrompt("test password"),
isTrusted: true,
}

keys, err := k.Keys()
Expand All @@ -131,7 +128,6 @@ func TestOSXKeychainKeyringListKeysWhenNotEmpty(t *testing.T) {
path: path,
service: "test",
passwordFunc: fixedStringPrompt("test password"),
isTrusted: true,
}

keys := []string{"key1", "key2", "key3"}
Expand Down Expand Up @@ -177,7 +173,6 @@ func TestOSXKeychainGetKeyWhenEmpty(t *testing.T) {
path: path,
passwordFunc: fixedStringPrompt("test password"),
service: "test",
isTrusted: true,
}

_, err := k.Get("no-such-key")
Expand All @@ -194,7 +189,6 @@ func TestOSXKeychainGetKeyWhenNotEmpty(t *testing.T) {
path: path,
passwordFunc: fixedStringPrompt("test password"),
service: "test",
isTrusted: true,
}
item := Item{
Key: "llamas",
Expand Down Expand Up @@ -224,7 +218,6 @@ func TestOSXKeychainRemoveKeyWhenEmpty(t *testing.T) {
path: path,
passwordFunc: fixedStringPrompt("test password"),
service: "test",
isTrusted: true,
}

err := k.Remove("no-such-key")
Expand All @@ -241,7 +234,6 @@ func TestOSXKeychainRemoveKeyWhenNotEmpty(t *testing.T) {
path: path,
passwordFunc: fixedStringPrompt("test password"),
service: "test",
isTrusted: true,
}
item := Item{
Key: "llamas",
Expand Down