obfs: tls max data length limitation

This commit is contained in:
ginuerzh 2020-03-03 18:56:43 +08:00
parent c1bac99a5d
commit ec5052e55f

15
obfs.go
View File

@ -25,6 +25,10 @@ import (
dissector "github.com/ginuerzh/tls-dissector" dissector "github.com/ginuerzh/tls-dissector"
) )
const (
maxTLSDataLen = 16384
)
type obfsHTTPTransporter struct { type obfsHTTPTransporter struct {
tcpTransporter tcpTransporter
} }
@ -544,10 +548,18 @@ func (c *obfsTLSConn) Write(b []byte) (n int, err error) {
} }
} }
for len(b) > 0 {
data := b
if len(b) > maxTLSDataLen {
data = b[:maxTLSDataLen]
b = b[maxTLSDdataLen:]
} else {
b = b[:0]
}
record := &dissector.Record{ record := &dissector.Record{
Type: dissector.AppData, Type: dissector.AppData,
Version: tls.VersionTLS12, Version: tls.VersionTLS12,
Opaque: b, Opaque: data,
} }
if c.wbuf.Len() > 0 { if c.wbuf.Len() > 0 {
@ -560,6 +572,7 @@ func (c *obfsTLSConn) Write(b []byte) (n int, err error) {
if _, err = record.WriteTo(c.Conn); err != nil { if _, err = record.WriteTo(c.Conn); err != nil {
return return
} }
}
return return
} }