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
d1f646e7eb
commit
7e062f5777
@ -41,7 +41,7 @@ func (listener AgentListener) Accept() (net.Conn, error) {
|
|||||||
conn.Close()
|
conn.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
conn = NewLocalAddrHackConn(conn, clientId)
|
conn = NewLocalAddrHackConn(conn, clientId.ClientId)
|
||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ func (s *AgentServerTestSuite) Test_clientIdPassedAsLocalAddr() {
|
|||||||
func() any {
|
func() any {
|
||||||
connection, err := serverChannel.Session.OpenStream()
|
connection, err := serverChannel.Session.OpenStream()
|
||||||
s.Nil(err)
|
s.Nil(err)
|
||||||
err = SendClientInfo(connection, clientId)
|
err = SendClientInfo(connection, ClientInfo{ClientId: clientId})
|
||||||
s.Nil(err)
|
s.Nil(err)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package comms
|
package comms
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/hashicorp/yamux"
|
"github.com/hashicorp/yamux"
|
||||||
"io"
|
"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
|
// decorates the yamux Session (which is a listener) and uses this connection to exchange some
|
||||||
// metadata before the connection is handed back to SSH.
|
// metadata before the connection is handed back to SSH.
|
||||||
|
|
||||||
// Cannot use GOB for sending clientinfo since this involves mixing of buffered reads by
|
func SendClientInfo(conn io.ReadWriter, info ClientInfo) error {
|
||||||
// GOB with ather reads. Alternatively, we could wrap the GOB message and encode its length,
|
channel := NewGOBChannel(conn)
|
||||||
// and then read the exacct number of bytes when decodeing. But since the clientInfo is just
|
return SendWithTimeout(channel, info)
|
||||||
// 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 ReceiveClientInfo(conn io.Reader) (string, error) {
|
func ReceiveClientInfo(conn io.ReadWriter) (ClientInfo, error) {
|
||||||
var length uint32
|
channel := NewGOBChannel(conn)
|
||||||
err := binary.Read(conn, binary.BigEndian, &length)
|
clientInfo, err := ReceiveWithTimeout[ClientInfo](channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return ClientInfo{}, err
|
||||||
}
|
}
|
||||||
bytes := make([]byte, length)
|
return clientInfo, nil
|
||||||
_, err = io.ReadFull(conn, bytes)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(bytes), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// message sent on the initial connection from server to agent to confirm the registration
|
// 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() {
|
func (s *AgentServerTestSuite) TestClientInfoEncodeDecode() {
|
||||||
for _, clientId := range []string{"abc", "djkdfadfha"} {
|
for _, clientId := range []string{"abc", "djkdfadfha"} {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
err := SendClientInfo(buf, clientId)
|
err := SendClientInfo(buf, ClientInfo{ClientId: clientId})
|
||||||
s.Nil(err)
|
s.Nil(err)
|
||||||
clientIdReceived, err := ReceiveClientInfo(buf)
|
clientIdReceived, err := ReceiveClientInfo(buf)
|
||||||
s.Nil(err)
|
s.Nil(err)
|
||||||
s.Equal(clientId, clientIdReceived)
|
s.Equal(clientId, clientIdReceived.ClientId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,10 @@ type EnvironmentInfo struct {
|
|||||||
Shell string
|
Shell string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ClientInfo struct {
|
||||||
|
ClientId string
|
||||||
|
}
|
||||||
|
|
||||||
type SessionInfo struct {
|
type SessionInfo struct {
|
||||||
ClientId string
|
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
|
// Before using this connection for SSH we use it to send client metadata to the
|
||||||
// agent
|
// agent
|
||||||
err = comms.SendClientInfo(agentConn, string(client.Info.ClientId))
|
err = comms.SendClientInfo(agentConn, comms.ClientInfo{ClientId: string(client.Info.ClientId)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user