Exemple #1
0
        private void BeginLogin()
        {
            // Sanity check some of the parameters
            if (CurrentContext.Params.ViewerDigest == null)
                CurrentContext.Params.ViewerDigest = String.Empty;
            if (CurrentContext.Params.Version == null)
                CurrentContext.Params.Version = String.Empty;
            if (CurrentContext.Params.Platform == null)
                CurrentContext.Params.Platform = String.Empty;
            if (CurrentContext.Params.Options == null)
                CurrentContext.Params.Options = new List<string>();
            if (CurrentContext.Params.MAC == null)
                CurrentContext.Params.MAC = String.Empty;
            if (CurrentContext.Params.Channel == null)
                CurrentContext.Params.Channel = String.Empty;
            if (CurrentContext.Params.Password == null)
                CurrentContext.Params.Password = String.Empty;

            // Convert the password to MD5 if it isn't already
            if (CurrentContext.Params.Password.Length != 35 && !CurrentContext.Params.Password.StartsWith("$1$"))
                CurrentContext.Params.Password = Helpers.MD5(CurrentContext.Params.Password);

            // Override SSL authentication mechanisms. DO NOT convert this to the 
            // .NET 2.0 preferred method, the equivalent function in Mono has a 
            // different name and it will break compatibility!
            ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
            // TODO: At some point, maybe we should check the cert?

            LoginMethodParams loginParams;
            loginParams.first = CurrentContext.Params.FirstName;
            loginParams.last = CurrentContext.Params.LastName;
            loginParams.passwd = CurrentContext.Params.Password;
            loginParams.start = CurrentContext.Params.Start;
            loginParams.channel = CurrentContext.Params.Channel;
            loginParams.version = CurrentContext.Params.Version;
            loginParams.platform = CurrentContext.Params.Platform;
            loginParams.mac = CurrentContext.Params.MAC;
            loginParams.agree_to_tos = "true";
            loginParams.read_critical = "true";
            loginParams.viewer_digest = CurrentContext.Params.ViewerDigest;

            List<string> options = new List<string>(CurrentContext.Params.Options.Count + CallbackOptions.Values.Count);
            options.AddRange(CurrentContext.Params.Options);
            foreach (string[] callbackOpts in CallbackOptions.Values)
            {
                if (callbackOpts != null)
                    foreach (string option in callbackOpts)
                        if (!options.Contains(option)) // TODO: Replace with some kind of Dictionary/Set?
                            options.Add(option);
            }
            loginParams.options = options.ToArray();

            try
            {
                LoginProxy proxy = new LoginProxy();

                proxy.KeepAlive = false;
                proxy.ResponseEvent += new XmlRpcResponseEventHandler(proxy_ResponseEvent);
                proxy.Url = CurrentContext.Params.URI;
                proxy.XmlRpcMethod = CurrentContext.Params.MethodName;
#if !PocketPC
                proxy.Expect100Continue = false;
#endif

                // Start the request
                proxy.BeginLoginToSimulator(loginParams, new AsyncCallback(LoginMethodCallback), new object[] { proxy, CurrentContext });
            }
            catch (Exception e)
            {
                UpdateLoginStatus(LoginStatus.Failed, "Error opening the login server connection: " + e);
            }
        }
Exemple #2
0
        private void BeginLogin()
        {
            // Sanity check some of the parameters
            if (CurrentContext.Params.ViewerDigest == null)
            {
                CurrentContext.Params.ViewerDigest = String.Empty;
            }
            if (CurrentContext.Params.Version == null)
            {
                CurrentContext.Params.Version = String.Empty;
            }
            if (CurrentContext.Params.Platform == null)
            {
                CurrentContext.Params.Platform = String.Empty;
            }
            if (CurrentContext.Params.Options == null)
            {
                CurrentContext.Params.Options = new List <string>();
            }
            if (CurrentContext.Params.MAC == null)
            {
                CurrentContext.Params.MAC = String.Empty;
            }
            if (CurrentContext.Params.Channel == null)
            {
                CurrentContext.Params.Channel = String.Empty;
            }
            if (CurrentContext.Params.Password == null)
            {
                CurrentContext.Params.Password = String.Empty;
            }

            // Convert the password to MD5 if it isn't already
            if (CurrentContext.Params.Password.Length != 35 && !CurrentContext.Params.Password.StartsWith("$1$"))
            {
                CurrentContext.Params.Password = Helpers.MD5(CurrentContext.Params.Password);
            }

            // Override SSL authentication mechanisms. DO NOT convert this to the
            // .NET 2.0 preferred method, the equivalent function in Mono has a
            // different name and it will break compatibility!
            ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
            // TODO: At some point, maybe we should check the cert?

            LoginMethodParams loginParams;

            loginParams.first         = CurrentContext.Params.FirstName;
            loginParams.last          = CurrentContext.Params.LastName;
            loginParams.passwd        = CurrentContext.Params.Password;
            loginParams.start         = CurrentContext.Params.Start;
            loginParams.channel       = CurrentContext.Params.Channel;
            loginParams.version       = CurrentContext.Params.Version;
            loginParams.platform      = CurrentContext.Params.Platform;
            loginParams.mac           = CurrentContext.Params.MAC;
            loginParams.agree_to_tos  = "true";
            loginParams.read_critical = "true";
            loginParams.viewer_digest = CurrentContext.Params.ViewerDigest;

            List <string> options = new List <string>(CurrentContext.Params.Options.Count + CallbackOptions.Values.Count);

            options.AddRange(CurrentContext.Params.Options);
            foreach (string[] callbackOpts in CallbackOptions.Values)
            {
                if (callbackOpts != null)
                {
                    foreach (string option in callbackOpts)
                    {
                        if (!options.Contains(option)) // TODO: Replace with some kind of Dictionary/Set?
                        {
                            options.Add(option);
                        }
                    }
                }
            }
            loginParams.options = options.ToArray();

            try
            {
                LoginProxy proxy = new LoginProxy();

                proxy.KeepAlive      = false;
                proxy.ResponseEvent += new XmlRpcResponseEventHandler(proxy_ResponseEvent);
                proxy.Url            = CurrentContext.Params.URI;
                proxy.XmlRpcMethod   = CurrentContext.Params.MethodName;
#if !PocketPC
                proxy.Expect100Continue = false;
#endif

                // Start the request
                proxy.BeginLoginToSimulator(loginParams, new AsyncCallback(LoginMethodCallback), new object[] { proxy, CurrentContext });
            }
            catch (Exception e)
            {
                UpdateLoginStatus(LoginStatus.Failed, "Error opening the login server connection: " + e);
            }
        }