Skip to content

Notification not sent due to hex2bin() error #372

Open
@montoyadamien

Description

@montoyadamien

NOTE: Please test in a least two browsers (i.e. Chrome and Firefox). This
helps with diagnosing problems quicker.

Please confirm the following:

  • I have read the README entirely
  • I have verified in the issues that my problem hasn't already been resolved

Setup

Please provide the following details, the more info you can provide the
better.

  • Operating System: Linux & Window
  • PHP Version: 8.1 & 8.2
  • web-push-php Version: 8.0.0

Please check that you have installed and enabled these PHP extensions :

  • curl
  • gmp
  • mbstring
  • openssl

Please select any browsers that you are experiencing problems with:

  • Chrome (Version 115.0.5790.171 (Build officiel) (64 bits))
  • Firefox
  • Firefox for Mobile
  • Opera for Android
  • Samsung Internet Browser
  • Other

Please specify the versions (i.e. Chrome Beta, Firefox Beta etc).

Problem

Please explain what behaviour you are seeing.

Hi, I am using this package in production and most of the notifications to differents users seems to work. But today I got the following error:

[13-Aug-2023 08:52:55 Europe/Paris] PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/XXX/public_html/vendor/minishlink/web-push/src/Utils.php on line 62 [13-Aug-2023 08:52:55 Europe/Paris] PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/XXX/public_html/vendor/minishlink/web-push/src/Utils.php on line 63 [13-Aug-2023 08:52:55 Europe/Paris] PHP Fatal error: Uncaught TypeError: Base64Url\Base64Url::encode(): Argument #1 ($data) must be of type string, bool given, called in /home/XXX/public_html/vendor/minishlink/web-push/src/Encryption.php on line 99 and defined in /home/XXX/public_html/vendor/spomky-labs/base64url/src/Base64Url.php:33 Stack trace: #0 /home/XXX/public_html/vendor/minishlink/web-push/src/Encryption.php(99): Base64Url\Base64Url::encode(false) #1 /home/XXX/public_html/vendor/minishlink/web-push/src/Encryption.php(61): Minishlink\WebPush\Encryption::deterministicEncrypt('{"title":"New p...', '\x04\x11<\x8D[a\xF6\xE1\xA1\xE7\x9B\xC2\xD1%3...', '\x01\xF8h*bA\xBCkox\xA0P\x8D,\xE6...', 'aes128gcm', Array, '-\xB4F\x8Ed\x05H\x96T\n\xC8\xFB\x00|\xCC...') #2 /home/XXX/public_html/vendor/minishlink/web-push/src/WebPush.php(217): Minishlink\WebPush\Encryption::encrypt('{"title":"New p...', 'BBE8jVth 9uGh55...', 'AfhoKmJBvGtveKB...', 'aes128gcm') #3 /home/XXX/public_html/vendor/minishlink/web-push/src/WebPush.php(164): Minishlink\WebPush\WebPush->prepare(Array) #4 /home/XXX/public_html/src/model/NotificationManager.php(176): Minishlink\WebPush\WebPush->flush() #5 /home/XXX/public_html/src/model/PrivateMessageManager.php(347): model\NotificationManager->sendNotification(15693, 'private_message', '/!\\ XXXXXXXX pr...') #6 /home/XXX/public_html/src/controller/PrivateMessagesController.php(112): model\PrivateMessageManager->sendNewMessage('Hi,\n\nBy being p...', 51966, 1) #7 /home/XXX/public_html/private-messages.php(22): controller\PrivateMessagesController->sendNewMessage() #8 {main} thrown in /home/XXX/public_html/vendor/spomky-labs/base64url/src/Base64Url.php on line 33

It seems that there is a problem in the file Utils.php line 62 on this lines:
return [ hex2bin(mb_substr($data, 0, $dataLength / 2, '8bit')), hex2bin(mb_substr($data, $dataLength / 2, null, '8bit')), ];

Expected

Please explain what you expected to happen

The notification should be sent like the other ones that works.

Features Used

  • VAPID Support
  • Sending with Payload

Example / Reproduce Case

Please provide a code sample that reproduces the issue. If there is a
repository that reproduces the issue please put the link here.

I can not really provide a code to reproduces that since I think I should not share my private key but do not hesitate to tell me if you need unsensitive data.

Here is an example of the code that init the web push and send the notifications maybe I missed something ?

$auth = [ 'VAPID' => [ 'subject' => WEB_PUSH_DOMAIN, 'publicKey' => WEB_PUSH_NOTIFICATION_PUBLIC_KEY, 'privateKey' => WEB_PUSH_NOTIFICATION_PRIVATE_KEY, ], ]; try { $webPush = new WebPush($auth); foreach ($webPushTokens as $token) { $webPush->queueNotification( Subscription::create([ 'endpoint' => $token['endpoint'], 'contentEncoding' => $token['content_encoding'], 'keys' => [ 'p256dh' => $token['p256dh'], 'auth' => $token['token'] ] ]), json_encode([ 'title' => $title, 'body' => $text ]) ); } foreach ($webPush->flush() as $report) { } } catch (Exception) { }

Other

Please put any remaining notes here.
I don't really know why it is not working for an user but I was not able to test it for firefox since I am not really able to reproduce that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions