public Boolean CheckMD5(chave_aut chave) { if (_body == null) { _body = new Byte[0]; } header_aut tmp = (header_aut)this.Clone(); tmp.md5 = new Byte[0]; tmp.nop = 0; Byte[] header = tmp.ToBytes(); Byte[] md5calc = new Byte[header.Length + _body.Length]; Array.Copy(header, 0, md5calc, 0, header.Length); Array.Copy(_body, 0, md5calc, header.Length, _body.Length); Byte[] msgBuffer = new Byte[16 + 16 + md5calc.Length]; Array.Copy(chave.akey, 0, msgBuffer, 0, 16); Array.Copy(md5calc, 0, msgBuffer, 16, md5calc.Length); Array.Copy(chave.akey, 0, msgBuffer, 16 + md5calc.Length, 16); md5 md5 = new md5(msgBuffer); md5.calc(); return(BitConverter.ToString(md5.getHash()) == BitConverter.ToString(base.md5)); }
internal Byte[] decriptaHeader(Byte[] buffer, Int32 size) { Byte[] pkt = new Byte[size]; Array.Copy(buffer, pkt, size); chave = gera_chave(password); pkt = aut_decripta_buffer(pkt, pkt.Length, 0, chave); return(pkt); }
internal Byte[] aut_decripta_buffer(Byte[] buffer, Int32 len, Int32 vet, chave_aut chave) { Byte[] iBuffer = new Byte[len]; Array.Copy(buffer, iBuffer, len); byte[] iv = new byte[8]; Array.Copy(BitConverter.GetBytes((Int32)vet), 0, iv, 0, 4); Array.Copy(BitConverter.GetBytes((Int32)(~vet)), 0, iv, 4, 4); BlowfishCBC bl = new BlowfishCBC(chave.key, iv); bl.decrypt(iBuffer); return(iBuffer); }
public void Start() { //recebe_pacote chave de sessão Byte[] buffer = new Byte[24]; Int32 size = _mainSock.Receive(buffer); if (size < 24) { throw new Exception("Erro ao receber chave de sessão"); } //WriteFile(buffer, 0, size); header_key header = new header_key(decriptaHeader(buffer, buffer.Length)); aut_seta_n(header.n); //Separa chave chave = new chave_aut(header.chave); Int32 cnt = 0; if (OnConnectionStarted != null) { OnConnectionStarted(_remoteEP, ref cnt); } //Prepara pacote para envio ao cliente ag_greeting greeting = new ag_greeting(); greeting.versao = 4; greeting.sub_ver = 0; greeting.release = 1; greeting.plataforma = (byte)1; //1 = lunix, 2 = Windows greeting.n_users = cnt; Byte[] sendBuffer = greeting.ToBytes(); envia_pacote(_mainSock, sendBuffer, sendBuffer.Length, FWAUT_OP_AG_GREETING, FWAUT_ST_OK); EsperaPacotes(); }
private void _Connect(ref Socket iSock) { iSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); iSock.Connect(remoteEP); chave = gera_chave(password); header_key header = new header_key(); header.chave = new Byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; header.n = 1; header.nop = BitConverter.ToUInt16(header.chave, 0); Byte[] buffer = header.ToBytes(); buffer = aut_encripta_buffer(buffer, buffer.Length, 0, chave); String tst = "0x" + BitConverter.ToString(buffer).Replace("-", ", 0x"); aut_seta_n(header.n); //Envia chave se sessão iSock.Send(buffer, 0, buffer.Length, SocketFlags.None); //Separa chave, com a propria chave gerada anteriormente //Para criptografia posteriores chave = new chave_aut(header.chave); packet pkt = recebe_pacote(iSock); aut_seta_n(pkt.n); if (pkt.operacao == 5) { greeting = new ag_greeting(pkt.body); } }