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
Post a Comment