Workaround for missing Type property

Some poor decisions that have been made made by KeePassXC lead to the case where they diverge from libsecret's implementation and implement their own incompatible API in the same Dbus namespace.

But they still call their API "Secret Service".

 Well then.
This commit is contained in:
brent s. 2022-01-09 00:56:56 -05:00
parent bb85cb8b52
commit b4419a6f8c
Signed by: bts
GPG Key ID: 8C004C2F93481F6B
3 changed files with 20 additions and 2 deletions

View File

@ -80,7 +80,9 @@ func (c *Collection) CreateItem(label string, attrs map[string]string, secret *S
}

props[DbusItemLabel] = dbus.MakeVariant(label)
props[DbusItemType] = dbus.MakeVariant(typeString)
if !c.service.Legacy {
props[DbusItemType] = dbus.MakeVariant(typeString)
}
props[DbusItemAttributes] = dbus.MakeVariant(attrs)
props[DbusItemCreated] = dbus.MakeVariant(uint64(time.Now().Unix()))
// props[DbusItemModified] = dbus.MakeVariant(uint64(time.Now().Unix()))

View File

@ -282,6 +282,11 @@ func (i *Item) Type() (itemType string, err error) {

var variant dbus.Variant

// Legacy spec.
if i.collection.service.Legacy {
return
}

if variant, err = i.Dbus.GetProperty(DbusItemType); err != nil {
return
}

View File

@ -74,6 +74,17 @@ type Service struct {
Session *Session `json:"-"`
// IsLocked indicates if the Service is locked or not. Status updated by Service.Locked.
IsLocked bool `json:"locked"`
/*
Legacy indicates that this SecretService implementation
breaks current spec by implementing the legacy/obsolete draft spec rather than current libsecret spec
for the Dbus API.

If you're using SecretService with KeePassXC, for instance, or a much older version of Gnome-Keyring *before* libsecret integration(?),
or if you are getting strange errors when performing a Service.SearchItems, you probably need to enable this field on the Service returned
by NewService. The coverage of this field may expand in the future, but currently it only prevents the (non-existent, in legacy spec)
Type property from being read or written on Items during NewItem and Collection.CreateItem.
*/
Legacy bool `json:"is_legacy"`
}

/*
@ -83,7 +94,7 @@ type Service struct {
*/
type Session struct {
*DbusObject
// collection tracks the Service this Session was created from.
// service tracks the Service this Session was created from.
service *Service
}