/
Intercept.cs
55 lines (47 loc) · 1.72 KB
/
Intercept.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.Collections.Generic;
using System.Web.Script.Serialization;
using Fiddler;
namespace KClient
{
class Intercept
{
private readonly MainFrm _main;
public Intercept(MainFrm main)
{
_main = main;
}
public void Start()
{
FiddlerApplication.AfterSessionComplete += FiddlerApplication_AfterSessionComplete;
FiddlerApplication.Startup(8888, true, true, true);
}
public void Stop()
{
FiddlerApplication.AfterSessionComplete -= FiddlerApplication_AfterSessionComplete;
if (!FiddlerApplication.IsStarted())
return;
FiddlerApplication.Shutdown();
}
private void FiddlerApplication_AfterSessionComplete(Session sess)
{
if (sess?.oRequest?.headers == null)
return;
if (sess.GetResponseBodyAsString().Contains("clienturl"))
{
var dictionary = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(sess.GetResponseBodyAsString());
if (!dictionary.ContainsKey("clienturl")) return;
var strArray = dictionary["clienturl"].Split('/');
_main.LogSucess($"SSO Gerado [{strArray[strArray.Length - 1]}]");
_main.AppendText(strArray[strArray.Length - 1]);
}
}
public bool HasInstalledCertificate()
{
return CertMaker.trustRootCert();
}
public bool InstallCertificate()
{
return HasInstalledCertificate() || CertMaker.createRootCert() && CertMaker.trustRootCert();
}
}
}