c# - SignalR with Certificates -


I want to make a simple signalar application. Using Http Everything works fine, but when I try to use https and certificates the application does not work.

Now, the only thing I want to do is get the client's certificate in the server.

Server (Authentication Handler):

  Public Class Client CertificateConfirmation: Authentication Handler & lt; Customer CertificateOfficial Option & gt; {Safe Override Work & lt; Authentication ticket & gt; AuthenticateCoreAsync () {var cert = context.Get & lt; X509 certificate & gt; ("Ssl.ClientCertificate"); If (cert == null) {return Task.FromResult & lt; AuthenticationTicket & gt; (Empty); } Try {Options.Validator.Validate (cert); } Hold {return work.formersalt & lt; AuthenticationTat & gt; (Empty); } Return tap; }}   

Customer (hub)

  var connection = new HubConnection ("https: // localhost: 8080 /" ); Connection.AddClientCertificate (X509Certificate.CreateFromCertFile ("c1.cer")); IHubProxy myHub = connection.CreateHubProxy ("MyHub"); Connection.Start () Wait () .;   

When I var cert = context.get & lt; X509 certificate & gt; ("Ssl.ClientCertificate"); me null .

So, am I doing wrong?

You must also tell IIS to use the client certificate. I web.config to:

  & lt; Location path = "signalr" & gt; & Lt; System.webServer & gt; & Lt; Security & gt; & Lt; Login sslFlags = "SslNegotiateCert" /> & Lt; / Safety & gt; & Lt; /system.webServer> & Lt; / Location & gt;   

My job code

  var cert = ServiceCallHelper.GetClientCertificate (); Var url = new URI (Settings.CoreUrl); Var str = String.Format ("https: // {0} / cert_signalr", url.Host); Var hub = new hub connection (str, false); Hub.AddClientCertificate (certificate);   

and

  object cert = null; If (! Hub.Context.Request.Environment.TryGetValue ("ssl.ClientCertificate", cert cert)) !! (Cert X509Certificate2 is)) {s_logger.WarnFormat ("Hub {0} without a certificate or cookie", Hub Context.Request.ToString ()); Throw a new exception ("not authenticated"); }    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -