Exemplo n.º 1
0
        private static SslConfigItem Deserialize(IntPtr pSslConfigSetStruct)
        {
            SslConfigItem item = new SslConfigItem();

            HttpApi.HTTP_SERVICE_CONFIG_SSL_SET sslStruct =
                (HttpApi.HTTP_SERVICE_CONFIG_SSL_SET)Marshal.PtrToStructure(pSslConfigSetStruct, typeof(HttpApi.HTTP_SERVICE_CONFIG_SSL_SET));

            item._port                          = (ushort)IPAddress.NetworkToHostOrder(Marshal.ReadInt16(sslStruct.KeyDesc.pIpPort, 2));
            item._address                       = new IPAddress((long)Marshal.ReadInt32(sslStruct.KeyDesc.pIpPort, 4) & 0x00000000ffffffff);
            item._appId                         = sslStruct.ParamDesc.AppId;
            item._certStoreName                 = sslStruct.ParamDesc.pSslCertStoreName;
            item._certCheckMode                 = sslStruct.ParamDesc.CertCheckMode;
            item._revocationFreshnessTime       = sslStruct.ParamDesc.RevocationFreshnessTime;
            item._revocationUrlRetrievalTimeout = sslStruct.ParamDesc.RevocationUrlRetrievalTimeout;
            item._sslCtlIdentifier              = sslStruct.ParamDesc.pSslCtlIdentifier;
            item._sslCtlStoreName               = sslStruct.ParamDesc.pSslCtlStoreName;
            item._flags                         = sslStruct.ParamDesc.Flags;
            item.Status                         = ModifiedStatus.Unmodified;
            item._hash                          = new byte[sslStruct.ParamDesc.SslHashLength];

            Marshal.Copy(sslStruct.ParamDesc.pSslHash, item._hash, 0, item._hash.Length);

            item.SetItems();

            return(item);
        }
Exemplo n.º 2
0
        private HttpApi.HTTP_SERVICE_CONFIG_SSL_SET ToStruct()
        {
            HttpApi.HTTP_SERVICE_CONFIG_SSL_SET sslStruct = new HttpApi.HTTP_SERVICE_CONFIG_SSL_SET();

            sslStruct.KeyDesc.pIpPort = HttpApi.BuildSockaddr(2, _port, _address);

            if (_hash != null)
            {
                sslStruct.ParamDesc.pSslHash = Marshal.AllocHGlobal(_hash.Length);

                Marshal.Copy(_hash, 0, sslStruct.ParamDesc.pSslHash, _hash.Length);

                sslStruct.ParamDesc.SslHashLength = _hash.Length;
            }

            sslStruct.ParamDesc.AppId                         = _appId;
            sslStruct.ParamDesc.pSslCertStoreName             = _certStoreName;
            sslStruct.ParamDesc.RevocationFreshnessTime       = _revocationFreshnessTime;
            sslStruct.ParamDesc.RevocationUrlRetrievalTimeout = _revocationUrlRetrievalTimeout;
            sslStruct.ParamDesc.pSslCtlIdentifier             = _sslCtlIdentifier;
            sslStruct.ParamDesc.pSslCtlStoreName              = _sslCtlStoreName;
            sslStruct.ParamDesc.Flags                         = _flags;

            sslStruct.ParamDesc.CertCheckMode = _certCheckMode;

            return(sslStruct);
        }
Exemplo n.º 3
0
        public override void ApplyConfig()
        {
            IntPtr pStruct = IntPtr.Zero;

            HttpApi.HTTP_SERVICE_CONFIG_SSL_SET setStruct = ToStruct();

            try
            {
                pStruct = Marshal.AllocHGlobal(Marshal.SizeOf(setStruct));

                Marshal.StructureToPtr(setStruct, pStruct, false);

                if ((Status == ModifiedStatus.Modified) || (Status == ModifiedStatus.Removed))
                {
                    HttpApi.Error error = HttpApi.HttpDeleteServiceConfiguration(
                        IntPtr.Zero,
                        HttpApi.HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo,
                        pStruct,
                        Marshal.SizeOf(setStruct),
                        IntPtr.Zero);

                    if (error != HttpApi.Error.NO_ERROR)
                    {
                        throw new HttpApiException(error, "HttpDeleteServiceConfiguration (SSL) failed.  Error = " + error);
                    }
                }

                if ((Status == ModifiedStatus.Modified) || (Status == ModifiedStatus.Added))
                {
                    HttpApi.Error error = HttpApi.HttpSetServiceConfiguration(
                        IntPtr.Zero,
                        HttpApi.HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo,
                        pStruct,
                        Marshal.SizeOf(setStruct),
                        IntPtr.Zero);

                    if (error != HttpApi.Error.NO_ERROR)
                    {
                        throw new HttpApiException(error, "HttpSetServiceConfiguration (SSL) failed.  Error = " + error);
                    }
                }
            }
            finally
            {
                if (pStruct != IntPtr.Zero)
                {
                    Marshal.DestroyStructure(pStruct, typeof(HttpApi.HTTP_SERVICE_CONFIG_SSL_SET));
                    Marshal.FreeHGlobal(pStruct);
                }

                FreeStruct(setStruct);
            }
        }
Exemplo n.º 4
0
 private static void FreeStruct(HttpApi.HTTP_SERVICE_CONFIG_SSL_SET sslStruct)
 {
     Marshal.FreeHGlobal(sslStruct.KeyDesc.pIpPort);
     Marshal.FreeHGlobal(sslStruct.ParamDesc.pSslHash);
 }