0

I am using Laravel websockets but Origin is going http instead of https.

Here are my files

Broadcasting.php

'connections' => [
    'pusher' => [
        'driver' => 'pusher',
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        'app_id' => env('PUSHER_APP_ID'),
        'options' => [
            'cluster' => env('PUSHER_APP_CLUSTER'),
            'encrypted' => false,
            'host' => 'domainlink',
            'port' => 6001,
            'scheme' => 'https',
            'useTLS' => true,
            'curl_options' => [
                CURLOPT_SSL_VERIFYHOST => 0,
                CURLOPT_SSL_VERIFYPEER => 0,
            ]
     ],
 ],

websockets.php

'ssl' => [
    /*
     * Path to local certificate file on filesystem. It must be a PEM encoded file which
     * contains your certificate and private key. It can optionally contain the
     * certificate chain of issuers. The private key also may be contained
     * in a separate file specified by local_pk.
     */
    'local_cert' => 'fullchain.pem',

    /*
     * Path to local private key file on filesystem in case of separate files for
     * certificate (local_cert) and private key.
     */
    'local_pk' =>'privkey.pem',

    /*
     * Passphrase for your local_cert file.
     */
    'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null),

    'verify_peer' => false,

    'allow_self_signed' => true,
    
],

app.js

  window.Echo = new Echo({
     broadcaster: 'pusher',
     key: "L698gJH67",
     encrypted: false,
     wsHost: window.location.hostname,
     wssHost: window.location.hostname,
     wsPort: 6001,
     wssPort: 6001,
     forceTLS: true,
     disableStats: true,
     enabledTransports: ['ws', 'wss'],
  });

enter image description here

Connection with socket is successful but while broadcasting message I am getting Invalid auth signature provided and if I change schema to http in broadcast.php I get Pusher error: cURL error 52: Empty reply from server.

Not sure what I am doing wrong. Thanks for the help in advance.

Sukhwinder Sodhi
  • 455
  • 1
  • 4
  • 18
  • Does your project run locally or on a remote server? I have a laravel project using the laravel websockets package over https/wss. I haven't got it to work locally with https, but on the server, with a valid certificate, it works fine. – Techno Dec 30 '22 at 15:46
  • Its on server with lets encrypt SSL – Sukhwinder Sodhi Jan 01 '23 at 10:04

1 Answers1

1

Since you are running laravel websockets on production, and I have a laravel project working roughly the same way, I figured it can't hurt to share my file configs with you.

websockets.php:

'ssl' => [
    'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null),
    'capath' => env('LARAVEL_WEBSOCKETS_SSL_CA', null),
    'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
    'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null),
    'verify_peer' => false,
    'allow_self_signed' => env('APP_ENV') !== 'production',
],

Broadcasting.php:

'pusher' => [
    'driver' => 'pusher',
    'key' => env('PUSHER_APP_KEY'),
    'secret' => env('PUSHER_APP_SECRET'),
    'app_id' => env('PUSHER_APP_ID'),
    'options' => [
        'cluster' => env('PUSHER_APP_CLUSTER'),
        'encrypted' => true,
        'host' => 'https://somehost.nl',
        'port' => 6001,
        'scheme' => 'https',
        'verify_peer' => false,
        'useTLS' => true,
        'curl_options' => [
            CURLOPT_SSL_VERIFYHOST => 0,
            CURLOPT_SSL_VERIFYPEER => 0,
        ],

    ],
],

bootstrap.js:

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'someKey',
    wsHost: window.location.hostname,
    wssPort: 6001,
    wsPort: 6001,
    encrypted: true,
    forceTLS: true,
    disableStats: true,
    enabledTransports: ['ws', 'wss']
});

So to be clear: This project works on my end, on a live server. The certificate is generated by certbot.

I see a few differences between my and your implementation, I would recommend adding/changing the config to resemble my structure, but with your values, and test :)

Techno
  • 1,668
  • 1
  • 9
  • 19