Пример #1
0
        static bool IsHttpApiLibAvailableHelper()
        {
            bool retVal  = false;
            int  retCode = SafeNativeMethods.NoError;

            try
            {
                retCode = SafeNativeMethods.HttpInitialize(new HttpApiVersion(1, 0), SafeNativeMethods.HTTP_INITIALIZE_CONFIG, IntPtr.Zero);
                SafeNativeMethods.HttpTerminate(SafeNativeMethods.HTTP_INITIALIZE_CONFIG, IntPtr.Zero);
                if (retCode != SafeNativeMethods.NoError)
                {
                    retVal = false;
                }
                else
                {
                    retVal = true;
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                retVal = false;
            }

            return(retVal);
        }
Пример #2
0
        void UnbindSSL()
        {
            int             retVal   = SafeNativeMethods.NoError;
            WinsockSockAddr sockAddr = null;

            try
            {
                retVal = SafeNativeMethods.HttpInitialize(HttpWrapper.HttpApiVersion1, SafeNativeMethods.HTTP_INITIALIZE_CONFIG, IntPtr.Zero);
                if (SafeNativeMethods.NoError == retVal)
                {
                    IntPtr pOverlapped = IntPtr.Zero;

                    sockAddr = new WinsockSockAddr(new IPAddress(0), (short)this.port);
                    HttpServiceConfigSslSet sslConf = new HttpServiceConfigSslSet();
                    sslConf.KeyDesc.pIpPort = sockAddr.PinnedSockAddr;
                    sslConf.ParamDesc.DefaultCertCheckMode           = 0;
                    sslConf.ParamDesc.DefaultFlags                   = SafeNativeMethods.HTTP_SERVICE_CONFIG_SSL_FLAG_NEGOTIATE_CLIENT_CERT;
                    sslConf.ParamDesc.DefaultRevocationFreshnessTime = 0;
                    sslConf.ParamDesc.pSslCertStoreName              = certificateStore;

                    byte[] sslHash = this.cert.GetCertHash();
                    sslConf.ParamDesc.pSslHash = new SafeLocalAllocation(sslHash.Length);
                    sslConf.ParamDesc.pSslHash.Copy(sslHash, 0, sslHash.Length);
                    sslConf.ParamDesc.SslHashLength = sslHash.Length;

                    int configInformationLength = System.Runtime.InteropServices.Marshal.SizeOf(sslConf);
                    retVal = SafeNativeMethods.HttpDeleteServiceConfiguration_Ssl(IntPtr.Zero,
                                                                                  HttpServiceConfigId.HttpServiceConfigSSLCertInfo,
                                                                                  ref sslConf,
                                                                                  configInformationLength, pOverlapped);
                    sslConf.ParamDesc.pSslHash.Close();

                    GC.KeepAlive(sockAddr);
                }
            }
            finally
            {
                if (sockAddr != null)
                {
                    sockAddr.Dispose();
                }
                SafeNativeMethods.HttpTerminate(SafeNativeMethods.HTTP_INITIALIZE_CONFIG, IntPtr.Zero);
            }

            if (retVal != SafeNativeMethods.NoError && retVal != SafeNativeMethods.FileNotFound && retVal != SafeNativeMethods.ErrorInvalidParameter)
            {
                throw new WsatAdminException(WsatAdminErrorCode.HTTPS_PORT_SSL_CERT_UNBINDING,
                                             SR.GetString(SR.ErrorHttpsPortSSLUnbinding, retVal));
            }
        }
Пример #3
0
        static void FreeURL(string networkURL, string securityDescriptor)
        {
            int retVal = SafeNativeMethods.NoError;

            try
            {
                retVal = SafeNativeMethods.HttpInitialize(HttpWrapper.HttpApiVersion1, SafeNativeMethods.HTTP_INITIALIZE_CONFIG, IntPtr.Zero);
                if (SafeNativeMethods.NoError == retVal)
                {
                    HttpServiceConfigUrlAclKey   urlAclKey   = new HttpServiceConfigUrlAclKey(networkURL);
                    HttpServiceConfigUrlAclParam urlAclParam = new HttpServiceConfigUrlAclParam(securityDescriptor);

                    HttpServiceConfigUrlAclSet configInformation = new HttpServiceConfigUrlAclSet();
                    configInformation.KeyDesc   = urlAclKey;
                    configInformation.ParamDesc = urlAclParam;

                    int configInformationSize = Marshal.SizeOf(configInformation);

                    retVal = SafeNativeMethods.HttpDeleteServiceConfiguration_UrlAcl(IntPtr.Zero,
                                                                                     HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                                                                                     ref configInformation,
                                                                                     configInformationSize,
                                                                                     IntPtr.Zero);
                }
            }
            finally
            {
                SafeNativeMethods.HttpTerminate(SafeNativeMethods.HTTP_INITIALIZE_CONFIG, IntPtr.Zero);
            }

            if (retVal != SafeNativeMethods.NoError && retVal != SafeNativeMethods.FileNotFound && retVal != SafeNativeMethods.ErrorInvalidParameter)
            {
                throw new WsatAdminException(WsatAdminErrorCode.UNREGISTER_HTTPS_PORT,
                                             SR.GetString(SR.ErrorUnregisterHttpsPort, retVal));
            }
        }
Пример #4
0
        static void ReserveURL(string networkURL, string securityDescriptor)
        {
            int retVal = SafeNativeMethods.NoError;

            try
            {
                retVal = SafeNativeMethods.HttpInitialize(HttpWrapper.HttpApiVersion1, SafeNativeMethods.HTTP_INITIALIZE_CONFIG, IntPtr.Zero);

                if (SafeNativeMethods.NoError == retVal)
                {
                    HttpServiceConfigUrlAclKey   keyDesc   = new HttpServiceConfigUrlAclKey(networkURL);
                    HttpServiceConfigUrlAclParam paramDesc = new HttpServiceConfigUrlAclParam(securityDescriptor);

                    HttpServiceConfigUrlAclSet configInformation = new HttpServiceConfigUrlAclSet();
                    configInformation.KeyDesc   = keyDesc;
                    configInformation.ParamDesc = paramDesc;

                    int configInformationLength = Marshal.SizeOf(configInformation);

                    retVal = SafeNativeMethods.HttpSetServiceConfiguration_UrlAcl(IntPtr.Zero,
                                                                                  HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                                                                                  ref configInformation,
                                                                                  configInformationLength,
                                                                                  IntPtr.Zero);

                    if (SafeNativeMethods.ErrorAlreadyExists == retVal)
                    {
                        retVal = SafeNativeMethods.HttpDeleteServiceConfiguration_UrlAcl(IntPtr.Zero,
                                                                                         HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                                                                                         ref configInformation,
                                                                                         configInformationLength,
                                                                                         IntPtr.Zero);

                        if (SafeNativeMethods.NoError == retVal)
                        {
                            retVal = SafeNativeMethods.HttpSetServiceConfiguration_UrlAcl(IntPtr.Zero,
                                                                                          HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                                                                                          ref configInformation,
                                                                                          configInformationLength,
                                                                                          IntPtr.Zero);
                        }
                    }
                }
            }
            finally
            {
                SafeNativeMethods.HttpTerminate(SafeNativeMethods.HTTP_INITIALIZE_CONFIG, IntPtr.Zero);
            }

            if (SafeNativeMethods.NoError != retVal)
            {
                if (SafeNativeMethods.ErrorAlreadyExists == retVal)
                {
                    throw new WsatAdminException(WsatAdminErrorCode.REGISTER_HTTPS_PORT_ALREADYEXISTS,
                                                 SR.GetString(SR.ErrorRegisterHttpsPortAlreadyExists));
                }
                else
                {
                    throw new WsatAdminException(WsatAdminErrorCode.REGISTER_HTTPS_PORT,
                                                 SR.GetString(SR.ErrorRegisterHttpsPort, retVal));
                }
            }
        }