c# - SignalR with Certificates -
c# - SignalR with Certificates -
i want create simple signalr application. using http works fine, when seek utilize https , certificates application don't work.
for now, thing want client's certificate in server.
server (authentication handler):
public class clientcertificateauthenticationhandler : authenticationhandler<clientcertificateauthenticationoptions> { protected override task<authenticationticket> authenticatecoreasync() { var cert = context.get<x509certificate>("ssl.clientcertificate"); if (cert == null) { homecoming task.fromresult<authenticationticket>(null); } seek { options.validator.validate(cert); } grab { homecoming task.fromresult<authenticationticket>(null); } homecoming null; } }
client (hub)
var connection = new hubconnection("https://localhost:8080/"); connection.addclientcertificate(x509certificate.createfromcertfile("c1.cer")); ihubproxy myhub = connection.createhubproxy("myhub"); connection.start().wait();
doing this, in server when var cert = context.get<x509certificate>("ssl.clientcertificate");
null
.
so, i'm doing wrong?
you have tell iis utilize client certificate. in web.config do
<location path="signalr"> <system.webserver> <security> <access sslflags="sslnegotiatecert" /> </security> </system.webserver> </location>
my working code
var cert = servicecallhelper.getclientcertificate(); var url = new uri(settings.coreurl); var str = string.format("https://{0}/cert_signalr", url.host); var hub = new hubconnection(str, false); hub.addclientcertificate(cert);
and
object cert = null; if (!hub.context.request.environment.trygetvalue("ssl.clientcertificate", out cert) || !(cert x509certificate2)) { s_logger.warnformat("hub {0} called without certificate or cookie", hub.context.request.tostring()); throw new exception("not authenticated"); }
c# ssl signalr ssl-certificate owin
Comments
Post a Comment