sta / sta/websocket-sharp

Exception while hosting secured websocket

Open
#79 5 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

Hi,

I tried to start websocket server in secured mode on localhost. For generating self signed certificate I used Pluralsight library (http://blog.pluralsight.com/selfcert-create-a-self-signed-certificate-interactively-gui-or-programmatically-in-net). Here is my code:

public void Start()
    {
        var server = new WebSocketServer(51002, true);
        server.Certificate = GenerateSelfSignedCertificate();
        server.AddWebSocketService<StatisticsListener>(@"/Stats");
        server.Start();
    }

    private X509Certificate2 GenerateSelfSignedCertificate()
    {
        using (CryptContext ctx = new CryptContext())
        {
            ctx.Open();

            X509Certificate2 cert = ctx.CreateSelfSignedCertificate(
                new SelfSignedCertProperties
                {
                    IsPrivateKeyExportable = true,
                    KeyBitLength = 4096,
                    Name = new X500DistinguishedName("cn=localhost"),
                    ValidFrom = DateTime.Today.AddDays(-1),
                    ValidTo = DateTime.Today.AddYears(1),
                });

            return cert;
        }
    }

Here is the exception thrown by webserver:

2014-10-01 14:26:48|Fatal|<>c__DisplayClass8.b__7:636|WebSocketSharp.WebSocketException: An exception has occurred while reading an HTTP request/response. ---> System.ArgumentOutOfRangeException: Określony argument jest spoza zakresu prawidłowych wartości.
Nazwa parametru: value
w WebSocketSharp.Ext.EqualsWith(Int32 value, Char c, Action1 action) w c:\Users\dahm\Desktop\websocket-sharp-master\websocket-sharp-master\websocket-sharp\Ext.cs:wiersz 440 w WebSocketSharp.HttpBase.readHeaders(Stream stream, Int32 maxLength) w c:\Users\dahm\Desktop\websocket-sharp-master\websocket-sharp-master\websocket-sharp\HttpBase.cs:wiersz 131 w WebSocketSharp.HttpBase.Read[T](Stream stream, Func2 parser, Int32 millisecondsTimeout) w c:\Users\dahm\Desktop\websocket-sharp-master\websocket-sharp-master\websocket-sharp\HttpBase.cs:wiersz 169
--- Koniec śladu stosu wyjątków wewnętrznych ---
w WebSocketSharp.HttpBase.Read[T](Stream stream, Func`2 parser, Int32 millisecondsTimeout) w c:\Users\dahm\Desktop\websocket-sharp-master\websocket-sharp-master\websocket-sharp\HttpBase.cs:wiersz 191
w WebSocketSharp.HttpRequest.Read(Stream stream, Int32 millisecondsTimeout) w c:\Users\dahm\Desktop\websocket-sharp-master\websocket-sharp-master\websocket-sharp\HttpRequest.cs:wiersz 165
w WebSocketSharp.Net.WebSockets.TcpListenerWebSocketContext..ctor(TcpClient tcpClient, String protocol, Boolean secure, X509Certificate certificate, Logger logger) w c:\Users\dahm\Desktop\websocket-sharp-master\websocket-sharp-master\websocket-sharp\Net\WebSockets\TcpListenerWebSocketContext.cs:wiersz 79
w WebSocketSharp.Ext.GetWebSocketContext(TcpClient tcpClient, String protocol, Boolean secure, X509Certificate certificate, Logger logger) w c:\Users\dahm\Desktop\websocket-sharp-master\websocket-sharp-master\websocket-sharp\Ext.cs:wiersz 555
w WebSocketSharp.Server.WebSocketServer.<>c__DisplayClass8.b__7(Object state) w c:\Users\dahm\Desktop\websocket-sharp-master\websocket-sharp-master\websocket-sharp\Server\WebSocketServer.cs:wiersz 636

This exception occurs even when I try different ways to generate a certificate or websocket clients. Could you tell me what is the cause of this error?

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

Start by reproducing the secured localhost server using the certificate-generation code in the issue. Read websocket-sharp/Ext.cs around EqualsWith, HttpBase.cs around readHeaders, and TcpListenerWebSocketContext.cs around the failing request path. Done means identifying the cause of the exception and documenting or correcting the secured WebSocket handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.