Exemplo n.º 1
0
 /**
  * @param Session $session
  * @param RequestEnvelope $env
  * @param Request[] $reqs
  * @throws Exception
  */
 public static function sign(Session $session, RequestEnvelope $env, $reqs)
 {
     if (!$session->hasAuthTicket()) {
         return;
     }
     $location = $session->getLocation();
     $rawTicket = $session->getAuthTicket()->toBinary();
     $microTime = MicroTime::get();
     $protoSignature = new ProtoSignature();
     $protoSignature->setTimestampSinceStart($microTime - $session->getStartMicroTime());
     // TODO: LocationFix
     // TODO: AndroidGpsInfo
     // TODO: SensorInfo
     // TODO: DeviceInfo
     // TODO: ActivityStatus
     $protoSignature->setLocationHash1(self::generateLocation1($rawTicket, $location));
     $protoSignature->setLocationHash2(self::generateLocation2($location));
     $protoSignature->setSessionHash($session->getSessionHash());
     $protoSignature->setTimestamp($microTime);
     foreach ($reqs as $req) {
         $protoSignature->addRequestHash(self::generateRequestHash($rawTicket, $req->toProto()->toStream()->getContents()));
     }
     $protoSignature->setUnknown25(9.909701338899655E+18);
     $uk6 = new Unknown6();
     $uk6->setRequestType(6);
     $uk2 = new Unknown2();
     $enc = Encrypt::encrypt($protoSignature->toStream()->getContents(), random_bytes(32));
     $uk2->setEncryptedSignature($enc);
     $uk6->setUnknown2($uk2);
     $env->setUnknown6($uk6);
     $session->getLogger()->debug("Signed request: " . strlen($enc) . " bytes");
 }
Exemplo n.º 2
0
 public function start()
 {
     $this->startMicroTime = MicroTime::get();
     $this->sessionHash = random_bytes(16);
 }