Skip to content

Commit

Permalink
fix tls server_name check
Browse files Browse the repository at this point in the history
  • Loading branch information
lxzan committed Jan 28, 2024
1 parent 5c407ad commit 6b1b30e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 50 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewClient(handler Event, option *ClientOption) (*Conn, *http.Response, erro
option.TlsConfig = &tls.Config{}
}
if option.TlsConfig.ServerName == "" {
option.TlsConfig.ServerName = URL.Host
option.TlsConfig.ServerName = URL.Hostname()
}
c.conn = tls.Client(c.conn, option.TlsConfig)
}
Expand Down
10 changes: 7 additions & 3 deletions examples/echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import (

func main() {
upgrader := gws.NewUpgrader(&Handler{}, &gws.ServerOption{
CheckUtf8Enabled: true,
Recovery: gws.Recovery,
PermessageDeflate: gws.PermessageDeflate{Enabled: true},
CheckUtf8Enabled: true,
Recovery: gws.Recovery,
PermessageDeflate: gws.PermessageDeflate{
Enabled: true,
ServerContextTakeover: true,
ClientContextTakeover: true,
},
})
http.HandleFunc("/connect", func(writer http.ResponseWriter, request *http.Request) {
socket, err := upgrader.Upgrade(writer, request)
Expand Down
30 changes: 12 additions & 18 deletions examples/wss/cert/server.crt
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
-----BEGIN CERTIFICATE-----
MIIDQjCCAioCCQCWPZ0wOmVAQzANBgkqhkiG9w0BAQsFADBjMQswCQYDVQQGEwJj
bjEOMAwGA1UECAwFaHVuYW4xETAPBgNVBAcMCGNoYW5nc2hhMQ8wDQYDVQQKDAZ3
ZWJ1bGwxIDAeBgkqhkiG9w0BCQEWEWx4emFuQGZveG1haWwuY29tMB4XDTIzMDIw
MjA4MTE1MloXDTIzMDMwNDA4MTE1MlowYzELMAkGA1UEBhMCY24xDjAMBgNVBAgM
BWh1bmFuMREwDwYDVQQHDAhjaGFuZ3NoYTEPMA0GA1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MQswCQYDVQQIEwJTWDELMAkGA1UEBxMC
WEExDTALBgNVBAoTBFNTTEkxDDAKBgNVBAsTA0NLUzEQMA4GA1UEAxMHZ3dzLmNv
bTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABBIucz8sAdVcn7dPzgLjXAPGu+ts
ARp67ZQwhG6YHSe5glwt13HSQem+zZmfADgl6yGEKqrcFUlqgFtcrSo10QyjgY4w
gYswDgYDVR0PAQH/BAQDAgWgMBMGA1UdJQQMMAoGCCsGAQUFBwMBMAwGA1UdEwEB
/wQCMAAwHQYDVR0OBBYEFCijWu4DjJLwRLDJuE3xu9GkamNqMB8GA1UdIwQYMBaA
FKQBG4R9776wna1HkpXBQPVitgV4MBYGA1UdEQQPMA2CC3d3dy5nd3MuY29tMAoG
CCqGSM49BAMCA0gAMEUCIQCKu+1SzRrL7IK+/rrZ5+HB/EUrf8whTNrvfmjySeTq
zgIgLmSkxZ3Z8qBwhRdsHzMPVfv2fL47ZsVnjdZJlOctpUE=
-----END CERTIFICATE-----
32 changes: 5 additions & 27 deletions examples/wss/cert/server.pem
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAy8NcnnaKMSSmYGubDCGt6wbVTMje1QdtnzEaRRIm2Qqi8VJP
ybeA1uQWwXS4Uyx1GZ2NUTpJnrWxbjUTA1im5W6AFt4t2cocnfvgQHVjJtN29rck
FZ9r2QLW/RWC1TJ6pDQ1ExuRLBFzTAR2i20KVEDq9CFLm4Fk6WqBssLjGqZEiR3/
zlWkdPgzl7Gij/T1L5jsrr9fET+IKpf/KUCm6K7J129SPG/3NLAKlWNFFp4cEu49
bZcHHekPmSeSvtxWaUTXstZ8kr/peYf74puX2y0o1UtuVIIwpCfHkRO09cOfG1Bh
Brr+vMS/WS4udevTAUZNXAp8jR/59SqUjKEW6wIDAQABAoIBAAkMLaqjnNM9y11w
qbvKKwzKiuIT8UEISWfOKFp0yeDNRhrtCrns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v3U2oi/2U0efR3Xe8444YkmX8Zr7m1ibdXyybQh9VtdB2DaXq
4uzx71k5Nu6EyUyKO4XfogBzCu/1GXpaqphulLUHHAXf/U2vBPwg
-----END RSA PRIVATE KEY-----
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEII/kL3k1cDAjslMfnwKwwmBc41/aTY5etTO1O15a0M7woAoGCCqGSM49
AwEHoUQDQgAEEi5zPywB1Vyft0/OAuNcA8a762wBGnrtlDCEbpgdJ7mCXC3XcdJB
6b7NmZ8AOCXrIYQqqtwVSWqAW1ytKjXRDA==
-----END EC PRIVATE KEY-----
3 changes: 2 additions & 1 deletion examples/wss/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ func init() {
func main() {
srv := gws.NewServer(new(Websocket), nil)

if err := srv.RunTLS(":3000", dir+"/server.crt", dir+"/server.pem"); err != nil {
// wss://www.gws.com:8443/
if err := srv.RunTLS(":8443", dir+"/server.crt", dir+"/server.pem"); err != nil {
log.Panicln(err.Error())
}
}
Expand Down

0 comments on commit 6b1b30e

Please sign in to comment.