Skip to content

Commit

Permalink
* Command for destroying certificates added.
Browse files Browse the repository at this point in the history
* Renamed command methods, nothing 'admin' about them.
  • Loading branch information
ArachisH committed May 11, 2020
1 parent 651ede2 commit 12c8740
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
33 changes: 23 additions & 10 deletions Tanji/Pages/Connection/ConnectionPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void CoTUpdateVariableBtn_Click(object sender, EventArgs e)

private void CoTDestroyCertificatesBtn_Click(object sender, EventArgs e)
{
Eavesdropper.Certifier.DestroyCertificates();
TryDestroyCertificateAuthority();
}
private void CoTExportCertificateAuthorityBtn_Click(object sender, EventArgs e)
{
Expand Down Expand Up @@ -461,6 +461,17 @@ private async Task InterceptConnectionAsync()
await Task.Delay(1000).ContinueWith(t => GC.Collect()).ConfigureAwait(false);
}

private void RunTanjiAsAdmin(string argument)
{
using (var proc = new Process())
{
proc.StartInfo.FileName = Path.GetFullPath("Tanji.exe");
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.Verb = "runas";
proc.StartInfo.Arguments = argument;
proc.Start();
}
}
private bool HasPingInstructions()
{
ABCFile abc = UI.Game.ABCFiles.Last();
Expand Down Expand Up @@ -490,20 +501,22 @@ private bool TryInstallCertificateAuthority()
{
if (!Eavesdropper.Certifier.CreateTrustedRootCertificate())
{
using (var proc = new Process())
{
proc.StartInfo.FileName = Path.GetFullPath("Tanji.exe");
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.Verb = "runas";
proc.StartInfo.Arguments = "aca";
proc.Start();
}

RunTanjiAsAdmin("ica");
// Will return true if the external process succeeded in installing certifcate with admin privileges.
return Eavesdropper.Certifier.CreateTrustedRootCertificate();
}
return true;
}
private bool TryDestroyCertificateAuthority()
{
if (!Eavesdropper.Certifier.DestroyCertificates())
{
RunTanjiAsAdmin("dcs");
// Will return true if the external process succeeded in destroying the certifcates with admin privileges.
return Eavesdropper.Certifier.DestroyCertificates();
}
return true;
}
private WebRequest TrimQuery(HttpWebRequest request)
{
if (string.IsNullOrWhiteSpace(request.RequestUri.Query)) return request;
Expand Down
13 changes: 10 additions & 3 deletions Tanji/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ private static void Main(string[] args)
switch (args[0].Substring(args[0].Length - 3))
{
case "swf": PatchClient(new FileInfo(Path.GetFullPath(args[0]))); break;
case "aca": AdminCAInstall(); break;
case "ica": InstallCertificateAuthority(); break;
case "dcs": DestroyCertificates(); break;
}
return;
}
Expand All @@ -45,10 +46,16 @@ private static void Main(string[] args)
Application.Run(new MainFrm());
}

private static void AdminCAInstall()
private static void DestroyCertificates()
{
var tanjiCertificateManager = new CertificateManager("Tanji", "Tanji Certificate Authority");
bool installedRootCA= tanjiCertificateManager.CreateTrustedRootCertificate();
bool destroyedCertificates = tanjiCertificateManager.DestroyCertificates();
Console.WriteLine("Tanji Generated Certificates Destroyed: " + destroyedCertificates);
}
private static void InstallCertificateAuthority()
{
var tanjiCertificateManager = new CertificateManager("Tanji", "Tanji Certificate Authority");
bool installedRootCA = tanjiCertificateManager.CreateTrustedRootCertificate();
Console.WriteLine("Tanji Certificate Authority Installed: " + installedRootCA);
}
private static void PatchClient(FileInfo clientInfo)
Expand Down

0 comments on commit 12c8740

Please sign in to comment.