protected function doRun()
 {
     $email = $this->getArgument(self::argEmail);
     Common::required($email);
     $hashedEmail = CryptTool::getInstance()->hashEmail($email);
     Common::l($hashedEmail);
 }
 protected function doRun()
 {
     $phoneNo = $this->getArgument(self::argPhoneNo);
     Common::required($phoneNo);
     $hashedPhoneNo = CryptTool::getInstance()->hashPhoneNo($phoneNo);
     Common::l($hashedPhoneNo);
 }
 protected function doRun()
 {
     $cryptTool = CryptTool::getInstance();
     $sendersThreemaId = $this->getArgumentThreemaId(self::argThreemaId);
     $id = $this->getArgumentThreemaId(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     $privateKey = $this->getArgumentPrivateKey(self::argPrivateKey);
     $nonce = $cryptTool->hex2bin($this->getArgument(self::argNonce));
     $messageId = $this->getArgument(self::argMessageId);
     $outputFolder = $this->getArgument(self::argOutputFolder);
     $box = $cryptTool->hex2bin($this->readStdIn());
     Common::required($box, $id, $secret, $privateKey, $nonce);
     $settings = new ConnectionSettings($id, $secret);
     $connector = new Connection($settings, $this->publicKeyStore);
     $helper = new E2EHelper($privateKey, $connector);
     $message = $helper->receiveMessage($sendersThreemaId, $messageId, $box, $nonce, $outputFolder);
     if (null === $message) {
         Common::e('invalid message');
         return;
     }
     if ($message->isSuccess()) {
         Common::l($message->getMessageId() . ' - ' . $message->getThreemaMessage());
         foreach ($message->getFiles() as $fileName => $filePath) {
             Common::l('   received file ' . $fileName . ' in ' . $filePath);
         }
     } else {
         Common::e('Error: ' . implode("\n", $message->getErrors()));
     }
 }
 protected function doRun()
 {
     $privateKey = $this->getArgumentPrivateKey(self::argPrivateKey);
     Common::required($privateKey);
     $cryptTool = CryptTool::getInstance();
     $publicKey = $cryptTool->derivePublicKey($privateKey);
     Common::l(Common::convertPublicKey($cryptTool->bin2hex($publicKey)));
 }
Example #5
0
 /**
  * @return array
  */
 public function getParams()
 {
     $cryptTool = CryptTool::getInstance();
     $p['to'] = $this->threemaId;
     $p['nonce'] = $cryptTool->bin2hex($this->getNonce());
     $p['box'] = $cryptTool->bin2hex($this->getBox());
     return $p;
 }
 /**
  * Convert to string
  *
  * @return string
  */
 public function __toString()
 {
     $cryptTool = CryptTool::getInstance();
     $str = "Delivery receipt (" . $this->getReceiptTypeName() . "): ";
     $hexMessageIds = array();
     foreach ($this->ackedMessageIds as $messageId) {
         $hexMessageIds[] = $cryptTool->bin2hex($messageId);
     }
     $str .= join(", ", $hexMessageIds);
     return $str;
 }
 protected function doRun()
 {
     $cryptTool = CryptTool::getInstance();
     Common::l('Version: ' . MSGAPI_SDK_VERSION);
     Common::l('Feature level: ' . MSGAPI_SDK_FEATURE_LEVEL);
     Common::l('CryptTool: ' . $cryptTool->getName() . ' (' . $cryptTool->getDescription() . ')');
     Common::l(' ╔═══════╤══════╤══════════════╤═══════╤══════╤═════════╗');
     Common::l(' ║ Level │ Text │ Capabilities │ Image │ File │ Credits ║');
     Common::l(' ╟───────┼──────┼──────────────┼───────┼──────┼─────────╢');
     Common::l(' ║ 1     │ X    │              │       │      │         ║');
     Common::l(' ║ 2     │ X    │ X            │ X     │ X    │         ║');
     Common::l("▶" . '║ 3     │ X    │ X            │ X     │ X    │ X       ║' . "");
     Common::l(' ╚═══════╧══════╧══════════════╧═══════╧══════╧═════════╝');
 }
Example #8
0
 /**
  * run the command
  */
 protected function doRun()
 {
     $privateKey = $this->getArgumentPrivateKey(self::argPrivateKey);
     $publicKey = $this->getArgumentPublicKey(self::argPublicKey);
     $textToEncrypt = $this->readStdIn();
     Common::required($privateKey, $publicKey, $textToEncrypt);
     $cryptTool = CryptTool::getInstance();
     //create a random nonce
     $newNonce = $cryptTool->randomNonce();
     $encryptedMessageText = $cryptTool->encryptMessageText($textToEncrypt, $privateKey, $publicKey, $newNonce);
     Common::ln($cryptTool->bin2hex($newNonce));
     //output encrypted text
     Common::ln($cryptTool->bin2hex($encryptedMessageText));
 }
 /**
  * Fetch a public key and check the capability of the threemaId
  *
  * @param string $threemaId
  * @param \Closure $capabilityCheck
  * @return string Public key as binary
  * @throws Exception
  */
 private final function fetchPublicKeyAndCheckCapability($threemaId, \Closure $capabilityCheck = null)
 {
     //fetch the public key
     $receiverPublicKey = $this->connection->fetchPublicKey($threemaId);
     if (null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) {
         throw new Exception('Invalid threema id');
     }
     if (null !== $capabilityCheck) {
         //check capability
         $capability = $this->connection->keyCapability($threemaId);
         if (null === $capability || false === $capabilityCheck->__invoke($capability)) {
             throw new Exception('threema id does not have the capability');
         }
     }
     return $this->cryptTool->hex2bin($receiverPublicKey->getPublicKey());
 }
 private function doTest(\Closure $c)
 {
     foreach (array('Salt' => CryptTool::createInstance(CryptTool::TYPE_SALT), 'Sodium' => CryptTool::createInstance(CryptTool::TYPE_SODIUM)) as $key => $instance) {
         if ($instance === null) {
             echo $key . ": could not instance crypt tool\n";
             break;
         }
         /** @noinspection PhpUndefinedMethodInspection */
         $this->assertTrue($instance->isSupported(), $key . ' not supported');
         $c->__invoke($instance, $key);
     }
 }
 /**
  * @return string
  */
 public function getPath()
 {
     return 'lookup/phone_hash/' . urlencode(CryptTool::getInstance()->hashPhoneNo($this->phoneNumber));
 }
 /**
  * @return string
  */
 public function getPath()
 {
     return 'lookup/email_hash/' . urlencode(CryptTool::getInstance()->hashEmail($this->emailAddress));
 }
Example #13
0
 private function help()
 {
     $defaultCryptTool = CryptTool::getInstance();
     Common::l();
     Common::l('Threema PHP MsgApi Tool');
     Common::l('Version: ' . MSGAPI_SDK_VERSION);
     Common::l('Feature level: ' . MSGAPI_FEATURE_LEVEL);
     Common::l('CryptTool: ' . $defaultCryptTool->getName() . ' (' . $defaultCryptTool->getDescription() . ')');
     Common::l(str_repeat('.', 40));
     Common::l();
     foreach ($this->commands as $data) {
         if (is_scalar($data)) {
             Common::l($data);
             Common::l(str_repeat('-', strlen($data)));
             Common::l();
         } else {
             list($key, $command) = $data;
             Common::ln($this->scriptName . ' ' . "" . implode(' ', $key) . "" . ' ' . $command->help());
             Common::l();
             /** @noinspection PhpUndefinedMethodInspection */
             Common::l($command->description(), 1);
             Common::l();
         }
     }
 }