web-push-libs / web-push-php

Web Push library for PHP
MIT License
1.69k stars 295 forks source link

PHP Fatal error: Uncaught TypeError: Jose\Component\Core\Util\Ecc\PrivateKey::create(): #338

Closed diloabininyeri closed 6 months ago

diloabininyeri commented 3 years ago
PHP Fatal error:  Uncaught TypeError: Jose\Component\Core\Util\Ecc\PrivateKey::create(): Argument #1 ($secret) must be of type Brick\Math\BigInteger, GMP given, called in /home/dppop/Desktop/push/vendor/minishlink/web-push/src/Encryption.php on line 392 and defined in /home/dppop/Desktop/push/vendor/web-token/jwt-util-ecc/PrivateKey.php:57
Stack trace:
#0 /home/dppop/Desktop/push/vendor/minishlink/web-push/src/Encryption.php(392): Jose\Component\Core\Util\Ecc\PrivateKey::create()
#1 /home/dppop/Desktop/push/vendor/minishlink/web-push/src/Encryption.php(118): Minishlink\WebPush\Encryption::calculateAgreementKey()
#2 /home/dppop/Desktop/push/vendor/minishlink/web-push/src/Encryption.php(66): Minishlink\WebPush\Encryption::deterministicEncrypt()
#3 /home/dppop/Desktop/push/vendor/minishlink/web-push/src/WebPush.php(230): Minishlink\WebPush\Encryption::encrypt()
#4 /home/dppop/Desktop/push/vendor/minishlink/web-push/src/WebPush.php(173): Minishlink\WebPush\WebPush->prepare()
#5 /home/dppop/Desktop/push/index.php(57): Minishlink\WebPush\WebPush->flush()
#6 {main}
  thrown in /home/dppop/Desktop/push/vendor/web-token/jwt-util-ecc/PrivateKey.php on line 57

my code

<?php

use Minishlink\WebPush\WebPush;
use Minishlink\WebPush\Subscription;

require_once "vendor/autoload.php";

// array of notifications
$notifications = [
    [
        'subscription' => Subscription::create([
            'endpoint' => 'https://updates.push.services.mozilla.com/push/abc...', // Firefox 43+,
            'publicKey' => 'BPcMbnWQL5GOYX/5LKZXT6sLmHiMsJSiEvIFvfcDvX7IZ9qqtq68onpTPEYmyxSQNiH7UD/98AUcQ12kBoxz/0s=', // base 64 encoded, should be 88 chars
            'authToken' => 'CxVX6QsVToEGEcjfYPqXQw==', // base 64 encoded, should be 24 chars
        ]),
        'payload' => 'hello !',
    ], [
        'subscription' => Subscription::create([
            'endpoint' => 'https://fcm.googleapis.com/fcm/send/abcdef...', // Chrome
        ]),
        'payload' => null,
    ], [
        'subscription' => Subscription::create([
            'endpoint' => 'http//localhost:63342/push',
            'publicKey' => 'BIjz9EfK9t_hVSOF4xTd2XVe8Cax3H_t7v4FpYJHIkdERyRSd6LqVUqFlSA5fNGHrDpMkEIVzV9V5Vt6WGmgL7g',
            'authToken' => 'NzXG5XJAgE8n3w4Jp7gCCk7Nfc2i1z_UYOLxDfvIizc',
            'contentEncoding' => 'aesgcm', // one of PushManager.supportedContentEncodings
        ]),
        'payload' => '{msg:"test"}',
    ], [
        'subscription' => Subscription::create([ // this is the structure for the working draft from october 2018 (https://www.w3.org/TR/2018/WD-push-api-20181026/)
            "endpoint" => "http//localhost:63342/push",
            "keys" => [
                'p256dh' => 'BIjz9EfK9t_hVSOF4xTd2XVe8Cax3H_t7v4FpYJHIkdERyRSd6LqVUqFlSA5fNGHrDpMkEIVzV9V5Vt6WGmgL7g',
                'auth' => 'NzXG5XJAgE8n3w4Jp7gCCk7Nfc2i1z_UYOLxDfvIizc'
            ],
        ]),
        'payload' => '{"msg":"Hello World!"}',
    ],
];

$webPush = new WebPush();

// send multiple notifications with payload
foreach ($notifications as $notification) {
    $webPush->queueNotification(
        $notification['subscription'],
        $notification['payload'] // optional (defaults null)
    );
}

/**
 * Check sent results
 * @var MessageSentReport $report
 */
foreach ($webPush->flush() as $report) {
    $endpoint = $report->getRequest()->getUri()->__toString();

    if ($report->isSuccess()) {
        echo "[v] Message sent successfully for subscription {$endpoint}.";
    } else {
        echo "[x] Message failed to sent for subscription {$endpoint}: {$report->getReason()}";
    }
}

/**
 * send one notification and flush directly
 * @var MessageSentReport $report
 */
$report = $webPush->sendOneNotification(
    $notifications[0]['subscription'],
    $notifications[0]['payload'] // opti
);
Slowie-32 commented 2 years ago

Did you solve this issue. im having the same problem but cannot find out why

alpastar commented 2 years ago

same problem web push ver 7.0.0 php-fpm 7.4.3

2022/04/13 22:39:46 [error] 368579#368579: *717 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught TypeError: Argument 1 passed to Jose\Component\Core\Util\Ecc\PrivateKey::create() must be an instance of Brick\Math\BigInteger, instance of GMP given, called in /var/www/public/push/vendor/minishlink/web-push/src/Encryption.php on line 355 and defined in /var/www/public/push/vendor/web-token/jwt-util-ecc/PrivateKey.php:57

Stack trace:

0 /var/www/public/push/vendor/minishlink/web-push/src/Encryption.php(355): Jose\Component\Core\Util\Ecc\PrivateKey::create()

1 /var/www/public/push/vendor/minishlink/web-push/src/Encryption.php(105): Minishlink\WebPush\Encryption::calculateAgreementKey()

2 /var/www/public/push/vendor/minishlink/web-push/src/Encryption.php(61): Minishlink\WebPush\Encryption::deterministicEncrypt()

3 /var/www/public/push/vendor/minishlink/web-push/src/WebPush.php(224): Minishlink\WebPush\Encryption::encrypt()

4 /var/www/public/push/vendor/minishlink/web-push/src/WebPush.php(171): Minishlink\WebPush\WebPush->prepare()