Skip to content

Commit

Permalink
Fix TLS version parsing (elastic#5800) (elastic#5952)
Browse files Browse the repository at this point in the history
Instead of reporting the raw version as encoded in the protocol (3.x),
identify SSL 3.0 (version 3.0) and TLS 1.x (versions 3.1 and up)
  • Loading branch information
adriansr authored and andrewkroh committed Dec 23, 2017
1 parent 04faf07 commit e621418
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 7 additions & 1 deletion packetbeat/protos/tls/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,13 @@ func parseCertificates(buffer bufferView) []*x509.Certificate {
}

func (version tlsVersion) String() string {
return fmt.Sprintf("%d.%d", version.major, version.minor)
if version.major == 3 {
if version.minor > 0 {
return fmt.Sprintf("TLS 1.%d", version.minor-1)
}
return "SSL 3.0"
}
return fmt.Sprintf("(raw %d.%d)", version.major, version.minor)
}

func getKeySize(key interface{}) int {
Expand Down
10 changes: 5 additions & 5 deletions packetbeat/protos/tls/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ func TestParseRecordHeader(t *testing.T) {
assert.NotNil(t, err)
_, err = readRecordHeader(sBuf(t, "11223344"))
assert.NotNil(t, err)
header, err := readRecordHeader(sBuf(t, "1122334455"))
header, err := readRecordHeader(sBuf(t, "1103024455"))
assert.Nil(t, err)
assert.Equal(t, recordType(0x11), header.recordType)
assert.Equal(t, "34.51", header.version.String())
assert.Equal(t, "TLS 1.1", header.version.String())
assert.Equal(t, uint16(0x4455), header.length)
assert.Equal(t, "recordHeader type[17] version[34.51] length[17493]", header.String())
assert.False(t, header.isValid())
header.version.major = 3
assert.Equal(t, "recordHeader type[17] version[TLS 1.1] length[17493]", header.String())
assert.True(t, header.isValid())
header.version.major = 2
assert.False(t, header.isValid())
}

func TestParseHandshakeHeader(t *testing.T) {
Expand Down

0 comments on commit e621418

Please sign in to comment.