Jelajahi Sumber

was accidentally referencing the wrong version of the spec

aeth 5 hari lalu
induk
melakukan
ebfb289265
8 mengubah file dengan 221 tambahan dan 213 penghapusan
  1. 1 1
      main.go
  2. 43 0
      pkg/collection.go
  3. 1 0
      pkg/item.go
  4. 0 212
      pkg/listener.go
  5. 10 0
      pkg/secret.go
  6. 104 0
      pkg/service.go
  7. 11 0
      pkg/session.go
  8. 51 0
      pkg/xml.go

+ 1 - 1
main.go

@@ -17,7 +17,7 @@ func main() {
 	defer conn.Close()
 
 	path := "/dev/aetherial/KeychainLinker"
-	session := &keychainlinker.SecretService{SessionBase: "/dev/aetherial/KeychainLinker/session/",
+	session := &keychainlinker.Service{SessionBase: "/dev/aetherial/KeychainLinker/session/",
 		CollectionBase: "/dev/aetherial/KeychainLinker/collection/",
 		Collections:    []dbus.ObjectPath{}}
 

+ 43 - 0
pkg/collection.go

@@ -0,0 +1,43 @@
+package keychainlinker
+
+import "github.com/godbus/dbus/v5"
+
+type Collection struct {
+	/*
+		Implying the org.freedesktop.Secret.Collection interface as per the v0.2 spec:
+		https://specifications.freedesktop.org/secret-service-spec/latest-single/#org.freedesktop.Secret.Collection
+	*/
+	Items    []dbus.ObjectPath // items in the collection
+	Private  string            // specifies whether the collection is private or not
+	Label    string            //  The displayable label of this collection.
+	Locked   string            //  Whether the collection is locked and must be authenticated by the client application.
+	Created  uint64            //  The unix time when the collection was created.
+	Modified uint64            //  The unix time when the collection was last modified.
+}
+
+// deletes the collection, returning an object path tied to a prompt incase it is necessary.
+func (c *Collection) Delete() (dbus.ObjectPath, *dbus.Error) {
+	return dbus.ObjectPath("prompt"), nil
+}
+
+/*
+Searches the collection for matching items
+
+	:param attr: the attributes to attempt to match to a key in the collection
+*/
+func (c *Collection) SearchItems(attr map[string]string) ([]dbus.ObjectPath, *dbus.Error) {
+	// implement a recursive searching thing
+	return []dbus.ObjectPath{}, nil
+}
+
+/*
+Creates a new item in the collection with the properties defined in 'props'.
+Returns the items dbus object path, as well as a path to a dbus prompt incase it is required to edit
+
+	:param fields: a map of properties to assign to the item. Will be used to match during lookups
+	:param secret: the secret to encode into the collection
+	:param replace: replace secret if a matching one is found in the store
+*/
+func (c *Collection) CreateItem(fields map[string]dbus.Variant, secret SecretStruct, replace bool) (dbus.ObjectPath, dbus.ObjectPath, *dbus.Error) {
+	return dbus.ObjectPath("/"), dbus.ObjectPath("/"), nil
+}

+ 1 - 0
pkg/item.go

@@ -0,0 +1 @@
+package keychainlinker

+ 0 - 212
pkg/listener.go

@@ -1,212 +0,0 @@
-package keychainlinker
-
-import (
-	"fmt"
-	"path"
-	"strconv"
-
-	"github.com/godbus/dbus/v5"
-	"github.com/godbus/dbus/v5/introspect"
-)
-
-const DbusAdv = `
-<node>
-	<interface name="dev.aetherial.git.KeychainLinker.Service">
-		<method name="OpenSession">
-		  <arg name="algorithm" direction="in" type="s"/>
-		  <arg name="input" direction="in" type="v"/>
-		  <arg name="output" direction="out" type="v"/>
-		  <arg name="result" direction="out" type="o"/>
-		</method>
-		<method name="CreateCollection">
-		  <arg name="properties" direction="in" type="a{sv}"/>
-		  <arg name="alias" direction="in" type="s"/>
-		  <arg name="collection" direction="out" type="o"/>
-		  <arg name="prompt" direction="out" type="o"/>
-		</method>
-		<method name="SearchItems">
-		  <arg name="attributes" direction="in" type="a{ss}"/>
-		  <arg name="unlocked" direction="out" type="ao"/>
-		  <arg name="locked" direction="out" type="ao"/>
-		</method>
-		<method name="Unlock">
-		  <arg name="objects" direction="in" type="ao"/>
-		  <arg name="unlocked" direction="out" type="ao"/>
-		  <arg name="prompt" direction="out" type="o"/>
-		</method>
-		<method name="Lock">
-		  <arg name="objects" direction="in" type="ao"/>
-		  <arg name="locked" direction="out" type="ao"/>
-		  <arg name="prompt" direction="out" type="o"/>
-		</method>
-		<method name="GetSecrets">
-		  <arg name="items" direction="in" type="ao"/>
-		  <arg name="session" direction="in" type="o"/>
-		  <arg name="secrets" direction="out" type="a{o(ayays)}"/>
-		</method>
-		<method name="ReadAlias">
-		  <arg name="name" direction="in" type="s"/>
-		  <arg name="collection" direction="out" type="o"/>
-		</method>
-		<method name="SetAlias">
-		  <arg name="name" direction="in" type="s"/>
-		  <arg name="collection" direction="in" type="o"/>
-		</method>
-		<property name="Collections" type="ao" access="read"/>
-	</interface>` + introspect.IntrospectDataString + `</node> `
-
-type Session struct {
-	Path string
-	Open int
-}
-
-/*
-Get the next session
-*/
-func (s *Session) next() int {
-	s.Open = s.Open + 1
-	return s.Open
-
-}
-
-func (s *Session) OpenSession(algorithm string, input dbus.Variant) (dbus.Variant, dbus.ObjectPath, *dbus.Error) {
-	if algorithm != "PLAIN" {
-		return dbus.Variant{}, dbus.ObjectPath(""), &dbus.ErrMsgInvalidArg
-	}
-	nextPath := path.Join(s.Path, strconv.Itoa(s.next()))
-	fmt.Println("recieved algorithm: ", algorithm, "\nresponding with path: ", nextPath)
-	return dbus.MakeVariant(algorithm), dbus.ObjectPath(nextPath), nil
-}
-
-type SecretStruct struct {
-	Session     dbus.ObjectPath
-	Parameters  []byte
-	Value       []byte
-	ContentType string
-}
-
-type SecretService struct {
-	Collections    []dbus.ObjectPath
-	SessionBase    string // e.g. "/org/freedesktop/secrets/session/"
-	CollectionBase string // e.g. "/org/freedesktop/secrets/collection/"
-}
-
-type Collection struct {
-	Items    []dbus.ObjectPath // items in the collection
-	Private  string            // specifies whether the collection is private or not
-	Label    string            //  The displayable label of this collection.
-	Locked   string            //  Whether the collection is locked and must be authenticated by the client application.
-	Created  uint64            //  The unix time when the collection was created.
-	Modified uint64            //  The unix time when the collection was last modified.
-}
-
-// deletes the collection
-func (c *Collection) Delete() (dbus.ObjectPath, *dbus.Error) {
-	return dbus.ObjectPath("prompt"), nil
-}
-
-/*
-Searches the collection for matching items
-
-	:param attr: the attributes to attempt to match to a key in the collection
-*/
-func (c *Collection) SearchItems(attr map[string]string) ([]dbus.ObjectPath, *dbus.Error) {
-	// implement a recursive searching thing
-	return []dbus.ObjectPath{}, nil
-}
-
-/*
-Creates a new item in the collection with the properties defined in 'props'.
-Returns the items dbus object path, as well as a path to a dbus prompt
-
-	:param fields: a map of properties to assign to the item. Will be used to match during lookups
-	:param secret: the secret to encode into the collection
-	:param replace: replace secret if a matching one is found in the store
-*/
-func (c *Collection) CreateItem(fields map[string]string, secret SecretStruct, replace bool) (dbus.ObjectPath, dbus.ObjectPath) {
-	return dbus.ObjectPath("/"), dbus.ObjectPath("/")
-}
-
-/*
-Opens a session for the Secret Service Interface
-
-	:param algorithm: the encryption algorithm to use with the client
-	:param input: the data used when implementing more advanced encryption algos
-*/
-func (s *SecretService) OpenSession(algorithm string, input dbus.Variant) (dbus.Variant, dbus.ObjectPath, *dbus.Error) {
-	if algorithm != "PLAIN" {
-		return dbus.Variant{}, "/", dbus.MakeFailedError(fmt.Errorf("only PLAIN is supported"))
-	}
-
-	sessionPath := dbus.ObjectPath(path.Join(s.SessionBase, "1"))
-	return input, sessionPath, nil
-}
-
-/*
-Creates a collection with the Service object
-
-	:param properties: a set of properties that are used by client apps
-	:param alias: the shortname of the collection
-*/
-func (s *SecretService) CreateCollection(properties map[string]dbus.Variant, alias string) (dbus.ObjectPath, dbus.ObjectPath, *dbus.Error) {
-	collPath := dbus.ObjectPath(path.Join(s.CollectionBase, "login"))
-	s.Collections = append(s.Collections, collPath)
-	return collPath, "/", nil
-}
-
-/*
-search for items in the keychain that satisfy 'attrs'
-
-	:param attrs: a map of search criteria
-*/
-func (s *SecretService) SearchItems(attrs map[string]string) ([]dbus.ObjectPath, []dbus.ObjectPath, *dbus.Error) {
-	// Just return empty results for now
-	return []dbus.ObjectPath{}, []dbus.ObjectPath{}, nil
-}
-
-/*
-sets all dbus.Objects in 'objects' to the 'unlocked' position
-
-	:param objects: a slice of dbus.Objects to unlock
-*/
-func (s *SecretService) Unlock(objects []dbus.ObjectPath) ([]dbus.ObjectPath, dbus.ObjectPath, *dbus.Error) {
-	return objects, "/", nil // No prompt
-}
-
-/*
-Sets all dbus.Objects in 'objects' to the 'locked' position
-
-	:param objects: a slice of dbus.Objects to unlock
-*/
-func (s *SecretService) Lock(objects []dbus.ObjectPath) ([]dbus.ObjectPath, dbus.ObjectPath, *dbus.Error) {
-	return objects, "/", nil // No prompt
-}
-
-/*
-retrives secrets from an array of items/collections
-
-	:param items: a slice of dbus.ObjectPath that will have their secrets returned
-*/
-func (s *SecretService) GetSecrets(items []dbus.ObjectPath, session dbus.ObjectPath) (map[dbus.ObjectPath]SecretStruct, *dbus.Error) {
-	return map[dbus.ObjectPath]SecretStruct{}, nil
-}
-
-/*
-returns the collection with the given alias 'name'
-
-	:param name: the name of the alias to return
-*/
-func (s *SecretService) ReadAlias(name string) (dbus.ObjectPath, *dbus.Error) {
-	return dbus.ObjectPath("/dev/aetherial/KeychainLinker/login"), nil
-}
-
-/*
-sets the collections alias name to the specified value in 'name'
-
-	:param name: the alias name to assign
-	:param collection: the dbus.ObjectPath to assign the alias name to
-*/
-func (s *SecretService) SetAlias(name string, collection dbus.ObjectPath) *dbus.Error {
-	// will implement later
-	return nil
-}

+ 10 - 0
pkg/secret.go

@@ -0,0 +1,10 @@
+package keychainlinker
+
+import "github.com/godbus/dbus/v5"
+
+type SecretStruct struct {
+	Session     dbus.ObjectPath
+	Parameters  []byte
+	Value       []byte
+	ContentType string
+}

+ 104 - 0
pkg/service.go

@@ -0,0 +1,104 @@
+package keychainlinker
+
+import (
+	"fmt"
+	"path"
+
+	"github.com/godbus/dbus/v5"
+)
+
+type Service struct {
+	/*
+		Working on implementing the org.freedesktop.Secret.Service interface, from their v0.2 spec:
+		https://specifications.freedesktop.org/secret-service-spec/latest-single/#org.freedesktop.Secret.Service
+	*/
+	Collections    []dbus.ObjectPath
+	SessionBase    string // e.g. "/org/freedesktop/secrets/session/"
+	CollectionBase string // e.g. "/org/freedesktop/secrets/collection/"
+}
+
+/*
+Opens a session for the Secret Service Interface
+
+	:param algorithm: the encryption algorithm to use with the client
+	:param input: the data used when implementing more advanced encryption algos
+*/
+func (s *Service) OpenSession(algorithm string, input dbus.Variant) (dbus.Variant, dbus.ObjectPath, *dbus.Error) {
+	if algorithm != "PLAIN" {
+		return dbus.Variant{}, "/", dbus.MakeFailedError(fmt.Errorf("only PLAIN is supported"))
+	}
+
+	sessionPath := dbus.ObjectPath(path.Join(s.SessionBase, "1"))
+	return input, sessionPath, nil
+}
+
+/*
+Creates a collection with the Service object
+
+	:param properties: a set of properties that are used by client apps
+	:param alias: the shortname of the collection
+*/
+func (s *Service) CreateCollection(properties map[string]dbus.Variant, alias string) (dbus.ObjectPath, dbus.ObjectPath, *dbus.Error) {
+	collPath := dbus.ObjectPath(path.Join(s.CollectionBase, "login"))
+	s.Collections = append(s.Collections, collPath)
+	return collPath, "/", nil
+}
+
+/*
+search for items in the keychain that satisfy 'attrs'
+
+	:param attrs: a map of search criteria
+*/
+func (s *Service) SearchItems(attrs map[string]string) ([]dbus.ObjectPath, []dbus.ObjectPath, *dbus.Error) {
+	// Just return empty results for now
+	return []dbus.ObjectPath{}, []dbus.ObjectPath{}, nil
+}
+
+/*
+attempts to return secrets that were either already unlocked, or unlocked without a prompt, in addition to
+a prompt path that can be used to unlock all remaining locked objects
+
+	:param objects: a slice of dbus.Objects to unlock
+*/
+func (s *Service) Unlock(objects []dbus.ObjectPath) ([]dbus.ObjectPath, dbus.ObjectPath, *dbus.Error) {
+	return []dbus.ObjectPath{}, dbus.ObjectPath("/"), nil // No prompt
+}
+
+/*
+Sets all dbus.Objects in 'objects' to the 'locked' position
+
+	:param objects: a slice of dbus.Objects to unlock
+*/
+func (s *Service) Lock(objects []dbus.ObjectPath) ([]dbus.ObjectPath, dbus.ObjectPath, *dbus.Error) {
+	return []dbus.ObjectPath{}, dbus.ObjectPath("/"), nil // No prompt
+}
+
+/*
+retrives secrets from an array of items/collections
+
+	:param items: a slice of dbus.ObjectPath that will have their secrets returned
+*/
+func (s *Service) GetSecrets(items []dbus.ObjectPath, session dbus.ObjectPath) (map[dbus.ObjectPath]SecretStruct, *dbus.Error) {
+	return map[dbus.ObjectPath]SecretStruct{}, nil
+}
+
+/*
+Return a collection based on the alias name
+
+	:param name: the alias to search for
+*/
+func (s *Service) ReadAlias(name string) (dbus.ObjectPath, *dbus.Error) {
+	return dbus.ObjectPath(""), nil
+
+}
+
+/*
+set the alias of the passed in collection
+
+	:param name: the alias to set the collection to
+	:param collection: the collection to modify
+*/
+func (s *Service) SetAlias(name string, collection dbus.ObjectPath) *dbus.Error {
+	return nil
+
+}

+ 11 - 0
pkg/session.go

@@ -0,0 +1,11 @@
+package keychainlinker
+
+import "github.com/godbus/dbus/v5"
+
+type Session struct{}
+
+func (s Session) Close() *dbus.Error {
+	return nil
+}
+
+// opens

+ 51 - 0
pkg/xml.go

@@ -0,0 +1,51 @@
+package keychainlinker
+
+import (
+	"github.com/godbus/dbus/v5/introspect"
+)
+
+const DbusAdv = `
+<node>
+	<interface name="dev.aetherial.git.KeychainLinker.Service">
+		<method name="OpenSession">
+		  <arg name="algorithm" type="s" direction="in"/>
+		  <arg name="input" type="v" direction="in"/>
+		  <arg name="output" type="v" direction="out"/>
+		  <arg name="session" type="o" direction="out"/>
+		</method>
+		<method name="SearchItems">
+		  <arg name="attributes" type="a{ss}" direction="in"/>
+		  <arg name="unlocked" type="ao" direction="out"/>
+		  <arg name="locked" type="ao" direction="out"/>
+		</method>
+		<method name="CreateCollection">
+		  <arg name="properties" type="a{sv}" direction="in"/>
+		  <arg name="alias" type="s" direction="in"/>
+		  <arg name="collection" type="o" direction="out"/>
+		  <arg name="prompt" type="o" direction="out"/>
+		</method>
+		<method name="Unlock">
+		  <arg name="objects" type="ao" direction="in"/>
+		  <arg name="unlocked" type="ao" direction="out"/>
+		  <arg name="prompt" type="o" direction="out"/>
+		</method>
+		<method name="Lock">
+		  <arg name="objects" type="ao" direction="in"/>
+		  <arg name="locked" type="ao" direction="out"/>
+		  <arg name="prompt" type="o" direction="out"/>
+		</method>
+		<method name="GetSecrets">
+		  <arg name="items" type="ao" direction="in"/>
+		  <arg name="session" type="o" direction="in"/>
+		  <arg name="secrets" type="a{o((oayays))}" direction="out"/>
+		</method>
+		<method name="ReadAlias">
+		  <arg name="name" type="s" direction="in"/>
+		  <arg name="collection" type="o" direction="out"/>
+		</method>
+		<method name="SetAlias">
+		  <arg name="name" type="s" direction="in"/>
+		  <arg name="collection" type="o" direction="in"/>
+		</method>
+		<property name="Collections" type="ao" access="read"/>	
+	</interface>` + introspect.IntrospectDataString + `</node> `