From 3d8a26981901dae2ff58b9dc77015997ea39d641 Mon Sep 17 00:00:00 2001 From: Owen Date: Thu, 4 Jun 2026 11:42:06 -0700 Subject: [PATCH] Fix windows compatibility issues Former-commit-id: 0e690a6a84ba4413f911e03f2a3edf14e9a5b81b --- browsergateway/ssh_native.go | 2 + browsergateway/ssh_native_windows.go | 16 +++++++ nativessh/pty.go | 2 + nativessh/server.go | 2 + nativessh/server_windows.go | 64 ++++++++++++++++++++++++++++ updates/advantech_windows.go | 8 ++++ 6 files changed, 94 insertions(+) create mode 100644 browsergateway/ssh_native_windows.go create mode 100644 nativessh/server_windows.go create mode 100644 updates/advantech_windows.go diff --git a/browsergateway/ssh_native.go b/browsergateway/ssh_native.go index 992f875..87adf92 100644 --- a/browsergateway/ssh_native.go +++ b/browsergateway/ssh_native.go @@ -1,3 +1,5 @@ +//go:build !windows + package browsergateway import ( diff --git a/browsergateway/ssh_native_windows.go b/browsergateway/ssh_native_windows.go new file mode 100644 index 0000000..3caff0a --- /dev/null +++ b/browsergateway/ssh_native_windows.go @@ -0,0 +1,16 @@ +//go:build windows + +package browsergateway + +import ( + "context" + "errors" + + "github.com/coder/websocket" + "github.com/fosrl/newt/nativessh" +) + +// serveNativeSSHSession is not supported on Windows. +func serveNativeSSHSession(_ context.Context, _ *websocket.Conn, _ string, _ *nativessh.CredentialStore) error { + return errors.New("native SSH is not supported on Windows") +} diff --git a/nativessh/pty.go b/nativessh/pty.go index 3d20e35..42cdd05 100644 --- a/nativessh/pty.go +++ b/nativessh/pty.go @@ -1,3 +1,5 @@ +//go:build !windows + package nativessh import ( diff --git a/nativessh/server.go b/nativessh/server.go index 0ccd7c3..20a13d9 100644 --- a/nativessh/server.go +++ b/nativessh/server.go @@ -1,3 +1,5 @@ +//go:build !windows + package nativessh import ( diff --git a/nativessh/server_windows.go b/nativessh/server_windows.go new file mode 100644 index 0000000..3394e13 --- /dev/null +++ b/nativessh/server_windows.go @@ -0,0 +1,64 @@ +//go:build windows + +package nativessh + +import ( + "errors" + "log" + "net" + "sync" + + "golang.org/x/crypto/ssh" +) + +// CredentialStore is a stub on Windows. Native SSH is not supported on Windows. +type CredentialStore struct { + mu sync.RWMutex + principals map[string]map[string]struct{} +} + +// NewCredentialStore returns an empty CredentialStore stub. +// Native SSH is not supported on Windows; a warning is logged. +func NewCredentialStore() *CredentialStore { + log.Println("WARNING: native SSH is not supported on Windows and will be disabled") + return &CredentialStore{ + principals: make(map[string]map[string]struct{}), + } +} + +// SetCAKey is a no-op stub on Windows. +func (s *CredentialStore) SetCAKey(_ string) error { + return errors.New("native SSH not supported on Windows") +} + +// AddPrincipals is a no-op stub on Windows. +func (s *CredentialStore) AddPrincipals(_, _ string) {} + +// get returns nil CA key and empty principals on Windows. +func (s *CredentialStore) get(_ string) (ssh.PublicKey, map[string]struct{}) { + return nil, nil +} + +// ServerConfig holds configuration for the native SSH server (stub on Windows). +type ServerConfig struct { + ListenAddr string + Credentials *CredentialStore +} + +// Server is a stub on Windows. +type Server struct{} + +// NewServer returns a stub Server and logs a warning. +func NewServer(cfg ServerConfig) *Server { + return &Server{} +} + +// ListenAndServe always returns an error on Windows. +func (s *Server) ListenAndServe() error { + return errors.New("native SSH not supported on Windows") +} + +// Serve always returns an error on Windows. +func (s *Server) Serve(_ net.Listener) error { + return errors.New("native SSH not supported on Windows") +} diff --git a/updates/advantech_windows.go b/updates/advantech_windows.go new file mode 100644 index 0000000..e6e302c --- /dev/null +++ b/updates/advantech_windows.go @@ -0,0 +1,8 @@ +//go:build windows + +package updates + +// postUpdateAdvantech is not supported on Windows. +func postUpdateAdvantech(newVersion, pidFile string) error { + return nil +}