I have a Windows Forms app that uses the WebBrowser control. The control loads a website that provides SSO login to Google using Firebase. I'd like for my app to be able to piggyback the sign-on data coming back from Firebase and store it locally for reference.
I am using the latest FiddlerCore4 from NuGet (4.4.8.4) which works just fine reading both decrypted HTTPS and the WebSocket data as well. However my app obviously posts a cert warning for the HTTPS communications and I'd like to not have those popups appear.
I have tried implementing two different cert adding techniques I have found in the Fiddler book. In both cases, when I add a trusted cert the WebSocket requests stop coming through. FiddlerApplication.Log.OnLogString event handler returns:
** LogString: Upgrading Session #4 to websocket
But then all other request capturing does not happen. This only is the case when I add the trusted cert. When I have the end user OK the cert manually, the data is captured by Fiddler.
I have tried both the CreateAndTrustRoot() method and the setMachineTrust(X509Certificate2 oRootCert) methods suggested in the Debugging with Fiddler manual.
I know there is some websocket functionality exposed in the later versions of FiddlerCore, but since I have been able to capture the requests using the BeforeResponse event handler without the trusted cert, I am confused about which direction to go.
Here's my code
public frmForm()
{
InitializeComponent();
SourceBrowser.DocumentCompleted += SourceBrowser_DocumentCompleted;
FiddlerApplication.BeforeResponse += FiddlerApplication_BeforeResponse;
if (CreateAndTrustRoot())
{
System.Threading.Thread.Sleep(200);
FiddlerApplication.Startup(8888, FiddlerCoreStartupFlags.DecryptSSL);
}
}
private bool CreateAndTrustRoot()
{
bool bCreatedRootCertificate, bTrustedRootCert;
// Ensure root exists
if (!CertMaker.rootCertExists())
{
bCreatedRootCertificate = CertMaker.createRootCert();
if (!bCreatedRootCertificate)
return false;
}
setMachineTrust(CertMaker.GetRootCertificate());
// Ensure root is trusted
if (!CertMaker.rootCertIsTrusted())
{
bTrustedRootCert = CertMaker.trustRootCert();
if (!bTrustedRootCert) return false;
}
return true;
}
private bool setMachineTrust(X509Certificate2 oRootCert)
{
try
{
X509Store certStore = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
certStore.Open(OpenFlags.ReadWrite);
try
{
certStore.Add(oRootCert);
}
finally
{
certStore.Close();
}
return true;
}
catch (Exception eX)
{
localLog.LogInfo(new LogInfo { Message = String.Format("Exception setting machine trust") });
return false;
}
}
void FiddlerApplication_BeforeResponse(Session oSession)
{
localLog.LogInfo(new LogInfo { Message = String.Format("** Session Request URL: {0}, RESPONSE Body: {1}", oSession.url, Encoding.ASCII.GetString(oSession.ResponseBody)) });
Uri sessionUri = new Uri(oSession.fullUrl);
if (sessionUri.Host.Contains("
firebaseio.com") && sessionUri.Query.Contains("&d0="))
{
FireBase fb = new FireBase();
fb.LogAgent(response);
}