IMPORTANT: Format of all files with Resharper
NO functional changes. If you have problems merging your changes, merge/rebase on previous commit then merge this. Conflicts can easily be resolved (take yours if in doubt) After that merge next commits
This commit is contained in:
1 parent
3a110804d8
commit
149026ec32
57 files changed
+1242
-1099
No files matched your search
@@ -1,4 +1,21 @@
|
||||
using Security.Cryptography;
|
||||
#region license
|
||||
// This file is part of Vocaluxe.
|
||||
//
|
||||
// Vocaluxe is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Vocaluxe is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
|
||||
#endregion
|
||||
|
||||
using Security.Cryptography;
|
||||
using Security.Cryptography.X509Certificates;
|
||||
using System;
|
||||
using System.Linq;
|
||||
@@ -11,7 +28,7 @@ namespace WebserverInitalConfig
|
||||
{
|
||||
public static class CConfigHttpApi
|
||||
{
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable InconsistentNaming
|
||||
private const String CLSID_NetFwMgr = "{304CE942-6E39-40D8-943A-B913C40C9CD4}";
|
||||
private const String CLSID_NetAuthApp = "{EC9846B3-2762-4A6B-A214-6ACB603462D2}";
|
||||
private const String CLSID_NetOpenPort = "{0CA545C6-37AD-4A6C-BF92-9F7610067EF5}";
|
||||
@@ -21,46 +38,39 @@ namespace WebserverInitalConfig
|
||||
HttpApi.ReserveURL(networkString, "D:(A;;GX;;;S-1-1-0)");
|
||||
}
|
||||
|
||||
|
||||
public static void BindCert(string ip, int port, X509Certificate2 cert)
|
||||
{
|
||||
IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse(ip), port);
|
||||
if (HttpApi.QuerySslCertificateInfo(endpoint) != null)
|
||||
{
|
||||
HttpApi.DeleteCertificateBinding(endpoint);
|
||||
}
|
||||
|
||||
HttpApi.BindCertificate(endpoint, cert.GetCertHash(), StoreName.My, new Guid("{7baf41f1-48b7-42cb-b145-f815499cb48f}"));
|
||||
}
|
||||
|
||||
|
||||
public static void AddCertToStore(X509Certificate2 cert)
|
||||
{
|
||||
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
|
||||
store.Open(OpenFlags.ReadWrite);
|
||||
|
||||
X509Certificate2Collection oldCerts = store.Certificates.Find(X509FindType.FindBySubjectDistinguishedName,
|
||||
cert.SubjectName.Name, false);
|
||||
cert.SubjectName.Name, false);
|
||||
|
||||
foreach (var oldCert in oldCerts)
|
||||
{
|
||||
foreach (X509Certificate2 oldCert in oldCerts)
|
||||
store.Remove(oldCert);
|
||||
}
|
||||
|
||||
store.Add(cert);
|
||||
store.Close();
|
||||
}
|
||||
|
||||
|
||||
public static X509Certificate2 GetSelfSignedCert(string subjectName)
|
||||
{
|
||||
var keyParam = new CngKeyCreationParameters
|
||||
{
|
||||
ExportPolicy = CngExportPolicies.AllowExport,
|
||||
KeyCreationOptions = CngKeyCreationOptions.MachineKey | CngKeyCreationOptions.OverwriteExistingKey,
|
||||
KeyUsage = CngKeyUsages.AllUsages,
|
||||
Provider = CngProvider.MicrosoftSoftwareKeyStorageProvider,
|
||||
};
|
||||
{
|
||||
ExportPolicy = CngExportPolicies.AllowExport,
|
||||
KeyCreationOptions = CngKeyCreationOptions.MachineKey | CngKeyCreationOptions.OverwriteExistingKey,
|
||||
KeyUsage = CngKeyUsages.AllUsages,
|
||||
Provider = CngProvider.MicrosoftSoftwareKeyStorageProvider,
|
||||
};
|
||||
|
||||
keyParam.Parameters.Add(new CngProperty("Length", BitConverter.GetBytes(2048), CngPropertyOptions.None));
|
||||
|
||||
@@ -69,7 +79,7 @@ namespace WebserverInitalConfig
|
||||
X509CertificateCreationParameters param = new X509CertificateCreationParameters(new X500DistinguishedName(subjectName))
|
||||
{
|
||||
SubjectName = new X500DistinguishedName(subjectName),
|
||||
EndTime = DateTime.Today.AddYears(20)//,SignatureAlgorithm = X509CertificateSignatureAlgorithm.RsaSha512
|
||||
EndTime = DateTime.Today.AddYears(20) //,SignatureAlgorithm = X509CertificateSignatureAlgorithm.RsaSha512
|
||||
};
|
||||
|
||||
OidCollection oc = new OidCollection {new Oid("1.3.6.1.5.5.7.3.1")};
|
||||
@@ -117,7 +127,7 @@ namespace WebserverInitalConfig
|
||||
openPort.Enabled = true;
|
||||
openPort.Port = port;
|
||||
openPort.Protocol = protocol;
|
||||
openPort.Name = "Vocaluxe("+port+")";
|
||||
openPort.Name = "Vocaluxe(" + port + ")";
|
||||
openPort.Scope = NET_FW_SCOPE_.NET_FW_SCOPE_ALL;
|
||||
|
||||
openPorts.Add(openPort);
|
||||
@@ -134,6 +144,7 @@ namespace WebserverInitalConfig
|
||||
_AddFirewallRuleForProfile(manage.LocalPolicy.GetProfileByType(NET_FW_PROFILE_TYPE_.NET_FW_PROFILE_STANDARD), exePath, port, isTCP);
|
||||
_AddFirewallRuleForProfile(manage.LocalPolicy.GetProfileByType(NET_FW_PROFILE_TYPE_.NET_FW_PROFILE_CURRENT), exePath, port, isTCP);
|
||||
}
|
||||
|
||||
/*public static X509Certificate2 getCert(string subject)
|
||||
{
|
||||
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
|
||||
@@ -157,4 +168,4 @@ namespace WebserverInitalConfig
|
||||
return new X509Certificate2(x509.Sign(rsa));
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user