Exemplo n.º 1
0
        // The following method is invoked by the RemoteCertificateValidationDelegate.
        public static bool ValidateServerCertificate(
            object sender,
            X509Certificate certificate,
            X509Chain chain,
            SslPolicyErrors sslPolicyErrors)
        {
            if (sslPolicyErrors == SslPolicyErrors.None)
            {
                return(true);
            }

            if (certificate == null)
            {
                return(false);
            }

            // Dump the error and certificate data.
            String errorString = String.Format(CultureInfo.InvariantCulture, "Certificate error: {0} Certificate: {1}", sslPolicyErrors, certificate);

            DiagnosticsHelper.LogMessage(DiagSeverity.Warning, errorString);

            // Microsoft seem to have certificate issues possibly related to load balancing.
            // We are seeing certificate name errors where CN=supportnatalapj.xbox.com and DNS Name = kinectsupport.xbox.com
            if (sslPolicyErrors == SslPolicyErrors.RemoteCertificateNameMismatch)
            {
                if (String.Compare(certificate.Issuer, "CN=Microsoft Secure Server Authority, DC=redmond, DC=corp, DC=microsoft, DC=com", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "ISSUER ACCEPTED: " + certificate.Issuer);

                    if (String.Compare(certificate.Subject, "CN=supportnatalapj.xbox.com", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "SUBJECT ACCEPTED: " + certificate.Subject);
                        return(true);
                    }
                    else
                    {
                        DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "SUBJECT NOT ACCEPTED: " + certificate.Subject);
                        return(true);
                    }
                }
                else
                {
                    DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "ISSUER NOT ACCEPTED: " + certificate.Issuer);
                }
            }

            // Do not allow this client to communicate with unauthenticated servers.
            return(false);
        }
Exemplo n.º 2
0
        public static bool DisableSleep()
        {
            bool ret = false;

            NativeMethods.EXECUTION_STATE newExecutionState;

            // This function returns the last state (not the state you are setting) - so call again to make sure it is set.
            // The retry is not really necessary.
            for (int i = 0; i < s_MaxSleepStateRetries; i++)
            {
                newExecutionState = NativeMethods.SetThreadExecutionState(NativeMethods.EXECUTION_STATE.ES_CONTINUOUS |
                                                                          NativeMethods.EXECUTION_STATE.ES_SYSTEM_REQUIRED);

                if ((newExecutionState & NativeMethods.EXECUTION_STATE.ES_SYSTEM_REQUIRED) ==
                    NativeMethods.EXECUTION_STATE.ES_SYSTEM_REQUIRED)
                {
                    ret = true;
                    break;
                }
                else
                {
                    if (i > 0)
                    {
                        DiagnosticsHelper.LogMessage(DiagSeverity.Information,
                                                     string.Format(CultureInfo.InvariantCulture,
                                                                   "Failed to disable Sleep/Hibernate, attempt {0}, new state is {1}",
                                                                   (i + 1),
                                                                   newExecutionState));
                    }
                }
            }

            if (ret)
            {
                DiagnosticsHelper.LogMessage(DiagSeverity.Information, "Sleep/Hibernate disabled");
            }
            else
            {
                DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "Failed to disable Sleep/Hibernate");
            }

            return(ret);
        }
Exemplo n.º 3
0
        public static bool EnableSleep()
        {
            bool ret = false;

            NativeMethods.EXECUTION_STATE newExecutionState;

            // It seems that this function needs to be called twice before the
            // new value will take...
            for (int i = 0; i < s_MaxSleepStateRetries; i++)
            {
                newExecutionState = NativeMethods.SetThreadExecutionState(NativeMethods.EXECUTION_STATE.ES_CONTINUOUS);

                if ((newExecutionState & NativeMethods.EXECUTION_STATE.ES_SYSTEM_REQUIRED) !=
                    NativeMethods.EXECUTION_STATE.ES_SYSTEM_REQUIRED)
                {
                    ret = true;
                    break;
                }
                else
                {
                    if (i > 0)
                    {
                        DiagnosticsHelper.LogMessage(DiagSeverity.Information,
                                                     string.Format(CultureInfo.InvariantCulture,
                                                                   "Failed to enable Sleep/Hibernate, attempt {0}, new state is {1}",
                                                                   (i + 1),
                                                                   newExecutionState));
                    }
                }
            }

            if (ret)
            {
                DiagnosticsHelper.LogMessage(DiagSeverity.Information, "Sleep/Hibernate enabled");
            }
            else
            {
                DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "Failed to enable Sleep/Hibernate");
            }

            return(ret);
        }