From 89a1e3056b21017adf10f7128513e37a2131b7af Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sat, 15 Feb 2014 14:14:21 +0100 Subject: [PATCH] Remove old files --- ConfigHttpApi/ConfigHttpApi.cs | 84 --- ConfigHttpApi/ConfigHttpApi.csproj | 64 --- ConfigHttpApi/HttpApi.cs | 643 ----------------------- ConfigHttpApi/Properties/AssemblyInfo.cs | 36 -- 4 files changed, 827 deletions(-) delete mode 100644 ConfigHttpApi/ConfigHttpApi.cs delete mode 100644 ConfigHttpApi/ConfigHttpApi.csproj delete mode 100644 ConfigHttpApi/HttpApi.cs delete mode 100644 ConfigHttpApi/Properties/AssemblyInfo.cs diff --git a/ConfigHttpApi/ConfigHttpApi.cs b/ConfigHttpApi/ConfigHttpApi.cs deleted file mode 100644 index f8353f72..00000000 --- a/ConfigHttpApi/ConfigHttpApi.cs +++ /dev/null @@ -1,84 +0,0 @@ -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; - -namespace ConfigHttpApi -{ - public static class ConfigHttpApi - { - [PrincipalPermission(SecurityAction.Demand, Role = @"BUILTIN\Administrators")] - public static void reserveURL(string networkString) - { - HttpApi.ReserveURL(networkString, "D:(A;;GX;;;S-1-1-0)"); - } - - [PrincipalPermission(SecurityAction.Demand, Role = @"BUILTIN\Administrators")] - 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")); - } - - [PrincipalPermission(SecurityAction.Demand, Role = @"BUILTIN\Administrators")] - public static void addCertToStore(X509Certificate2 cert) - { - X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine); - store.Open(OpenFlags.ReadWrite); - store.Add(cert); - store.Close(); - } - - [PrincipalPermission(SecurityAction.Demand, Role = @"BUILTIN\Administrators")] - public static X509Certificate2 getSelfSignedCert(string subjectName) - { - CngKey key = CngKey.Create(CngAlgorithm2.Rsa); - X509CertificateCreationParameters param = new X509CertificateCreationParameters( - new X500DistinguishedName("CN=Vocaluxe Server")); - param.SubjectName = new X500DistinguishedName("CN=localhost"); - param.EndTime = DateTime.Today.AddYears(20); - param.SignatureAlgorithm = X509CertificateSignatureAlgorithm.RsaSha512; - OidCollection oc = new OidCollection(); - oc.Add(new Oid("1.3.6.1.5.5.7.3.1")); - X509Extension eku = new X509EnhancedKeyUsageExtension(oc, true); - param.Extensions.Add(eku); - - return key.CreateSelfSignedCertificate(param); - } - - /*public static X509Certificate2 getCert(string subject) - { - RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); - - Mono.Security.Authenticode.PrivateKey key = new Mono.Security.Authenticode.PrivateKey { RSA=RSA.Create()}; - - - Mono.Security.X509.X509CertificateBuilder x509 = new Mono.Security.X509.X509CertificateBuilder(); - x509.IssuerName = "CN=Vocaluxe Server"; - x509.NotAfter = DateTime.Today.AddYears(20); - x509.NotBefore = DateTime.Today.AddDays(-1); - x509.SubjectName = subject; - x509.SerialNumber = new byte[] { 1 }; - x509.Version = 3; - x509.SubjectPublicKey = rsa; - - ExtendedKeyUsageExtension eku = new ExtendedKeyUsageExtension(); - eku.KeyPurpose.Add("1.3.6.1.5.5.7.3.1"); - x509.Extensions.Add(eku); - - return new X509Certificate2(x509.Sign(rsa)); - }*/ - } -} diff --git a/ConfigHttpApi/ConfigHttpApi.csproj b/ConfigHttpApi/ConfigHttpApi.csproj deleted file mode 100644 index 368c0a49..00000000 --- a/ConfigHttpApi/ConfigHttpApi.csproj +++ /dev/null @@ -1,64 +0,0 @@ - - - - - Debug - AnyCPU - {EC28CFA6-35A8-4971-AB07-37A54E010F69} - Exe - Properties - ConfigHttpApi - ConfigHttpApi - v4.0 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - ..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio 11.0\Libs\clrsecurity_june10\Security.dll - - - ..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio 11.0\Libs\clrsecurity_june10\Security.Cryptography.dll - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ConfigHttpApi/HttpApi.cs b/ConfigHttpApi/HttpApi.cs deleted file mode 100644 index e5d104a0..00000000 --- a/ConfigHttpApi/HttpApi.cs +++ /dev/null @@ -1,643 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Net; -using System.Net.Sockets; -using System.Runtime.InteropServices; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Threading.Tasks; - -namespace ConfigHttpApi -{ - internal 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( - 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( - IntPtr serviceIntPtr, - HTTP_SERVICE_CONFIG_ID configId, - IntPtr pConfigInformation, - int configInformationLength, - IntPtr pOverlapped); - - [DllImport("httpapi.dll", SetLastError = true)] - 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); - - - enum HTTP_SERVICE_CONFIG_ID - { - - HttpServiceConfigIPListenList = 0, - HttpServiceConfigSSLCertInfo, - HttpServiceConfigUrlAclInfo, - HttpServiceConfigMax - } - - [StructLayout(LayoutKind.Sequential)] - 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 - { - public IntPtr pIpPort; - - public HTTP_SERVICE_CONFIG_SSL_KEY(IntPtr pIpPort) - { - this.pIpPort = pIpPort; - } - } - - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] - struct HTTP_SERVICE_CONFIG_SSL_PARAM - { - public int SslHashLength; - public IntPtr pSslHash; - public Guid AppId; - [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; - public uint DefaultFlags; - } - - [StructLayout(LayoutKind.Sequential, Pack = 2)] - struct HTTPAPI_VERSION - { - public ushort HttpApiMajorVersion; - public ushort HttpApiMinorVersion; - - public HTTPAPI_VERSION(ushort majorVersion, ushort minorVersion) - { - HttpApiMajorVersion = majorVersion; - HttpApiMinorVersion = minorVersion; - } - } - - [StructLayout(LayoutKind.Sequential)] - 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 - { - HttpServiceConfigQueryExact = 0, - HttpServiceConfigQueryNext, - HttpServiceConfigQueryMax - } - - [StructLayout(LayoutKind.Sequential)] - struct HTTP_SERVICE_CONFIG_URLACL_SET - { - public HTTP_SERVICE_CONFIG_URLACL_KEY KeyDesc; - public HTTP_SERVICE_CONFIG_URLACL_PARAM ParamDesc; - } - - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] - public struct HTTP_SERVICE_CONFIG_URLACL_KEY - { - [MarshalAs(UnmanagedType.LPWStr)] - public string pUrlPrefix; - - public HTTP_SERVICE_CONFIG_URLACL_KEY(string urlPrefix) - { - pUrlPrefix = urlPrefix; - } - } - - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] - struct HTTP_SERVICE_CONFIG_URLACL_PARAM - { - [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; - private const uint NOERROR = 0; - private const uint ERROR_INSUFFICIENT_BUFFER = 122; - 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; } - public Guid AppId { get; set; } - public string StoreName { get; set; } - public IPEndPoint IpPort { get; set; } - } - - public static SslCertificateInfo QuerySslCertificateInfo(IPEndPoint ipPort) - { - SslCertificateInfo result = null; - - 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; - - 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; - - result = new SslCertificateInfo { AppId = appId, Hash = hash, StoreName = storeName, IpPort = ipPort }; - } - finally - { - Marshal.FreeCoTaskMem(pOutputConfigInfo); - } - } - else - { - ThrowWin32ExceptionIfError(retVal); - } - - } - 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"); - - 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); - - 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(); - } - }); - } - - public static void DeleteCertificateBinding(params IPEndPoint[] ipPorts) - { - if (ipPorts == null || ipPorts.Length == 0) - 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 - { - 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() - { - var result = new List(); - - 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, - }; - - 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 - { - 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); - - }); - - 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"); - - 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); - - if ((uint)ERROR_ALREADY_EXISTS == retVal) // ERROR_ALREADY_EXISTS = 183 - { - retVal = HttpApi.HttpDeleteServiceConfiguration(IntPtr.Zero, - HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, - pInputConfigInfo, - Marshal.SizeOf(inputConfigInfoSet), - IntPtr.Zero); - - if ((uint)NOERROR == retVal) - { - retVal = HttpApi.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); - } - }); - } - - #endregion - - private static void ThrowWin32ExceptionIfError(uint retVal) - { - if (NOERROR != retVal) - { - throw new Win32Exception(Convert.ToInt32(retVal)); - } - } - - private static void CallHttpApi(Action body) - { - uint retVal = HttpInitialize(HttpApiVersion, HTTP_INITIALIZE_CONFIG, IntPtr.Zero); - ThrowWin32ExceptionIfError(retVal); - - try - { - body(); - } - finally - { - HttpTerminate(HTTP_INITIALIZE_CONFIG, IntPtr.Zero); - } - } - - /// - /// Creates an unmanaged sockaddr structure to pass to a WinAPI function. - /// - /// IP address and port number - /// a handle for the structure. Use the AddrOfPinnedObject Method to get a stable pointer to the object. - /// When the handle goes out of scope you must explicitly release it by calling the Free method; otherwise, memory leaks may occur. - private static GCHandle CreateSockaddrStructure(IPEndPoint ipEndPoint) - { - SocketAddress socketAddress = ipEndPoint.Serialize(); - - // use an array of bytes instead of the sockaddr structure - 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; - } - - /// - /// Reads the unmanaged sockaddr structure returned by a WinAPI function - /// - /// pointer to the unmanaged sockaddr structure - /// IP address and port number - private static IPEndPoint ReadSockaddrStructure(IntPtr pSockaddrStructure) - { - short sAddressFamily = Marshal.ReadInt16(pSockaddrStructure); - AddressFamily addressFamily = (AddressFamily)sAddressFamily; - - int sockAddrSructureSize; - IPEndPoint ipEndPointAny; - switch (addressFamily) - { - case AddressFamily.InterNetwork: - // IP v4 address - sockAddrSructureSize = 16; - ipEndPointAny = new IPEndPoint(IPAddress.Any, 0); - break; - case AddressFamily.InterNetworkV6: - // IP v6 address - sockAddrSructureSize = 28; - ipEndPointAny = new IPEndPoint(IPAddress.IPv6Any, 0); - break; - default: - throw new ArgumentOutOfRangeException("pSockaddrStructure", "Unknown address family"); - } - - - // get bytes of the sockadrr structure - byte[] sockAddrSructureBytes = new byte[sockAddrSructureSize]; - Marshal.Copy(pSockaddrStructure, sockAddrSructureBytes, 0, sockAddrSructureSize); - - // 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); - - return result; - } - } -} diff --git a/ConfigHttpApi/Properties/AssemblyInfo.cs b/ConfigHttpApi/Properties/AssemblyInfo.cs deleted file mode 100644 index c63c94dd..00000000 --- a/ConfigHttpApi/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -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("ConfigHttpApi")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ConfigHttpApi")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// 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("89f719af-3a0d-4704-be7f-16e5b4e19c02")] - -// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: -// -// Hauptversion -// Nebenversion -// Buildnummer -// Revision -// -// 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")]