Ejemplo n.º 1
0
 private void TL_Server_DH_inner_data(TL.Object obj) {
   g = BigInteger.valueOf(obj.getInt("g"));
   dh_prime = new BigInteger(1, obj.getBytes("dh_prime"));
   g_a = new BigInteger(1, obj.getBytes("g_a"));
   time_delta =
       (int) ((long) obj.getInt("server_time") - (long) System.currentTimeMillis() / 1000L);
   last_message_id = 0;
   send_client_DH_inner_data(0);
 }
Ejemplo n.º 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();
  }
Ejemplo n.º 3
0
  private void TL_ResPQ(TL.Object obj) {
    sv_nonce = obj.getBytes("server_nonce");
    BigInteger pq = new BigInteger(1, obj.getBytes("pq"));
    TL.Vector v_fp = obj.getVector("server_public_key_fingerprints");
    fp = v_fp.getLong(0);
    Common.logError("pq: " + pq.toString());

    // prime factorization for pq
    BigInteger q = Common.rho(pq);
    BigInteger p = pq.divide(q);
    if (p.compareTo(q) > 0) {
      BigInteger t = p;
      p = q;
      q = t;
    }
    SecureRandom rnd = new SecureRandom();
    new_nonce = new byte[32];
    rnd.nextBytes(new_nonce);

    // generate encrypted_data
    TL.Object data_obj = TL.newObject("p_q_inner_data", pq, p, q, cl_nonce, sv_nonce, new_nonce);

    byte[] data = data_obj.serialize();
    byte[] hash = Common.getSHA1(data);

    byte[] data_with_hash = new byte[255];
    System.arraycopy(hash, 0, data_with_hash, 0, hash.length);
    System.arraycopy(data, 0, data_with_hash, hash.length, data.length);
    GEN_random_bytes(data_with_hash, data.length + hash.length, 255);

    byte[] encrypted_data = Common.RSA(RSA_MODULUS, RSA_EXPONENT, data_with_hash);

    // req_DH_params
    TL.Object req_obj = TL.newObject("req_DH_params", cl_nonce, sv_nonce, p, q, fp, encrypted_data);
    send(req_obj, false, false);
  }
Ejemplo n.º 4
0
  private void TL_Config(TL.Object obj) {
    dc_date = obj.getInt("date");
    MTProto.dc_this = obj.getInt("this_dc");
    dcState.set("id", dc_this);
    updateDcStates();

    TL.Vector dc_options = obj.getVector("dc_options");

    ArrayList<TL.Object> new_dcStates = new ArrayList<TL.Object>();

    for (int i = 0; i < dc_options.count; i++) {
      TL.Object dcObj = dc_options.getObject(i);
      int id = dcObj.getInt("id");

      TL.Object state =
          TL.newObject(
              "joim.dcState",
              id,
              dcObj.getString("ip_address"),
              dcObj.getInt("port"),
              new byte[0],
              false,
              GEN_session_id(),
              0L,
              0);

      for (int j = 0; j < MTProto.dcStates.size(); j++) {
        TL.Object item = MTProto.dcStates.get(j);
        if (id == item.getInt("id") && state.getString("ip").equals(item.getString("ip"))) {
          state.set("auth_key", item.getBytes("auth_key"));
          state.set("bind", item.getBool("bind"));
          state.set("session", item.getLong("session"));
          state.set("server_salt", item.getLong("server_salt"));
          state.set("seqno", item.getInt("seqno"));
          if (state.getInt("port") == item.getInt("port")) dcState = state;
          break;
        }
      }

      new_dcStates.add(state);
    }

    dcStates = new_dcStates;
    send_queue();
    cb.onReady();
  }
Ejemplo n.º 5
0
  // MTProto
  public MTProto(int dc_id, MTProtoListener callback, int reuseFlag) {
    this.reuseFlag = reuseFlag;
    cb = callback;
    for (int i = 0; i < dcStates.size(); i++)
      if (dcStates.get(i).getInt("id") == dc_id) {
        dcState = dcStates.get(i);
        // Common.hexStringToByteArray("23D03699CE2AB29BA2273084D95DA126EC3A1D55BE4C317615CE66609D5562BDC0EFDE5AE1F9185001C35781F622B31DF5294685559340DE7D5CC8D7F6F86AE049107D8E498EB2AC3D6FA735DF90648EEC34A6B7BE3A5075A455F5696DB39280BF68C1637E1580E1EBA3F0C12EF2C03B8E9B5ECCFD3E4885BF636863388E3EC9E9EF60C722FF9B45CD93FA5E8D0D277B45A6A9370860582A159187F2F352D418D195D8E9310B5559E170F51CB2056F6CB6DB586E9349192A1B7EAA50887C115A14F996F5A855E90E47635A81EA3048615F4FD91347D73335E5503179857D0D29132483271B28E6591172C3D94686BD96E91FDB7AD9591A526218B3DDFC7A2A09")
        setAuthKey(dcState.getBytes("auth_key"));
        bind = dcState.getBool("bind");
        seqno = dcState.getInt("seqno");
        session = dcState.getLong("session");
        server_salt = dcState.getLong("server_salt");
        Common.logError("session: " + session + " seqno: " + seqno);

        connected = false;
        Thread netThread = new Thread(transport = new TransportTCP(this, true));
        netThread.setPriority(Thread.MIN_PRIORITY);
        netThread.start();

        return;
      }
    Common.logError("dc not found: " + dc_id);
  }