Skip to content

Commit

Permalink
Add package comment and comments for exported variables and functions…
Browse files Browse the repository at this point in the history
… in sni package.
  • Loading branch information
DanielcoderX committed Sep 4, 2023
1 parent a94bcc1 commit 57b547a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/srwiley/oksvg v0.0.0-20220731023508-a61f04f16b76 // indirect
github.com/srwiley/rasterx v0.0.0-20210519020934-456a8d69b780 // indirect
github.com/stretchr/testify v1.8.3 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tevino/abool v1.2.0 // indirect
github.com/v2pro/plz v0.0.0-20221028024117-e5f9aec5b631 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
Expand Down
2 changes: 2 additions & 0 deletions sni/http.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package sni provides functionality for parsing the first HTTP request on a connection
// and returning metadata for virtual host muxing.
package sni

import (
Expand Down
16 changes: 10 additions & 6 deletions sni/tls.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package sni provides functionality for handling Server Name Indication (SNI) in TLS connections.
package sni

import (
Expand All @@ -24,7 +25,7 @@ const (

// TLS extension numbers
var (
extensionServerName uint16 = 0
extensionServerName uint16
extensionStatusRequest uint16 = 5
extensionSupportedCurves uint16 = 10
extensionSupportedPoints uint16 = 11
Expand Down Expand Up @@ -202,11 +203,14 @@ func ReadClientHello(rd io.Reader) (*ClientHelloMsg, error) {
return msg, nil
}

// ClientHelloMsg represents a TLS ClientHello message. It contains various fields
// that store information about the client's hello message during a TLS handshake.
type ClientHelloMsg struct {
// Raw contains the raw bytes of the ClientHello message.
Raw []byte
Versions uint16
Random []byte
SessionId []byte
SessionID []byte
CipherSuites []uint16
CompressionMethods []uint8
NextProtoNeg bool
Expand All @@ -225,12 +229,12 @@ func (m *ClientHelloMsg) unmarshal(data []byte) bool {
m.Raw = data
m.Versions = uint16(data[4])<<8 | uint16(data[5])
m.Random = data[6:38]
sessionIdLen := int(data[38])
if sessionIdLen > 32 || len(data) < 39+sessionIdLen {
sessionIDLen := int(data[38])
if sessionIDLen > 32 || len(data) < 39+sessionIDLen {
return false
}
m.SessionId = data[39 : 39+sessionIdLen]
data = data[39+sessionIdLen:]
m.SessionID = data[39 : 39+sessionIDLen]
data = data[39+sessionIDLen:]
if len(data) < 2 {
return false
}
Expand Down

0 comments on commit 57b547a

Please sign in to comment.