Skip to content

Commit 6a3f018

Browse files
authored
Merge pull request #19 from rymdport/secret
WIP: Implement Secret interface
2 parents e1765e3 + 2a0ea03 commit 6a3f018

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ The list below contains all of the portal interfaces available within the projec
7676
- [x] Request
7777
- [ ] ScreenCast
7878
- [x] Screenshot
79-
- [ ] Secret
79+
- [x] Secret
8080
- [x] Session
8181
- [x] Settings
8282
- [x] Trash

secret/retrieve.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package secret
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/godbus/dbus/v5"
7+
"github.com/rymdport/portal/internal/apis"
8+
"github.com/rymdport/portal/internal/convert"
9+
"github.com/rymdport/portal/internal/request"
10+
)
11+
12+
const retrieveSecretCallName = interfaceName + ".RetrieveSecret"
13+
14+
// RetrieveOptions contains options for the RetrieveSecret function call.
15+
type RetrieveOptions struct {
16+
HandleToken string // A string that will be used as the last element of the handle. Must be a valid object path element.
17+
Token string // An opaque string returned by a previous org.freedesktop.portal.Secret.RetrieveSecret call.
18+
}
19+
20+
// RetrieveSecret retrieves a master secret for a sandboxed application.
21+
// The master secret is unique per application and does not change as
22+
// long as the application is installed (once it has been created).
23+
// In a typical backend implementation, it is stored in the user’s keyring,
24+
// under the application ID as a key.
25+
// The parameter fd is a writable file descriptor for transporting the secret.
26+
//
27+
// The portal may return an additional identifier associated with the secret in the results.
28+
// In the next call of this method, the application shall provide a token element in options.
29+
func RetrieveSecret(fd uintptr, options *RetrieveOptions) (string, error) {
30+
data := map[string]dbus.Variant{}
31+
if options != nil {
32+
if options.HandleToken != "" {
33+
data["handle_token"] = convert.FromString(options.HandleToken)
34+
}
35+
if options.Token != "" {
36+
data["token"] = convert.FromString(options.Token)
37+
}
38+
}
39+
40+
result, err := apis.Call(retrieveSecretCallName, dbus.UnixFD(fd), data)
41+
if err != nil {
42+
return "", err
43+
}
44+
45+
path := result.(dbus.ObjectPath)
46+
status, results, err := request.OnSignalResponse(path)
47+
if err != nil {
48+
return "", err
49+
} else if status > request.Success {
50+
return "", nil
51+
}
52+
53+
if token, ok := results["token"]; ok {
54+
return token.Value().(string), nil
55+
} else if len(results) != 0 {
56+
fmt.Println("Please contribute this information to rymdport/portal: ", results)
57+
}
58+
59+
return "", nil
60+
}

secret/secret.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Package secret allows sandboxed applications to retrieve a per-application secret. The secret can then be used for encrypting confidential data inside the sandbox.
2+
package secret
3+
4+
const interfaceName = "org.freedesktop.portal.Secret"

0 commit comments

Comments
 (0)