From b4419a6f8c1b9e0a79d2b1af8ee4ec1392e469ca Mon Sep 17 00:00:00 2001 From: brent s Date: Sun, 9 Jan 2022 00:56:56 -0500 Subject: [PATCH] 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. --- collection_funcs.go | 4 +++- item_funcs.go | 5 +++++ types.go | 13 ++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/collection_funcs.go b/collection_funcs.go index 5fc2068..21aa087 100644 --- a/collection_funcs.go +++ b/collection_funcs.go @@ -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())) diff --git a/item_funcs.go b/item_funcs.go index 145eaaf..0702c65 100644 --- a/item_funcs.go +++ b/item_funcs.go @@ -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 } diff --git a/types.go b/types.go index 9cce73d..8d81b2b 100644 --- a/types.go +++ b/types.go @@ -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 }