@@ -15,6 +15,8 @@ const (
1515 ServerHelloTLSVal = 0x02
1616)
1717
18+ var TLSTooShortErr = fmt .Errorf ("tls message too short" )
19+
1820type TLSVersion struct {
1921 Value uint16
2022 Desc string
@@ -117,7 +119,7 @@ type TLSClientHello struct {
117119 TypeDesc string
118120 Length int // 3 bytes int(uint(b[2]) | uint(b[1])<<8 | uint(b[0])<<16))
119121 Version * TLSVersion
120- Random []byte //32 bytes
122+ Random []byte // 32 bytes
121123 SessionIDLength uint8 // if 0 no session follows
122124 SessionID string
123125 CipherSuitesLength uint16
@@ -178,12 +180,12 @@ func (tch *TLSClientHello) String() string {
178180 - Random: %s
179181 - SessionIDLength: %d
180182 - SessionID: %s
181- - CipherSuitesLength: %d
183+ - CipherSuitesLength: %d
182184 - CipherSuites: %v
183185 - CmprMethodsLength: %d
184- - CmprMethods: %v
186+ - CmprMethods: %v
185187 - ExtensionLength: %d
186- - Extensions: %v
188+ - Extensions: %v
187189 - %s
188190 - ALPN: %v
189191` ,
@@ -233,7 +235,7 @@ func (tch *TLSClientHello) ParseHS(data []byte) error {
233235 }
234236 csl := binary .BigEndian .Uint16 (data [sid : sid + 2 ]) // data[71:73] suites count * 2 bytes
235237 tch .CipherSuitesLength = csl
236- offset := uint16 (sid + 2 ) //73
238+ offset := uint16 (sid + 2 ) // 73
237239 cmproffset := csl + offset // 107
238240 css := make ([]* CipherSuite , 0 , csl / 2 )
239241 var i uint16
@@ -285,8 +287,8 @@ func (tch *TLSClientHello) ParseHS(data []byte) error {
285287 return err
286288 }
287289 tch .ServerName = sn
288- case 16 : //ALPN
289- //skip data[i+4:i+6] alpn extension length
290+ case 16 : // ALPN
291+ // skip data[i+4:i+6] alpn extension length
290292 if len (data ) < int (i + 6 ) {
291293 return nil
292294 }
@@ -318,7 +320,7 @@ type TLSServerHello struct {
318320 TypeDesc string
319321 Length int // 3 bytes int(uint(b[2]) | uint(b[1])<<8 | uint(b[0])<<16))
320322 Version * TLSVersion
321- Random []byte //32 bytes
323+ Random []byte // 32 bytes
322324 SessionIDLength uint8 // if 0 no session follows
323325 SessionID string
324326 CipherSuite * CipherSuite
@@ -374,10 +376,10 @@ func (tsh *TLSServerHello) String() string {
374376 - SessionIDLength: %d
375377 - SessionID: %s
376378 - CipherSuite: %s
377- - CmprMethod: %d
379+ - CmprMethod: %d
378380 - ExtensionLength: %d
379- - Extensions: %v
380- - Supported Version: %s
381+ - Extensions: %v
382+ - Supported Version: %s
381383` ,
382384 tsh .TypeDesc ,
383385 tsh .Type ,
@@ -539,7 +541,7 @@ func (t *TLSMessage) printRecords() string {
539541func (t * TLSMessage ) Parse (data []byte ) error {
540542 t .Records = make ([]* Record , 0 , 5 )
541543 if len (data ) < headerSizeTLS {
542- return nil
544+ return TLSTooShortErr
543545 }
544546 for len (data ) > 0 {
545547 ctype := data [0 ]
@@ -1388,6 +1390,7 @@ func csuitedesc(csuite uint16) string {
13881390 }
13891391 return csuitedesc
13901392}
1393+
13911394func extdesc (ext uint16 ) string {
13921395 var extdesc string
13931396 switch ext {
0 commit comments