feat(bsr): Remove ascii format of protocol
This was originally introduced to ensure that the meta files only included ascii characters. However, this makes reading the protocol from meta file less reliable since it does not exactly match the protocol string. Instead protocol strings will be recorded in the meta files as is. Generally protocol strings should include readable characters. This also updates the ssh.Protocol to be 4 readable characters.
This commit is contained in:
5 files changed
+5
-50
No files matched your search
@@ -21,10 +21,10 @@ func TestPopulateMeta(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
sessionId := "session"
|
||||
sessionProtocol := "TEST"
|
||||
sessionProtocol := Protocol("TEST")
|
||||
|
||||
// Populate session meta
|
||||
sessionMeta := TestSessionMeta(sessionId, Protocol((sessionProtocol)))
|
||||
sessionMeta := TestSessionMeta(sessionId, sessionProtocol)
|
||||
s, err := NewSession(ctx, sessionMeta, &fstest.MemFS{}, keys, WithSupportsMultiplex(true))
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, s)
|
||||
@@ -35,7 +35,7 @@ func TestPopulateMeta(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
s.Meta = sm
|
||||
require.Equal(t, s.Meta.Id, sessionId)
|
||||
require.Equal(t, s.Meta.Protocol.ToText(), sessionProtocol)
|
||||
require.Equal(t, s.Meta.Protocol, sessionProtocol)
|
||||
require.Equal(t, s.Meta.Target, sessionMeta.Target)
|
||||
require.Equal(t, s.Meta.User, sessionMeta.User)
|
||||
require.Equal(t, s.Meta.StaticHost, sessionMeta.StaticHost)
|
||||
|
||||
@@ -738,7 +738,7 @@ func (s SessionMeta) writeMeta(ctx context.Context, c *container) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.WriteMeta(ctx, "protocol", s.Protocol.ToText())
|
||||
_, err = c.WriteMeta(ctx, "protocol", string(s.Protocol))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
package bsr
|
||||
|
||||
import "regexp"
|
||||
|
||||
// Protocol identifies the protocol of the data captured in a chunk.
|
||||
type Protocol string
|
||||
|
||||
@@ -12,10 +10,3 @@ type Protocol string
|
||||
func ValidProtocol(p Protocol) bool {
|
||||
return len(p) <= protocolSize
|
||||
}
|
||||
|
||||
// ToText converts a protocol to a text-safe string
|
||||
func (p Protocol) ToText() string {
|
||||
re := regexp.MustCompile("[[:^ascii:]]")
|
||||
t := re.ReplaceAllLiteralString(string(p), "")
|
||||
return t
|
||||
}
|
||||
@@ -35,39 +35,3 @@ func TestValidProtocol(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestToText(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
in bsr.Protocol
|
||||
want string
|
||||
}{
|
||||
{
|
||||
"all ascii",
|
||||
bsr.Protocol("BOOM"),
|
||||
"BOOM",
|
||||
},
|
||||
{
|
||||
"not all ascii",
|
||||
bsr.Protocol("SSH\x87"),
|
||||
"SSH",
|
||||
},
|
||||
{
|
||||
"mostly not ascii",
|
||||
bsr.Protocol("S\x89\x99\x87"),
|
||||
"S",
|
||||
},
|
||||
{
|
||||
"no ascii",
|
||||
bsr.Protocol("\x95\x89\x99\x87"),
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got := tc.in.ToText()
|
||||
assert.Equal(t, tc.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ func init() {
|
||||
|
||||
const (
|
||||
// Protocol is used to identify chunks that are recorded from SSH.
|
||||
Protocol bsr.Protocol = "SSH\x87"
|
||||
Protocol bsr.Protocol = "BSSH"
|
||||
|
||||
// MaxPacketSize is used by the DataWriter to determine if SSH data should
|
||||
// be broken into multiple chunks.
|
||||
|
||||
Reference in new issue
Block a user