2019-03-20 10:02:18 +00:00
|
|
|
|
using System;
|
2019-09-21 00:57:46 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
2019-03-20 10:02:18 +00:00
|
|
|
|
using System.Net;
|
2019-03-20 21:41:17 +00:00
|
|
|
|
using System.Net.Security;
|
2019-12-17 00:59:45 +00:00
|
|
|
|
using System.Reflection;
|
2019-03-20 21:41:17 +00:00
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
2019-03-20 10:02:18 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace network.loki.lokinet.win32.ui
|
|
|
|
|
{
|
|
|
|
|
public partial class dlgBootstrap : Form
|
|
|
|
|
{
|
|
|
|
|
public dlgBootstrap()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
if (Program.platform == PlatformID.Win32NT)
|
2019-12-04 03:40:16 +00:00
|
|
|
|
default_path = Environment.ExpandEnvironmentVariables("%APPDATA%\\.lokinet");
|
2019-03-20 10:02:18 +00:00
|
|
|
|
else
|
2019-12-04 03:40:16 +00:00
|
|
|
|
default_path = Environment.ExpandEnvironmentVariables("%HOME%/.lokinet");
|
|
|
|
|
label2.Text = String.Format("This file is automatically saved as {0}{1}{2}.", default_path, Path.DirectorySeparatorChar, rcName);
|
2019-03-20 10:02:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private WebClient wc;
|
|
|
|
|
private string default_path;
|
2019-12-04 03:40:16 +00:00
|
|
|
|
private const string rcName = "bootstrap.signed";
|
|
|
|
|
|
2019-03-20 10:02:18 +00:00
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-12-04 03:40:16 +00:00
|
|
|
|
Directory.CreateDirectory(default_path);
|
2019-12-17 00:59:45 +00:00
|
|
|
|
var build = ((AssemblyInformationalVersionAttribute)Assembly
|
|
|
|
|
.GetAssembly(typeof(main_frame))
|
|
|
|
|
.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)[0])
|
|
|
|
|
.InformationalVersion;
|
2019-03-20 10:02:18 +00:00
|
|
|
|
// add something more unique, this is the IE 5.0 default string
|
|
|
|
|
try
|
2019-09-21 01:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
ServicePointManager.ServerCertificateValidationCallback += cert_check;
|
|
|
|
|
ServicePointManager.SecurityProtocol = (SecurityProtocolType)48 | 0 | (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
|
|
|
|
|
wc = new WebClient();
|
2019-12-17 00:59:45 +00:00
|
|
|
|
wc.Headers.Add("User-Agent", string.Format("Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 5.0); lokinet-win32-managed-ui/{0}", build));
|
2019-12-04 03:40:16 +00:00
|
|
|
|
wc.DownloadFile(uriBox.Text, string.Format("{0}{1}{2}", default_path, Path.DirectorySeparatorChar, rcName));
|
2019-03-20 10:02:18 +00:00
|
|
|
|
MessageBox.Show("LokiNET node bootstrapped", "LokiNET", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
}
|
2019-09-21 01:42:09 +00:00
|
|
|
|
catch (Exception ex)
|
2019-09-21 00:57:46 +00:00
|
|
|
|
{
|
|
|
|
|
string lokinetExeString;
|
|
|
|
|
Process lokinet_bootstrap = new Process();
|
|
|
|
|
|
|
|
|
|
if (Program.platform == PlatformID.Win32NT)
|
|
|
|
|
lokinetExeString = String.Format("{0}\\lokinet-bootstrap.exe", Directory.GetCurrentDirectory());
|
|
|
|
|
else
|
|
|
|
|
lokinetExeString = String.Format("{0}/lokinet-bootstrap", Directory.GetCurrentDirectory());
|
|
|
|
|
|
|
|
|
|
lokinet_bootstrap.StartInfo.UseShellExecute = false;
|
|
|
|
|
lokinet_bootstrap.StartInfo.CreateNoWindow = true;
|
|
|
|
|
lokinet_bootstrap.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory();
|
|
|
|
|
lokinet_bootstrap.StartInfo.FileName = lokinetExeString;
|
2019-12-04 03:40:16 +00:00
|
|
|
|
lokinet_bootstrap.StartInfo.Arguments = string.Format("--cacert rootcerts.pem -L {0} --output \"{1}{2}{3}\"", uriBox.Text, default_path, Path.DirectorySeparatorChar, rcName);
|
2019-09-21 00:57:46 +00:00
|
|
|
|
lokinet_bootstrap.Start();
|
|
|
|
|
lokinet_bootstrap.WaitForExit();
|
|
|
|
|
if (lokinet_bootstrap.ExitCode == 0)
|
2019-09-21 01:42:09 +00:00
|
|
|
|
{
|
2019-09-21 00:57:46 +00:00
|
|
|
|
DialogResult = DialogResult.OK;
|
2019-09-21 01:42:09 +00:00
|
|
|
|
MessageBox.Show("LokiNET node bootstrapped", "LokiNET", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
2019-09-21 00:57:46 +00:00
|
|
|
|
else
|
2019-09-21 01:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(string.Format("An error occured while downloading data. {0}", ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
|
|
|
|
|
DialogResult = DialogResult.Abort;
|
|
|
|
|
}
|
2019-03-20 10:02:18 +00:00
|
|
|
|
}
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 21:41:17 +00:00
|
|
|
|
private bool cert_check(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
|
|
|
|
|
{
|
|
|
|
|
// If the certificate is a valid, signed certificate, return true.
|
|
|
|
|
if (error == System.Net.Security.SslPolicyErrors.None)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MessageBox.Show(string.Format("X509Certificate [{0}] Policy Error: '{1}'",
|
|
|
|
|
cert.Subject,
|
|
|
|
|
error.ToString()), "SSL Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 10:02:18 +00:00
|
|
|
|
private void button1_Click_1(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|