跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

windows_host_enrollment.go

90 行 · 2.7 KB历史下载
1package guestos
2
3import (
4 "errors"
5 "fmt"
6 "syscall"
7
8 "github.com/google/uuid"
9)
10
11// WindowsHostEnrollmentPipeError exposes only a fixed operation and an OS code.
12// The underlying PathError can contain the private pipe name.
13type WindowsHostEnrollmentPipeError struct {
14 Operation string
15 Win32 syscall.Errno
16}
17
18func (err *WindowsHostEnrollmentPipeError) Error() string {
19 return fmt.Sprintf("enrollment_pipe_%s_failed (win32=%d)", err.Operation, err.Win32)
20}
21
22func enrollmentPipeError(operation string, err error) error {
23 var code syscall.Errno
24 errors.As(err, &code)
25 return &WindowsHostEnrollmentPipeError{Operation: operation, Win32: code}
26}
27
28// Options are captured by the original, unprivileged setup process. A pipe
29// client cannot replace these paths, identities, or installation choices.
30type WindowsHostEnrollmentOptions struct {
31 VMID uuid.UUID
32 InstallationID uuid.UUID
33 HostSID string
34 Profile string
35 State string
36 Pipe string
37 ParentPID uint32
38}
39
40type windowsHostEnrollmentRequest struct {
41 Version int `json:"version"`
42 Challenge string `json:"challenge"`
43 Action string `json:"action"`
44 VMID uuid.UUID `json:"vm_id"`
45 GUIUserSID string `json:"gui_user_sid,omitempty"`
46 PID uint32 `json:"pid,omitempty"`
47 ProcessHandle uint64 `json:"process_handle,omitempty"`
48}
49
50type windowsHostEnrollmentReply struct {
51 Version int `json:"version"`
52 OK bool `json:"ok"`
53 Challenge string `json:"challenge,omitempty"`
54 Authorized bool `json:"authorized,omitempty"`
55 Error string `json:"error,omitempty"`
56}
57
58func (request windowsHostEnrollmentRequest) validate(vm uuid.UUID, owner bool, guestSID string) error {
59 if request.Version != 1 || request.VMID != vm {
60 return errors.New("enrollment_request_invalid")
61 }
62 if owner {
63 switch request.Action {
64 case "ready", "stop":
65 if request.PID != 0 || request.ProcessHandle != 0 || request.GUIUserSID != "" {
66 return errors.New("enrollment_request_invalid")
67 }
68 case "allow-admin":
69 if request.PID == 0 || request.ProcessHandle == 0 || request.GUIUserSID != "" {
70 return errors.New("enrollment_request_invalid")
71 }
72 default:
73 return errors.New("enrollment_action_invalid")
74 }
75 } else {
76 if request.PID != 0 || request.ProcessHandle != 0 || !windowsGUISID.MatchString(request.GUIUserSID) || guestSID != "" && request.GUIUserSID != guestSID {
77 return errors.New("enrollment_request_invalid")
78 }
79 switch request.Action {
80 case "deliver-gui", "deliver-packet":
81 case "finalize":
82 if guestSID == "" {
83 return errors.New("enrollment_request_invalid")
84 }
85 default:
86 return errors.New("enrollment_action_invalid")
87 }
88 }
89 return nil
90}