sta / sta/websocket-sharp

Provide client certificate in WebSocketContext

Open
#164 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 have following scenario:

  • WebSocket server running 3 URLs
  • 1st and 2nd URL need to validate client certificate
  • 3rd URL should accept calls without client certificate

Current implementation allows me to only set

server.SslConfiguration.ClientCertificateRequired = true;
server.SslConfiguration.ClientCertificateValidationCallback = ...;

However this validation happens in context where I can't get to URL. I can't validate certificate differently per URL. Because this callback comes from .NET class there is not much we could do here.

What we can do is to provide access to the certificate in the WebSocketContext. I can then do:

protected override void OnOpen()
{
    if (Context.RequestUri.AbsolutePath != "/public")
    {
        X509Certificate certificate = Context.ClientCertificate;
        ValidateCertificate(certificate);  // throws if certificate is invalid
    }
    // ... rest of logic ...
}

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 tracing how the server's SslConfiguration and .NET client-certificate callback feed into WebSocketContext, then inspect the WebSocketContext API used from OnOpen. The change is done when handlers can access the client certificate through Context while retaining URL-specific validation.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.