Skip to content

Commit

Permalink
fix reading in gnome keyring
Browse files Browse the repository at this point in the history
remove debug code

tidy up
  • Loading branch information
leejw51crypto committed Mar 31, 2021
1 parent d9b6b92 commit 997bc31
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion libsecret.go
Expand Up @@ -3,9 +3,12 @@
package keyring

import (
"encoding/hex"
"encoding/json"
"errors"

"strings"

"github.com/godbus/dbus"
"github.com/gsterjov/go-libsecret"
)
Expand Down Expand Up @@ -56,6 +59,28 @@ func (e *secretsError) Error() string {

var errCollectionNotFound = errors.New("The collection does not exist. Please add a key first")

func decodeKeyringString(src string) string {

var dst strings.Builder
for i := 0; i < len(src); i++ {
if src[i] != '_' {
dst.WriteString(string(src[i]))
} else {
if i+3 > len(src) {
return src
}
hexstring := src[i+1 : i+3]
decoded, err := hex.DecodeString(hexstring)
if err != nil {
return src
}
dst.Write(decoded)
i += 2
}
}
return dst.String()
}

func (k *secretsKeyring) openSecrets() error {
session, err := k.service.Open()
if err != nil {
Expand All @@ -72,7 +97,7 @@ func (k *secretsKeyring) openSecrets() error {
path := libsecret.DBusPath + "/collection/" + k.name

for _, collection := range collections {
if string(collection.Path()) == path {
if decodeKeyringString(string(collection.Path())) == path || string(collection.Path()) == path {
k.collection = &collection
return nil
}
Expand Down

0 comments on commit 997bc31

Please sign in to comment.