Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 44 additions & 22 deletions cmd/wshd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/creack/pty"

"github.com/xconnio/berncrypt/go"
berncrypt "github.com/xconnio/berncrypt/go"
"github.com/xconnio/wamp-webrtc-go"
"github.com/xconnio/wampproto-go/serializers"
"github.com/xconnio/wampshell"
Expand Down Expand Up @@ -93,7 +93,6 @@ func (p *interactiveShellSession) handleShell(e *wampshell.EncryptionManager) fu
inv *xconn.Invocation) *xconn.InvocationResult {
return func(_ context.Context, inv *xconn.Invocation) *xconn.InvocationResult {
caller := inv.Caller()

key, ok := e.Key(inv.Caller())
if !ok {
return xconn.NewInvocationError("wamp.error.unavailable", "unavailable")
Expand Down Expand Up @@ -296,6 +295,11 @@ func addRealm(router *xconn.Router, realm string) {
}

func main() {
loadConfig, err := wampshell.LoadConfig()
if err != nil {
log.Fatalf("failed to load config: %v", err)
}

address := fmt.Sprintf("%s:%d", defaultHost, defaultPort)
path := os.ExpandEnv("$HOME/.wampshell/authorized_keys")

Expand All @@ -308,9 +312,13 @@ func main() {

authenticator := wampshell.NewAuthenticator(keyStore)

privateKey, err := wampshell.ReadPrivateKeyFromFile()
if err != nil {
log.Fatalf("Error reading private key: %s", err)
}

router := xconn.NewRouter()
addRealm(router, defaultRealm)

for realm := range authenticator.Realms() {
addRealm(router, realm)
}
Expand Down Expand Up @@ -356,28 +364,42 @@ func main() {
log.Fatalf("failed to connect to server: %v", err)
}

webRtcManager := wamp_webrtc_go.NewWebRTCHandler()
cfg := &wamp_webrtc_go.ProviderConfig{
Session: session,
ProcedureHandleOffer: procedureWebRTCOffer,
TopicHandleRemoteCandidates: topicAnswererOnCandidate,
TopicPublishLocalCandidate: topicOffererOnCandidate,
Serializer: &serializers.CBORSerializer{},
Authenticator: authenticator,
Router: router,
}
err = webRtcManager.Setup(cfg)
if err != nil {
log.Printf("Failed to setup WebRTC: %v", err)
return
var sessions []*xconn.Session
sessions = append(sessions, session)

for _, p := range loadConfig.Principals {
sess, err := xconn.ConnectCryptosign(context.Background(), p.URL, p.Realm, "", privateKey)
if err != nil {
continue
}

sessions = append(sessions, sess)
}

for _, proc := range procedures {
registerResponse := session.Register(proc.name, proc.handler).Do()
if registerResponse.Err != nil {
log.Fatalln(registerResponse.Err)
for _, sess := range sessions {
webRtcManager := wamp_webrtc_go.NewWebRTCHandler()
cfg := &wamp_webrtc_go.ProviderConfig{
Session: sess,
ProcedureHandleOffer: procedureWebRTCOffer,
TopicHandleRemoteCandidates: topicAnswererOnCandidate,
TopicPublishLocalCandidate: topicOffererOnCandidate,
Serializer: &serializers.CBORSerializer{},
Authenticator: authenticator,
Router: router,
}
err = webRtcManager.Setup(cfg)
if err != nil {
log.Printf("Failed to setup WebRTC: %v", err)
return
}

for _, proc := range procedures {
registerResponse := sess.Register(proc.name, proc.handler).Do()
if registerResponse.Err != nil {
log.Fatalln(registerResponse.Err)
}
log.Printf("Procedure registered: %s", proc.name)
}
log.Printf("Procedure registered: %s", proc.name)
}

log.Printf("listening on rs://%s", address)
Expand Down
34 changes: 34 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package wampshell

import (
"fmt"
"os"
"path/filepath"

"gopkg.in/yaml.v3"
)

type Config struct {
Principals []Principal `yaml:"principals"`
}

type Principal struct {
URL string `yaml:"url"`
Realm string `yaml:"realm"`
}

func LoadConfig() (*Config, error) {
configPath := filepath.Join(os.Getenv("HOME"), ".wampshell", "config.yaml")

data, err := os.ReadFile(configPath)
if err != nil {
return nil, fmt.Errorf("failed to read config: %w", err)
}

var cfg Config
if err := yaml.Unmarshal(data, &cfg); err != nil {
return nil, fmt.Errorf("failed to parse config: %w", err)
}

return &cfg, nil
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/xconnio/wampproto-go v0.0.0-20250915142018-1ae321b40fec
github.com/xconnio/xconn-go v0.0.0-20250918124058-95e16bcd2454
golang.org/x/term v0.35.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/jessevdk/go-flags v1.6.1 h1:Cvu5U8UGrLay1rZfv/zP7iLpSHGUZ/Ou68T0iX1bBK4=
github.com/jessevdk/go-flags v1.6.1/go.mod h1:Mk8T1hIAWpOiJiHa9rJASDK2UGWji0EuPGBnNLMooyc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw=
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
github.com/pion/datachannel v1.5.9 h1:LpIWAOYPyDrXtU+BW7X0Yt/vGtYxtXQ8ql7dFfYUVZA=
Expand Down Expand Up @@ -131,6 +135,8 @@ golang.org/x/term v0.35.0/go.mod h1:TPGtkTLesOwf2DE8CgVYiZinHAOuy5AYUYT1lENIZnA=
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading