Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report tls: first record does not look like a TLS handshake when dial with tls option #204

Open
mebest100 opened this issue Oct 1, 2024 · 2 comments

Comments

@mebest100
Copy link

Hi,
it report "tls: first record does not look like a TLS handshake" when dial with tls option

And the code is as follows:

	dialer := ws.Dialer{
		Header: ws.HandshakeHeaderHTTP(header), 
		NetDial: func(ctx context.Context, network, addr string) (net.Conn, error) {
			
			rawConn, err := net.Dial(network, addr)
			if err != nil {
				log.Logf("websocket dial tcp fail, err==> %v", err)
				return nil, err
			}
		
			tlsConn := tls.Client(rawConn, tlsConfig)
			return tlsConn, nil
		},
	}

	
	conn, _, _, err := dialer.Dial(context.Background(), url)

the tlsConfig is generated by self-signed , but the same config work well with gorilla/websocket lib.
Pls kindly advise the probal causes and solutions. Thx!

@cristaloleg
Copy link
Collaborator

Hey, I think it should be 'tls.Dial' and not 'net.Dial'

@mebest100
Copy link
Author

Hi,
I changed ws.Dialer option, now with no tls error, but report unexpected HTTP response status: 403
What's the probal cause? Thx!
Frankly gobwas is too hard to use, I do not encounter so many problems with gorilla when the same config

	addr := "wss://ip:443/mypath"
	serverName := "mydomain.xxx"
	tlsConfig := GenTlsCfg()
	tlsConfig.ServerName = serverName
	tlsConfig.InsecureSkipVerify = true

	header := http.Header{}
	header.Set("Host", serverName)



	dialer := ws.Dialer{
		Header: ws.HandshakeHeaderHTTP(header),
		//Header:    ws.HandshakeHeaderHTTP(header),
		TLSConfig: tlsConfig,
	}

	_, _, _, err = dialer.Dial(context.Background(), addr)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants