Refactoring to make names conistent and remove warnings

This commit is contained in:
Flamefire committed 2014-02-15 13:08:24 +01:00
1 parent ff8fa48f3c
commit 8b1b44ad49
5 files changed
+32 -39

No files matched your search

+1
View File
@@ -62,3 +62,4 @@ Output/Vocaluxe_x64.exe
/Output/VocaluxeServerConfig.exe
/Output/VocaluxeServerConfig.exe.config
/PhoneGap/
/Output/Profiles
@@ -1,4 +1,5 @@
using System;
using System.Net.Sockets;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Diagnostics;
@@ -1,28 +1,24 @@
using Security.Cryptography;
using Security.Cryptography.X509Certificates;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
using NetFwTypeLib;
namespace WebserverInitalConfig
{
public static class ConfigHttpApi
public static class CConfigHttpApi
{
public static void reserveURL(string networkString)
public static void ReserveUrl(string networkString)
{
HttpApi.ReserveURL(networkString, "D:(A;;GX;;;S-1-1-0)");
}
public static void bindCert(string ip, int port, X509Certificate2 cert)
public static void BindCert(string ip, int port, X509Certificate2 cert)
{
IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse(ip), port);
if (HttpApi.QuerySslCertificateInfo(endpoint) != null)
@@ -34,7 +30,7 @@ namespace WebserverInitalConfig
}
public static void addCertToStore(X509Certificate2 cert)
public static void AddCertToStore(X509Certificate2 cert)
{
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadWrite);
@@ -52,7 +48,7 @@ namespace WebserverInitalConfig
}
public static X509Certificate2 getSelfSignedCert(string subjectName)
public static X509Certificate2 GetSelfSignedCert(string subjectName)
{
var keyParam = new CngKeyCreationParameters
{
@@ -66,26 +62,27 @@ namespace WebserverInitalConfig
CngKey key = CngKey.Create(CngAlgorithm2.Rsa, Guid.NewGuid().ToString(), keyParam);
X509CertificateCreationParameters param = new X509CertificateCreationParameters(
new X500DistinguishedName(subjectName));
param.SubjectName = new X500DistinguishedName(subjectName);
param.EndTime = DateTime.Today.AddYears(20);
//param.SignatureAlgorithm = X509CertificateSignatureAlgorithm.RsaSha512;
X509CertificateCreationParameters param = new X509CertificateCreationParameters(new X500DistinguishedName(subjectName))
{
SubjectName = new X500DistinguishedName(subjectName),
EndTime = DateTime.Today.AddYears(20)//,SignatureAlgorithm = X509CertificateSignatureAlgorithm.RsaSha512
};
OidCollection oc = new OidCollection();
oc.Add(new Oid("1.3.6.1.5.5.7.3.1"));
OidCollection oc = new OidCollection {new Oid("1.3.6.1.5.5.7.3.1")};
X509Extension eku = new X509EnhancedKeyUsageExtension(oc, true);
param.Extensions.Add(eku);
param.TakeOwnershipOfKey = true;
byte[] rawData = key.CreateSelfSignedCertificate(param).Export(X509ContentType.Pfx, "");
var cert = new X509Certificate2(rawData, "", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
cert.FriendlyName = "Vocaluxe Server Certificate";
var cert = new X509Certificate2(rawData, "", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet)
{
FriendlyName = "Vocaluxe Server Certificate"
};
return cert;
}
public static void addFirewallrule(string exePath, int port, bool isTCP)
public static void AddFirewallrule(string exePath, int port, bool isTCP)
{
INetFwMgr manage = (INetFwMgr)Activator.CreateInstance(
Type.GetTypeFromCLSID(new Guid("{304CE942-6E39-40D8-943A-B913C40C9CD4}")));
@@ -94,9 +91,9 @@ namespace WebserverInitalConfig
if (isFirewallEnabled)
{
INetFwAuthorizedApplications applications = manage.LocalPolicy.CurrentProfile.AuthorizedApplications;
if ((from INetFwAuthorizedApplication a in applications
where a.ProcessImageFileName == exePath
select a).Count() == 0)
if (!(from INetFwAuthorizedApplication a in applications
where a.ProcessImageFileName == exePath
select a).Any())
{
INetFwAuthorizedApplication application = (INetFwAuthorizedApplication)Activator.CreateInstance(
Type.GetTypeFromCLSID(new Guid("{EC9846B3-2762-4A6B-A214-6ACB603462D2}")));
@@ -107,10 +104,10 @@ namespace WebserverInitalConfig
applications.Add(application);
}
INetFwOpenPorts openPorts = manage.LocalPolicy.CurrentProfile.GloballyOpenPorts;
if ((from INetFwOpenPort p in openPorts
where (p.Port == port &&
(p.Protocol == (isTCP?NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP : NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_UDP)))
select p).Count() == 0)
if (!(from INetFwOpenPort p in openPorts
where (p.Port == port &&
(p.Protocol == (isTCP?NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP : NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_UDP)))
select p).Any())
{
INetFwOpenPort openPort = (INetFwOpenPort)Activator.CreateInstance(
Type.GetTypeFromCLSID(new Guid("{0CA545C6-37AD-4A6C-BF92-9F7610067EF5}")));
+6 -12
View File
@@ -1,12 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
namespace WebserverInitalConfig
{
@@ -20,19 +14,19 @@ namespace WebserverInitalConfig
Environment.Exit(-1);
}
ConfigHttpApi.addFirewallrule(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"Vocaluxe.exe"), Int32.Parse(args[0]), true);
CConfigHttpApi.AddFirewallrule(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"Vocaluxe.exe"), Int32.Parse(args[0]), true);
if (args[1].ToLower() == "true")
{
string hostname = Dns.GetHostName();
var cert = ConfigHttpApi.getSelfSignedCert("CN=" + hostname + " C=DE O=Vocaluxe OU=Vocaluxe Server");
ConfigHttpApi.addCertToStore(cert);
ConfigHttpApi.bindCert("0.0.0.0", Int32.Parse(args[0]), cert);
ConfigHttpApi.reserveURL("https://+:" + args[0] + "/");
var cert = CConfigHttpApi.GetSelfSignedCert("CN=" + hostname + " C=DE O=Vocaluxe OU=Vocaluxe Server");
CConfigHttpApi.AddCertToStore(cert);
CConfigHttpApi.BindCert("0.0.0.0", Int32.Parse(args[0]), cert);
CConfigHttpApi.ReserveUrl("https://+:" + args[0] + "/");
}
else
{
ConfigHttpApi.reserveURL("http://+:" + args[0] + "/");
CConfigHttpApi.ReserveUrl("http://+:" + args[0] + "/");
}
}
@@ -61,7 +61,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConfigHttpApi.cs" />
<Compile Include="CConfigHttpApi.cs" />
<Compile Include="HttpApi.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />