@@ -13,6 +13,9 @@ import (
1313
1414const (
1515 // the default collection in most X11 sessions would be 'login'
16+ // it is created by default through PAM, see https://wiki.gnome.org/Projects/GnomeKeyring/Pam.
17+ //
18+ // NOTE: do not use this directly, always call [getDefaultCollection]
1619 loginKeychainObjectPath = dbus .ObjectPath ("/org/freedesktop/secrets/collection/login" )
1720)
1821
@@ -30,10 +33,11 @@ func (k *keychainStore[T]) itemAttributes(id store.ID) map[string]string {
3033// getDefaultCollection gets the secret service collection dbus object path.
3134//
3235// It prefers the loginKeychainObjectPath, since most users on X11 would have
33- // this available.
36+ // this available via PAM, see https://wiki.gnome.org/Projects/GnomeKeyring/Pam .
3437//
35- // As a fallback it queries the secret service for the default collection and
36- // returns that instead.
38+ // As a fallback it queries the secret service for the default collection.
39+ // It is possible that the host does not have a collection set up, in that case
40+ // the only option is to error.
3741func (k * keychainStore [T ]) getDefaultCollection (service * kc.SecretService ) (dbus.ObjectPath , error ) {
3842 variant , err := service .ServiceObj ().GetProperty ("org.freedesktop.Secret.Service.Collections" )
3943 if err != nil {
@@ -56,6 +60,10 @@ func (k *keychainStore[T]) getDefaultCollection(service *kc.SecretService) (dbus
5660 return "" , err
5761 }
5862
63+ if ! defaultKeychainObjectPath .IsValid () {
64+ return "" , errors .New ("the default collection object path is invalid" )
65+ }
66+
5967 return defaultKeychainObjectPath , nil
6068}
6169
0 commit comments