c# - How to verify a certificate in fiddler core? -
i want verify certificate issued server valid , alert user choose if cannot verified. presently seems certificates accepted fiddler without alerting user. there mechanism it? perhaps in following code found in fiddler core sample project. want alert user self-signed certificates untrusted root.
static void checkcert(object sender, validateservercertificateeventargs e) { if (null != e.servercertificate) { console.writeline("certificate " + e.expectedcn + " site " + e.servercertificate.subject + " , errors " + e.certificatepolicyerrors.tostring()); if (e.servercertificate.subject.contains("fiddler2.com")) { console.writeline("got certificate fiddler2.com. we'll other site, https://fiddlertool.com."); e.validitystate = certificatevalidity.forcevalid; } } }
by default, fiddlercore validate remote certificate part of trusted chain unless set fiddler.config.ignoreservercerterrors = true;
however, means self-signed certificate rejected fiddlercore, , since fiddlercore doesn't show ui allow user override, that's problem.
the way fix use implement certificate validation event handler: fiddlerapplication.onvalidateservercertificate += new system.eventhandler<validateservercertificateeventargs>(checkcert);
inside handler, you'd this:
private void checkcert(object sender, validateservercertificateeventargs e) { if (sslpolicyerrors.none == e.certificatepolicyerrors) { return; } dialogresult oresult = messagebox.show("accept invalid certificate\nyour details here", "certificate warning", messageboxbuttons.yesno, messageboxicon.question, messageboxdefaultbutton.button2)); if (dialogresult.yes == oresult) { e.validitystate = certificatevalidity.forcevalid; } else { e.validitystate = certificatevalidity.forceinvalid; }
you'd typically want cache user's choice avoid prompting them on every connection.
see http://fiddler2.com/blog/blog/2013/01/03/evaluating-certificates-in-fiddler-and-fiddlercore more detail, including full example.
Comments
Post a Comment