move client hello parser to separate package
This commit is contained in:
parent
9d8ff3601f
commit
43900e63a4
|
@ -7,7 +7,7 @@
|
|||
// https://github.com/golang/go/blob/master/src/crypto/tls/handshake_messages.go#L69
|
||||
// https://cs.opensource.google/go/go/+/refs/tags/go1.18:src/crypto/tls/handshake_messages.go;l=69
|
||||
|
||||
package main
|
||||
package clienthello
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
|
@ -211,7 +211,7 @@ type highlights struct {
|
|||
JA3MD5 byteSlice `json:"ja3_md5"`
|
||||
}
|
||||
|
||||
type clientHelloMsg struct {
|
||||
type ClientHelloMsg struct {
|
||||
Raw byteSlice `json:"raw"`
|
||||
RecordHeaderTLSVersion uint16 `json:"record_header_tls_version"` // TLSv1.0 (769)
|
||||
TLSVersion uint16 `json:"client_tls_version"` // TLSv1.2 (771)
|
||||
|
@ -223,8 +223,8 @@ type clientHelloMsg struct {
|
|||
Highlights highlights `json:"highlights"`
|
||||
}
|
||||
|
||||
func (m *clientHelloMsg) unmarshal(data []byte) bool {
|
||||
*m = clientHelloMsg{Raw: data}
|
||||
func (m *ClientHelloMsg) Unmarshal(data []byte) bool {
|
||||
*m = ClientHelloMsg{Raw: data}
|
||||
s := cryptobyte.String(data)
|
||||
|
||||
var random []byte
|
11
server.go
11
server.go
|
@ -16,6 +16,7 @@ import (
|
|||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"tildegit.org/nervuri/client-hello-mirror/clienthello"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -125,8 +126,8 @@ func requestHandler(conn *tls.Conn, rawClientHello []byte) {
|
|||
}
|
||||
|
||||
// Parse Client Hello message.
|
||||
var clientHello clientHelloMsg
|
||||
if !clientHello.unmarshal(rawClientHello) {
|
||||
var clientHelloMsg clienthello.ClientHelloMsg
|
||||
if !clientHelloMsg.Unmarshal(rawClientHello) {
|
||||
log.Println("Failed to parse Client Hello")
|
||||
return
|
||||
}
|
||||
|
@ -158,10 +159,10 @@ func requestHandler(conn *tls.Conn, rawClientHello []byte) {
|
|||
resp.StatusLine = "20 application/json"
|
||||
}
|
||||
output := struct {
|
||||
ClientHello clientHelloMsg `json:"client_hello"`
|
||||
TlsConnectionInfo tlsConnectionInfo `json:"connection_info"`
|
||||
ClientHello clienthello.ClientHelloMsg `json:"client_hello"`
|
||||
TlsConnectionInfo tlsConnectionInfo `json:"connection_info"`
|
||||
}{
|
||||
clientHello,
|
||||
clientHelloMsg,
|
||||
tlsConnInfo,
|
||||
}
|
||||
outputJSON, err := json.MarshalIndent(output, "", " ")
|
||||
|
|
Loading…
Reference in New Issue