c# - Check SSL certificate from request - if it comes from expected website -


i need validate web request targets our website, , if comes 'some.site.com' -> response ok.

i don't want base check on client ip address since can changed across time. try check cn ssl certificate (from request) , if expected response ok.

if correct?

 httpclientcertificate cs = request.clientcertificate;  if(cs.subject.tostring().contains("site.com") {      ... } 

the problem can not simulate scenario. then, instead of tried following:

 servicepointmanager.expect100continue = true;  servicepointmanager.securityprotocol = securityprotocoltype.tls12;  servicepointmanager.servercertificatevalidationcallback += servercertificatevalidationcallback;  try  {       var request = webrequest.create("https://" + request.userhostaddress.tostring());       var response = request.getresponse();       ...  }  catch (exception ex)  {       ...  }   private static bool servercertificatevalidationcallback(object sender, x509certificate certificate, x509chain chain, sslpolicyerrors sslpolicyerrors) {     file.appendalltext(file_path, "subject: " + certificate.subject);     return true; } 

on way got subject correctly (name of computer sent request from). how sure got 'site.com'?


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -