Pusher未解密传入的通知。

huangapple go评论121阅读模式
英文:

Pusher not decrypting incoming notifications

问题

我正在开发一个使用React前端的Laravel应用程序。我已经使用Pusher设置了通知,一切正常。

我正在尝试使用端到端加密,如此处所述:https://pusher.com/docs/channels/using_channels/encrypted-channels

在我的config/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'),
        'useTLS' => true,
        'encryption_master_key' => env('PUSHER_ENCRYPTION_KEY'),
    ],
]

在我的.env文件中,我设置了PUSHER_ENCRYPTION_KEY,我可以在Pusher的调试控制台中看到通知以我期望的方式加密。

在我的前端代码中,我像这样实例化了Pusher:

const socket = new Pusher(process.env.MIX_PUSHER_APP_KEY, {
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    authEndpoint: '/api/broadcasting/auth',
});
socket.subscribe('private-encrypted-user.' + props.user.id);

socket.bind('App\\Events\\TaskCreated', function (data) {
    console.log(data)
});

我可以在网络选项卡中看到/api/broadcasting/auth响应了一个名为shared_secret的额外字段。根据文档,这用于解密传入的通知,解密应该是自动的。当我触发App\\Events\\TaskCreated时,console.log(data)会运行,但数据仍然是加密的。

文档还说,如果客户端无法解密消息,它将再次向您的auth端点发出请求以获取新的解密密钥。如果客户端仍然无法使用新密钥解密消息,它将引发错误。但是,没有错误被抛出,也没有进一步的请求发送到/api/broadcasting/auth

我已启用了Pusher.logToConsole = true;,一切看起来都正常。甚至会收到"pusher_internal:subscription_succeeded","channel":"private-encrypted-user.2",这让我相信授权部分正在按预期工作。

有人能看出我漏掉了什么吗?

英文:

I am working on a Laravel application which has a React front end. I have notifications setup using pusher which all works fine.

I am trying to use end to end encryption as described here https://pusher.com/docs/channels/using_channels/encrypted-channels

In my config/broadcasting.php I have the following

'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'),
            'useTLS' => true,
            'encryption_master_key' => env('PUSHER_ENCRYPTION_KEY'),
        ],
] 

In my .env PUSHER_ENCRYPTION_KEY is set and I can see notifications coming through in the Pusher debug console, encrypted as I would expect.

In my front end I am instantiating Pusher like this

const socket = new Pusher(process.env.MIX_PUSHER_APP_KEY, {
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    authEndpoint: '/api/broadcasting/auth'
});
socket.subscribe('private-encrypted-user.' + props.user.id);

socket.bind('App\\Events\\TaskCreated' , function (data) {            
    console.log(data)
});

I can see in my network tab /api/broadcasting/auth responds with an extra field now called shared_secret. According to the docs this is used to decrypt the incoming notification and decryption should be automatic. When I trigger App\\Events\\TaskCreated console.log(data) runs but the data is still encrypted.

It also says in the docs if a client is unable to decrypt a message, it will make another request to your auth endpoint to obtain a new decryption key. If the client is still unable to decrypt the message with the new key, it will throw an error. yet no errors are thrown and no further requests are made to /api/broadcasting/auth

I have enabled Pusher.logToConsole = true; and everything looks fine. I even get "pusher_internal:subscription_succeeded","channel":"private-encrypted-user.2" which leads me to believe the auth side of things is working as expected.

Can anyone see what I am missing?

答案1

得分: 1

我解决了!

在我上面的代码中,我将事件绑定到了套接字,但我需要将其绑定到通道。浪费了一天的时间,但以下是可以工作的代码,以防其他人也遇到相同的问题

const socket = new Pusher(process.env.MIX_PUSHER_APP_KEY, {
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    authEndpoint: '/api/broadcasting/auth'
});

const channel = socket.subscribe('private-encrypted-user.' + props.user.id);

channel.bind('App\\Events\\TaskCreated', function (data) {            
    console.log(data)
});
英文:

I worked it out!

In my code above I am binding the event to the socket when I need to bind it to the channel. A day wasted but below is working code in case anyone else struggles with the same issue

const socket = new Pusher(process.env.MIX_PUSHER_APP_KEY, {
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    authEndpoint: '/api/broadcasting/auth'
});

const channel = socket.subscribe('private-encrypted-user.' + props.user.id);

channel.bind('App\\Events\\TaskCreated' , function (data) {            
    console.log(data)
});

huangapple
  • 本文由 发表于 2020年1月6日 19:44:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611532.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定