Skip to content

Commit 5c15109

Browse files
committed
feature: Add remote-control server based on team protocol
1 parent 504a9d0 commit 5c15109

16 files changed

+790
-156
lines changed

config/ssl-game-controller.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ server:
1212
address: :10008
1313
address-tls: :10108
1414
trusted-keys-dir: config/trusted_keys/team
15+
remote-control:
16+
address: :10011
17+
address-tls: :10111
18+
trusted-keys-dir: config/trusted_keys/remote-control
1519
ci:
1620
address: :10009
1721
engine:

generateProto.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_gc_referee_m
2828
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_gc_rcon.proto
2929
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_gc_rcon_autoref.proto
3030
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_gc_rcon_team.proto
31+
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_gc_rcon_remotecontrol.proto
3132

3233
# internal communication
3334
protoc -I"./proto" -I"$GOPATH/src" --go_out="$GOPATH/src" proto/ssl_gc_state.proto

internal/app/config/config.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ type Network struct {
7070

7171
// Server holds configs for the available server services
7272
type Server struct {
73-
AutoRef ServerAutoRef `yaml:"auto-ref"`
74-
Team ServerTeam `yaml:"team"`
75-
Ci ServerCi `yaml:"ci"`
73+
AutoRef ServerAutoRef `yaml:"auto-ref"`
74+
Team ServerTeam `yaml:"team"`
75+
Ci ServerCi `yaml:"ci"`
76+
RemoteControl RemoteControlTeam `yaml:"remote-control"`
7677
}
7778

7879
// ServerAutoRef holds configs for the autoRef server
@@ -89,6 +90,13 @@ type ServerTeam struct {
8990
TrustedKeysDir string `yaml:"trusted-keys-dir"`
9091
}
9192

93+
// RemoteControlTeam holds configs for the remote control server
94+
type RemoteControlTeam struct {
95+
Address string `yaml:"address"`
96+
AddressTls string `yaml:"address-tls"`
97+
TrustedKeysDir string `yaml:"trusted-keys-dir"`
98+
}
99+
92100
// ServerCi holds configs for the CI server
93101
type ServerCi struct {
94102
Address string `yaml:"address"`
@@ -197,6 +205,9 @@ func DefaultControllerConfig() (c Controller) {
197205
c.Server.Team.Address = ":10008"
198206
c.Server.Team.AddressTls = ":10108"
199207
c.Server.Team.TrustedKeysDir = "config/trusted_keys/team"
208+
c.Server.RemoteControl.Address = ":10011"
209+
c.Server.RemoteControl.AddressTls = ":10111"
210+
c.Server.RemoteControl.TrustedKeysDir = "config/trusted_keys/remote-control"
200211
c.Server.Ci.Address = ":10009"
201212

202213
c.Game.DefaultGeometry = map[Division]Geometry{}

internal/app/config/testdata/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ server:
1212
address: :10008
1313
address-tls: :10108
1414
trusted-keys-dir: config/trusted_keys/team
15+
remote-control:
16+
address: :10011
17+
address-tls: :10111
18+
trusted-keys-dir: config/trusted_keys/remote-control
1519
ci:
1620
address: :10009
1721
engine:

internal/app/engine/ssl_gc_engine.pb.go

Lines changed: 60 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/app/gc/gc.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ import (
1313

1414
// GameController contains all the different connected modules of the game controller
1515
type GameController struct {
16-
config config.Controller
17-
gcEngine *engine.Engine
18-
publisher *publish.Publisher
19-
messageGenerator *publish.MessageGenerator
20-
apiServer *api.Server
21-
autoRefServer *rcon.AutoRefServer
22-
autoRefServerTls *rcon.AutoRefServer
23-
teamServer *rcon.TeamServer
24-
teamServerTls *rcon.TeamServer
25-
ciServer *ci.Server
26-
visionReceiver *vision.Receiver
27-
trackerReceiver *tracker.Receiver
16+
config config.Controller
17+
gcEngine *engine.Engine
18+
publisher *publish.Publisher
19+
messageGenerator *publish.MessageGenerator
20+
apiServer *api.Server
21+
autoRefServer *rcon.AutoRefServer
22+
autoRefServerTls *rcon.AutoRefServer
23+
teamServer *rcon.TeamServer
24+
teamServerTls *rcon.TeamServer
25+
remoteControlServer *rcon.RemoteControlServer
26+
remoteControlServerTls *rcon.RemoteControlServer
27+
ciServer *ci.Server
28+
visionReceiver *vision.Receiver
29+
trackerReceiver *tracker.Receiver
2830
}
2931

3032
// NewGameController creates a new GameController
@@ -41,6 +43,9 @@ func NewGameController(cfg config.Controller) (c *GameController) {
4143
c.teamServer = rcon.NewTeamServer(cfg.Server.Team.Address, c.gcEngine)
4244
c.teamServerTls = rcon.NewTeamServer(cfg.Server.Team.AddressTls, c.gcEngine)
4345
c.teamServerTls.Tls = true
46+
c.remoteControlServer = rcon.NewRemoteControlServer(cfg.Server.RemoteControl.Address, c.gcEngine)
47+
c.remoteControlServerTls = rcon.NewRemoteControlServer(cfg.Server.RemoteControl.AddressTls, c.gcEngine)
48+
c.remoteControlServerTls.Tls = true
4449
c.ciServer = ci.NewServer(cfg.Server.Ci.Address)
4550
c.visionReceiver = vision.NewReceiver(cfg.Network.VisionAddress)
4651
c.visionReceiver.GeometryCallback = c.gcEngine.ProcessGeometry
@@ -77,6 +82,8 @@ func (c *GameController) Start() {
7782
c.autoRefServerTls.Server.Start()
7883
c.teamServer.Server.Start()
7984
c.teamServerTls.Server.Start()
85+
c.remoteControlServer.Server.Start()
86+
c.remoteControlServerTls.Server.Start()
8087

8188
if err := c.gcEngine.Start(); err != nil {
8289
panic(err)
@@ -95,6 +102,8 @@ func (c *GameController) Stop() {
95102
c.autoRefServerTls.Server.Stop()
96103
c.teamServer.Server.Stop()
97104
c.teamServerTls.Server.Stop()
105+
c.remoteControlServer.Server.Stop()
106+
c.remoteControlServerTls.Server.Stop()
98107
c.gcEngine.Stop()
99108
}
100109

internal/app/rcon/autoref.go

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (c *AutoRefClient) receiveRegistration(server *AutoRefServer) error {
4747
}
4848
c.pubKey = server.trustedKeys[c.id]
4949
if c.pubKey != nil {
50-
if err := c.verifyRegistration(registration); err != nil {
50+
if err := c.Client.verifyMessage(&registration); err != nil {
5151
return err
5252
}
5353
} else {
@@ -59,50 +59,6 @@ func (c *AutoRefClient) receiveRegistration(server *AutoRefServer) error {
5959
return nil
6060
}
6161

62-
func (c *AutoRefClient) verifyRegistration(registration AutoRefRegistration) error {
63-
if registration.Signature == nil {
64-
return errors.New("Missing signature")
65-
}
66-
if registration.Signature.Token == nil || *registration.Signature.Token != c.token {
67-
sendToken := ""
68-
if registration.Signature.Token != nil {
69-
sendToken = *registration.Signature.Token
70-
}
71-
return errors.Errorf("AutoRef Client %v sent an invalid token: %v != %v", c.id, sendToken, c.token)
72-
}
73-
signature := registration.Signature.Pkcs1V15
74-
registration.Signature.Pkcs1V15 = []byte{}
75-
err := VerifySignature(c.pubKey, &registration, signature)
76-
registration.Signature.Pkcs1V15 = signature
77-
if err != nil {
78-
return errors.New("Invalid signature")
79-
}
80-
c.token = uuid.New()
81-
return nil
82-
}
83-
84-
func (c *AutoRefClient) verifyRequest(req AutoRefToController) error {
85-
if req.Signature == nil {
86-
return errors.New("Missing signature")
87-
}
88-
if req.Signature.Token == nil || *req.Signature.Token != c.token {
89-
sendToken := ""
90-
if req.Signature.Token != nil {
91-
sendToken = *req.Signature.Token
92-
}
93-
return errors.Errorf("Invalid token: %v != %v", sendToken, c.token)
94-
}
95-
signature := req.Signature.Pkcs1V15
96-
req.Signature.Pkcs1V15 = []byte{}
97-
err := VerifySignature(c.pubKey, &req, signature)
98-
req.Signature.Pkcs1V15 = signature
99-
if err != nil {
100-
return errors.Wrap(err, "Verification failed.")
101-
}
102-
c.token = uuid.New()
103-
return nil
104-
}
105-
10662
func (s *AutoRefServer) handleClientConnection(conn net.Conn) {
10763
defer func() {
10864
if err := conn.Close(); err != nil {
@@ -154,7 +110,7 @@ func (s *AutoRefServer) handleClientConnection(conn net.Conn) {
154110
continue
155111
}
156112
if client.pubKey != nil {
157-
if err := client.verifyRequest(req); err != nil {
113+
if err := client.verifyMessage(&req); err != nil {
158114
client.reply(client.Reject(err.Error()))
159115
continue
160116
}

internal/app/rcon/rconserver.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"crypto/x509"
99
"encoding/pem"
1010
"github.com/golang/protobuf/proto"
11+
"github.com/odeke-em/go-uuid"
1112
"github.com/pkg/errors"
1213
"io/ioutil"
1314
"log"
@@ -33,6 +34,11 @@ type Client struct {
3334
verifiedConnection bool
3435
}
3536

37+
type SignedMessage interface {
38+
GetSignature() *Signature
39+
proto.Message
40+
}
41+
3642
func NewServer(address string) (s *Server) {
3743
s = new(Server)
3844
s.address = address
@@ -200,3 +206,26 @@ func VerifySignature(key *rsa.PublicKey, message proto.Message, signature []byte
200206
d := hash.Sum(nil)
201207
return rsa.VerifyPKCS1v15(key, crypto.SHA256, d, signature)
202208
}
209+
210+
func (c *Client) verifyMessage(message SignedMessage) error {
211+
signature := message.GetSignature()
212+
if signature == nil {
213+
return errors.New("Missing signature")
214+
}
215+
if signature.Token == nil || *signature.Token != c.token {
216+
sendToken := ""
217+
if signature.Token != nil {
218+
sendToken = *signature.Token
219+
}
220+
return errors.Errorf("Client %v sent an invalid token: %v != %v", c.id, sendToken, c.token)
221+
}
222+
sig := signature.Pkcs1V15
223+
signature.Pkcs1V15 = []byte{}
224+
err := VerifySignature(c.pubKey, message, sig)
225+
signature.Pkcs1V15 = sig
226+
if err != nil {
227+
return errors.New("Invalid signature")
228+
}
229+
c.token = uuid.New()
230+
return nil
231+
}

0 commit comments

Comments
 (0)