reintroduced ClientInfo because it does appear to work.
Most likely some error elsewhere caused it not to work previously
This commit is contained in:
parent
d21f9c847f
commit
78e3556787
@ -41,7 +41,7 @@ func (listener AgentListener) Accept() (net.Conn, error) {
|
||||
conn.Close()
|
||||
return nil, err
|
||||
}
|
||||
conn = NewLocalAddrHackConn(conn, clientId)
|
||||
conn = NewLocalAddrHackConn(conn, clientId.ClientId)
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ func (s *AgentServerTestSuite) Test_clientIdPassedAsLocalAddr() {
|
||||
func() any {
|
||||
connection, err := serverChannel.Session.OpenStream()
|
||||
s.Nil(err)
|
||||
err = SendClientInfo(connection, clientId)
|
||||
err = SendClientInfo(connection, ClientInfo{ClientId: clientId})
|
||||
s.Nil(err)
|
||||
return nil
|
||||
})
|
||||
|
@ -1,7 +1,6 @@
|
||||
package comms
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"github.com/hashicorp/yamux"
|
||||
"io"
|
||||
@ -227,31 +226,18 @@ func CheckProtocolVersion(role Role, channel GOBChannel) error {
|
||||
// decorates the yamux Session (which is a listener) and uses this connection to exchange some
|
||||
// metadata before the connection is handed back to SSH.
|
||||
|
||||
// Cannot use GOB for sending clientinfo since this involves mixing of buffered reads by
|
||||
// GOB with ather reads. Alternatively, we could wrap the GOB message and encode its length,
|
||||
// and then read the exacct number of bytes when decodeing. But since the clientInfo is just
|
||||
// a string, this is easier.
|
||||
func SendClientInfo(conn io.Writer, info string) error {
|
||||
err := binary.Write(conn, binary.BigEndian, uint32(len(info)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = conn.Write([]byte(info))
|
||||
return err
|
||||
func SendClientInfo(conn io.ReadWriter, info ClientInfo) error {
|
||||
channel := NewGOBChannel(conn)
|
||||
return SendWithTimeout(channel, info)
|
||||
}
|
||||
|
||||
func ReceiveClientInfo(conn io.Reader) (string, error) {
|
||||
var length uint32
|
||||
err := binary.Read(conn, binary.BigEndian, &length)
|
||||
func ReceiveClientInfo(conn io.ReadWriter) (ClientInfo, error) {
|
||||
channel := NewGOBChannel(conn)
|
||||
clientInfo, err := ReceiveWithTimeout[ClientInfo](channel)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return ClientInfo{}, err
|
||||
}
|
||||
bytes := make([]byte, length)
|
||||
_, err = io.ReadFull(conn, bytes)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(bytes), nil
|
||||
return clientInfo, nil
|
||||
}
|
||||
|
||||
// message sent on the initial connection from server to agent to confirm the registration
|
||||
|
@ -64,11 +64,11 @@ func TestAgentServerTestSuite(t *testing.T) {
|
||||
func (s *AgentServerTestSuite) TestClientInfoEncodeDecode() {
|
||||
for _, clientId := range []string{"abc", "djkdfadfha"} {
|
||||
buf := &bytes.Buffer{}
|
||||
err := SendClientInfo(buf, clientId)
|
||||
err := SendClientInfo(buf, ClientInfo{ClientId: clientId})
|
||||
s.Nil(err)
|
||||
clientIdReceived, err := ReceiveClientInfo(buf)
|
||||
s.Nil(err)
|
||||
s.Equal(clientId, clientIdReceived)
|
||||
s.Equal(clientId, clientIdReceived.ClientId)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,10 @@ type EnvironmentInfo struct {
|
||||
Shell string
|
||||
}
|
||||
|
||||
type ClientInfo struct {
|
||||
ClientId string
|
||||
}
|
||||
|
||||
type SessionInfo struct {
|
||||
ClientId string
|
||||
|
||||
|
@ -180,7 +180,7 @@ func (admin *Admin) AddClient(publicId models.RendezVousId, clientConn iowrapper
|
||||
|
||||
// Before using this connection for SSH we use it to send client metadata to the
|
||||
// agent
|
||||
err = comms.SendClientInfo(agentConn, string(client.Info.ClientId))
|
||||
err = comms.SendClientInfo(agentConn, comms.ClientInfo{ClientId: string(client.Info.ClientId)})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user