protected function doRun()
 {
     $phoneNo = $this->getArgument(self::argPhoneNo);
     Common::required($phoneNo);
     $hashedPhoneNo = CryptTool::getInstance()->hashPhoneNo($phoneNo);
     Common::l($hashedPhoneNo);
 }
 protected function doRun()
 {
     $email = $this->getArgument(self::argEmail);
     Common::required($email);
     $hashedEmail = CryptTool::getInstance()->hashEmail($email);
     Common::l($hashedEmail);
 }
 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)));
 }
 protected function doRun()
 {
     $cryptTool = CryptTool::getInstance();
     $keyPair = $cryptTool->generateKeyPair();
     $privateKeyHex = $cryptTool->bin2hex($keyPair->privateKey);
     $publicKeyHex = $cryptTool->bin2hex($keyPair->publicKey);
     file_put_contents($this->getArgument(self::argPrivateKeyFile), Common::convertPrivateKey($privateKeyHex) . "\n");
     file_put_contents($this->getArgument(self::argPublicKeyFile), Common::convertPublicKey($publicKeyHex) . "\n");
     Common::l('key pair generated');
 }
 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 #7
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));
 }
 protected function doRun()
 {
     $id = $this->getArgumentThreemaId(self::argThreemaId);
     $from = $this->getArgumentThreemaId(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     Common::required($id, $from, $secret);
     //define connection settings
     $settings = new ConnectionSettings($from, $secret);
     //create a connection
     $connector = new Connection($settings, $this->publicKeyStore);
     $result = $connector->fetchPublicKey($id);
     if ($result->isSuccess()) {
         Common::l(Common::convertPublicKey($result->getPublicKey()));
     } else {
         Common::e($result->getErrorMessage());
     }
 }
Example #9
0
 protected function doRun()
 {
     $from = $this->getArgumentThreemaId(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     Common::required($from, $secret);
     //define connection settings
     $settings = new ConnectionSettings($from, $secret);
     //create a connection
     $connector = new Connection($settings, $this->publicKeyStore);
     $result = $connector->credits();
     Common::required($result);
     if ($result->isSuccess()) {
         Common::l("remaining credits: " . $result->getCredits());
     } else {
         Common::e($result->getErrorMessage());
     }
 }
 protected function doRun()
 {
     $phoneNo = $this->getArgument(self::argPhoneNo);
     $from = $this->getArgumentThreemaId(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     Common::required($phoneNo, $from, $secret);
     //define connection settings
     $settings = new ConnectionSettings($from, $secret);
     //create a connection
     $connector = new Connection($settings, $this->publicKeyStore);
     $result = $connector->keyLookupByPhoneNumber($phoneNo);
     Common::required($result);
     if ($result->isSuccess()) {
         Common::l($result->getId());
     } else {
         Common::e($result->getErrorMessage());
     }
 }
 protected function doRun()
 {
     $threemaId = $this->getArgument(self::argThreemaId);
     $from = $this->getArgument(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     $privateKey = $this->getArgumentPrivateKey(self::argPrivateKey);
     $path = $this->getArgumentFile(self::argImageFile);
     Common::required($threemaId, $from, $secret, $privateKey, $path);
     $settings = new ConnectionSettings($from, $secret);
     $connector = new Connection($settings, $this->publicKeyStore);
     $helper = new E2EHelper($privateKey, $connector);
     $result = $helper->sendImageMessage($threemaId, $path);
     if ($result->isSuccess()) {
         Common::l('Message ID: ' . $result->getMessageId());
     } else {
         Common::e('Error: ' . $result->getErrorMessage());
     }
 }
 protected function doRun()
 {
     $to = $this->getArgument(self::argThreemaId);
     $from = $this->getArgument(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     Common::required($to, $from, $secret);
     $message = $this->readStdIn();
     if (strlen($message) === 0) {
         throw new \InvalidArgumentException('please define a message');
     }
     $settings = new ConnectionSettings($from, $secret);
     $connector = new Connection($settings, $this->publicKeyStore);
     $receiver = new Receiver($to, Receiver::TYPE_ID);
     $result = $connector->sendSimple($receiver, $message);
     if ($result->isSuccess()) {
         Common::l('Message ID: ' . $result->getMessageId());
     } else {
         Common::l('Error: ' . $result->getErrorMessage());
     }
 }
 protected function doRun()
 {
     $threemaId = $this->getArgumentThreemaId(self::argThreemaId);
     $from = $this->getArgumentThreemaId(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     Common::required($threemaId, $from, $secret);
     if (strlen($threemaId) != 8) {
         throw new Exception('invalid threema id');
     }
     //define connection settings
     $settings = new ConnectionSettings($from, $secret);
     //create a connection
     $connector = new Connection($settings, $this->publicKeyStore);
     $result = $connector->keyCapability($threemaId);
     Common::required($result);
     if ($result->isSuccess()) {
         Common::l(implode("\n", $result->getCapabilities()));
     } else {
         Common::e($result->getErrorMessage());
     }
 }
 protected function doRun()
 {
     $threemaId = $this->getArgumentThreemaId(self::argThreemaId);
     $from = $this->getArgument(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     $privateKey = $this->getArgumentPrivateKey(self::argPrivateKey);
     Common::required($threemaId, $from, $secret, $privateKey);
     $message = $this->readStdIn();
     if (strlen($message) === 0) {
         throw new \InvalidArgumentException('please define a message');
     }
     $settings = new ConnectionSettings($from, $secret);
     $connector = new Connection($settings, $this->publicKeyStore);
     $helper = new E2EHelper($privateKey, $connector);
     $result = $helper->sendTextMessage($threemaId, $message);
     if ($result->isSuccess()) {
         Common::l('Message ID: ' . $result->getMessageId());
     } else {
         Common::e('Error: ' . $result->getErrorMessage());
     }
 }
 public function testConvertPublicKey()
 {
     $p = Common::convertPublicKey('PUBKEYSTRING');
     $this->assertEquals($p, 'public:PUBKEYSTRING', 'convertPublicKey failed');
 }
Example #16
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();
         }
     }
 }
Example #17
0
 /**
  * @param string $pos
  * @return null|string
  */
 public function getArgumentPublicKey($pos)
 {
     $content = Common::getPublicKey($this->getArgumentStringOrFileContent($pos));
     $cryptTool = CryptTool::getInstance();
     if (null !== $content) {
         return $cryptTool->hex2bin($content);
     }
     return null;
 }
 public function testEncryptImage()
 {
     $threemaIconContent = file_get_contents(dirname(__FILE__) . '/threema.jpg');
     /** @noinspection PhpUnusedParameterInspection */
     $this->doTest(function (CryptTool $cryptTool, $prefix) use($threemaIconContent) {
         $privateKey = $cryptTool->hex2bin(Common::getPrivateKey(Constants::myPrivateKey));
         $publicKey = $cryptTool->hex2bin(Common::getPublicKey(Constants::myPublicKey));
         $otherPrivateKey = $cryptTool->hex2bin(Common::getPrivateKey(Constants::otherPrivateKey));
         $otherPublicKey = $cryptTool->hex2bin(Common::getPublicKey(Constants::otherPublicKey));
         $result = $cryptTool->encryptImage($threemaIconContent, $privateKey, $otherPublicKey);
         $decryptedImage = $cryptTool->decryptImage($result->getData(), $publicKey, $otherPrivateKey, $result->getNonce());
         $this->assertEquals($decryptedImage, $threemaIconContent, 'decryption of image failed');
     });
 }