Allow Remote sessions to outlive connection forms

This commit is contained in:
ak47 committed 2026-11-04 17:19:19 -05:00
1 parent b60cf5d5f2
commit b4896a2eb4
10 files changed
+233 -16

No files matched your search

+8 -1
View File
@@ -26,6 +26,9 @@ type Interaction struct {
Done bool `json:"done,omitempty"`
Reader *ReaderRequest `json:"reader,omitempty"`
Remote *RemoteRequest `json:"remote,omitempty"`
// RemoteBackground ends this interaction while retaining an already-open
// lease owned by this process session. It grants no new access or lifetime.
RemoteBackground *RemoteLease `json:"remote_background,omitempty"`
}
// RemoteRequest asks the reader to show its own local consent form. It never
@@ -80,7 +83,11 @@ func DecodeInteraction(data []byte) (Interaction, error) {
if value.Source != "" && value.Source != "focus" && value.Source != "clipboard" {
return value, ErrProtocol
}
if value.Remote != nil {
if value.RemoteBackground != nil {
if len(value.RemoteBackground.Lease) != 32 || value.RemoteBackground.Epoch == 0 || !value.Done || value.Next != "" || value.Poll != "" || value.Form != nil || value.Source != "" || value.Clipboard != nil || value.Reader != nil || value.Remote != nil || value.Uninterruptible {
return value, ErrProtocol
}
} else if value.Remote != nil {
if !ValidRoleGrants(value.Remote.Role, value.Remote.Grants) || value.Next == "" || value.Reader != nil || value.Form != nil || value.Source != "" || value.Poll != "" || value.Clipboard != nil || value.Done {
return value, ErrProtocol
}
@@ -4,6 +4,7 @@ package tentaclewire
import (
"encoding/json"
"strings"
"testing"
)
@@ -32,3 +33,29 @@ func TestRemoteConsentInteractionValidation(t *testing.T) {
}
}
}
func TestRemoteBackgroundInteractionValidation(t *testing.T) {
lease := RemoteLease{Lease: strings.Repeat("a", 32), Epoch: 1}
valid := Interaction{RemoteBackground: &lease, Done: true, Presentation: Presentation{Speech: "Connection controls closed"}}
data, _ := json.Marshal(valid)
if _, err := DecodeInteraction(data); err != nil {
t.Fatal(err)
}
for _, raw := range []string{
`{"remote_background":null,"done":true}`,
`{"remote_background":{"lease":"short","epoch":1},"done":true}`,
`{"remote_background":{"lease":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","epoch":0},"done":true}`,
`{"remote_background":{"lease":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","epoch":1,"session":"other"},"done":true}`,
`{"remote_background":{"lease":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","epoch":1}}`,
} {
if _, err := DecodeInteraction([]byte(raw)); err == nil {
t.Fatal("invalid background interaction accepted", raw)
}
}
for _, field := range []string{`"form":{"title":"Menu","elements":[]}`, `"next":"submit"`, `"poll":"poll"`, `"source":"focus"`, `"clipboard":"text"`, `"reader":{"snapshot":true}`, `"remote":{"role":"controller","grants":["remote-present"]}`, `"uninterruptible":true`} {
raw := `{"remote_background":{"lease":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","epoch":1},"done":true,"speech":"Closed",` + field + `}`
if _, err := DecodeInteraction([]byte(raw)); err == nil {
t.Fatal("background interaction mixed with another effect", field)
}
}
}