be specified either by the string @code{"session"}, or by @code{nil},
whenever a collection parameter is needed in the following functions.
+However, not all Secret Service provider create this temporary
+@code{"session"} collection, like KeePassXC. You shall check first
+that this collection exists, before you use it.
+
@defun secrets-list-items collection
Returns all the item labels of @var{collection} as a list.
@end defun
starting with a colon. Example:
@example
-;;; The session is "session", the label is "my item"
+;;; The collection is "session", the label is "my item"
;;; and the secret (password) is "geheim".
(secrets-create-item "session" "my item" "geheim"
:method "sudo" :user "joe" :host "remote-host")
;; </signal>
;; </interface>
+;; This is not guaranteed to exist. For example, KeePassXC does not offer this.
(defconst secrets-session-collection-path
"/org/freedesktop/secrets/collection/session"
"The D-Bus temporary session collection object path.")
(defconst secrets-interface-item-type-generic "org.freedesktop.Secret.Generic"
"The default item type we are using.")
-;; We cannot use introspection, because some servers, like
-;; mate-keyring-daemon, don't provide relevant data. Once the dust
-;; has settled, we shall assume the new interface, and get rid of the test.
-(defconst secrets-struct-secret-content-type
- (ignore-errors
- (let ((content-type "text/plain")
- (path (cadr
- (dbus-call-method
- :session secrets-service secrets-path
- secrets-interface-service
- "OpenSession" "plain" '(:variant ""))))
- result)
- ;; Create a dummy item.
- (setq result
- (dbus-call-method
- :session secrets-service secrets-session-collection-path
- secrets-interface-collection "CreateItem"
- ;; Properties.
- `(:array
- (:dict-entry ,(concat secrets-interface-item ".Label")
- (:variant " ")))
- ;; Secret.
- `(:struct :object-path ,path
- (:array :signature "y")
- ,(dbus-string-to-byte-array " ")
- :string ,content-type)
- ;; Don't replace.
- nil))
- ;; Remove it.
- (dbus-call-method
- :session secrets-service (car result)
- secrets-interface-item "Delete")
- ;; Result.
- `(,content-type)))
- "The content_type of a secret struct.
-It must be wrapped as list, because we add it via `append'. This
-is an interface introduced in 2011.")
+(defconst secrets-struct-secret-content-type "text/plain"
+ "The content_type of a secret struct.")
(defconst secrets-interface-session "org.freedesktop.Secret.Session"
"A session tracks state between the service and a client application.")
`((:dict-entry ,(concat secrets-interface-item ".Attributes")
(:variant ,(append '(:array) props))))))
;; Secret.
- (append
- `(:struct :object-path ,secrets-session-path
- (:array :signature "y") ;; No parameters.
- ,(dbus-string-to-byte-array password))
- ;; We add the content_type. In backward compatibility
- ;; mode, nil is appended, which means nothing.
- secrets-struct-secret-content-type)
+ `(:struct :object-path ,secrets-session-path
+ (:array :signature "y") ;; No parameters.
+ ,(dbus-string-to-byte-array password)
+ ,secrets-struct-secret-content-type)
;; Do not replace. Replace does not seem to work.
nil))
(secrets-prompt (cadr result))
(defun secrets--test-delete-all-session-items ()
"Delete all items of collection \"session\" bound to this Emacs."
- (dolist (item (secrets-list-items "session"))
- (secrets-delete-item "session" item)))
+ ;; If the "session" collection does not exist, a `dbus-error' is
+ ;; fired, which we ignore.
+ (dbus-ignore-errors
+ (dolist (item (secrets-list-items "session"))
+ (secrets-delete-item "session" item))))
(ert-deftest secrets-test01-sessions ()
"Test opening / closing a secrets session."
(unwind-protect
(progn
(should (secrets-open-session))
- (should (member "session" (secrets-list-collections)))
+ (skip-unless (member "session" (secrets-list-collections)))
;; Create a random collection. This asks for a password
;; outside our control, so we make it in the interactive case
(unwind-protect
(let (item-path)
(should (secrets-open-session))
+ (skip-unless (member "session" (secrets-list-collections)))
;; Cleanup. There could be items in the "session" collection.
(secrets--test-delete-all-session-items)
(unwind-protect
(progn
(should (secrets-open-session))
+ (skip-unless (member "session" (secrets-list-collections)))
;; Cleanup. There could be items in the "session" collection.
(secrets--test-delete-all-session-items)