sta / sta/websocket-sharp

ERR_CONNECTION_REFUSED in browser when using HTTPS server

Open
#461 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
6.1k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

I am trying to start an https server and attach web socket services to it. It works fine with regular http, but if I try to use SSL it doesn't work.

Here's the part where I start the server (modified from the echo example):

`
X509Certificate2 serverCert = new X509Certificate2(serverDir + "/server-crt.pem");

    // this returns false, but I figure that should only make the browser complain
    UnityEngine.Debug.Log("cert valid? " + serverCert.Verify());

    httpsv = new HttpServer(System.Net.IPAddress.Parse(localIpAddr), 8084, true);
    httpsv.SslConfiguration.ServerCertificate = serverCert;

    httpsv.SslConfiguration.ClientCertificateRequired = false;
    httpsv.SslConfiguration.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls;

    // shouldn't be necessary if no client cert required, but put it here anyway...
    httpsv.SslConfiguration.ClientCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
    {
        UnityEngine.Debug.Log("ssl validation callback called");
        return true;
    };

    UnityEngine.Debug.Log("secure connection? " + httpsv.IsSecure);`

No errors in Unity (where I'm starting the server from), but the html/js client I'm trying to serve from this https server doesn't work (Chrome just says ERR_CONNECTION_REFUSED).

I have tried using this simple python https server to verify that the certificate I generated with openssl is not completely broken:

`import BaseHTTPServer, SimpleHTTPServer
import ssl

httpd = BaseHTTPServer.HTTPServer(('192.168.1.136', 8084), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='./server-crt.pem', keyfile='./server-key.pem', server_side=True)
httpd.serve_forever()`

As expected, the browser warns that the cert is untrusted, but I can still connect. So, what do I need to do to start an https server (not just a wss server)?

Thanks for any help.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure using the provided Unity snippet, then inspect the HttpServer construction and SslConfiguration setup used for the HTTPS listener. Compare its behavior with the working Python HTTPS server and determine what prevents the browser from connecting. Done means the browser can reach the HTTPS server and receive the served HTML or JavaScript, while the certificate warning remains acceptable.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.