Esempio n. 1
0
        private void SendInitialMessage(IMORZEContact to)
        {
            SMSInitialMessage imsg = new SMSInitialMessage(m_account, to);

            //Monitor.Enter(this);
            ////if (m_InitalMessages == null)
            ////    m_InitalMessages = new List<MORZEInitialMessage>();
            ////m_InitalMessages.Add(imsg);
            //Monitor.Exit(this);

            imsg.Send(m_netStream);
            SMSSendExt ext = new SMSSendExt(this);

            imsg.InitExtParam(ext);
            ext.Send(m_netStream);
        }
Esempio n. 2
0
        public string setExtParam(ExtKey key)
        {
            string err = null;

            //set server filter setting
            try
            {
                SMSSendExt setext = new SMSSendExt();
                setext.pushExt(key.HashID, key.Ext);
                setext.SMSNet = this;
                setext.Send(m_netStream);
            }
            catch (Exception exp)
            {
                err = exp.Message;
                OnConnectChange(false, err);
            }
            return(err);
        }
 public void InitExtParam(SMSSendExt ext)
 {
     ext.pushExt(m_newExt.HashID, m_newExt.Ext);
 }
        bool operateAsyncType1(byte[] data, byte[] tail)
        {
            bool isSuccess = false;
            int  off       = 1;

            byte[]      ext    = null;
            byte[]      sync   = null;
            byte[]      iv     = null;
            SMSHash     hashid = SMSHash.None;
            SMSSyncAlgo syncid = SMSSyncAlgo.None;

            int extlen = 0;
            int synlen = 0;

            switch (data[off])
            {
            case 1:    //MD5
                extlen = 0x10;
                hashid = SMSHash.MD5;

                break;
            }

            if (extlen > 0)
            {
                off++;
                ext = new byte[extlen];
                Array.Copy(data, off, ext, 0, ext.Length);
                off += ext.Length;
            }

            if (hashid != SMSHash.None)
            {
                switch (data[off])
                {
                case 1:    //DES
                    syncid = SMSSyncAlgo.DES;
                    synlen = 8;
                    break;
                }
            }
            if (synlen > 0)
            {
                off++;
                sync = new byte[synlen];
                iv   = new byte[synlen];
                Array.Copy(data, off, sync, 0, sync.Length);
                off += sync.Length;
                Array.Copy(data, off, iv, 0, iv.Length);
                off += iv.Length;
            }
            if (off + 2 == data.Length) // +2  - CRC16
            {
                byte[] contactaddres;
                string cont = null;
                if (string.IsNullOrEmpty(SMSCrypt.SyncDecode(syncid, tail, sync, iv, out contactaddres)) == false)
                {
                    contactaddres = null;
                }
                if (contactaddres != null)
                {
                    try
                    {
                        cont = Encoding.ASCII.GetString(contactaddres);
                        Convert.FromBase64String(cont.Substring(4));
                        isSuccess = m_acc.updateSynKey(hashid, ext, syncid, sync, iv, cont);
                    }
                    catch
                    {
                        isSuccess = false;
                    }
                }
            }
            if (isSuccess == true)
            {
                MORZESendMessage cmdMsgTyp2;

                //---------------
                cmdMsgTyp2 = new MORZESendMessage();

                BufferBuilder bb = new BufferBuilder();
                bb.AddByte(2); // Type 2 - уведомление о получении ключей
                bb.AddByte((byte)hashid);
                bb.AddBytes(SMSCrypt.CalcHash(hashid, sync));

                //byte[] msg = bb.GetAllBytes();
                //bb = new BufferBuilder();
                //bb.AddByte((byte)((int)0x80 ^ (int)hashid));
                //bb.AddBytes(SMSCrypt.CalcHash(hashid, msg));
                //bb.AddBytes(ext);
                //bb.AddBytes(msg);
                //cmdMsgTyp2.WriteBytes(bb.GetAllBytes());
                byte[] res;
                if (string.IsNullOrEmpty(SMSCrypt.SyncEncode(syncid, bb.GetAllBytes(), sync, iv, out res)) == true)
                {//send notify to client
                    cmdMsgTyp2.AddMessageBody(res, hashid, ext);
                    if (m_responses == null)
                    {
                        m_responses = new List <SMSSendCommand>();
                    }

                    //set server filter setting
                    SMSSendExt setext = new SMSSendExt();
                    setext.pushExt(hashid, ext);
                    m_responses.Add(setext);
                    m_responses.Add(cmdMsgTyp2);
                }
                else
                {
                    isSuccess = false;
                }
            }
            return(isSuccess);
        }
Esempio n. 5
0
        private void thRecvCommand()
        {
            MORZERecvCommand rcmd;
            MORZECommand     cmd;

            try
            {
                do
                {
                    rcmd = new MORZERecvCommand(m_account, m_netStream);
                    cmd  = rcmd.recvCmd();
                    if (cmd != null)
                    {
                        SMSRecvHello rcvhl = null;
                        if (rcvhl == null && cmd is SMSRecvHello == true)
                        {
                            rcvhl = cmd as SMSRecvHello;
                            if (rcvhl.isValid(m_helloSign) == true)
                            {
                                OnConnectChange(true, string.Empty);
                            }
                            else
                            {
                                OnConnectChange(false, string.Empty);
                            }
                        }
                        //else if (rcvhl == null && cmd is SMSRecvHello == false)
                        //    OnConnectChange(false , "Неверный ответ сервера");
                    }
                    if (cmd != null && cmd is MORZERecvSynKey == true)
                    {
                        MORZERecvSynKey srvSync = cmd as MORZERecvSynKey;
                        srvSync.SetAsync(m_sendAsyngCmd, m_helloSign);
                        m_sendAsyngCmd.Dispose();
                        m_sendAsyngCmd = null;
                        m_sync         = srvSync.SyncCryptor;

                        if (OnConnected != null)
                        {
                            OnConnected();
                        }
                    }
                    if (cmd != null && cmd is MORZERecvMessages == true)
                    {//принято сообщение
                        MORZERecvMessages rm = cmd as MORZERecvMessages;
                        if (rm.isResponses == true)
                        {//есть ответные сообщения
                            List <SMSSendCommand> res = rm.Responses;
                            foreach (SMSSendCommand cm in res)
                            {
                                SMSSendExt setext = cm as SMSSendExt;
                                if (setext != null)
                                {
                                    setext.SMSNet = this;
                                }
                                cm.Send(m_netStream);
                            }
                        }
                    }
                } while (m_stop == false);
            }
            catch (Exception exp)
            {
                if (m_stop == false)
                {
                    OnConnectChange(false, exp.Message);
                }
            }
        }