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