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:
Timothy Messier committed 2023-05-31 12:18:21 +00:00
1 parent 4112c4e8fe
commit 916a919bf0
5 files changed
+5 -50

No files matched your search

+3 -3
View File
@@ -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)
+1 -1
View File
@@ -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
}
-9
View File
@@ -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
}
-36
View File
@@ -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)
})
}
}
+1 -1
View File
@@ -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.