@@ -3,6 +3,7 @@ package layers
3
3
import (
4
4
"encoding/binary"
5
5
"encoding/hex"
6
+ "encoding/json"
6
7
"fmt"
7
8
"strings"
8
9
)
@@ -129,6 +130,47 @@ type TLSClientHello struct {
129
130
ALPN []string
130
131
}
131
132
133
+ type TLSClientHelloRequestWrapper struct {
134
+ Request TLSClientHelloRequest `json:"tls_request"`
135
+ }
136
+
137
+ type TLSClientHelloRequest struct {
138
+ SNI string `json:"sni,omitempty"`
139
+ Type string `json:"type,omitempty"`
140
+ Version string `json:"version,omitempty"`
141
+ SessionID string `json:"session_id,omitempty"`
142
+ CipherSuites []string `json:"cipher_suites,omitempty"`
143
+ Extensions []string `json:"extensions,omitempty"`
144
+ ALPN []string `json:"alpn,omitempty"`
145
+ }
146
+
147
+ func (tch * TLSClientHello ) MarshalJSON () ([]byte , error ) {
148
+ cs := make ([]string , 0 , len (tch .CipherSuites ))
149
+ for _ , c := range tch .CipherSuites {
150
+ cs = append (cs , c .String ())
151
+ }
152
+ es := make ([]string , 0 , len (tch .Extensions ))
153
+ for _ , e := range tch .Extensions {
154
+ es = append (es , e .String ())
155
+ }
156
+ var ver , sn string
157
+ if tch .Version != nil {
158
+ ver = tch .Version .String ()
159
+ }
160
+ if tch .ServerName != nil {
161
+ sn = tch .ServerName .SNName
162
+ }
163
+ return json .Marshal (& TLSClientHelloRequestWrapper {Request : TLSClientHelloRequest {
164
+ SNI : sn ,
165
+ Type : fmt .Sprintf ("%s (%d)" , tch .TypeDesc , tch .Type ),
166
+ Version : ver ,
167
+ SessionID : tch .SessionID ,
168
+ CipherSuites : cs ,
169
+ Extensions : es ,
170
+ ALPN : tch .ALPN ,
171
+ }})
172
+ }
173
+
132
174
func (tch * TLSClientHello ) String () string {
133
175
return fmt .Sprintf (` - Type: %s (%d)
134
176
- Length: %d
@@ -286,6 +328,44 @@ type TLSServerHello struct {
286
328
SupportedVersion * TLSVersion
287
329
}
288
330
331
+ type TLSServerHelloResponseWrapper struct {
332
+ Response TLSServerHelloResponse `json:"tls_response"`
333
+ }
334
+
335
+ type TLSServerHelloResponse struct {
336
+ Type string `json:"type,omitempty"`
337
+ Version string `json:"version,omitempty"`
338
+ SessionID string `json:"session_id,omitempty"`
339
+ CipherSuite string `json:"cipher_suite,omitempty"`
340
+ Extensions []string `json:"extensions,omitempty"`
341
+ SupportedVersion string `json:"supported_version,omitempty"`
342
+ }
343
+
344
+ func (tsh * TLSServerHello ) MarshalJSON () ([]byte , error ) {
345
+ es := make ([]string , 0 , len (tsh .Extensions ))
346
+ for _ , e := range tsh .Extensions {
347
+ es = append (es , e .String ())
348
+ }
349
+ var ver , supver , cs string
350
+ if tsh .Version != nil {
351
+ ver = tsh .Version .String ()
352
+ }
353
+ if tsh .SupportedVersion != nil {
354
+ supver = tsh .SupportedVersion .String ()
355
+ }
356
+ if tsh .CipherSuite != nil {
357
+ cs = tsh .CipherSuite .String ()
358
+ }
359
+ return json .Marshal (& TLSServerHelloResponseWrapper {Response : TLSServerHelloResponse {
360
+ Type : fmt .Sprintf ("%s (%d)" , tsh .TypeDesc , tsh .Type ),
361
+ Version : ver ,
362
+ SessionID : tsh .SessionID ,
363
+ CipherSuite : cs ,
364
+ Extensions : es ,
365
+ SupportedVersion : supver ,
366
+ }})
367
+ }
368
+
289
369
func (tsh * TLSServerHello ) String () string {
290
370
return fmt .Sprintf (` - Type: %s (%d)
291
371
- Length: %d
0 commit comments