Giter VIP home page Giter VIP logo

Comments (11)

chronoxor avatar chronoxor commented on May 22, 2024 1

In "NetCoreServer\examples\WssChatClient\Program.cs" there is an example how to prepare HttpRequest in OnWsConnecting() handler:

        public override void OnWsConnecting(HttpRequest request)
        {
            request.SetBegin("GET", "/");
            request.SetHeader("Host", "localhost");
            request.SetHeader("Origin", "http://localhost");
            request.SetHeader("Upgrade", "websocket");
            request.SetHeader("Connection", "Upgrade");
            request.SetHeader("Sec-WebSocket-Key", Convert.ToBase64String(WsNonce));
            request.SetHeader("Sec-WebSocket-Protocol", "chat, superchat");
            request.SetHeader("Sec-WebSocket-Version", "13");
            request.SetBody();
        }

from netcoreserver.

chronoxor avatar chronoxor commented on May 22, 2024 1

Fixed

from netcoreserver.

chronoxor avatar chronoxor commented on May 22, 2024

Will see for the Let's encrypt certs solution

from netcoreserver.

JocPelletier avatar JocPelletier commented on May 22, 2024

Is it possible now to use the WssClient (or other sslclient) with a server using Let's encrypt sertificate? For example, my .net core server is behind a nginx reverse proxy handling the SSL validation

from netcoreserver.

chronoxor avatar chronoxor commented on May 22, 2024

You need to export Let's encrypt certificate to pfx file and use it in WssServer.
Sample instruction can be found here: https://www.alitajran.com/export-lets-encrypt-certificate-in-windows-server/

from netcoreserver.

JocPelletier avatar JocPelletier commented on May 22, 2024

This is valid for the server, but not sure I can do the same for client certificate

from netcoreserver.

chronoxor avatar chronoxor commented on May 22, 2024

I think SSL client handshake should be updated in SslClient.Connect() method. Can you please try to replace:

_sslStream.AuthenticateAsClient(Address, Context.Certificates ?? new X509CertificateCollection(new[] { Context.Certificate }), Context.Protocols, true);

with

_sslStream.AuthenticateAsClient(Address); 

From MSDN:

Starting with .NET Framework 4.7, this method authenticates using None, which allows the operating system to choose the best protocol to use, and to block protocols that are not secure. In .NET Framework 4.6 (and .NET Framework 4.5 with the latest security patches installed), the allowed TLS/SSL protocols versions are 1.2, 1.1, and 1.0 (unless you disable strong cryptography by editing the Windows Registry). No client certificates are used in the authentication. The certificate revocation list is not checked during authentication. The value specified for targetHost must match the name on the server's certificate.

from netcoreserver.

JocPelletier avatar JocPelletier commented on May 22, 2024

I have to switch on another project for now, but here are my tests/observations:

SslClient
I changed IPEndPoint to EndPoint
Added a new constructor accepting a DnsEndPoint (and added it to HttpsClient / WssClient)
Modified CreateSocket() so, if the AddressFamily is not set I use AddressFamily.InterNetwork, which is the case when using DnsEndPoint
Modified _sslStream.AuthenticateAsClient(dnsEndPoint.Host); like you said

It works but, I had BadRequest error from my Nginx reverse proxy, so:

HttpRequest
For a WssClient, it's not sending a valid header structure, I've set all the required headers in OnWsConnecting but my Nginx was returning a BadRequest error. After investigating, I found that there is a missing \r\n line after the last header entry. I did a modification to HttpRequest to append a \r\n for my WssClient and it's now accepted by Nginx.

This missing line is added by other fonctions like AddBody() after appending the Content-Length header

Now, it seems to connect but my WsServer doesn't receive anything, might be an error with my reverse proxy configuration but I have to switch on another project. Hope this can help someone

from netcoreserver.

JocPelletier avatar JocPelletier commented on May 22, 2024

That's perfect, just need to update the Readme

from netcoreserver.

JocPelletier avatar JocPelletier commented on May 22, 2024

I did a pull request #165 to support
DnsName, let's encrypt certificates. Work perfectly with Nginx reverse proxy

from netcoreserver.

chronoxor avatar chronoxor commented on May 22, 2024

Great, thank! I'll look and merge it soon.

from netcoreserver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.