@@ -8,49 +8,64 @@ import (
8
8
errors "github.com/pkg/errors"
9
9
)
10
10
11
+ // SecretServiceInterface
11
12
const SecretServiceInterface = "org.freedesktop.secrets"
13
+
14
+ // SecretServiceObjectPath
12
15
const SecretServiceObjectPath dbus.ObjectPath = "/org/freedesktop/secrets"
13
16
14
17
// DefaultCollection need not necessarily exist in the user's keyring.
15
18
const DefaultCollection dbus.ObjectPath = "/org/freedesktop/secrets/aliases/default"
16
19
17
- type authenticationMode string
20
+ // AuthenticationMode
21
+ type AuthenticationMode string
22
+
23
+ // AuthenticationInsecurePlain
24
+ const AuthenticationInsecurePlain AuthenticationMode = "plain"
18
25
19
- const AuthenticationInsecurePlain authenticationMode = "plain"
20
- const AuthenticationDHAES authenticationMode = "dh-ietf1024-sha256-aes128-cbc-pkcs7"
26
+ // AuthenticationDHAES
27
+ const AuthenticationDHAES AuthenticationMode = "dh-ietf1024-sha256-aes128-cbc-pkcs7"
21
28
29
+ // NilFlags
22
30
const NilFlags = 0
23
31
32
+ // Attributes
24
33
type Attributes map [string ]string
25
34
35
+ // Secret
26
36
type Secret struct {
27
37
Session dbus.ObjectPath
28
38
Parameters []byte
29
39
Value []byte
30
40
ContentType string
31
41
}
32
42
43
+ // PromptCompletedResult
33
44
type PromptCompletedResult struct {
34
45
Dismissed bool
35
46
Paths dbus.Variant
36
47
}
37
48
49
+ // SecretService
38
50
type SecretService struct {
39
51
conn * dbus.Conn
40
52
signalCh <- chan * dbus.Signal
41
53
sessionOpenTimeout time.Duration
42
54
}
43
55
56
+ // Session
44
57
type Session struct {
45
- Mode authenticationMode
58
+ Mode AuthenticationMode
46
59
Path dbus.ObjectPath
47
60
Public * big.Int
48
61
Private * big.Int
49
62
AESKey []byte
50
63
}
51
64
65
+ // DefaultSessionOpenTimeout
52
66
const DefaultSessionOpenTimeout = 10 * time .Second
53
67
68
+ // NewService
54
69
func NewService () (* SecretService , error ) {
55
70
conn , err := dbus .SessionBus ()
56
71
if err != nil {
@@ -61,14 +76,17 @@ func NewService() (*SecretService, error) {
61
76
return & SecretService {conn : conn , signalCh : signalCh , sessionOpenTimeout : DefaultSessionOpenTimeout }, nil
62
77
}
63
78
79
+ // SetSessionOpenTimeout
64
80
func (s * SecretService ) SetSessionOpenTimeout (d time.Duration ) {
65
81
s .sessionOpenTimeout = d
66
82
}
67
83
84
+ // ServiceObj
68
85
func (s * SecretService ) ServiceObj () * dbus.Object {
69
86
return s .conn .Object (SecretServiceInterface , SecretServiceObjectPath )
70
87
}
71
88
89
+ // Obj
72
90
func (s * SecretService ) Obj (path dbus.ObjectPath ) * dbus.Object {
73
91
return s .conn .Object (SecretServiceInterface , path )
74
92
}
@@ -78,14 +96,15 @@ type sessionOpenResponse struct {
78
96
path dbus.ObjectPath
79
97
}
80
98
81
- func (s * SecretService ) openSessionRaw (mode authenticationMode , sessionAlgorithmInput dbus.Variant ) (resp sessionOpenResponse , err error ) {
99
+ func (s * SecretService ) openSessionRaw (mode AuthenticationMode , sessionAlgorithmInput dbus.Variant ) (resp sessionOpenResponse , err error ) {
82
100
err = s .ServiceObj ().
83
101
Call ("org.freedesktop.Secret.Service.OpenSession" , NilFlags , mode , sessionAlgorithmInput ).
84
102
Store (& resp .algorithmOutput , & resp .path )
85
103
return resp , errors .Wrap (err , "failed to open secretservice session" )
86
104
}
87
105
88
- func (s * SecretService ) OpenSession (mode authenticationMode ) (session * Session , err error ) {
106
+ // OpenSession
107
+ func (s * SecretService ) OpenSession (mode AuthenticationMode ) (session * Session , err error ) {
89
108
var sessionAlgorithmInput dbus.Variant
90
109
91
110
session = new (Session )
@@ -157,10 +176,12 @@ func (s *SecretService) OpenSession(mode authenticationMode) (session *Session,
157
176
return session , nil
158
177
}
159
178
179
+ // CloseSession
160
180
func (s * SecretService ) CloseSession (session * Session ) {
161
181
s .Obj (session .Path ).Call ("org.freedesktop.Secret.Session.Close" , NilFlags )
162
182
}
163
183
184
+ // SearchColleciton
164
185
func (s * SecretService ) SearchCollection (collection dbus.ObjectPath , attributes Attributes ) (items []dbus.ObjectPath , err error ) {
165
186
err = s .Obj (collection ).
166
187
Call ("org.freedesktop.Secret.Collection.SearchItems" , NilFlags , attributes ).
@@ -171,11 +192,16 @@ func (s *SecretService) SearchCollection(collection dbus.ObjectPath, attributes
171
192
return items , nil
172
193
}
173
194
195
+ // ReplaceBehavior
174
196
type ReplaceBehavior int
175
197
198
+ // ReplaceBehaviorDoNotReplace
176
199
const ReplaceBehaviorDoNotReplace = 0
200
+
201
+ // ReplaceBehaviorReplace
177
202
const ReplaceBehaviorReplace = 1
178
203
204
+ // CreateItem
179
205
func (s * SecretService ) CreateItem (collection dbus.ObjectPath , properties map [string ]dbus.Variant , secret Secret , replaceBehavior ReplaceBehavior ) (item dbus.ObjectPath , err error ) {
180
206
var replace bool
181
207
switch replaceBehavior {
@@ -201,6 +227,7 @@ func (s *SecretService) CreateItem(collection dbus.ObjectPath, properties map[st
201
227
return item , nil
202
228
}
203
229
230
+ // DeleteItem
204
231
func (s * SecretService ) DeleteItem (item dbus.ObjectPath ) (err error ) {
205
232
var prompt dbus.ObjectPath
206
233
err = s .Obj (item ).
@@ -216,6 +243,7 @@ func (s *SecretService) DeleteItem(item dbus.ObjectPath) (err error) {
216
243
return nil
217
244
}
218
245
246
+ // GetAttributes
219
247
func (s * SecretService ) GetAttributes (item dbus.ObjectPath ) (attributes Attributes , err error ) {
220
248
attributesV , err := s .Obj (item ).GetProperty ("org.freedesktop.Secret.Item.Attributes" )
221
249
if err != nil {
@@ -228,6 +256,7 @@ func (s *SecretService) GetAttributes(item dbus.ObjectPath) (attributes Attribut
228
256
return Attributes (attributesMap ), nil
229
257
}
230
258
259
+ // GetSecret
231
260
func (s * SecretService ) GetSecret (item dbus.ObjectPath , session Session ) (secretPlaintext []byte , err error ) {
232
261
var secretI []interface {}
233
262
err = s .Obj (item ).
@@ -258,8 +287,10 @@ func (s *SecretService) GetSecret(item dbus.ObjectPath, session Session) (secret
258
287
return secretPlaintext , nil
259
288
}
260
289
290
+ // NullPrompt
261
291
const NullPrompt = "/"
262
292
293
+ // Unlock
263
294
func (s * SecretService ) Unlock (items []dbus.ObjectPath ) (err error ) {
264
295
var dummy []dbus.ObjectPath
265
296
var prompt dbus.ObjectPath
@@ -276,6 +307,7 @@ func (s *SecretService) Unlock(items []dbus.ObjectPath) (err error) {
276
307
return nil
277
308
}
278
309
310
+ // LockItems
279
311
func (s * SecretService ) LockItems (items []dbus.ObjectPath ) (err error ) {
280
312
var dummy []dbus.ObjectPath
281
313
var prompt dbus.ObjectPath
@@ -292,10 +324,12 @@ func (s *SecretService) LockItems(items []dbus.ObjectPath) (err error) {
292
324
return nil
293
325
}
294
326
327
+ // PromptDismissedError
295
328
type PromptDismissedError struct {
296
329
err error
297
330
}
298
331
332
+ // Error
299
333
func (p PromptDismissedError ) Error () string {
300
334
return p .err .Error ()
301
335
}
@@ -336,13 +370,15 @@ func (s *SecretService) PromptAndWait(prompt dbus.ObjectPath) (paths *dbus.Varia
336
370
}
337
371
}
338
372
373
+ // NewSecretProperties
339
374
func NewSecretProperties (label string , attributes map [string ]string ) map [string ]dbus.Variant {
340
375
return map [string ]dbus.Variant {
341
376
"org.freedesktop.Secret.Item.Label" : dbus .MakeVariant (label ),
342
377
"org.freedesktop.Secret.Item.Attributes" : dbus .MakeVariant (attributes ),
343
378
}
344
379
}
345
380
381
+ // NewSecret
346
382
func (session * Session ) NewSecret (secretBytes []byte ) (Secret , error ) {
347
383
switch session .Mode {
348
384
case AuthenticationInsecurePlain :
0 commit comments