Beispiel #1
0
 /**
  * Get next tree of node
  *
  * @param null $input
  *
  * @return null|ProtocolNode
  * @throws \Exception
  */
 public function nextTree($input = null)
 {
     if ($input != null) {
         $this->input = $input;
     }
     $stanzaFlag = ($this->peekInt8() & 0xf0) >> 4;
     $stanzaSize = $this->peekInt16(1);
     if ($stanzaSize > strlen($this->input)) {
         throw new \Exception("Incomplete message {$stanzaSize} != " . strlen($this->input));
     }
     $this->readInt24();
     if ($stanzaFlag & 8) {
         if (isset($this->key)) {
             $realSize = $stanzaSize - 4;
             $this->input = $this->key->decodeMessage($this->input, $realSize, 0, $realSize);
             // . $remainingData;
         } else {
             throw new \Exception("Encountered encrypted message, missing key");
         }
     }
     if ($stanzaSize > 0) {
         return $this->nextTreeInternal();
     }
     return null;
 }
Beispiel #2
0
 /**
  * Authenticate with the Whatsapp Server.
  *
  * @return String
  *   Returns binary string
  */
 protected function authenticate()
 {
     $keys = KeyStream::generateKeys(base64_decode($this->password), $this->challengeData);
     $this->inputKey = new KeyStream($keys[2], $keys[3]);
     $this->outputKey = new KeyStream($keys[0], $keys[1]);
     //$phone           = $this->dissectPhone();
     $array = "" . $this->phoneNumber . $this->challengeData;
     // . time() . static::WHATSAPP_USER_AGENT . " MccMnc/" . str_pad($phone["mcc"], 3, "0", STR_PAD_LEFT) . "001";
     $response = $this->outputKey->encodeMessage($array, 0, 4, strlen($array) - 4);
     return $response;
 }