service.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package keychainlinker
  2. import (
  3. "fmt"
  4. "path"
  5. "github.com/godbus/dbus/v5"
  6. )
  7. type Service struct {
  8. /*
  9. Working on implementing the org.freedesktop.Secret.Service interface, from their v0.2 spec:
  10. https://specifications.freedesktop.org/secret-service-spec/latest-single/#org.freedesktop.Secret.Service
  11. */
  12. Collections []dbus.ObjectPath
  13. SessionBase string // e.g. "/org/freedesktop/secrets/session/"
  14. CollectionBase string // e.g. "/org/freedesktop/secrets/collection/"
  15. }
  16. /*
  17. Opens a session for the Secret Service Interface
  18. :param algorithm: the encryption algorithm to use with the client
  19. :param input: the data used when implementing more advanced encryption algos
  20. */
  21. func (s *Service) OpenSession(algorithm string, input dbus.Variant) (dbus.Variant, dbus.ObjectPath, *dbus.Error) {
  22. if algorithm != "PLAIN" {
  23. return dbus.Variant{}, "/", dbus.MakeFailedError(fmt.Errorf("only PLAIN is supported"))
  24. }
  25. sessionPath := dbus.ObjectPath(path.Join(s.SessionBase, "1"))
  26. return input, sessionPath, nil
  27. }
  28. /*
  29. Creates a collection with the Service object
  30. :param properties: a set of properties that are used by client apps
  31. :param alias: the shortname of the collection
  32. */
  33. func (s *Service) CreateCollection(properties map[string]dbus.Variant, alias string) (dbus.ObjectPath, dbus.ObjectPath, *dbus.Error) {
  34. collPath := dbus.ObjectPath(path.Join(s.CollectionBase, "login"))
  35. s.Collections = append(s.Collections, collPath)
  36. return collPath, "/", nil
  37. }
  38. /*
  39. search for items in the keychain that satisfy 'attrs'
  40. :param attrs: a map of search criteria
  41. */
  42. func (s *Service) SearchItems(attrs map[string]string) ([]dbus.ObjectPath, []dbus.ObjectPath, *dbus.Error) {
  43. // Just return empty results for now
  44. return []dbus.ObjectPath{}, []dbus.ObjectPath{}, nil
  45. }
  46. /*
  47. attempts to return secrets that were either already unlocked, or unlocked without a prompt, in addition to
  48. a prompt path that can be used to unlock all remaining locked objects
  49. :param objects: a slice of dbus.Objects to unlock
  50. */
  51. func (s *Service) Unlock(objects []dbus.ObjectPath) ([]dbus.ObjectPath, dbus.ObjectPath, *dbus.Error) {
  52. return []dbus.ObjectPath{}, dbus.ObjectPath("/"), nil // No prompt
  53. }
  54. /*
  55. Sets all dbus.Objects in 'objects' to the 'locked' position
  56. :param objects: a slice of dbus.Objects to unlock
  57. */
  58. func (s *Service) Lock(objects []dbus.ObjectPath) ([]dbus.ObjectPath, dbus.ObjectPath, *dbus.Error) {
  59. return []dbus.ObjectPath{}, dbus.ObjectPath("/"), nil // No prompt
  60. }
  61. /*
  62. retrives secrets from an array of items/collections
  63. :param items: a slice of dbus.ObjectPath that will have their secrets returned
  64. */
  65. func (s *Service) GetSecrets(items []dbus.ObjectPath, session dbus.ObjectPath) (map[dbus.ObjectPath]SecretStruct, *dbus.Error) {
  66. return map[dbus.ObjectPath]SecretStruct{}, nil
  67. }
  68. /*
  69. Return a collection based on the alias name
  70. :param name: the alias to search for
  71. */
  72. func (s *Service) ReadAlias(name string) (dbus.ObjectPath, *dbus.Error) {
  73. return dbus.ObjectPath(""), nil
  74. }
  75. /*
  76. set the alias of the passed in collection
  77. :param name: the alias to set the collection to
  78. :param collection: the collection to modify
  79. */
  80. func (s *Service) SetAlias(name string, collection dbus.ObjectPath) *dbus.Error {
  81. return nil
  82. }