@@ -461,7 +461,7 @@ public function proxyPushToDevice(int $id, IUser $user, array $devices, INotific
461461 $ this ->printInfo ('Device token: ' . $ device ['token ' ]);
462462
463463 try {
464- $ payload = json_encode ($ this ->encryptAndSign ($ userKey , $ device , $ id , $ notification , $ isTalkNotification ), JSON_THROW_ON_ERROR );
464+ $ payload = json_encode ($ this ->encryptAndSign ($ userKey-> getPrivate () , $ device , $ id , $ notification , $ isTalkNotification ), JSON_THROW_ON_ERROR );
465465
466466 $ proxyServer = rtrim ($ device ['proxyserver ' ], '/ ' );
467467 if (!isset ($ this ->payloadsToSend [$ proxyServer ])) {
@@ -629,7 +629,7 @@ public function proxyPushDeleteToDevice(string $userId, IUser $user, array $devi
629629 }
630630
631631 if ($ deleteAll ) {
632- $ data = $ this ->encryptAndSignDelete ($ userKey , $ device , null );
632+ $ data = $ this ->encryptAndSignDelete ($ userKey-> getPrivate () , $ device , null );
633633 try {
634634 $ this ->payloadsToSend [$ proxyServer ][] = json_encode ($ data ['payload ' ], JSON_THROW_ON_ERROR );
635635 } catch (\JsonException $ e ) {
@@ -640,7 +640,7 @@ public function proxyPushDeleteToDevice(string $userId, IUser $user, array $devi
640640 // use to not support `delete-multiple`
641641 if (!\in_array ($ app , ['spreed ' , 'talk ' , 'admin_notification_talk ' ], true )) {
642642 foreach ($ notificationIds ?? [] as $ notificationId ) {
643- $ data = $ this ->encryptAndSignDelete ($ userKey , $ device , [$ notificationId ]);
643+ $ data = $ this ->encryptAndSignDelete ($ userKey-> getPrivate () , $ device , [$ notificationId ]);
644644 try {
645645 $ this ->payloadsToSend [$ proxyServer ][] = json_encode ($ data ['payload ' ], JSON_THROW_ON_ERROR );
646646 } catch (\JsonException $ e ) {
@@ -650,7 +650,7 @@ public function proxyPushDeleteToDevice(string $userId, IUser $user, array $devi
650650 } else {
651651 $ temp = $ notificationIds ;
652652 while (!empty ($ temp )) {
653- $ data = $ this ->encryptAndSignDelete ($ userKey , $ device , $ temp );
653+ $ data = $ this ->encryptAndSignDelete ($ userKey-> getPrivate () , $ device , $ temp );
654654 $ temp = $ data ['remaining ' ];
655655 try {
656656 $ this ->payloadsToSend [$ proxyServer ][] = json_encode ($ data ['payload ' ], JSON_THROW_ON_ERROR );
@@ -948,7 +948,7 @@ protected function getNotifTopicAndUrgency(string $app, string $type): array {
948948 }
949949
950950 /**
951- * @param Key $userKey
951+ * @param string $userPrivateKey
952952 * @param array $device
953953 * @param int $id
954954 * @param INotification $notification
@@ -958,14 +958,16 @@ protected function getNotifTopicAndUrgency(string $app, string $type): array {
958958 * @throws InvalidTokenException
959959 * @throws \InvalidArgumentException
960960 */
961- protected function encryptAndSign (Key $ userKey , array $ device , int $ id , INotification $ notification , bool $ isTalkNotification ): array {
961+ protected function encryptAndSign (string $ userPrivateKey , array $ device , int $ id , INotification $ notification , bool $ isTalkNotification ): array {
962962 $ data = $ this ->encodeNotif ($ id , $ notification , 200 );
963963 $ ret = $ this ->getNotifTopicAndUrgency ($ data ['app ' ], $ data ['type ' ]);
964964 $ priority = $ ret ['urgency ' ];
965965 $ type = $ ret ['type ' ];
966966
967+ $ jsonData = json_encode ($ data , JSON_THROW_ON_ERROR );
968+
967969 $ this ->printInfo ('Device public key size: ' . strlen ((string )$ device ['devicepublickey ' ]));
968- $ this ->printInfo ('Data to encrypt is: ' . json_encode ( $ data ) );
970+ $ this ->printInfo ('Data to encrypt is: ' . $ jsonData );
969971
970972 $ padding = $ this ->appConfig ->getAppValueString ('push_encryption_padding ' , 'PKCS1 ' ) === 'OAEP ' ? OPENSSL_PKCS1_OAEP_PADDING : OPENSSL_PKCS1_PADDING ;
971973 if (!openssl_public_encrypt (json_encode ($ data ), $ encryptedSubject , $ device ['devicepublickey ' ], $ padding )) {
@@ -975,13 +977,13 @@ protected function encryptAndSign(Key $userKey, array $device, int $id, INotific
975977 throw new \InvalidArgumentException ('Failed to encrypt message for device ' );
976978 }
977979
978- if (openssl_sign ($ encryptedSubject , $ signature , $ userKey -> getPrivate () , OPENSSL_ALGO_SHA512 )) {
980+ if (openssl_sign ($ encryptedSubject , $ signature , $ userPrivateKey , OPENSSL_ALGO_SHA512 )) {
979981 $ this ->printInfo ('Signed encrypted push subject ' );
980982 } else {
981983 $ this ->printInfo ('<error>Failed to signed encrypted push subject</error> ' );
982984 }
983- $ base64EncryptedSubject = base64_encode (( string ) $ encryptedSubject );
984- $ base64Signature = base64_encode (( string ) $ signature );
985+ $ base64EncryptedSubject = base64_encode ($ encryptedSubject );
986+ $ base64Signature = base64_encode ($ signature );
985987
986988 return [
987989 'deviceIdentifier ' => $ device ['deviceidentifier ' ],
@@ -994,15 +996,15 @@ protected function encryptAndSign(Key $userKey, array $device, int $id, INotific
994996 }
995997
996998 /**
997- * @param Key $userKey
999+ * @param string $userPrivateKey
9981000 * @param array $device
9991001 * @param ?int[] $ids
10001002 * @return array
1001- * @psalm-return array{remaining: list< int>, payload: array{deviceIdentifier: string, pushTokenHash: string, subject: string, signature: string, priority: string, type: string}}
1003+ * @psalm-return array{remaining: array<array-key, int>, payload: array{deviceIdentifier: string, pushTokenHash: string, subject: string, signature: string, priority: string, type: string}}
10021004 * @throws InvalidTokenException
10031005 * @throws \InvalidArgumentException
10041006 */
1005- protected function encryptAndSignDelete (Key $ userKey , array $ device , ?array $ ids ): array {
1007+ protected function encryptAndSignDelete (string $ userPrivateKey , array $ device , ?array $ ids ): array {
10061008 $ ret = $ this ->encodeDeleteNotifs ($ ids );
10071009 $ remainingIds = $ ret ['remaining ' ];
10081010 $ data = $ ret ['data ' ];
@@ -1013,9 +1015,9 @@ protected function encryptAndSignDelete(Key $userKey, array $device, ?array $ids
10131015 throw new \InvalidArgumentException ('Failed to encrypt message for device ' );
10141016 }
10151017
1016- openssl_sign ($ encryptedSubject , $ signature , $ userKey -> getPrivate () , OPENSSL_ALGO_SHA512 );
1017- $ base64EncryptedSubject = base64_encode (( string ) $ encryptedSubject );
1018- $ base64Signature = base64_encode (( string ) $ signature );
1018+ openssl_sign ($ encryptedSubject , $ signature , $ userPrivateKey , OPENSSL_ALGO_SHA512 );
1019+ $ base64EncryptedSubject = base64_encode ($ encryptedSubject );
1020+ $ base64Signature = base64_encode ($ signature );
10191021
10201022 return [
10211023 'remaining ' => $ remainingIds ,
0 commit comments