public void Dispose() { m_stop = true; ReleaseSock(); if (m_netStream != null) { try { m_netStream.Close(); } finally { m_netStream.Dispose(); m_netStream = null; } } if (m_morze != null) { try { m_morze.Close(); } finally { m_morze = null; } } if (m_sendAsyngCmd != null) { m_sendAsyngCmd.Dispose(); m_sendAsyngCmd = null; } }
public SMSNet(IMORZEAccount account) { m_stop = false; //m_rspHello = null; m_rnd = new Random(); m_netStream = null; m_morze = null; m_helloSign = new byte[4]; m_sendAsyngCmd = null; m_rnd.NextBytes(m_helloSign); // m_InitalMessages = null; m_account = account; }
private void OnConnectChange(bool isConnected, string err) { if (isConnected == true && string.IsNullOrEmpty(err) == true) {//отправить открытый ключ , для шифрования ключа симметричного алгоритма m_sendAsyngCmd = new MORZESendAsync(m_helloSign); m_sendAsyngCmd.Send(m_netStream); } if (isConnected == false) { ReleaseSock(); if (OnDisconnected != null) { OnDisconnected(err); } } }
public SMSSync SetAsync(MORZESendAsync async, byte[] hellosign) { byte [] syncKey = async.Decrypt(m_Data); byte[] t; byte algo = syncKey[0]; SMSSync sync = null; switch (algo) { case 1: //DES t = new byte[syncKey.Length - 1]; Array.Copy(syncKey, 1, t, 0, t.Length); sync = new SMSDES(t, hellosign); m_Sync = sync; break; default: throw new Exception(string.Format("Неподдреживаемый алгоритм симметричного шифрования - {0}", algo.ToString())); } return(sync); }
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); } } }