Implements the SSH relay server (Task 2.1) that validates single-use Redis tokens via GETDEL, dials SSH to the target device with PTY, and bridges WebSocket binary/text frames to SSH stdin/stdout/stderr with idle timeout and per-user/per-device session limits. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
29 lines
509 B
Go
29 lines
509 B
Go
package sshrelay
|
|
|
|
import (
|
|
"context"
|
|
"sync/atomic"
|
|
"time"
|
|
|
|
"golang.org/x/crypto/ssh"
|
|
)
|
|
|
|
type Session struct {
|
|
ID string
|
|
DeviceID string
|
|
TenantID string
|
|
UserID string
|
|
SourceIP string
|
|
StartTime time.Time
|
|
LastActive int64 // atomic, unix nanoseconds
|
|
sshClient *ssh.Client
|
|
sshSession *ssh.Session
|
|
ptyCols int
|
|
ptyRows int
|
|
cancel context.CancelFunc
|
|
}
|
|
|
|
func (s *Session) IdleDuration() time.Duration {
|
|
return time.Since(time.Unix(0, atomic.LoadInt64(&s.LastActive)))
|
|
}
|