Exemple #1
0
  public void onReceive(ByteBuffer b) {
    if (b.remaining() == 4) {
      Common.logError("invalid packet:");
      byte[] data = new byte[b.remaining()];
      b.get(data);
      Common.print_dump(data);
      //	retry( TLMessage.keyAt(  TLMessage.size() - 1) );
      return;
    }

    try {
      if (b.getLong() == 0) { // auth_key_id
        b.getLong(); // message_id
        b.getInt(); // message length
        process(TL.deserialize(b));
      } else {
        byte[] msg_key = new byte[16];
        b.get(msg_key);
        byte[] data = new byte[b.remaining()];
        b.get(data);

        synchronized (aes) {
          aes.prepare(false, msg_key, auth_key);
          data = aes.IGE(data, false);
        }

        ByteBuffer btmp = ByteBuffer.wrap(data);
        btmp.order(ByteOrder.LITTLE_ENDIAN);
        server_salt = btmp.getLong();
        btmp.getLong(); // session_id
        cur_message_id = btmp.getLong(); // message_id
        cur_msg_seq = btmp.getInt(); // seq_no
        // if (cur_msg_seq > seqno)
        //	seqno = cur_msg_seq + cur_msg_seq % 2;
        int bsize = btmp.getInt();
        if (bsize < 0 || bsize > 1024 * 1024) {
          Common.print_dump(btmp.array());
          Common.logError(new String(btmp.array()));
          Common.logError("FFFUUUUUUUUUUU!!!");
        }

        b = BufferAlloc(bsize);
        btmp.get(b.array());
        b.getInt();
        ack_message(cur_msg_seq, cur_message_id);
        b.position(0);

        process(TL.deserialize(b));
        send_accept();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemple #2
0
  private void TL_Server_DH_Params(TL.Object obj) {
    if (obj.name.equals("server_DH_params_ok")) {
      aes.prepare(cl_nonce, sv_nonce, new_nonce);
      byte[] answer = aes.IGE(obj.getBytes("encrypted_answer"), false);

      ByteBuffer btmp = ByteBuffer.wrap(answer);
      btmp.order(ByteOrder.LITTLE_ENDIAN);
      btmp.position(20);
      process(TL.deserialize(btmp));
    }

    if (obj.name.equals("server_DH_params_fail")) transport.disconnect();
  }