annotate lisp/net/secrets.el @ 107389:51ddd70d1fa1

* etc/NEWS: Add secrets.el. * lisp/Makefile.in (ELCFILES): Add net/secrets.elc. * lisp/net/secrets.el: New file.
author Michael Albinus <albinus@detlef>
date Sat, 13 Mar 2010 21:33:54 +0100
parents
children d5de7ba3f80f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
107389
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
1 ;;; secrets.el --- Client interface to gnome-keyring and kwallet.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
2
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
3 ;; Copyright (C) 2010 Free Software Foundation, Inc.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
4
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
6 ;; Keywords: comm password passphrase
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
7
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
9
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
13 ;; (at your option) any later version.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
14
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
18 ;; GNU General Public License for more details.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
19
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
22
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
23 ;;; Commentary:
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
24
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
25 ;; This package provides an implementation of the Secret Service API
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
26 ;; <http://www.freedesktop.org/wiki/Specifications/secret-storage-spec>.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
27 ;; This API is meant to make GNOME-Keyring- and KWallet-like daemons
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
28 ;; available under a common D-BUS interface and thus increase
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
29 ;; interoperability between GNOME, KDE and other applications having
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
30 ;; the need to securely store passwords and other confidential
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
31 ;; information.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
32
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
33 ;; In order to activate this package, you must add the following code
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
34 ;; into your .emacs:
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
35
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
36 ;; (require 'secrets)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
37
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
38 ;; The atomic objects to be managed by the Secret Service API are
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
39 ;; secret items, which are something an application wishes to store
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
40 ;; securely. A good example is a password that an application needs
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
41 ;; to save and use at a later date.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
42
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
43 ;; Secret items are grouped in collections. A collection is similar
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
44 ;; in concept to the terms 'keyring' or 'wallet'. A common collection
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
45 ;; is called "login". A collection is stored permanently under the
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
46 ;; user's permissions, and can be accessed in a user session context.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
47
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
48 ;; A collection can have an alias name. The use case for this is to
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
49 ;; set the alias "default" for a given collection, making it
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
50 ;; transparent for clients, which collection is used. Other aliases
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
51 ;; are not supported (yet). Since an alias is visible to all
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
52 ;; applications, this setting shall be performed with care.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
53
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
54 ;; A list of all available collections is available by
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
55 ;;
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
56 ;; (secrets-list-collections)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
57 ;; => ("session" "login" "ssh keys")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
58
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
59 ;; The "default" alias could be set to the "login" collection by
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
60 ;;
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
61 ;; (secrets-set-alias "login" "default")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
62
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
63 ;; An alias can also be dereferenced
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
64 ;;
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
65 ;; (secrets-get-alias "default")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
66 ;; => "login"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
67
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
68 ;; Collections can be created and deleted. As already said,
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
69 ;; collections are used by different applications. Therefore, those
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
70 ;; operations shall also be performed with care. Common collections,
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
71 ;; like "login", shall not be changed except adding or deleting secret
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
72 ;; items.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
73 ;;
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
74 ;; (secrets-delete-collection "my collection")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
75 ;; (secrets-create-collection "my collection")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
76
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
77 ;; There exists a special collection called "session", which has the
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
78 ;; lifetime of the corrresponding client session (aka Emacs'
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
79 ;; lifetime). It is created automatically when Emacs uses the Secret
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
80 ;; Service interface, and it is deleted when Emacs is killed.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
81 ;; Therefore, it can be used to store and retrieve secret items
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
82 ;; temporarily. This shall be preferred over creation of a persistent
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
83 ;; collection, when the information shall not live longer than Emacs.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
84 ;; The session collection can be addressed either by the string
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
85 ;; "session", or by `nil', whenever a collection parameter is needed.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
86
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
87 ;; As already said, a collection is a group of secret items. A secret
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
88 ;; item has a label, the "secret" (which is a string), and a set of
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
89 ;; lookup attributes. The attributes can be used to search and
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
90 ;; retrieve a secret item at a later date.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
91
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
92 ;; A list of all available secret items of a collection is available by
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
93 ;;
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
94 ;; (secrets-list-items "my collection")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
95 ;; => ("this item" "another item")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
96
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
97 ;; Secret items can be added or deleted to a collection. In the
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
98 ;; following examples, we use the special collection "session", which
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
99 ;; is bound to Emacs' lifetime.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
100 ;;
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
101 ;; (secrets-delete-item "session" "my item")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
102 ;; (secrets-create-item "session" "my item" "geheim"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
103 ;; :user "joe" :host "remote-host")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
104
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
105 ;; The string "geheim" is the secret of the secret item "my item".
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
106 ;; The secret string can be retrieved from items:
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
107 ;;
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
108 ;; (secrets-get-secret "session" "my item")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
109 ;; => "geheim"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
110
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
111 ;; The lookup attributes, which are specified during creation of a
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
112 ;; secret item, must be a key-value pair. Keys are keyword symbols,
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
113 ;; starting with a colon; values are strings. They can be retrieved
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
114 ;; from a given secret item:
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
115 ;;
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
116 ;; (secrets-get-attribute "session" "my item" :host)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
117 ;; => "remote-host"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
118 ;;
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
119 ;; (secrets-get-attributes "session" "my item")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
120 ;; => ((:user . "joe") (:host ."remote-host"))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
121
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
122 ;; The lookup attributes can be used for searching of items. If you,
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
123 ;; for example, are looking for all secret items for the user "joe",
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
124 ;; you would perform
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
125 ;;
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
126 ;; (secrets-search-items "session" :user "joe")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
127 ;; => ("my item" "another item")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
128
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
129 ;;; Code:
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
130
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
131 ;; It has been tested with GNOME Keyring 2.29.92. An implementation
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
132 ;; for KWallet will be available at
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
133 ;; svn://anonsvn.kde.org/home/kde/trunk/playground/base/ksecretservice;
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
134 ;; not tested yet.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
135
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
136 ;; Pacify byte-compiler. D-Bus support in the Emacs core can be
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
137 ;; disabled with configuration option "--without-dbus". Declare used
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
138 ;; subroutines and variables of `dbus' therefore.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
139 (eval-when-compile
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
140 (require 'cl))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
141
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
142 (declare-function dbus-call-method "dbusbind.c")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
143 (declare-function dbus-register-signal "dbusbind.c")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
144 (defvar dbus-debug)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
145
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
146 (require 'dbus)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
147
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
148 (defvar secrets-debug t
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
149 "Write debug messages")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
150
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
151 (defconst secrets-service "org.freedesktop.secrets"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
152 "The D-Bus name used to talk to Secret Service.")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
153
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
154 (defconst secrets-path "/org/freedesktop/secrets"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
155 "The D-Bus root object path used to talk to Secret Service.")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
156
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
157 (defconst secrets-empty-path "/"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
158 "The D-Bus object path representing an empty object.")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
159
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
160 (defsubst secrets-empty-path (path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
161 "Check, whether PATH is a valid object path.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
162 It returns t if not."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
163 (or (not (stringp path))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
164 (string-equal path secrets-empty-path)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
165
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
166 (defconst secrets-interface-service "org.freedesktop.Secret.Service"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
167 "The D-Bus interface managing sessions and collections.")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
168
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
169 ;; <interface name="org.freedesktop.Secret.Service">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
170 ;; <property name="Collections" type="ao" access="read"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
171 ;; <method name="OpenSession">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
172 ;; <arg name="algorithm" type="s" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
173 ;; <arg name="input" type="v" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
174 ;; <arg name="output" type="v" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
175 ;; <arg name="result" type="o" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
176 ;; </method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
177 ;; <method name="CreateCollection">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
178 ;; <arg name="props" type="a{sv}" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
179 ;; <arg name="collection" type="o" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
180 ;; <arg name="prompt" type="o" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
181 ;; </method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
182 ;; <method name="SearchItems">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
183 ;; <arg name="attributes" type="a{ss}" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
184 ;; <arg name="unlocked" type="ao" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
185 ;; <arg name="locked" type="ao" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
186 ;; </method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
187 ;; <method name="Unlock">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
188 ;; <arg name="objects" type="ao" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
189 ;; <arg name="unlocked" type="ao" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
190 ;; <arg name="prompt" type="o" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
191 ;; </method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
192 ;; <method name="Lock">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
193 ;; <arg name="objects" type="ao" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
194 ;; <arg name="locked" type="ao" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
195 ;; <arg name="Prompt" type="o" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
196 ;; </method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
197 ;; <method name="GetSecrets">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
198 ;; <arg name="items" type="ao" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
199 ;; <arg name="session" type="o" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
200 ;; <arg name="secrets" type="a{o(oayay)}" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
201 ;; </method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
202 ;; <method name="ReadAlias">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
203 ;; <arg name="name" type="s" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
204 ;; <arg name="collection" type="o" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
205 ;; </method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
206 ;; <method name="SetAlias">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
207 ;; <arg name="name" type="s" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
208 ;; <arg name="collection" type="o" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
209 ;; </method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
210 ;; <signal name="CollectionCreated">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
211 ;; <arg name="collection" type="o"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
212 ;; </signal>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
213 ;; <signal name="CollectionDeleted">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
214 ;; <arg name="collection" type="o"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
215 ;; </signal>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
216 ;; </interface>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
217
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
218 (defconst secrets-interface-collection "org.freedesktop.Secret.Collection"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
219 "A collection of items containing secrets.")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
220
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
221 ;; <interface name="org.freedesktop.Secret.Collection">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
222 ;; <property name="Items" type="ao" access="read"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
223 ;; <property name="Label" type="s" access="readwrite"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
224 ;; <property name="Locked" type="s" access="read"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
225 ;; <property name="Created" type="t" access="read"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
226 ;; <property name="Modified" type="t" access="read"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
227 ;; <method name="Delete">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
228 ;; <arg name="prompt" type="o" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
229 ;; </method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
230 ;; <method name="SearchItems">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
231 ;; <arg name="attributes" type="a{ss}" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
232 ;; <arg name="results" type="ao" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
233 ;; </method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
234 ;; <method name="CreateItem">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
235 ;; <arg name="props" type="a{sv}" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
236 ;; <arg name="secret" type="(oayay)" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
237 ;; <arg name="replace" type="b" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
238 ;; <arg name="item" type="o" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
239 ;; <arg name="prompt" type="o" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
240 ;; </method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
241 ;; <signal name="ItemCreated">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
242 ;; <arg name="item" type="o"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
243 ;; </signal>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
244 ;; <signal name="ItemDeleted">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
245 ;; <arg name="item" type="o"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
246 ;; </signal>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
247 ;; <signal name="ItemChanged">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
248 ;; <arg name="item" type="o"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
249 ;; </signal>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
250 ;; </interface>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
251
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
252 (defconst secrets-session-collection-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
253 "/org/freedesktop/secrets/collection/session"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
254 "The D-Bus temporary session collection object path.")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
255
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
256 (defconst secrets-interface-prompt "org.freedesktop.Secret.Prompt"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
257 "A session tracks state between the service and a client application.")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
258
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
259 ;; <interface name="org.freedesktop.Secret.Prompt">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
260 ;; <method name="Prompt">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
261 ;; <arg name="window-id" type="s" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
262 ;; </method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
263 ;; <method name="Dismiss"></method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
264 ;; <signal name="Completed">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
265 ;; <arg name="dismissed" type="b"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
266 ;; <arg name="result" type="v"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
267 ;; </signal>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
268 ;; </interface>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
269
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
270 (defconst secrets-interface-item "org.freedesktop.Secret.Item"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
271 "A collection of items containing secrets.")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
272
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
273 ;; <interface name="org.freedesktop.Secret.Item">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
274 ;; <property name="Locked" type="b" access="read"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
275 ;; <property name="Attributes" type="a{ss}" access="readwrite"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
276 ;; <property name="Label" type="s" access="readwrite"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
277 ;; <property name="Created" type="t" access="read"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
278 ;; <property name="Modified" type="t" access="read"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
279 ;; <method name="Delete">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
280 ;; <arg name="prompt" type="o" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
281 ;; </method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
282 ;; <method name="GetSecret">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
283 ;; <arg name="session" type="o" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
284 ;; <arg name="secret" type="(oayay)" direction="out"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
285 ;; </method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
286 ;; <method name="SetSecret">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
287 ;; <arg name="secret" type="(oayay)" direction="in"/>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
288 ;; </method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
289 ;; </interface>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
290 ;;
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
291 ;; STRUCT secret
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
292 ;; OBJECT PATH session
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
293 ;; ARRAY BYTE parameters
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
294 ;; ARRAY BYTE value
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
295
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
296 (defconst secrets-interface-item-type-generic "org.freedesktop.Secret.Generic"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
297 "The default item type we are using.")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
298
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
299 (defconst secrets-interface-session "org.freedesktop.Secret.Session"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
300 "A session tracks state between the service and a client application.")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
301
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
302 ;; <interface name="org.freedesktop.Secret.Session">
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
303 ;; <method name="Close"></method>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
304 ;; </interface>
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
305
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
306 ;;; Sessions.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
307
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
308 (defvar secrets-session-path secrets-empty-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
309 "The D-Bus session path of the active session.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
310 A session path `secrets-empty-path' indicates there is no open session.")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
311
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
312 (defun secrets-close-session ()
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
313 "Close the secret service session, if any."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
314 (dbus-ignore-errors
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
315 (dbus-call-method
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
316 :session secrets-service secrets-session-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
317 secrets-interface-session "Close"))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
318 (setq secrets-session-path secrets-empty-path))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
319
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
320 (defun secrets-open-session (&optional reopen)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
321 "Open a new session with \"plain\" algorithm.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
322 If there exists another active session, and REOPEN is nil, that
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
323 session will be used. The object path of the session will be
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
324 returned, and it will be stored in `secrets-session-path'."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
325 (when reopen (secrets-close-session))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
326 (when (secrets-empty-path secrets-session-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
327 (setq secrets-session-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
328 (cadr
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
329 (dbus-call-method
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
330 :session secrets-service secrets-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
331 secrets-interface-service "OpenSession" "plain" '(:variant "")))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
332 (when secrets-debug
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
333 (message "Secret Service session: %s" secrets-session-path))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
334 secrets-session-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
335
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
336 ;;; Prompts.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
337
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
338 (defvar secrets-prompt-signal nil
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
339 "Internal variable to catch signals from `secrets-interface-prompt'.")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
340
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
341 (defun secrets-prompt (prompt)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
342 "Handle the prompt identified by object path PROMPT."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
343 (unless (secrets-empty-path prompt)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
344 (let ((object
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
345 (dbus-register-signal
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
346 :session secrets-service prompt
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
347 secrets-interface-prompt "Completed" 'secrets-prompt-handler)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
348 (dbus-call-method
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
349 :session secrets-service prompt
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
350 secrets-interface-prompt "Prompt" (frame-parameter nil 'window-id))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
351 (unwind-protect
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
352 (progn
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
353 ;; Wait until the returned prompt signal has put the
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
354 ;; result into `secrets-prompt-signal'.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
355 (while (null secrets-prompt-signal)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
356 (read-event nil nil 0.1))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
357 ;; Return the object(s). It is a variant, so we must use a car.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
358 (car secrets-prompt-signal))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
359 ;; Cleanup.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
360 (setq secrets-prompt-signal nil)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
361 (dbus-unregister-object object)))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
362
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
363 (defun secrets-prompt-handler (&rest args)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
364 "Handler for signals emitted by `secrets-interface-prompt'."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
365 ;; An empty object path is always identified as `secrets-empty-path'
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
366 ;; or `nil'. Either we set it explicitely, or it is returned by the
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
367 ;; "Completed" signal.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
368 (if (car args) ;; dismissed
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
369 (setq secrets-prompt-signal (list secrets-empty-path))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
370 (setq secrets-prompt-signal (cadr args))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
371
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
372 ;;; Collections.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
373
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
374 (defvar secrets-collection-paths nil
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
375 "Cached D-Bus object paths of available collections.")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
376
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
377 (defun secrets-collection-handler (&rest args)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
378 "Handler for signals emitted by `secrets-interface-service'."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
379 (cond
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
380 ((string-equal (dbus-event-member-name last-input-event) "CollectionCreated")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
381 (add-to-list 'secrets-collection-paths (car args)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
382 ((string-equal (dbus-event-member-name last-input-event) "CollectionDeleted")
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
383 (setq secrets-collection-paths
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
384 (delete (car args) secrets-collection-paths)))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
385
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
386 (dbus-register-signal
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
387 :session secrets-service secrets-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
388 secrets-interface-service "CollectionCreated" 'secrets-collection-handler)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
389
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
390 (dbus-register-signal
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
391 :session secrets-service secrets-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
392 secrets-interface-service "CollectionDeleted" 'secrets-collection-handler)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
393
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
394 (defun secrets-get-collections ()
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
395 "Return the object paths of all available collections."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
396 (setq secrets-collection-paths
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
397 (or secrets-collection-paths
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
398 (dbus-get-property
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
399 :session secrets-service secrets-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
400 secrets-interface-service "Collections"))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
401
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
402 (defun secrets-get-collection-properties (collection-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
403 "Return all properties of collection identified by COLLECTION-PATH."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
404 (unless (secrets-empty-path collection-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
405 (dbus-get-all-properties
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
406 :session secrets-service collection-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
407 secrets-interface-collection)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
408
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
409 (defun secrets-get-collection-property (collection-path property)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
410 "Return property PROPERTY of collection identified by COLLECTION-PATH."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
411 (unless (or (secrets-empty-path collection-path) (not (stringp property)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
412 (dbus-get-property
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
413 :session secrets-service collection-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
414 secrets-interface-collection property)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
415
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
416 (defun secrets-list-collections ()
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
417 "Return a list of collection names."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
418 (mapcar
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
419 (lambda (collection-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
420 (if (string-equal collection-path secrets-session-collection-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
421 "session"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
422 (secrets-get-collection-property collection-path "Label")))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
423 (secrets-get-collections)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
424
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
425 (defun secrets-collection-path (collection)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
426 "Return the object path of collection labelled COLLECTION.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
427 If COLLECTION is nil, return the session collection path.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
428 If there is no such COLLECTION, return nil."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
429 (or
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
430 ;; The "session" collection.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
431 (if (or (null collection) (string-equal "session" collection))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
432 secrets-session-collection-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
433 ;; Check for an alias.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
434 (let ((collection-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
435 (dbus-call-method
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
436 :session secrets-service secrets-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
437 secrets-interface-service "ReadAlias" collection)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
438 (unless (secrets-empty-path collection-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
439 collection-path))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
440 ;; Check the collections.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
441 (catch 'collection-found
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
442 (dolist (collection-path (secrets-get-collections) nil)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
443 (when
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
444 (string-equal
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
445 collection
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
446 (secrets-get-collection-property collection-path "Label"))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
447 (throw 'collection-found collection-path))))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
448
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
449 (defun secrets-create-collection (collection)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
450 "Create collection labelled COLLECTION if it doesn't exist.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
451 Return the D-Bus object path for collection."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
452 (let ((collection-path (secrets-collection-path collection)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
453 ;; Create the collection.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
454 (when (secrets-empty-path collection-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
455 (setq collection-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
456 (secrets-prompt
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
457 (cadr
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
458 ;; "CreateCollection" returns the prompt path as second arg.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
459 (dbus-call-method
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
460 :session secrets-service secrets-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
461 secrets-interface-service "CreateCollection"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
462 `(:array (:dict-entry "Label" (:variant ,collection))))))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
463 ;; Return object path of the collection.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
464 collection-path))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
465
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
466 (defun secrets-get-alias (alias)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
467 "Return the collection name ALIAS is referencing to.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
468 For the time being, only the alias \"default\" is supported."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
469 (secrets-get-collection-property
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
470 (dbus-call-method
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
471 :session secrets-service secrets-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
472 secrets-interface-service "ReadAlias" alias)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
473 "Label"))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
474
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
475 (defun secrets-set-alias (collection alias)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
476 "Set ALIAS as alias of collection labelled COLLECTION.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
477 For the time being, only the alias \"default\" is supported."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
478 (let ((collection-path (secrets-collection-path collection)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
479 (unless (secrets-empty-path collection-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
480 (dbus-call-method
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
481 :session secrets-service secrets-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
482 secrets-interface-service "SetAlias"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
483 alias :object-path collection-path))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
484
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
485 (defun secrets-unlock-collection (collection)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
486 "Unlock collection labelled COLLECTION.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
487 If successful, return the object path of the collection."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
488 (let ((collection-path (secrets-collection-path collection)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
489 (unless (secrets-empty-path collection-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
490 (secrets-prompt
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
491 (cadr
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
492 (dbus-call-method
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
493 :session secrets-service secrets-path secrets-interface-service
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
494 "Unlock" `(:array :object-path ,collection-path)))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
495 collection-path))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
496
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
497 (defun secrets-delete-collection (collection)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
498 "Delete collection labelled COLLECTION."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
499 (let ((collection-path (secrets-collection-path collection)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
500 (unless (secrets-empty-path collection-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
501 (secrets-prompt
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
502 (dbus-call-method
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
503 :session secrets-service collection-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
504 secrets-interface-collection "Delete")))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
505
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
506 ;;; Items.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
507
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
508 (defun secrets-get-items (collection-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
509 "Return the object paths of all available items in COLLECTION-PATH."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
510 (unless (secrets-empty-path collection-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
511 (secrets-open-session)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
512 (dbus-get-property
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
513 :session secrets-service collection-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
514 secrets-interface-collection "Items")))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
515
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
516 (defun secrets-get-item-properties (item-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
517 "Return all properties of item identified by ITEM-PATH."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
518 (unless (secrets-empty-path item-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
519 (dbus-get-all-properties
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
520 :session secrets-service item-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
521 secrets-interface-item)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
522
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
523 (defun secrets-get-item-property (item-path property)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
524 "Return property PROPERTY of item identified by ITEM-PATH."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
525 (unless (or (secrets-empty-path item-path) (not (stringp property)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
526 (dbus-get-property
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
527 :session secrets-service item-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
528 secrets-interface-item property)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
529
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
530 (defun secrets-list-items (collection)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
531 "Return a list of all item labels of COLLECTION."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
532 (let ((collection-path (secrets-unlock-collection collection)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
533 (unless (secrets-empty-path collection-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
534 (mapcar
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
535 (lambda (item-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
536 (secrets-get-item-property item-path "Label"))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
537 (secrets-get-items collection-path)))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
538
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
539 (defun secrets-search-items (collection &rest attributes)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
540 "Search items in COLLECTION with ATTRIBUTES.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
541 ATTRIBUTES are key-value pairs. The keys are keyword symbols,
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
542 starting with a colon. Example:
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
543
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
544 \(secrets-create-item \"Tramp collection\" \"item\" \"geheim\"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
545 :method \"sudo\" :user \"joe\" :host \"remote-host\"\)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
546
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
547 The object paths of the found items are returned as list."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
548 (let ((collection-path (secrets-unlock-collection collection))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
549 result props)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
550 (unless (secrets-empty-path collection-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
551 ;; Create attributes list.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
552 (while (consp (cdr attributes))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
553 (unless (keywordp (car attributes))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
554 (error 'wrong-type-argument (car attributes)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
555 (setq props (add-to-list
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
556 'props
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
557 (list :dict-entry
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
558 (symbol-name (car attributes))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
559 (cadr attributes))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
560 'append)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
561 attributes (cddr attributes)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
562 ;; Search. The result is a list of two lists, the object paths
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
563 ;; of the unlocked and the locked items.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
564 (setq result
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
565 (dbus-call-method
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
566 :session secrets-service collection-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
567 secrets-interface-collection "SearchItems"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
568 (if props
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
569 (cons :array props)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
570 '(:array :signature "{ss}"))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
571 ;; Return the found items.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
572 (mapcar
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
573 (lambda (item-path) (secrets-get-item-property item-path "Label"))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
574 (append (car result) (cadr result))))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
575
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
576 (defun secrets-create-item (collection item password &rest attributes)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
577 "Create a new item in COLLECTION with label ITEM and password PASSWORD.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
578 ATTRIBUTES are key-value pairs set for the created item. The
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
579 keys are keyword symbols, starting with a colon. Example:
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
580
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
581 \(secrets-create-item \"Tramp collection\" \"item\" \"geheim\"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
582 :method \"sudo\" :user \"joe\" :host \"remote-host\"\)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
583
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
584 The object path of the created item is returned."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
585 (unless (member item (secrets-list-items collection))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
586 (let ((collection-path (secrets-unlock-collection collection))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
587 result props)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
588 (unless (secrets-empty-path collection-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
589 ;; Create attributes list.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
590 (while (consp (cdr attributes))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
591 (unless (keywordp (car attributes))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
592 (error 'wrong-type-argument (car attributes)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
593 (setq props (add-to-list
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
594 'props
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
595 (list :dict-entry
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
596 (symbol-name (car attributes))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
597 (cadr attributes))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
598 'append)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
599 attributes (cddr attributes)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
600 ;; Create the item.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
601 (setq result
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
602 (dbus-call-method
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
603 :session secrets-service collection-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
604 secrets-interface-collection "CreateItem"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
605 ;; Properties.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
606 (append
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
607 `(:array
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
608 (:dict-entry "Label" (:variant ,item))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
609 (:dict-entry
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
610 "Type" (:variant ,secrets-interface-item-type-generic)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
611 (when props
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
612 `((:dict-entry
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
613 "Attributes" (:variant ,(append '(:array) props))))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
614 ;; Secret.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
615 `(:struct :object-path ,secrets-session-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
616 (:array :signature "y") ;; no parameters.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
617 ,(dbus-string-to-byte-array password))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
618 ;; Do not replace. Replace does not seem to work.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
619 nil))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
620 (secrets-prompt (cadr result))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
621 ;; Return the object path.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
622 (car result)))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
623
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
624 (defun secrets-item-path (collection item)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
625 "Return the object path of item labelled ITEM in COLLECTION.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
626 If there is no such item, return nil."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
627 (let ((collection-path (secrets-unlock-collection collection)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
628 (catch 'item-found
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
629 (dolist (item-path (secrets-get-items collection-path))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
630 (when (string-equal item (secrets-get-item-property item-path "Label"))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
631 (throw 'item-found item-path))))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
632
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
633 (defun secrets-get-secret (collection item)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
634 "Return the secret of item labelled ITEM in COLLECTION.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
635 If there is no such item, return nil."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
636 (let ((item-path (secrets-item-path collection item)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
637 (unless (secrets-empty-path item-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
638 (dbus-byte-array-to-string
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
639 (caddr
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
640 (dbus-call-method
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
641 :session secrets-service item-path secrets-interface-item
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
642 "GetSecret" :object-path secrets-session-path))))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
643
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
644 (defun secrets-get-attributes (collection item)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
645 "Return the lookup attributes of item labelled ITEM in COLLECTION.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
646 If there is no such item, or the item has no attributes, return nil."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
647 (unless (stringp collection) (setq collection "default"))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
648 (let ((item-path (secrets-item-path collection item)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
649 (unless (secrets-empty-path item-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
650 (mapcar
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
651 (lambda (attribute) (cons (intern (car attribute)) (cadr attribute)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
652 (dbus-get-property
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
653 :session secrets-service item-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
654 secrets-interface-item "Attributes")))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
655
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
656 (defun secrets-get-attribute (collection item attribute)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
657 "Return the value of ATTRIBUTE of item labelled ITEM in COLLECTION.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
658 If there is no such item, or the item doesn't own this attribute, return nil."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
659 (cdr (assoc attribute (secrets-get-attributes collection item))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
660
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
661 (defun secrets-delete-item (collection item)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
662 "Delete ITEM in COLLECTION."
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
663 (let ((item-path (secrets-item-path collection item)))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
664 (unless (secrets-empty-path item-path)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
665 (secrets-prompt
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
666 (dbus-call-method
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
667 :session secrets-service item-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
668 secrets-interface-item "Delete")))))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
669
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
670 ;; We must reset all variables, when there is a new instance of the
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
671 ;; "org.freedesktop.secrets" service.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
672
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
673 (dbus-register-signal
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
674 :session dbus-service-dbus dbus-path-dbus
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
675 dbus-interface-dbus "NameOwnerChanged"
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
676 (lambda (&rest args)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
677 (when secrets-debug (message "Secret Service has changed: %S" args))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
678 (setq secrets-session-path secrets-empty-path
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
679 secrets-prompt-signal nil
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
680 secrets-collection-paths nil))
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
681 secrets-service)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
682
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
683 (provide 'secrets)
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
684
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
685 ;;; TODO:
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
686
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
687 ;; * secrets-debug should be structured like auth-source-debug to
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
688 ;; prevent leaking sensitive information. Right now I don't see
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
689 ;; anything sensitive though.
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
690 ;; * Check, whether the dh-ietf1024-aes128-cbc-pkcs7 algorithm can be
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
691 ;; used for the transfer of the secrets. Currently, we use the
51ddd70d1fa1 * etc/NEWS: Add secrets.el.
Michael Albinus <albinus@detlef>
parents:
diff changeset
692 ;; plain algorithm.