Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

websocket - Error in connection establishment: net::ERR_INSECURE_RESPONSE

Tags:

Can't connect to websocket server..

I use the exact same private.key and public.crt that I use with nginx

The cert is self-signed but works fine with the rest of the website over HTTPS via nginx

The websocket server works when using ws:// when the line with http.ListenAndServe() is uncommented

package main

import (
    "flag"
    "fmt"
    "log"
    "net/http"
)

const PORT uint = 8000

func main(){
    host := parse_flags()

    hub := newHub()
    go hub.run()

    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        serve(hub, w, r)
    })

    server_host := fmt.Sprintf("%s:%d", host, PORT)

    log.Println("Server listening on:", server_host)

    err := http.ListenAndServeTLS(server_host, fmt.Sprintf("/var/ini/ssl/%s/public.crt", host), fmt.Sprintf("/var/ini/ssl/%s/private.key", host), nil)
    //err := http.ListenAndServe(server_host, nil)
    if err != nil {
        log.Fatal("ListenAndServe:", err)
    }
}
like image 693
clarkk Avatar asked Mar 09 '17 15:03

clarkk


People also ask

What is WebSocket connection error?

The error event is fired when a connection with a WebSocket has been closed due to an error (some data couldn't be sent for example).


2 Answers

I had the same error, but I don't know your urls.

I used https://localhost:port for HTTPS and wss://127.0.0.1:port for WS. So I had to accept the cert for https://localhost and https://127.0.0.1 (only in Chrome).

like image 176
Appyx Avatar answered Sep 28 '22 19:09

Appyx


It looks like newest version of Chrome now rejects SHA-1 certs as being insecure. You probably need to move to SHA-2 certs.

like image 38
teriyaki Avatar answered Sep 28 '22 19:09

teriyaki