public function decryptMessage($from, $ciphertext, $type, $id, $t, $retry_from = null, $skip_unpad = false) { $version = '1'; $this->parent->debugPrint("\n-> Decrypted Message: "); if ($type == 'pkmsg') { if (in_array(ExtractNumber($from), $this->parent->getv2Jids())) { $version = '2'; } try { $preKeyWhisperMessage = new PreKeyWhisperMessage(null, null, null, null, null, null, null, $ciphertext); $sessionCipher = $this->parent->getSessionCipher(ExtractNumber($from)); $plaintext = $sessionCipher->decryptPkmsg($preKeyWhisperMessage); if ($version == '2' && !$skip_unpad) { $plaintext = unpadV2Plaintext($plaintext); } $this->parent->debugPrint(parseText($plaintext) . "\n\n"); return $plaintext; } catch (Exception $e) { if ($e instanceof UntrustedIdentityException) { $this->parent->getAxolotlStore()->clearRecipient(ExtractNumber($from)); } $this->parent->debugPrint($e->getMessage() . ' - ' . $e->getFile() . ' - ' . $e->getLine()); // if ($e->getMessage() != "Null values!"){ $this->parent->debugPrint("Message {$id} could not be decrypted, sending retry.\n\n"); $participant = null; if ($retry_from != null) { if (strpos($retry_from, '-') !== false) { $participant = $from; } $from = $retry_from; } //$this->sendRetry($from, $id, $t, $participant); return false; //} } } elseif ($type == 'msg') { if (in_array(ExtractNumber($from), $this->parent->getv2Jids())) { $version = '2'; } try { $whisperMessage = new WhisperMessage(null, null, null, null, null, null, null, null, $ciphertext); $sessionCipher = $this->parent->getSessionCipher(ExtractNumber($from)); $plaintext = $sessionCipher->decryptMsg($whisperMessage); if ($version == '2' && !$skip_unpad) { $plaintext = unpadV2Plaintext($plaintext); } $this->parent->debugPrint(parseText($plaintext) . "\n\n"); return $plaintext; } catch (Exception $e) { $this->parent->debugPrint($e->getMessage() . ' - ' . $e->getFile() . ' - ' . $e->getLine()); $this->parent->debugPrint("Message {$id} could not be decrypted, sending retry.\n\n"); if ($retry_from != null) { $from = $retry_from; } //$this->sendRetry($from, $id, $t); return false; } } elseif ($type == 'skmsg') { if (in_array($from[1], $this->parent->v2Jids)) { $version = '2'; } try { $groupCipher = $this->parent->getGroupCipher(ExtractNumber($from[0]) . ':' . $from[1]); $plaintext = $groupCipher->decrypt($ciphertext); if ($version == '2' && !$skip_unpad) { $plaintext = unpadV2Plaintext($plaintext); } $this->parent->debugPrint("Message {$id} decrypted to " . parseText($plaintext) . "\n\n"); return $plaintext; } catch (Exception $e) { $this->parent->debugPrint($e->getMessage() . ' - ' . $e->getFile() . ' - ' . $e->getLine()); if ($retry_from != null) { $from = $retry_from; } $this->parent->sendRetry($this->node, $this->parent->getJID($from[0]), $id, $t); return false; } } }
function decryptMessage($from, $ciphertext, $type, $id, $t, $retry_from = null, $skip_unpad = false) { $version = "1"; $this->parent->debugPrint("\n-> Decrypted Message: "); if ($type == "pkmsg") { if (in_array(ExtractNumber($from), $this->parent->getv2Jids())) { $version = "2"; } try { $preKeyWhisperMessage = new PreKeyWhisperMessage(null, null, null, null, null, null, null, $ciphertext); $sessionCipher = $this->parent->getSessionCipher(ExtractNumber($from)); $plaintext = $sessionCipher->decryptPkmsg($preKeyWhisperMessage); if ($version == "2" && !$skip_unpad) { $plaintext = unpadV2Plaintext($plaintext); } $this->parent->debugPrint(parseText($plaintext) . "\n\n"); return $plaintext; } catch (Exception $e) { $this->parent->debugPrint($e->getMessage() . " - " . $e->getFile() . " - " . $e->getLine()); if ($e->getMessage() != "Null values!") { $this->parent->debugPrint("Message {$id} could not be decrypted, sending retry.\n\n"); $participant = null; if ($retry_from != null) { if (strpos($retry_from, "-") !== false) { $participant = $from; } $from = $retry_from; } //$this->sendRetry($from, $id, $t, $participant); return false; } } } else { if ($type == "msg") { if (in_array(ExtractNumber($from), $this->parent->getv2Jids())) { $version = "2"; } try { $whisperMessage = new WhisperMessage(null, null, null, null, null, null, null, null, $ciphertext); $sessionCipher = $this->parent->getSessionCipher(ExtractNumber($from)); $plaintext = $sessionCipher->decryptMsg($whisperMessage); if ($version == "2" && !$skip_unpad) { $plaintext = unpadV2Plaintext($plaintext); } $this->parent->debugPrint(parseText($plaintext) . "\n\n"); return $plaintext; } catch (Exception $e) { $this->parent->debugPrint($e->getMessage() . " - " . $e->getFile() . " - " . $e->getLine()); $this->parent->debugPrint("Message {$id} could not be decrypted, sending retry.\n\n"); if ($retry_from != null) { $from = $retry_from; } //$this->sendRetry($from, $id, $t); return false; } } else { if ($type == "skmsg") { if (in_array($from[1], $this->v2Jids)) { $version = "2"; } try { $groupCipher = $this->parent->getGroupCipher(ExtractNumber($from[0]) . ":" . $from[1]); $plaintext = $groupCipher->decrypt($ciphertext); if ($version == "2" && !$skip_unpad) { $plaintext = unpadV2Plaintext($plaintext); } $this->parent->debugPrint("Message {$id} decrypted to " . parseText($plaintext) . "\n\n"); return $plaintext; } catch (Exception $e) { $this->parent->debugPrint($e->getMessage() . " - " . $e->getFile() . " - " . $e->getLine()); if ($retry_from != null) { $from = $retry_from; } $this->parent->sendRetry($this->parent->getJID($from[0]), $id, $t); return false; } } } } }