Skip to content

Commit e48db2a

Browse files
SystemKeeperbackportbot[bot]
authored andcommitted
fix: Psalm for encrypt methods
Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
1 parent a0f9d7d commit e48db2a

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

lib/Push.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public function pushToDevice(int $id, INotification $notification): void {
296296
}
297297

298298
try {
299-
$payload = json_encode($this->encryptAndSign($userKey, $device, $id, $notification, $isTalkNotification), JSON_THROW_ON_ERROR);
299+
$payload = json_encode($this->encryptAndSign($userKey->getPrivate(), $device, $id, $notification, $isTalkNotification), JSON_THROW_ON_ERROR);
300300

301301
$proxyServer = rtrim($device['proxyserver'], '/');
302302
if (!isset($this->payloadsToSend[$proxyServer])) {
@@ -393,7 +393,7 @@ public function pushDeleteToDevice(string $userId, ?array $notificationIds, stri
393393
}
394394

395395
if ($deleteAll) {
396-
$data = $this->encryptAndSignDelete($userKey, $device, null);
396+
$data = $this->encryptAndSignDelete($userKey->getPrivate(), $device, null);
397397
try {
398398
$this->payloadsToSend[$proxyServer][] = json_encode($data['payload'], JSON_THROW_ON_ERROR);
399399
} catch (\JsonException $e) {
@@ -644,14 +644,14 @@ protected function encryptAndSign(Key $userKey, array $device, int $id, INotific
644644
$this->printInfo('Data to encrypt is: ' . json_encode($data));
645645

646646
$padding = $this->appConfig->getAppValueString('push_encryption_padding', 'PKCS1') === 'OAEP' ? OPENSSL_PKCS1_OAEP_PADDING : OPENSSL_PKCS1_PADDING;
647-
if (!openssl_public_encrypt(json_encode($data), $encryptedSubject, $device['devicepublickey'], $padding)) {
648-
$error = openssl_error_string();
647+
if (!openssl_public_encrypt($jsonData, $encryptedSubject, $device['devicepublickey'], $padding)) {
648+
$error = openssl_error_string() ?: 'Unknown OpenSSL error';
649649
$this->log->error($error, ['app' => 'notifications']);
650650
$this->printInfo('<error>Error while encrypting data: "' . $error . '"</error>');
651651
throw new \InvalidArgumentException('Failed to encrypt message for device');
652652
}
653653

654-
if (openssl_sign($encryptedSubject, $signature, $userKey->getPrivate(), OPENSSL_ALGO_SHA512)) {
654+
if (openssl_sign($encryptedSubject, $signature, $userPrivateKey, OPENSSL_ALGO_SHA512)) {
655655
$this->printInfo('Signed encrypted push subject');
656656
} else {
657657
$this->printInfo('<error>Failed to signed encrypted push subject</error>');
@@ -670,11 +670,11 @@ protected function encryptAndSign(Key $userKey, array $device, int $id, INotific
670670
}
671671

672672
/**
673-
* @param Key $userKey
673+
* @param string $userPrivateKey
674674
* @param array $device
675675
* @param ?int[] $ids
676676
* @return array
677-
* @psalm-return array{remaining: list<int>, payload: array{deviceIdentifier: string, pushTokenHash: string, subject: string, signature: string, priority: string, type: string}}
677+
* @psalm-return array{remaining: array<array-key, int>, payload: array{deviceIdentifier: string, pushTokenHash: string, subject: string, signature: string, priority: string, type: string}}
678678
* @throws InvalidTokenException
679679
* @throws \InvalidArgumentException
680680
*/
@@ -698,8 +698,9 @@ protected function encryptAndSignDelete(Key $userKey, array $device, ?array $ids
698698
}
699699

700700
$padding = $this->appConfig->getAppValueString('push_encryption_padding', 'PKCS1') === 'OAEP' ? OPENSSL_PKCS1_OAEP_PADDING : OPENSSL_PKCS1_PADDING;
701-
if (!openssl_public_encrypt(json_encode($data), $encryptedSubject, $device['devicepublickey'], $padding)) {
702-
$this->log->error(openssl_error_string(), ['app' => 'notifications']);
701+
if (!openssl_public_encrypt(json_encode($data, JSON_THROW_ON_ERROR), $encryptedSubject, $device['devicepublickey'], $padding)) {
702+
$error = openssl_error_string() ?: 'Unknown OpenSSL error';
703+
$this->log->error($error, ['app' => 'notifications']);
703704
throw new \InvalidArgumentException('Failed to encrypt message for device');
704705
}
705706

tests/psalm-baseline.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
<code><![CDATA[$this->keyManager]]></code>
2828
<code><![CDATA[$this->tokenProvider]]></code>
2929
<code><![CDATA[ClientException]]></code>
30-
<code><![CDATA[Key]]></code>
31-
<code><![CDATA[Key]]></code>
3230
<code><![CDATA[ServerException]]></code>
3331
<code><![CDATA[protected]]></code>
3432
<code><![CDATA[protected]]></code>

0 commit comments

Comments
 (0)