Make server config catch errors instead of crashing

Remove Security.dll, not required and causes problems (name conflict with system.dll, DO NOT READD)
This commit is contained in:
Flamefire committed 2014-03-20 02:30:29 +01:00
1 parent 8c7a22103b
commit a9ff5f6004
5 files changed
+73 -42

No files matched your search

+10 -5
View File
@@ -16,9 +16,9 @@
#endregion #endregion
using System; using System;
using System.Diagnostics;
using System.ServiceModel; using System.ServiceModel;
using System.ServiceModel.Web; using System.ServiceModel.Web;
using System.Diagnostics;
using System.Net; using System.Net;
namespace ServerLib namespace ServerLib
@@ -191,10 +191,15 @@ namespace ServerLib
CreateNoWindow = true, CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden, WindowStyle = ProcessWindowStyle.Hidden,
}; };
Process p = Process.Start(info); try
p.WaitForExit(); {
p.Close(); using (Process p = Process.Start(info))
{
p.WaitForExit();
p.Close();
}
}
catch (Exception) {}
#else #else
//Required? //Required?
Binary file not shown.
+22 -1
View File
@@ -17,6 +17,7 @@
using System.Security.Authentication; using System.Security.Authentication;
using System.Security.Principal; using System.Security.Principal;
using System.Windows.Forms;
using Security.Cryptography; using Security.Cryptography;
using Security.Cryptography.X509Certificates; using Security.Cryptography.X509Certificates;
using System; using System;
@@ -124,7 +125,22 @@ namespace WebserverInitalConfig
keyParam.Parameters.Add(new CngProperty("Length", BitConverter.GetBytes(2048), CngPropertyOptions.None)); keyParam.Parameters.Add(new CngProperty("Length", BitConverter.GetBytes(2048), CngPropertyOptions.None));
CngKey key = CngKey.Create(CngAlgorithm2.Rsa, Guid.NewGuid().ToString(), keyParam); CngKey key;
try
{
key= CngKey.Create(CngAlgorithm2.Rsa, Guid.NewGuid().ToString(), keyParam);
}
catch (PlatformNotSupportedException)
{
try
{
key = CngKey.Create(CngAlgorithm2.Aes, Guid.NewGuid().ToString(), keyParam);
}
catch (PlatformNotSupportedException)
{
return null;
}
}
X509CertificateCreationParameters param = new X509CertificateCreationParameters(new X500DistinguishedName(subjectName)) X509CertificateCreationParameters param = new X509CertificateCreationParameters(new X500DistinguishedName(subjectName))
{ {
@@ -156,6 +172,11 @@ namespace WebserverInitalConfig
if (!IsAdministrator()) if (!IsAdministrator())
throw new AuthenticationException(); throw new AuthenticationException();
cert = _GetSelfSignedCert(certName); cert = _GetSelfSignedCert(certName);
if (cert == null)
{
MessageBox.Show("Could not create certificate. Secure server connection may not work. Disable it if required.");
return;
}
_AddCertToStore(cert); _AddCertToStore(cert);
} }
_BindCert(cert); _BindCert(cert);
+40 -32
View File
@@ -20,6 +20,7 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Security.Authentication; using System.Security.Authentication;
using System.Windows.Forms;
namespace WebserverInitalConfig namespace WebserverInitalConfig
{ {
@@ -29,49 +30,56 @@ namespace WebserverInitalConfig
private static void Main(string[] args) private static void Main(string[] args)
// ReSharper restore InconsistentNaming // ReSharper restore InconsistentNaming
{ {
int port; try
if (args.Length < 2 || !int.TryParse(args[0], out port))
{ {
Console.WriteLine("Usage: VocaluxeServerConfig port isHttps"); int port;
Environment.Exit(-1); if (args.Length < 2 || !int.TryParse(args[0], out port))
}
else
{
CConfigHttpApi config = new CConfigHttpApi("Vocaluxe", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Vocaluxe.exe"), "0.0.0.0", port, true);
try
{ {
config.AddFirewallRule(); Console.WriteLine("Usage: VocaluxeServerConfig port isHttps");
if (args[1].ToLower() == "true") Environment.Exit(-1);
config.CreateAndAddCert(Dns.GetHostName());
if ((args.Length >= 3 && args[2] == "reserve") || CConfigHttpApi.IsAdministrator())
config.ReserveUrl();
} }
catch (AuthenticationException) else
{ {
ProcessStartInfo proc = new ProcessStartInfo CConfigHttpApi config = new CConfigHttpApi("Vocaluxe", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Vocaluxe.exe"), "0.0.0.0", port, true);
{
UseShellExecute = true,
WorkingDirectory = Environment.CurrentDirectory,
FileName = Process.GetCurrentProcess().MainModule.FileName,
Arguments = args[0] + " " + args[1],
Verb = "runas",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
};
try try
{ {
Process.Start(proc); config.AddFirewallRule();
if (args[1].ToLower() == "true")
config.CreateAndAddCert(Dns.GetHostName());
if ((args.Length >= 3 && args[2] == "reserve") || CConfigHttpApi.IsAdministrator())
config.ReserveUrl();
} }
catch catch (AuthenticationException)
{ {
// The user refused the elevation. ProcessStartInfo proc = new ProcessStartInfo
// Do nothing and return directly ... {
Environment.Exit(-1); UseShellExecute = true,
WorkingDirectory = Environment.CurrentDirectory,
FileName = Process.GetCurrentProcess().MainModule.FileName,
Arguments = args[0] + " " + args[1],
Verb = "runas",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
};
try
{
Process.Start(proc);
}
catch
{
// The user refused the elevation.
// Do nothing and return directly ...
Environment.Exit(-1);
}
} }
} }
} }
catch (Exception e)
{
MessageBox.Show("Error while installing server: " + e.Message);
}
} }
} }
} }
@@ -41,16 +41,13 @@
<EmbedInteropTypes>True</EmbedInteropTypes> <EmbedInteropTypes>True</EmbedInteropTypes>
<HintPath>..\Output\Interop.NetFwTypeLib.dll</HintPath> <HintPath>..\Output\Interop.NetFwTypeLib.dll</HintPath>
</Reference> </Reference>
<Reference Include="Security, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Output\Security.dll</HintPath>
</Reference>
<Reference Include="Security.Cryptography, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="Security.Cryptography, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\Output\Security.Cryptography.dll</HintPath> <HintPath>..\Output\Security.Cryptography.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />