update vendor

This commit is contained in:
ginuerzh 2018-11-22 16:02:29 +08:00
parent a020c7bc33
commit aebd6842a9
2 changed files with 106 additions and 23 deletions

View File

@ -2,7 +2,9 @@ package dissector
import ( import (
"bytes" "bytes"
"crypto/tls"
"encoding/binary" "encoding/binary"
"fmt"
"io" "io"
) )
@ -62,6 +64,11 @@ func (h *ClientHelloHandshake) ReadFrom(r io.Reader) (n int64, err error) {
} }
length := int(b[1])<<16 | int(b[2])<<8 | int(b[3]) length := int(b[1])<<16 | int(b[2])<<8 | int(b[3])
if length < 34 { // length of version + random
err = fmt.Errorf("bad length, need at least 34 bytes, got %d", length)
return
}
b = make([]byte, length) b = make([]byte, length)
nn, err = io.ReadFull(r, b) nn, err = io.ReadFull(r, b)
n += int64(nn) n += int64(nn)
@ -69,6 +76,10 @@ func (h *ClientHelloHandshake) ReadFrom(r io.Reader) (n int64, err error) {
return return
} }
h.Version = Version(binary.BigEndian.Uint16(b[:2])) h.Version = Version(binary.BigEndian.Uint16(b[:2]))
if h.Version < tls.VersionTLS12 {
err = fmt.Errorf("bad version: only TLSv1.2 is supported")
return
}
pos := 2 pos := 2
h.Random.Time = binary.BigEndian.Uint32(b[pos : pos+4]) h.Random.Time = binary.BigEndian.Uint32(b[pos : pos+4])
@ -76,41 +87,113 @@ func (h *ClientHelloHandshake) ReadFrom(r io.Reader) (n int64, err error) {
copy(h.Random.Opaque[:], b[pos:pos+28]) copy(h.Random.Opaque[:], b[pos:pos+28])
pos += 28 pos += 28
sessionLen := int(b[pos]) nn, err = h.readSession(b[pos:])
pos++ if err != nil {
h.SessionID = make([]byte, sessionLen) return
copy(h.SessionID, b[pos:pos+sessionLen])
pos += sessionLen
cipherLen := int(binary.BigEndian.Uint16(b[pos : pos+2]))
pos += 2
for i := 0; i < cipherLen/2; i++ {
h.CipherSuites = append(h.CipherSuites, CipherSuite(binary.BigEndian.Uint16(b[pos:pos+2])))
pos += 2
} }
pos += nn
compLen := int(b[pos]) nn, err = h.readCipherSuites(b[pos:])
pos++ if err != nil {
for i := 0; i < compLen; i++ { return
h.CompressionMethods = append(h.CompressionMethods, CompressionMethod(b[pos]))
pos++
} }
pos += nn
// extLen := int(binary.BigEndian.Uint16(b[pos : pos+2])) nn, err = h.readCompressionMethods(b[pos:])
pos += 2 if err != nil {
if pos >= len(b) { return
}
pos += nn
nn, err = h.readExtensions(b[pos:])
if err != nil {
return
}
// pos += nn
return
}
func (h *ClientHelloHandshake) readSession(b []byte) (n int, err error) {
if len(b) == 0 {
err = fmt.Errorf("bad length: data too short for session")
return return
} }
br := bytes.NewReader(b[pos:]) nlen := int(b[0])
n++
if len(b) < n+nlen {
err = fmt.Errorf("bad length: malformed data for session")
}
if nlen > 0 && n+nlen <= len(b) {
h.SessionID = make([]byte, nlen)
copy(h.SessionID, b[n:n+nlen])
n += nlen
}
return
}
func (h *ClientHelloHandshake) readCipherSuites(b []byte) (n int, err error) {
if len(b) < 2 {
err = fmt.Errorf("bad length: data too short for cipher suites")
return
}
nlen := int(binary.BigEndian.Uint16(b[:2]))
n += 2
if len(b) < n+nlen {
err = fmt.Errorf("bad length: malformed data for cipher suites")
}
for i := 0; i < nlen/2; i++ {
h.CipherSuites = append(h.CipherSuites, CipherSuite(binary.BigEndian.Uint16(b[n:n+2])))
n += 2
}
return
}
func (h *ClientHelloHandshake) readCompressionMethods(b []byte) (n int, err error) {
if len(b) == 0 {
err = fmt.Errorf("bad length: data too short for compression methods")
return
}
nlen := int(b[0])
n++
if len(b) < n+nlen {
err = fmt.Errorf("bad length: malformed data for compression methods")
}
for i := 0; i < nlen; i++ {
h.CompressionMethods = append(h.CompressionMethods, CompressionMethod(b[n]))
n++
}
return
}
func (h *ClientHelloHandshake) readExtensions(b []byte) (n int, err error) {
if len(b) < 2 {
err = fmt.Errorf("bad length: data too short for extensions")
return
}
nlen := int(binary.BigEndian.Uint16(b[:2]))
n += 2
if len(b) < n+nlen {
err = fmt.Errorf("bad length: malformed data for extensions")
return
}
br := bytes.NewReader(b[n:])
for br.Len() > 0 { for br.Len() > 0 {
cn := br.Len()
var ext Extension var ext Extension
ext, err = ReadExtension(br) ext, err = ReadExtension(br)
if err != nil { if err != nil {
return return
} }
h.Extensions = append(h.Extensions, ext) h.Extensions = append(h.Extensions, ext)
n += (cn - br.Len())
} }
return return
} }

6
vendor/vendor.json vendored
View File

@ -105,10 +105,10 @@
"revisionTime": "2017-09-11T08:28:29Z" "revisionTime": "2017-09-11T08:28:29Z"
}, },
{ {
"checksumSHA1": "oAor5oKUyfFTHUT7ICWfe/aZTrY=", "checksumSHA1": "Mwt6O7YzbBVMQiMb5Zkxx5HU8uc=",
"path": "github.com/ginuerzh/tls-dissector", "path": "github.com/ginuerzh/tls-dissector",
"revision": "7037c35ed6947fe9d9c33785fca4ac96eef8e62b", "revision": "c277f49352a96cef91b8a57ad0bc23ac7fe28bf1",
"revisionTime": "2018-11-03T04:46:17Z" "revisionTime": "2018-11-22T08:01:35Z"
}, },
{ {
"checksumSHA1": "fBx0fqiyrl26gkGo14J9pJ8zB2Y=", "checksumSHA1": "fBx0fqiyrl26gkGo14J9pJ8zB2Y=",