Beispiel #1
0
 /**
  * Send a text message to the user/group.
  *
  * @param string $to  The recipient.
  * @param string $txt The text message.
  * @param bool   $enc
  *
  * @return string     Message ID.
  */
 public function sendMessage($to, $plaintext, $force_plain = false)
 {
     if (extension_loaded('curve25519') && extension_loaded('protobuf') && !$force_plain) {
         $to_num = ExtractNumber($to);
         if (!(strpos($to, '-') !== false)) {
             if (!$this->axolotlStore->containsSession($to_num, 1)) {
                 $this->sendGetCipherKeysFromUser($to_num);
             }
             $sessionCipher = $this->getSessionCipher($to_num);
             if (in_array($to_num, $this->v2Jids)) {
                 $version = "2";
                 $plaintext = padMessage($plaintext);
             } else {
                 $version = "1";
             }
             $cipherText = $sessionCipher->encrypt($plaintext);
             if ($cipherText instanceof WhisperMessage) {
                 $type = "msg";
             } else {
                 $type = "pkmsg";
             }
             $message = $cipherText->serialize();
             $msgNode = new ProtocolNode("enc", array("v" => $version, "type" => $type), null, $message);
         } else {
             /*  $type = "skmsg";
                 if (in_array($to, $this->v2Jids))
                 {
                   $version = "2";
                   $plaintext = padMessage($plaintext);
                 }
                 else
                   $version = "1";
                 die("NOT IMPLEMENTED\n");
                 //$message = "\x03".openssl_random_pseudo_bytes(30);*/
             //NOT IMPLEMENTED GROUP ENCRIPTED MESSAGE";
             $msgNode = new ProtocolNode("body", null, null, $plaintext);
         }
     } else {
         $msgNode = new ProtocolNode("body", null, null, $plaintext);
     }
     $id = $this->sendMessageNode($to, $msgNode, null);
     if ($this->messageStore !== null) {
         $this->messageStore->saveMessage($this->phoneNumber, $to, $plaintext, $id, time());
     }
     return $id;
 }
Beispiel #2
0
 /**
  * Send a text message to the user/group.
  *
  * @param string $to  The recipient.
  * @param string $txt The text message.
  * @param bool   $enc
  *
  * @return string Message ID.
  */
 public function sendMessage($to, $plaintext, $force_plain = false)
 {
     if (extension_loaded('curve25519') && extension_loaded('protobuf') && !$force_plain) {
         $to_num = ExtractNumber($to);
         if (!(strpos($to, '-') !== false)) {
             if (!$this->axolotlStore->containsSession($to_num, 1)) {
                 $this->sendGetCipherKeysFromUser($to_num);
             }
             $sessionCipher = $this->getSessionCipher($to_num);
             if (in_array($to_num, $this->v2Jids) && !isset($this->v1Only[$to_num])) {
                 $version = '2';
                 $alteredText = padMessage($plaintext);
             } else {
                 $version = '1';
                 $alteredText = $plaintext;
             }
             $cipherText = $sessionCipher->encrypt($alteredText);
             if ($cipherText instanceof WhisperMessage) {
                 $type = 'msg';
             } else {
                 $type = 'pkmsg';
             }
             $message = $cipherText->serialize();
             $msgNode = new ProtocolNode('enc', ['v' => $version, 'type' => $type], null, $message);
         } else {
             /* if (in_array($to, $this->v2Jids))
                       {
                         $version = "2";
                         $plaintext = padMessage($plaintext);
                       }
                       else
                         $version = "1";
             
                       if(!$this->axolotlStore->containsSenderKey($to)){
                         $gsb = new GroupSessionBuilder($this->axolotlStore);
                         $senderKey = $gsb->process ($groupId, $keyId, $iteration, $chainKey, $signatureKey)
                       }
                       $thi*/
             $msgNode = new ProtocolNode('body', null, null, $plaintext);
         }
     } else {
         $msgNode = new ProtocolNode('body', null, null, $plaintext);
     }
     $plaintextNode = new ProtocolNode('body', null, null, $plaintext);
     $id = $this->sendMessageNode($to, $msgNode, null, $plaintextNode);
     if ($this->messageStore !== null) {
         $this->messageStore->saveMessage($this->phoneNumber, $to, $plaintext, $id, time());
     }
     return $id;
 }