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));
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
+368
-379
@@ -1,4 +1,21 @@
|
||||
using System;
|
||||
#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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
@@ -11,28 +28,19 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace WebserverInitalConfig
|
||||
{
|
||||
internal static class HttpApi
|
||||
static class HttpApi
|
||||
{
|
||||
private static readonly HTTPAPI_VERSION HttpApiVersion = new HTTPAPI_VERSION(1, 0);
|
||||
|
||||
#region DllImport
|
||||
|
||||
[DllImport("httpapi.dll", SetLastError = true)]
|
||||
static extern uint HttpInitialize(
|
||||
private static extern uint HttpInitialize(
|
||||
HTTPAPI_VERSION version,
|
||||
uint flags,
|
||||
IntPtr pReserved);
|
||||
|
||||
[DllImport("httpapi.dll", SetLastError = true)]
|
||||
static extern uint HttpSetServiceConfiguration(
|
||||
IntPtr serviceIntPtr,
|
||||
HTTP_SERVICE_CONFIG_ID configId,
|
||||
IntPtr pConfigInformation,
|
||||
int configInformationLength,
|
||||
IntPtr pOverlapped);
|
||||
|
||||
[DllImport("httpapi.dll", SetLastError = true)]
|
||||
static extern uint HttpDeleteServiceConfiguration(
|
||||
private static extern uint HttpSetServiceConfiguration(
|
||||
IntPtr serviceIntPtr,
|
||||
HTTP_SERVICE_CONFIG_ID configId,
|
||||
IntPtr pConfigInformation,
|
||||
@@ -40,26 +48,31 @@ namespace WebserverInitalConfig
|
||||
IntPtr pOverlapped);
|
||||
|
||||
[DllImport("httpapi.dll", SetLastError = true)]
|
||||
static extern uint HttpTerminate(
|
||||
private static extern uint HttpDeleteServiceConfiguration(
|
||||
IntPtr serviceIntPtr,
|
||||
HTTP_SERVICE_CONFIG_ID configId,
|
||||
IntPtr pConfigInformation,
|
||||
int configInformationLength,
|
||||
IntPtr pOverlapped);
|
||||
|
||||
[DllImport("httpapi.dll", SetLastError = true)]
|
||||
private static extern uint HttpTerminate(
|
||||
uint Flags,
|
||||
IntPtr pReserved);
|
||||
|
||||
[DllImport("httpapi.dll", SetLastError = true)]
|
||||
static extern uint HttpQueryServiceConfiguration(
|
||||
IntPtr serviceIntPtr,
|
||||
HTTP_SERVICE_CONFIG_ID configId,
|
||||
IntPtr pInputConfigInfo,
|
||||
int inputConfigInfoLength,
|
||||
IntPtr pOutputConfigInfo,
|
||||
int outputConfigInfoLength,
|
||||
[Optional]
|
||||
out int pReturnLength,
|
||||
IntPtr pOverlapped);
|
||||
private static extern uint HttpQueryServiceConfiguration(
|
||||
IntPtr serviceIntPtr,
|
||||
HTTP_SERVICE_CONFIG_ID configId,
|
||||
IntPtr pInputConfigInfo,
|
||||
int inputConfigInfoLength,
|
||||
IntPtr pOutputConfigInfo,
|
||||
int outputConfigInfoLength,
|
||||
[Optional] out int pReturnLength,
|
||||
IntPtr pOverlapped);
|
||||
|
||||
|
||||
enum HTTP_SERVICE_CONFIG_ID
|
||||
private enum HTTP_SERVICE_CONFIG_ID
|
||||
{
|
||||
|
||||
HttpServiceConfigIPListenList = 0,
|
||||
HttpServiceConfigSSLCertInfo,
|
||||
HttpServiceConfigUrlAclInfo,
|
||||
@@ -67,14 +80,14 @@ namespace WebserverInitalConfig
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct HTTP_SERVICE_CONFIG_SSL_SET
|
||||
private struct HTTP_SERVICE_CONFIG_SSL_SET
|
||||
{
|
||||
public HTTP_SERVICE_CONFIG_SSL_KEY KeyDesc;
|
||||
public HTTP_SERVICE_CONFIG_SSL_PARAM ParamDesc;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct HTTP_SERVICE_CONFIG_SSL_KEY
|
||||
private struct HTTP_SERVICE_CONFIG_SSL_KEY
|
||||
{
|
||||
public IntPtr pIpPort;
|
||||
|
||||
@@ -85,25 +98,22 @@ namespace WebserverInitalConfig
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
struct HTTP_SERVICE_CONFIG_SSL_PARAM
|
||||
private struct HTTP_SERVICE_CONFIG_SSL_PARAM
|
||||
{
|
||||
public int SslHashLength;
|
||||
public IntPtr pSslHash;
|
||||
public Guid AppId;
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
public string pSslCertStoreName;
|
||||
[MarshalAs(UnmanagedType.LPWStr)] public string pSslCertStoreName;
|
||||
public uint DefaultCertCheckMode;
|
||||
public int DefaultRevocationFreshnessTime;
|
||||
public int DefaultRevocationUrlRetrievalTimeout;
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
public string pDefaultSslCtlIdentifier;
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
public string pDefaultSslCtlStoreName;
|
||||
[MarshalAs(UnmanagedType.LPWStr)] public string pDefaultSslCtlIdentifier;
|
||||
[MarshalAs(UnmanagedType.LPWStr)] public string pDefaultSslCtlStoreName;
|
||||
public uint DefaultFlags;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
struct HTTPAPI_VERSION
|
||||
private struct HTTPAPI_VERSION
|
||||
{
|
||||
public ushort HttpApiMajorVersion;
|
||||
public ushort HttpApiMinorVersion;
|
||||
@@ -116,14 +126,14 @@ namespace WebserverInitalConfig
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct HTTP_SERVICE_CONFIG_SSL_QUERY
|
||||
private struct HTTP_SERVICE_CONFIG_SSL_QUERY
|
||||
{
|
||||
public HTTP_SERVICE_CONFIG_QUERY_TYPE QueryDesc;
|
||||
public HTTP_SERVICE_CONFIG_SSL_KEY KeyDesc;
|
||||
public uint dwToken;
|
||||
}
|
||||
|
||||
enum HTTP_SERVICE_CONFIG_QUERY_TYPE
|
||||
private enum HTTP_SERVICE_CONFIG_QUERY_TYPE
|
||||
{
|
||||
HttpServiceConfigQueryExact = 0,
|
||||
HttpServiceConfigQueryNext,
|
||||
@@ -131,7 +141,7 @@ namespace WebserverInitalConfig
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct HTTP_SERVICE_CONFIG_URLACL_SET
|
||||
private struct HTTP_SERVICE_CONFIG_URLACL_SET
|
||||
{
|
||||
public HTTP_SERVICE_CONFIG_URLACL_KEY KeyDesc;
|
||||
public HTTP_SERVICE_CONFIG_URLACL_PARAM ParamDesc;
|
||||
@@ -140,8 +150,7 @@ namespace WebserverInitalConfig
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
public struct HTTP_SERVICE_CONFIG_URLACL_KEY
|
||||
{
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
public string pUrlPrefix;
|
||||
[MarshalAs(UnmanagedType.LPWStr)] public string pUrlPrefix;
|
||||
|
||||
public HTTP_SERVICE_CONFIG_URLACL_KEY(string urlPrefix)
|
||||
{
|
||||
@@ -150,21 +159,18 @@ namespace WebserverInitalConfig
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
struct HTTP_SERVICE_CONFIG_URLACL_PARAM
|
||||
private struct HTTP_SERVICE_CONFIG_URLACL_PARAM
|
||||
{
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
public string pStringSecurityDescriptor;
|
||||
[MarshalAs(UnmanagedType.LPWStr)] public string pStringSecurityDescriptor;
|
||||
|
||||
public HTTP_SERVICE_CONFIG_URLACL_PARAM(string securityDescriptor)
|
||||
{
|
||||
pStringSecurityDescriptor = securityDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constants
|
||||
|
||||
public const uint HTTP_INITIALIZE_CONFIG = 0x00000002;
|
||||
public const uint HTTP_SERVICE_CONFIG_SSL_FLAG_NEGOTIATE_CLIENT_CERT = 0x00000002;
|
||||
public const uint HTTP_SERVICE_CONFIG_SSL_FLAG_NO_RAW_FILTER = 0x00000004;
|
||||
@@ -173,11 +179,9 @@ namespace WebserverInitalConfig
|
||||
private const uint ERROR_ALREADY_EXISTS = 183;
|
||||
private const uint ERROR_FILE_NOT_FOUND = 2;
|
||||
private const int ERROR_NO_MORE_ITEMS = 259;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
|
||||
public class SslCertificateInfo
|
||||
{
|
||||
public byte[] Hash { get; set; }
|
||||
@@ -192,162 +196,158 @@ namespace WebserverInitalConfig
|
||||
|
||||
uint retVal;
|
||||
CallHttpApi(delegate
|
||||
{
|
||||
GCHandle sockAddrHandle = CreateSockaddrStructure(ipPort);
|
||||
IntPtr pIpPort = sockAddrHandle.AddrOfPinnedObject();
|
||||
HTTP_SERVICE_CONFIG_SSL_KEY sslKey = new HTTP_SERVICE_CONFIG_SSL_KEY(pIpPort);
|
||||
|
||||
HTTP_SERVICE_CONFIG_SSL_QUERY inputConfigInfoQuery =
|
||||
new HTTP_SERVICE_CONFIG_SSL_QUERY
|
||||
{
|
||||
QueryDesc = HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryExact,
|
||||
KeyDesc = sslKey
|
||||
};
|
||||
|
||||
IntPtr pInputConfigInfo =
|
||||
Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_SSL_QUERY)));
|
||||
Marshal.StructureToPtr(inputConfigInfoQuery, pInputConfigInfo, false);
|
||||
|
||||
IntPtr pOutputConfigInfo = IntPtr.Zero;
|
||||
int returnLength = 0;
|
||||
|
||||
try
|
||||
{
|
||||
HTTP_SERVICE_CONFIG_ID queryType = HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo;
|
||||
int inputConfigInfoSize = Marshal.SizeOf(inputConfigInfoQuery);
|
||||
retVal = HttpQueryServiceConfiguration(IntPtr.Zero,
|
||||
queryType,
|
||||
pInputConfigInfo,
|
||||
inputConfigInfoSize,
|
||||
pOutputConfigInfo,
|
||||
returnLength,
|
||||
out returnLength,
|
||||
IntPtr.Zero);
|
||||
if (retVal == ERROR_FILE_NOT_FOUND)
|
||||
return;
|
||||
GCHandle sockAddrHandle = CreateSockaddrStructure(ipPort);
|
||||
IntPtr pIpPort = sockAddrHandle.AddrOfPinnedObject();
|
||||
HTTP_SERVICE_CONFIG_SSL_KEY sslKey = new HTTP_SERVICE_CONFIG_SSL_KEY(pIpPort);
|
||||
|
||||
if (ERROR_INSUFFICIENT_BUFFER == retVal) // ERROR_INSUFFICIENT_BUFFER = 122
|
||||
HTTP_SERVICE_CONFIG_SSL_QUERY inputConfigInfoQuery =
|
||||
new HTTP_SERVICE_CONFIG_SSL_QUERY
|
||||
{
|
||||
QueryDesc = HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryExact,
|
||||
KeyDesc = sslKey
|
||||
};
|
||||
|
||||
IntPtr pInputConfigInfo =
|
||||
Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_SSL_QUERY)));
|
||||
Marshal.StructureToPtr(inputConfigInfoQuery, pInputConfigInfo, false);
|
||||
|
||||
IntPtr pOutputConfigInfo = IntPtr.Zero;
|
||||
int returnLength = 0;
|
||||
|
||||
try
|
||||
{
|
||||
pOutputConfigInfo = Marshal.AllocCoTaskMem(returnLength);
|
||||
HTTP_SERVICE_CONFIG_ID queryType = HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo;
|
||||
int inputConfigInfoSize = Marshal.SizeOf(inputConfigInfoQuery);
|
||||
retVal = HttpQueryServiceConfiguration(IntPtr.Zero,
|
||||
queryType,
|
||||
pInputConfigInfo,
|
||||
inputConfigInfoSize,
|
||||
pOutputConfigInfo,
|
||||
returnLength,
|
||||
out returnLength,
|
||||
IntPtr.Zero);
|
||||
if (retVal == ERROR_FILE_NOT_FOUND)
|
||||
return;
|
||||
|
||||
try
|
||||
if (ERROR_INSUFFICIENT_BUFFER == retVal) // ERROR_INSUFFICIENT_BUFFER = 122
|
||||
{
|
||||
retVal = HttpQueryServiceConfiguration(IntPtr.Zero,
|
||||
queryType,
|
||||
pInputConfigInfo,
|
||||
inputConfigInfoSize,
|
||||
pOutputConfigInfo,
|
||||
returnLength,
|
||||
out returnLength,
|
||||
IntPtr.Zero);
|
||||
pOutputConfigInfo = Marshal.AllocCoTaskMem(returnLength);
|
||||
|
||||
try
|
||||
{
|
||||
retVal = HttpQueryServiceConfiguration(IntPtr.Zero,
|
||||
queryType,
|
||||
pInputConfigInfo,
|
||||
inputConfigInfoSize,
|
||||
pOutputConfigInfo,
|
||||
returnLength,
|
||||
out returnLength,
|
||||
IntPtr.Zero);
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
|
||||
var outputConfigInfo =
|
||||
(HTTP_SERVICE_CONFIG_SSL_SET)
|
||||
Marshal.PtrToStructure(pOutputConfigInfo, typeof(HTTP_SERVICE_CONFIG_SSL_SET));
|
||||
|
||||
byte[] hash = new byte[outputConfigInfo.ParamDesc.SslHashLength];
|
||||
Marshal.Copy(outputConfigInfo.ParamDesc.pSslHash, hash, 0, hash.Length);
|
||||
|
||||
Guid appId = outputConfigInfo.ParamDesc.AppId;
|
||||
string storeName = outputConfigInfo.ParamDesc.pSslCertStoreName;
|
||||
|
||||
result = new SslCertificateInfo {AppId = appId, Hash = hash, StoreName = storeName, IpPort = ipPort};
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeCoTaskMem(pOutputConfigInfo);
|
||||
}
|
||||
}
|
||||
else
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
|
||||
var outputConfigInfo =
|
||||
(HTTP_SERVICE_CONFIG_SSL_SET)
|
||||
Marshal.PtrToStructure(pOutputConfigInfo, typeof(HTTP_SERVICE_CONFIG_SSL_SET));
|
||||
|
||||
byte[] hash = new byte[outputConfigInfo.ParamDesc.SslHashLength];
|
||||
Marshal.Copy(outputConfigInfo.ParamDesc.pSslHash, hash, 0, hash.Length);
|
||||
|
||||
Guid appId = outputConfigInfo.ParamDesc.AppId;
|
||||
string storeName = outputConfigInfo.ParamDesc.pSslCertStoreName;
|
||||
|
||||
result = new SslCertificateInfo { AppId = appId, Hash = hash, StoreName = storeName, IpPort = ipPort };
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeCoTaskMem(pOutputConfigInfo);
|
||||
}
|
||||
}
|
||||
else
|
||||
finally
|
||||
{
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
Marshal.FreeCoTaskMem(pInputConfigInfo);
|
||||
if (sockAddrHandle.IsAllocated)
|
||||
sockAddrHandle.Free();
|
||||
}
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeCoTaskMem(pInputConfigInfo);
|
||||
if (sockAddrHandle.IsAllocated)
|
||||
sockAddrHandle.Free();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void BindCertificate(IPEndPoint ipPort, byte[] hash, StoreName storeName, Guid appId)
|
||||
{
|
||||
if (ipPort == null) throw new ArgumentNullException("ipPort");
|
||||
if (hash == null) throw new ArgumentNullException("hash");
|
||||
if (ipPort == null)
|
||||
throw new ArgumentNullException("ipPort");
|
||||
if (hash == null)
|
||||
throw new ArgumentNullException("hash");
|
||||
|
||||
CallHttpApi(
|
||||
delegate
|
||||
{
|
||||
HTTP_SERVICE_CONFIG_SSL_SET configSslSet = new HTTP_SERVICE_CONFIG_SSL_SET();
|
||||
|
||||
GCHandle sockAddrHandle = CreateSockaddrStructure(ipPort);
|
||||
IntPtr pIpPort = sockAddrHandle.AddrOfPinnedObject();
|
||||
HTTP_SERVICE_CONFIG_SSL_KEY httpServiceConfigSslKey =
|
||||
new HTTP_SERVICE_CONFIG_SSL_KEY(pIpPort);
|
||||
HTTP_SERVICE_CONFIG_SSL_PARAM configSslParam = new HTTP_SERVICE_CONFIG_SSL_PARAM();
|
||||
|
||||
|
||||
GCHandle handleHash = GCHandle.Alloc(hash, GCHandleType.Pinned);
|
||||
configSslParam.AppId = appId;
|
||||
configSslParam.DefaultCertCheckMode = 0;
|
||||
configSslParam.DefaultFlags = 0; //HTTP_SERVICE_CONFIG_SSL_FLAG_NEGOTIATE_CLIENT_CERT;
|
||||
configSslParam.DefaultRevocationFreshnessTime = 0;
|
||||
configSslParam.DefaultRevocationUrlRetrievalTimeout = 0;
|
||||
configSslParam.pSslCertStoreName = storeName.ToString();
|
||||
configSslParam.pSslHash = handleHash.AddrOfPinnedObject();
|
||||
configSslParam.SslHashLength = hash.Length;
|
||||
configSslSet.ParamDesc = configSslParam;
|
||||
configSslSet.KeyDesc = httpServiceConfigSslKey;
|
||||
|
||||
IntPtr pInputConfigInfo =
|
||||
Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_SSL_SET)));
|
||||
Marshal.StructureToPtr(configSslSet, pInputConfigInfo, false);
|
||||
|
||||
try
|
||||
{
|
||||
uint retVal = HttpSetServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo,
|
||||
pInputConfigInfo,
|
||||
Marshal.SizeOf(configSslSet),
|
||||
IntPtr.Zero);
|
||||
HTTP_SERVICE_CONFIG_SSL_SET configSslSet = new HTTP_SERVICE_CONFIG_SSL_SET();
|
||||
|
||||
if (ERROR_ALREADY_EXISTS != retVal)
|
||||
{
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
retVal = HttpDeleteServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo,
|
||||
pInputConfigInfo,
|
||||
Marshal.SizeOf(configSslSet),
|
||||
IntPtr.Zero);
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
GCHandle sockAddrHandle = CreateSockaddrStructure(ipPort);
|
||||
IntPtr pIpPort = sockAddrHandle.AddrOfPinnedObject();
|
||||
HTTP_SERVICE_CONFIG_SSL_KEY httpServiceConfigSslKey =
|
||||
new HTTP_SERVICE_CONFIG_SSL_KEY(pIpPort);
|
||||
HTTP_SERVICE_CONFIG_SSL_PARAM configSslParam = new HTTP_SERVICE_CONFIG_SSL_PARAM();
|
||||
|
||||
retVal = HttpSetServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo,
|
||||
pInputConfigInfo,
|
||||
Marshal.SizeOf(configSslSet),
|
||||
IntPtr.Zero);
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
|
||||
GCHandle handleHash = GCHandle.Alloc(hash, GCHandleType.Pinned);
|
||||
configSslParam.AppId = appId;
|
||||
configSslParam.DefaultCertCheckMode = 0;
|
||||
configSslParam.DefaultFlags = 0; //HTTP_SERVICE_CONFIG_SSL_FLAG_NEGOTIATE_CLIENT_CERT;
|
||||
configSslParam.DefaultRevocationFreshnessTime = 0;
|
||||
configSslParam.DefaultRevocationUrlRetrievalTimeout = 0;
|
||||
configSslParam.pSslCertStoreName = storeName.ToString();
|
||||
configSslParam.pSslHash = handleHash.AddrOfPinnedObject();
|
||||
configSslParam.SslHashLength = hash.Length;
|
||||
configSslSet.ParamDesc = configSslParam;
|
||||
configSslSet.KeyDesc = httpServiceConfigSslKey;
|
||||
|
||||
IntPtr pInputConfigInfo =
|
||||
Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_SSL_SET)));
|
||||
Marshal.StructureToPtr(configSslSet, pInputConfigInfo, false);
|
||||
|
||||
try
|
||||
{
|
||||
uint retVal = HttpSetServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo,
|
||||
pInputConfigInfo,
|
||||
Marshal.SizeOf(configSslSet),
|
||||
IntPtr.Zero);
|
||||
|
||||
if (ERROR_ALREADY_EXISTS != retVal)
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
else
|
||||
{
|
||||
retVal = HttpDeleteServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo,
|
||||
pInputConfigInfo,
|
||||
Marshal.SizeOf(configSslSet),
|
||||
IntPtr.Zero);
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
|
||||
retVal = HttpSetServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo,
|
||||
pInputConfigInfo,
|
||||
Marshal.SizeOf(configSslSet),
|
||||
IntPtr.Zero);
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeCoTaskMem(pInputConfigInfo);
|
||||
if (handleHash.IsAllocated)
|
||||
handleHash.Free();
|
||||
if (sockAddrHandle.IsAllocated)
|
||||
sockAddrHandle.Free();
|
||||
}
|
||||
});
|
||||
finally
|
||||
{
|
||||
Marshal.FreeCoTaskMem(pInputConfigInfo);
|
||||
if (handleHash.IsAllocated)
|
||||
handleHash.Free();
|
||||
if (sockAddrHandle.IsAllocated)
|
||||
sockAddrHandle.Free();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void DeleteCertificateBinding(params IPEndPoint[] ipPorts)
|
||||
@@ -356,41 +356,41 @@ namespace WebserverInitalConfig
|
||||
return;
|
||||
|
||||
CallHttpApi(
|
||||
delegate
|
||||
{
|
||||
foreach (var ipPort in ipPorts)
|
||||
{
|
||||
HTTP_SERVICE_CONFIG_SSL_SET configSslSet =
|
||||
new HTTP_SERVICE_CONFIG_SSL_SET();
|
||||
|
||||
GCHandle sockAddrHandle = CreateSockaddrStructure(ipPort);
|
||||
IntPtr pIpPort = sockAddrHandle.AddrOfPinnedObject();
|
||||
HTTP_SERVICE_CONFIG_SSL_KEY httpServiceConfigSslKey =
|
||||
new HTTP_SERVICE_CONFIG_SSL_KEY(pIpPort);
|
||||
configSslSet.KeyDesc = httpServiceConfigSslKey;
|
||||
|
||||
IntPtr pInputConfigInfo =
|
||||
Marshal.AllocCoTaskMem(
|
||||
Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_SSL_SET)));
|
||||
Marshal.StructureToPtr(configSslSet, pInputConfigInfo, false);
|
||||
|
||||
try
|
||||
delegate
|
||||
{
|
||||
uint retVal = HttpDeleteServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo,
|
||||
pInputConfigInfo,
|
||||
Marshal.SizeOf(configSslSet),
|
||||
IntPtr.Zero);
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeCoTaskMem(pInputConfigInfo);
|
||||
if (sockAddrHandle.IsAllocated)
|
||||
sockAddrHandle.Free();
|
||||
}
|
||||
}
|
||||
});
|
||||
foreach (IPEndPoint ipPort in ipPorts)
|
||||
{
|
||||
HTTP_SERVICE_CONFIG_SSL_SET configSslSet =
|
||||
new HTTP_SERVICE_CONFIG_SSL_SET();
|
||||
|
||||
GCHandle sockAddrHandle = CreateSockaddrStructure(ipPort);
|
||||
IntPtr pIpPort = sockAddrHandle.AddrOfPinnedObject();
|
||||
HTTP_SERVICE_CONFIG_SSL_KEY httpServiceConfigSslKey =
|
||||
new HTTP_SERVICE_CONFIG_SSL_KEY(pIpPort);
|
||||
configSslSet.KeyDesc = httpServiceConfigSslKey;
|
||||
|
||||
IntPtr pInputConfigInfo =
|
||||
Marshal.AllocCoTaskMem(
|
||||
Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_SSL_SET)));
|
||||
Marshal.StructureToPtr(configSslSet, pInputConfigInfo, false);
|
||||
|
||||
try
|
||||
{
|
||||
uint retVal = HttpDeleteServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo,
|
||||
pInputConfigInfo,
|
||||
Marshal.SizeOf(configSslSet),
|
||||
IntPtr.Zero);
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeCoTaskMem(pInputConfigInfo);
|
||||
if (sockAddrHandle.IsAllocated)
|
||||
sockAddrHandle.Free();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static SslCertificateInfo[] QuerySslCertificateInfo()
|
||||
@@ -399,193 +399,186 @@ namespace WebserverInitalConfig
|
||||
|
||||
CallHttpApi(
|
||||
delegate
|
||||
{
|
||||
uint token = 0;
|
||||
|
||||
uint retVal;
|
||||
do
|
||||
{
|
||||
HTTP_SERVICE_CONFIG_SSL_QUERY inputConfigInfoQuery =
|
||||
new HTTP_SERVICE_CONFIG_SSL_QUERY
|
||||
{
|
||||
QueryDesc = HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryNext,
|
||||
dwToken = token,
|
||||
};
|
||||
uint token = 0;
|
||||
|
||||
IntPtr pInputConfigInfo =
|
||||
Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_SSL_QUERY)));
|
||||
Marshal.StructureToPtr(inputConfigInfoQuery, pInputConfigInfo, false);
|
||||
|
||||
IntPtr pOutputConfigInfo = IntPtr.Zero;
|
||||
int returnLength = 0;
|
||||
|
||||
const HTTP_SERVICE_CONFIG_ID queryType = HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo;
|
||||
|
||||
try
|
||||
uint retVal;
|
||||
do
|
||||
{
|
||||
int inputConfigInfoSize = Marshal.SizeOf(inputConfigInfoQuery);
|
||||
retVal = HttpQueryServiceConfiguration(IntPtr.Zero,
|
||||
queryType,
|
||||
pInputConfigInfo,
|
||||
inputConfigInfoSize,
|
||||
pOutputConfigInfo,
|
||||
returnLength,
|
||||
out returnLength,
|
||||
IntPtr.Zero);
|
||||
if (ERROR_NO_MORE_ITEMS == retVal)
|
||||
break;
|
||||
if (ERROR_INSUFFICIENT_BUFFER == retVal) // ERROR_INSUFFICIENT_BUFFER = 122
|
||||
{
|
||||
pOutputConfigInfo = Marshal.AllocCoTaskMem(returnLength);
|
||||
|
||||
try
|
||||
{
|
||||
retVal = HttpQueryServiceConfiguration(IntPtr.Zero,
|
||||
queryType,
|
||||
pInputConfigInfo,
|
||||
inputConfigInfoSize,
|
||||
pOutputConfigInfo,
|
||||
returnLength,
|
||||
out returnLength,
|
||||
IntPtr.Zero);
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
|
||||
var outputConfigInfo = (HTTP_SERVICE_CONFIG_SSL_SET)Marshal.PtrToStructure(
|
||||
pOutputConfigInfo, typeof(HTTP_SERVICE_CONFIG_SSL_SET));
|
||||
|
||||
byte[] hash = new byte[outputConfigInfo.ParamDesc.SslHashLength];
|
||||
Marshal.Copy(outputConfigInfo.ParamDesc.pSslHash, hash, 0, hash.Length);
|
||||
|
||||
Guid appId = outputConfigInfo.ParamDesc.AppId;
|
||||
string storeName = outputConfigInfo.ParamDesc.pSslCertStoreName;
|
||||
IPEndPoint ipPort = ReadSockaddrStructure(outputConfigInfo.KeyDesc.pIpPort);
|
||||
|
||||
var resultItem = new SslCertificateInfo
|
||||
HTTP_SERVICE_CONFIG_SSL_QUERY inputConfigInfoQuery =
|
||||
new HTTP_SERVICE_CONFIG_SSL_QUERY
|
||||
{
|
||||
AppId = appId,
|
||||
Hash = hash,
|
||||
StoreName = storeName,
|
||||
IpPort = ipPort
|
||||
QueryDesc = HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryNext,
|
||||
dwToken = token,
|
||||
};
|
||||
result.Add(resultItem);
|
||||
token++;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeCoTaskMem(pOutputConfigInfo);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
IntPtr pInputConfigInfo =
|
||||
Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_SSL_QUERY)));
|
||||
Marshal.StructureToPtr(inputConfigInfoQuery, pInputConfigInfo, false);
|
||||
|
||||
IntPtr pOutputConfigInfo = IntPtr.Zero;
|
||||
int returnLength = 0;
|
||||
|
||||
const HTTP_SERVICE_CONFIG_ID queryType = HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo;
|
||||
|
||||
try
|
||||
{
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
int inputConfigInfoSize = Marshal.SizeOf(inputConfigInfoQuery);
|
||||
retVal = HttpQueryServiceConfiguration(IntPtr.Zero,
|
||||
queryType,
|
||||
pInputConfigInfo,
|
||||
inputConfigInfoSize,
|
||||
pOutputConfigInfo,
|
||||
returnLength,
|
||||
out returnLength,
|
||||
IntPtr.Zero);
|
||||
if (ERROR_NO_MORE_ITEMS == retVal)
|
||||
break;
|
||||
if (ERROR_INSUFFICIENT_BUFFER == retVal) // ERROR_INSUFFICIENT_BUFFER = 122
|
||||
{
|
||||
pOutputConfigInfo = Marshal.AllocCoTaskMem(returnLength);
|
||||
|
||||
try
|
||||
{
|
||||
retVal = HttpQueryServiceConfiguration(IntPtr.Zero,
|
||||
queryType,
|
||||
pInputConfigInfo,
|
||||
inputConfigInfoSize,
|
||||
pOutputConfigInfo,
|
||||
returnLength,
|
||||
out returnLength,
|
||||
IntPtr.Zero);
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
|
||||
var outputConfigInfo = (HTTP_SERVICE_CONFIG_SSL_SET)Marshal.PtrToStructure(
|
||||
pOutputConfigInfo, typeof(HTTP_SERVICE_CONFIG_SSL_SET));
|
||||
|
||||
byte[] hash = new byte[outputConfigInfo.ParamDesc.SslHashLength];
|
||||
Marshal.Copy(outputConfigInfo.ParamDesc.pSslHash, hash, 0, hash.Length);
|
||||
|
||||
Guid appId = outputConfigInfo.ParamDesc.AppId;
|
||||
string storeName = outputConfigInfo.ParamDesc.pSslCertStoreName;
|
||||
IPEndPoint ipPort = ReadSockaddrStructure(outputConfigInfo.KeyDesc.pIpPort);
|
||||
|
||||
var resultItem = new SslCertificateInfo
|
||||
{
|
||||
AppId = appId,
|
||||
Hash = hash,
|
||||
StoreName = storeName,
|
||||
IpPort = ipPort
|
||||
};
|
||||
result.Add(resultItem);
|
||||
token++;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeCoTaskMem(pOutputConfigInfo);
|
||||
}
|
||||
}
|
||||
else
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeCoTaskMem(pInputConfigInfo);
|
||||
}
|
||||
|
||||
} while (NOERROR == retVal);
|
||||
|
||||
});
|
||||
finally
|
||||
{
|
||||
Marshal.FreeCoTaskMem(pInputConfigInfo);
|
||||
}
|
||||
} while (NOERROR == retVal);
|
||||
});
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
public static void ReserveURL(string networkURL, string securityDescriptor)
|
||||
{
|
||||
if (String.IsNullOrEmpty(networkURL)) throw new ArgumentNullException("networkURL");
|
||||
if (String.IsNullOrEmpty(securityDescriptor)) throw new ArgumentNullException("securityDescriptor");
|
||||
if (String.IsNullOrEmpty(networkURL))
|
||||
throw new ArgumentNullException("networkURL");
|
||||
if (String.IsNullOrEmpty(securityDescriptor))
|
||||
throw new ArgumentNullException("securityDescriptor");
|
||||
|
||||
CallHttpApi(
|
||||
delegate
|
||||
{
|
||||
uint retVal = (uint)NOERROR; // NOERROR = 0
|
||||
|
||||
HTTP_SERVICE_CONFIG_URLACL_KEY keyDesc = new HTTP_SERVICE_CONFIG_URLACL_KEY(networkURL);
|
||||
HTTP_SERVICE_CONFIG_URLACL_PARAM paramDesc = new HTTP_SERVICE_CONFIG_URLACL_PARAM(securityDescriptor);
|
||||
|
||||
HTTP_SERVICE_CONFIG_URLACL_SET inputConfigInfoSet = new HTTP_SERVICE_CONFIG_URLACL_SET();
|
||||
inputConfigInfoSet.KeyDesc = keyDesc;
|
||||
inputConfigInfoSet.ParamDesc = paramDesc;
|
||||
|
||||
IntPtr pInputConfigInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_SET)));
|
||||
Marshal.StructureToPtr(inputConfigInfoSet, pInputConfigInfo, false);
|
||||
try
|
||||
{
|
||||
retVal = HttpApi.HttpSetServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
|
||||
pInputConfigInfo,
|
||||
Marshal.SizeOf(inputConfigInfoSet),
|
||||
IntPtr.Zero);
|
||||
uint retVal = (uint)NOERROR; // NOERROR = 0
|
||||
|
||||
if ((uint)ERROR_ALREADY_EXISTS == retVal) // ERROR_ALREADY_EXISTS = 183
|
||||
HTTP_SERVICE_CONFIG_URLACL_KEY keyDesc = new HTTP_SERVICE_CONFIG_URLACL_KEY(networkURL);
|
||||
HTTP_SERVICE_CONFIG_URLACL_PARAM paramDesc = new HTTP_SERVICE_CONFIG_URLACL_PARAM(securityDescriptor);
|
||||
|
||||
HTTP_SERVICE_CONFIG_URLACL_SET inputConfigInfoSet = new HTTP_SERVICE_CONFIG_URLACL_SET();
|
||||
inputConfigInfoSet.KeyDesc = keyDesc;
|
||||
inputConfigInfoSet.ParamDesc = paramDesc;
|
||||
|
||||
IntPtr pInputConfigInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_SET)));
|
||||
Marshal.StructureToPtr(inputConfigInfoSet, pInputConfigInfo, false);
|
||||
try
|
||||
{
|
||||
retVal = HttpApi.HttpDeleteServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
|
||||
pInputConfigInfo,
|
||||
Marshal.SizeOf(inputConfigInfoSet),
|
||||
IntPtr.Zero);
|
||||
retVal = HttpSetServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
|
||||
pInputConfigInfo,
|
||||
Marshal.SizeOf(inputConfigInfoSet),
|
||||
IntPtr.Zero);
|
||||
|
||||
if ((uint)NOERROR == retVal)
|
||||
if (ERROR_ALREADY_EXISTS == retVal) // ERROR_ALREADY_EXISTS = 183
|
||||
{
|
||||
retVal = HttpApi.HttpSetServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
|
||||
pInputConfigInfo,
|
||||
Marshal.SizeOf(inputConfigInfoSet),
|
||||
IntPtr.Zero);
|
||||
}
|
||||
else if ((uint)ERROR_FILE_NOT_FOUND == retVal) // ERROR_FILE_NOT_FOUND = 2
|
||||
{
|
||||
string networkURLOld = networkURL.Contains("https") ? networkURL.Replace("https", "http") :
|
||||
networkURL.Replace("http", "https");
|
||||
HTTP_SERVICE_CONFIG_URLACL_KEY keyDescOld = new HTTP_SERVICE_CONFIG_URLACL_KEY(networkURLOld);
|
||||
HTTP_SERVICE_CONFIG_URLACL_PARAM paramDescOld = new HTTP_SERVICE_CONFIG_URLACL_PARAM(securityDescriptor);
|
||||
retVal = HttpDeleteServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
|
||||
pInputConfigInfo,
|
||||
Marshal.SizeOf(inputConfigInfoSet),
|
||||
IntPtr.Zero);
|
||||
|
||||
HTTP_SERVICE_CONFIG_URLACL_SET inputConfigInfoSetOld = new HTTP_SERVICE_CONFIG_URLACL_SET();
|
||||
inputConfigInfoSetOld.KeyDesc = keyDescOld;
|
||||
inputConfigInfoSetOld.ParamDesc = paramDescOld;
|
||||
|
||||
IntPtr pInputConfigInfoOld = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_SET)));
|
||||
Marshal.StructureToPtr(inputConfigInfoSetOld, pInputConfigInfoOld, false);
|
||||
|
||||
retVal = HttpApi.HttpDeleteServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
|
||||
pInputConfigInfoOld,
|
||||
Marshal.SizeOf(inputConfigInfoSetOld),
|
||||
IntPtr.Zero);
|
||||
|
||||
if ((uint)NOERROR == retVal)
|
||||
if (NOERROR == retVal)
|
||||
{
|
||||
retVal = HttpApi.HttpSetServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
|
||||
pInputConfigInfo,
|
||||
Marshal.SizeOf(inputConfigInfoSet),
|
||||
IntPtr.Zero);
|
||||
retVal = HttpSetServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
|
||||
pInputConfigInfo,
|
||||
Marshal.SizeOf(inputConfigInfoSet),
|
||||
IntPtr.Zero);
|
||||
}
|
||||
else if (ERROR_FILE_NOT_FOUND == retVal) // ERROR_FILE_NOT_FOUND = 2
|
||||
{
|
||||
string networkURLOld = networkURL.Contains("https") ? networkURL.Replace("https", "http") :
|
||||
networkURL.Replace("http", "https");
|
||||
HTTP_SERVICE_CONFIG_URLACL_KEY keyDescOld = new HTTP_SERVICE_CONFIG_URLACL_KEY(networkURLOld);
|
||||
HTTP_SERVICE_CONFIG_URLACL_PARAM paramDescOld = new HTTP_SERVICE_CONFIG_URLACL_PARAM(securityDescriptor);
|
||||
|
||||
HTTP_SERVICE_CONFIG_URLACL_SET inputConfigInfoSetOld = new HTTP_SERVICE_CONFIG_URLACL_SET();
|
||||
inputConfigInfoSetOld.KeyDesc = keyDescOld;
|
||||
inputConfigInfoSetOld.ParamDesc = paramDescOld;
|
||||
|
||||
IntPtr pInputConfigInfoOld = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_SET)));
|
||||
Marshal.StructureToPtr(inputConfigInfoSetOld, pInputConfigInfoOld, false);
|
||||
|
||||
retVal = HttpDeleteServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
|
||||
pInputConfigInfoOld,
|
||||
Marshal.SizeOf(inputConfigInfoSetOld),
|
||||
IntPtr.Zero);
|
||||
|
||||
if (NOERROR == retVal)
|
||||
{
|
||||
retVal = HttpSetServiceConfiguration(IntPtr.Zero,
|
||||
HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
|
||||
pInputConfigInfo,
|
||||
Marshal.SizeOf(inputConfigInfoSet),
|
||||
IntPtr.Zero);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeCoTaskMem(pInputConfigInfo);
|
||||
HttpApi.HttpTerminate(HttpApi.HTTP_INITIALIZE_CONFIG, IntPtr.Zero);
|
||||
}
|
||||
if ((uint)NOERROR != retVal)
|
||||
{
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
}
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeCoTaskMem(pInputConfigInfo);
|
||||
HttpTerminate(HTTP_INITIALIZE_CONFIG, IntPtr.Zero);
|
||||
}
|
||||
if (NOERROR != retVal)
|
||||
ThrowWin32ExceptionIfError(retVal);
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private static void ThrowWin32ExceptionIfError(uint retVal)
|
||||
{
|
||||
if (NOERROR != retVal)
|
||||
{
|
||||
throw new Win32Exception(Convert.ToInt32(retVal));
|
||||
}
|
||||
}
|
||||
|
||||
private static void CallHttpApi(Action body)
|
||||
@@ -604,7 +597,7 @@ namespace WebserverInitalConfig
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an unmanaged sockaddr structure to pass to a WinAPI function.
|
||||
/// Creates an unmanaged sockaddr structure to pass to a WinAPI function.
|
||||
/// </summary>
|
||||
/// <param name="ipEndPoint">IP address and port number</param>
|
||||
/// <returns>a handle for the structure. Use the AddrOfPinnedObject Method to get a stable pointer to the object. </returns>
|
||||
@@ -617,14 +610,12 @@ namespace WebserverInitalConfig
|
||||
byte[] sockAddrStructureBytes = new byte[socketAddress.Size];
|
||||
GCHandle sockAddrHandle = GCHandle.Alloc(sockAddrStructureBytes, GCHandleType.Pinned);
|
||||
for (int i = 0; i < socketAddress.Size; ++i)
|
||||
{
|
||||
sockAddrStructureBytes[i] = socketAddress[i];
|
||||
}
|
||||
return sockAddrHandle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the unmanaged sockaddr structure returned by a WinAPI function
|
||||
/// Reads the unmanaged sockaddr structure returned by a WinAPI function
|
||||
/// </summary>
|
||||
/// <param name="pSockaddrStructure">pointer to the unmanaged sockaddr structure</param>
|
||||
/// <returns>IP address and port number</returns>
|
||||
@@ -659,9 +650,7 @@ namespace WebserverInitalConfig
|
||||
// create SocketAddress from bytes
|
||||
var socketAddress = new SocketAddress(AddressFamily.Unspecified, sockAddrSructureSize);
|
||||
for (int i = 0; i < sockAddrSructureSize; i++)
|
||||
{
|
||||
socketAddress[i] = sockAddrSructureBytes[i];
|
||||
}
|
||||
|
||||
// create IPEndPoint from SocketAddress
|
||||
IPEndPoint result = (IPEndPoint)ipEndPointAny.Create(socketAddress);
|
||||
@@ -669,4 +658,4 @@ namespace WebserverInitalConfig
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,30 @@
|
||||
using System;
|
||||
#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 System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace WebserverInitalConfig
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
if (args.Length != 2)
|
||||
{
|
||||
@@ -14,22 +32,18 @@ namespace WebserverInitalConfig
|
||||
Environment.Exit(-1);
|
||||
}
|
||||
|
||||
CConfigHttpApi.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 = CConfigHttpApi.GetSelfSignedCert("CN=" + hostname + " C=DE O=Vocaluxe OU=Vocaluxe Server");
|
||||
X509Certificate2 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
|
||||
{
|
||||
CConfigHttpApi.ReserveUrl("http://+:" + args[0] + "/");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,28 @@
|
||||
using System.Reflection;
|
||||
#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 System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die mit einer Assembly verknüpft sind.
|
||||
|
||||
[assembly: AssemblyTitle("Vocaluxe Server Config")]
|
||||
[assembly: AssemblyDescription("Configures your computer to run the Vocaluxe Server")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
@@ -17,9 +35,11 @@ using System.Runtime.InteropServices;
|
||||
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
|
||||
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
|
||||
[assembly: Guid("b2df9255-3927-4125-ab3c-23c35794b04d")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
@@ -32,5 +52,6 @@ using System.Runtime.InteropServices;
|
||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Reference in new issue
Block a user