Esempio n. 1
0
 /// <summary>
 /// Cancel and clear the current KMOD query, if there is one.
 /// </summary>
 private void ClearKmodQuery()
 {
     if (m_query != null)
     {
         m_query.Cancel();
         m_query = null;
     }
 }
Esempio n. 2
0
        public override void Start()
        {
            try
            {
                // Make sure we can login on the KPS.
                if (!KwmCfg.Cur.CanLoginOnKps())
                {
                    throw new EAnpExInvalidKpsConfig();
                }

                // Get a ticket.
                m_step = OpStep.TicketReply;
                WmLoginTicketQuery ticketQuery = new WmLoginTicketQuery();
                m_kmodQuery = ticketQuery;
                ticketQuery.Submit(Wm.KmodBroker, KwmCfg.Cur, OnKmodTicketResult);
            }

            catch (Exception ex)
            {
                HandleFailure(ex);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Handle the results of the lookup query.
 /// </summary>
 private void HandleLookupRecAddrResult(KmodQuery query)
 {
     if (!CheckCtx(KwmCoreKwsOpStep.LookupRec)) return;
     m_ih.HandleLookupRecAddrResult(query);
     CompleteOp();
 }
Esempio n. 4
0
        /// <summary>
        /// Called when the login query results are available.
        /// </summary>
        private void OnLoginResult(KmodQuery query)
        {
            Logging.Log("OnLoginResult() called.");
            ClearKmodQuery();
            K3p.kmo_server_info_ack ack = query.OutMsg as K3p.kmo_server_info_ack;

            if (ack != null)
            {
                creds.Token = ack.Token;
                WmLoginTicketQuery ticketQuery = new WmLoginTicketQuery();
                SaveCredentials();
                m_query = ticketQuery;
                ticketQuery.Submit(m_broker, WmWinRegistry.Spawn(), OnTicketResult);
            }

            else
            {
                K3p.kmo_server_info_nack nack = query.OutMsg as K3p.kmo_server_info_nack;

                if (nack != null)
                {
                    if (nack.Error.StartsWith("cannot resolve ")) creds.SetServerError(nack.Error);
                    else creds.SetCredError(nack.Error);
                }

                else
                {
                    creds.SetServerError(query.OutDesc);
                }

                this.Enabled = true;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Handle the results of the lookup query.
        /// </summary>
        public void HandleLookupRecAddrResult(KmodQuery query)
        {
            Debug.Assert(Op.m_kmodQuery == query);
            Op.m_kmodQuery = null;

            try
            {
                K3p.kmo_lookup_rec_addr res = query.OutMsg as K3p.kmo_lookup_rec_addr;

                // We got valid results.
                if (res != null)
                {
                    if (res.RecArray.Length != (UInt32)InviteParams.NotAlreadyInvitedUserArray.Count)
                        throw new Exception("invalid number of users in lookup");

                    for (int i = 0; i < InviteParams.NotAlreadyInvitedUserArray.Count; i++)
                    {
                        KwsInviteOpUser u = InviteParams.NotAlreadyInvitedUserArray[i];
                        K3p.kmo_lookup_rec_addr_rec a = res.RecArray[i];
                        u.KeyID = (a.KeyID == "") ? 0 : Convert.ToUInt64(a.KeyID);
                        u.OrgName = a.OrgName;

                        Logging.Log("user " + u.EmailAddress + ": " + u.KeyID + " (" + (u.OrgName == "" ? "<none>" : u.OrgName) + ")");
                    }
                }

                else throw new Exception(query.OutDesc);
            }

            // Ignore the failed query.
            catch (Exception ex)
            {
                Logging.Log(2, "The query to lookup the recipient addresses failed: " + ex.Message);
            }
        }
Esempio n. 6
0
        private void ConfigKPPSignIn_SetActive(object sender, CancelEventArgs e)
        {
            try
            {
                if (m_autoSignIn)
                {
                    m_autoSignIn = false;
                    this.Enabled = false;

                    // Submit the login query.
                    K3p.K3pLoginTest cmd = creds.GetLoginCommand();
                    m_query = new KmodQuery();
                    m_query.Submit(m_broker, new K3pCmd[] { cmd }, OnLoginResult);

                    return;
                }

                if (m_skippedRegistration)
                    SetWizardButtons(WizardButtons.Next | WizardButtons.Cancel);
                else
                    SetWizardButtons(WizardButtons.Back | WizardButtons.Next | WizardButtons.Cancel);

                LoginSuccess = false;

                UpdateNextButton();
                creds.ResetError();
                creds.Focus();
                creds.AdjustFocus();
            }
            catch (Exception ex)
            {
                Base.HandleException(ex);
            }
        }
Esempio n. 7
0
        private void ConfigKPPSignIn_WizardNext(object sender, WizardPageEventArgs e)
        {
            // Clear the current query if there is one.
            this.Enabled = false;
            e.Cancel = true;

            ClearKmodQuery();

            // Submit the login query.
            K3p.K3pLoginTest cmd = creds.GetLoginCommand();
            m_query = new KmodQuery();
            m_query.Submit(m_broker, new K3pCmd[] { cmd }, OnLoginResult);
        }
Esempio n. 8
0
        /// <summary>
        /// Analyze the results of the login query and call the callback.
        /// </summary>
        private void AnalyseResults(KmodQuery ignored)
        {
            if (OutMsg is K3p.kmo_invalid_config)
            {
                Res = WmLoginTicketQueryRes.InvalidCfg;
            }

            else if (OutMsg is K3p.kmo_get_kws_ticket)
            {
                try
                {
                    Res = WmLoginTicketQueryRes.OK;
                    Ticket = new WmLoginTicket();
                    Ticket.FromB64Ticket(((K3p.kmo_get_kws_ticket)OutMsg).Ticket);
                }

                catch (Exception ex)
                {
                    Res = WmLoginTicketQueryRes.MiscError;
                    OutDesc = "cannot parse ticket: " + ex.Message;
                }
            }

            else
            {
                Res = WmLoginTicketQueryRes.MiscError;
            }

            Callback2(this);
        }
Esempio n. 9
0
 /// <summary>
 /// Cancel and clear the current KMOD query, if any.
 /// </summary>
 public virtual void ClearKmodQuery()
 {
     if (m_kmodQuery != null)
     {
         m_kmodQuery.Cancel();
         m_kmodQuery = null;
     }
 }
Esempio n. 10
0
        public override void Start()
        {
            try
            {
                // Make sure we can login on the KPS.
                if (!KwmCfg.Cur.CanLoginOnKps()) throw new EAnpExInvalidKpsConfig();

                // Get a ticket.
                m_step = OpStep.TicketReply;
                WmLoginTicketQuery ticketQuery = new WmLoginTicketQuery();
                m_kmodQuery = ticketQuery;
                ticketQuery.Submit(Wm.KmodBroker, KwmCfg.Cur, OnKmodTicketResult);
            }

            catch (Exception ex)
            {
                HandleFailure(ex);
            }
        }
Esempio n. 11
0
        private void ConfigKPPCredentials_WizardNext(object sender, WizardPageEventArgs e)
        {
            // Clear the current query if there is one.
            ClearKmodQuery();

            if (rbHaveAccount.Checked)
            {
                if (LoginSuccess)
                {
                    e.NewPage = "ConfigKPPSuccess";
                }
                else
                {
                    this.Enabled = false;
                    e.Cancel = true;

                    // Submit the login query.
                    K3p.K3pLoginTest cmd = creds.GetLoginCommand();
                    m_query = new KmodQuery();
                    m_query.Submit(m_broker, new K3pCmd[] { cmd }, OnLoginResult);
                }
            }

            else
            {
                e.NewPage = "ConfigKPPCreateAccount";
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Submit the login query to KMOD.
        /// </summary>
        private void SubmitKmodLoginQuery()
        {
            K3p.K3pLoginTest cmd = new K3p.K3pLoginTest();
            cmd.Info.kps_login = KpsUserName;
            cmd.Info.kps_secret = KpsUserPwd;
            cmd.Info.secret_is_pwd = 1;
            cmd.Info.kps_net_addr = KpsAddr;
            cmd.Info.kps_port_num = 443;

            m_kmodQuery = new KmodQuery();
            m_kmodQuery.Submit(Wm.KmodBroker, new K3pCmd[] { cmd }, OnKmodLoginResult);
        }
Esempio n. 13
0
 /// <summary>
 /// Submit the ticket query to KMOD.
 /// </summary>
 private void SubmitKmodTicketQuery()
 {
     WmLoginTicketQuery ticketQuery = new WmLoginTicketQuery();
     m_kmodQuery = ticketQuery;
     KwmCfg cfg = new KwmCfg();
     UpdateRegistryObject(cfg);
     ticketQuery.Submit(Wm.KmodBroker, cfg, OnKmodTicketResult);
 }
Esempio n. 14
0
        /// <summary>
        /// Called when the KMOD ticket query results are available.
        /// </summary>
        private void OnKmodTicketResult(WmLoginTicketQuery query)
        {
            if (m_kmodQuery != query) return;
            m_kmodQuery = null;

            // Generic failure.
            if (query.Res != WmLoginTicketQueryRes.OK)
            {
                m_kmodResCode = EAnpRegisterKpsCode.Failure;
                m_kmodEx = new Exception(query.OutDesc);
            }

            // No KCD failure.
            else if (query.Ticket.KcdAddr == "")
                m_kmodResCode = EAnpRegisterKpsCode.NoKcd;

            // Query completed.
            OnQueryCompletion();
        }
Esempio n. 15
0
        /// <summary>
        /// Called when the KMOD login query results are available.
        /// </summary>
        private void OnKmodLoginResult(KmodQuery query)
        {
            if (m_kmodQuery != query) return;
            m_kmodQuery = null;

            K3p.kmo_server_info_ack ack = query.OutMsg as K3p.kmo_server_info_ack;

            // Success.
            if (ack != null)
            {
                // Cache the login token.
                KpsLoginToken = ack.Token;

                // Submit the ticket query.
                SubmitKmodTicketQuery();
            }

            // Failure.
            else
            {
                m_kmodResCode = EAnpRegisterKpsCode.Failure;
                K3p.kmo_server_info_nack nack = query.OutMsg as K3p.kmo_server_info_nack;
                if (nack != null) m_kmodEx = new Exception(nack.Error);
                else m_kmodEx = new Exception(query.OutDesc);
                OnQueryCompletion();
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Handle the results of the lookup query.
        /// </summary>
        private void HandleLookupRecAddrResult(KmodQuery query)
        {
            if (m_kmodQuery != query) return;
            m_kmodQuery = null;

            try
            {
                K3p.kmo_lookup_rec_addr res = query.OutMsg as K3p.kmo_lookup_rec_addr;

                // We got valid results.
                if (res != null)
                {
                    for (int i = 0; i < EmailList.Count; i++)
                    {
                        K3p.kmo_lookup_rec_addr_rec a = res.RecArray[i];
                        Rec r = new Rec();
                        RecList.Add(r);
                        r.Email = EmailList[i];
                        r.KeyID = (a.KeyID == "") ? 0 : Convert.ToUInt64(a.KeyID);
                        r.OrgName = a.OrgName;
                    }
                }

                else throw new Exception(query.OutDesc);
            }

            catch (Exception ex)
            {
                HandleFailure(ex);
                return;
            }

            Complete();
        }
Esempio n. 17
0
 public override void Start()
 {
     K3p.K3pSetServerInfo ssi = new K3p.K3pSetServerInfo();
     WmK3pServerInfo.RegToServerInfo(KwmCfg.Cur, ssi.Info);
     K3p.kpp_lookup_rec_addr lra = new K3p.kpp_lookup_rec_addr();
     lra.AddrArray = EmailList.ToArray();
     m_kmodQuery = new KmodQuery();
     m_kmodQuery.Submit(Wm.KmodBroker, new K3pCmd[] { ssi, lra }, HandleLookupRecAddrResult);
 }
Esempio n. 18
0
 /// <summary>
 /// Cancel the KMOD query specified and set its reference to null, 
 /// if needed.
 /// </summary>
 protected void ClearKmodQuery(ref KmodQuery query)
 {
     if (query != null)
     {
         query.Cancel();
         query = null;
     }
 }
Esempio n. 19
0
        /// <summary>
        /// Called when the KMOD ticket query results are available.
        /// </summary>
        private void OnKmodTicketResult(WmLoginTicketQuery query)
        {
            if (m_kmodQuery != query) return;
            m_kmodQuery = null;
            Debug.Assert(m_step == OpStep.TicketReply);

            try
            {
                // Update the registry information.
                query.UpdateRegistry();

                // Generic failure.
                if (query.Res != WmLoginTicketQueryRes.OK) throw new Exception(query.OutDesc);

                // We cannot create a workspace.
                if (!KwmCfg.Cur.CanCreateKws()) throw new EAnpExInvalidKpsConfig();

                // Update the credentials.
                Creds.Ticket = query.Ticket.BinaryTicket;
                Creds.UserName = query.Ticket.AnpTicket.Elements[0].String;
                Creds.UserEmailAddress = query.Ticket.AnpTicket.Elements[1].String;

                // Set the KCD address.
                if (KwmCfg.Cur.CustomKcdFlag) Creds.KcdAddress = KwmCfg.Cur.CustomKcdAddress;
                else Creds.KcdAddress = KwmCfg.Cur.KpsKcdAddr;
                if (Creds.KcdAddress == "") throw new Exception("invalid KCD address");

                // Create the workspace object.
                Kws = Wm.CreateWorkspace(Creds);
                RegisterToKws();

                // Start the spawn operation and wait for the connection.
                m_step = OpStep.Connecting;
                Kws.Sm.RequestTaskSwitch(KwsTask.Spawn);
                SendCreateKwsCmdIfNeeded();
            }

            catch (Exception ex)
            {
                HandleFailure(ex);
            }
        }
Esempio n. 20
0
 /// <summary>
 /// Handle the results of the lookup query.
 /// </summary>
 private void HandleLookupRecAddrResult(KmodQuery query)
 {
     Logging.Log(1, "HandleLookupRecAddrResult()");
     if (!CheckCtx(KwmCoreKwsOpStep.LookupRec)) return;
     m_ih.HandleLookupRecAddrResult(query);
     PromptForPwd();
 }