Skip to content

Commit

Permalink
phpstan fixes for AssocArray (deleted)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavarnos committed Aug 15, 2018
1 parent e448be0 commit 48b22a8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/Threema/Console/Symfony/GenerateKeyPairCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Threema\MsgApi\Helpers\KeyPrefix;
use Threema\MsgApi\Encryptor\AbstractEncryptor;

class GenerateKeyPairCommand extends AbstractLocalCommand
{
Expand Down
43 changes: 29 additions & 14 deletions src/Threema/MsgApi/Encryptor/AbstractEncryptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Threema\MsgApi\Exceptions\BadMessageException;
use Threema\MsgApi\Exceptions\DecryptionFailedException;
use Threema\MsgApi\Exceptions\UnsupportedMessageTypeException;
use Threema\MsgApi\Helpers\AssocArray;
use Threema\MsgApi\Helpers\EncryptResult;
use Threema\MsgApi\Helpers\FileAnalysisResult;
use Threema\MsgApi\Helpers\KeyPair;
Expand Down Expand Up @@ -183,9 +182,9 @@ final public function decryptMessage($box, $recipientPrivateKey, $senderPublicKe
throw new BadMessageException();
}

$receiptType = ord($data[1]);
$messageIds = str_split(substr($data, 2), self::MESSAGE_ID_LEN);
$messageIdHex = array_map([$this,'bin2hex'], $messageIds);
$receiptType = ord($data[1]);
$messageIds = str_split(substr($data, 2), self::MESSAGE_ID_LEN);
$messageIdHex = array_map([$this, 'bin2hex'], $messageIds);
return new DeliveryReceipt($receiptType, $messageIdHex);

case ImageMessage::TYPE_CODE:
Expand All @@ -201,19 +200,18 @@ final public function decryptMessage($box, $recipientPrivateKey, $senderPublicKe

case FileMessage::TYPE_CODE:
/* Image Message */
$decodeResult = json_decode(substr($data, 1), true);
if (empty($decodeResult)) {
$values = json_decode(substr($data, 1), true);
if (empty($values)) {
throw new BadMessageException();
}

$values = AssocArray::byJsonString(substr($data, 1), ['b', 't', 'k', 'm', 'n', 's']);
return new FileMessage(
$values->getValue('b'),
$values->getValue('t'),
$values->getValue('k'),
$values->getValue('m'),
$values->getValue('n'),
$values->getValue('s'));
$values['b'],
$values['t'],
$values['k'],
$values['m'],
$values['n'],
$values['s']);
default:
throw new UnsupportedMessageTypeException();
}
Expand Down Expand Up @@ -250,6 +248,24 @@ final public function hashPhoneNo($phoneNo)
return hash_hmac('sha256', $phoneNoClean, self::PHONENO_HMAC_KEY);
}

/**
* Check the HMAC of an incoming Threema message request. Always do this before decrypting the message.
*
* @param string $threemaId
* @param string $gatewayId
* @param string $messageId
* @param string $date
* @param string $nonce nonce as hex encoded string
* @param string $box box as hex encoded string
* @param string $secret hex
* @return string the message mac
*/
public final function calculateMac(string $threemaId, string $gatewayId, string $messageId, string $date,
string $nonce, string $box, string $secret): string
{
return hash_hmac('sha256', $threemaId . $gatewayId . $messageId . $date . $nonce . $box, $secret);
}

/**
* Generate a random nonce.
*
Expand Down Expand Up @@ -384,7 +400,6 @@ public function bin2hex($binaryString)
*
* @param string $hexString The hex string to convert
* @param string|null $ignore (optional) Characters to ignore
* @throws \Threema\MsgApi\Exceptions\Exception
* @return string
*/
public function hex2bin($hexString, $ignore = null)
Expand Down
3 changes: 0 additions & 3 deletions src/Threema/MsgApi/Request/LookupEmailRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ class LookupEmailRequest implements RequestInterface
/** @var string */
private $hashedEmail;

/**
* @param string $emailAddress
*/
public function __construct(string $emailAddress, string $hashedEmail)
{
$this->emailAddress = $emailAddress;
Expand Down

0 comments on commit 48b22a8

Please sign in to comment.