alexryd / node-shellies-ng

Handles communication with the next generation of Shelly devices
GNU General Public License v3.0
14 stars 30 forks source link

Re-auth if a new nonce is received #3

Open wagnerand opened 1 year ago

wagnerand commented 1 year ago

Fix https://github.com/alexryd/homebridge-shelly-ng/issues/37. Fix https://github.com/alexryd/homebridge-shelly-ng/issues/53. Fix https://github.com/alexryd/homebridge-shelly-ng/issues/59.

According to the documentation, auth for websockets should never expire, but it seems it does. This checks if a new nonce was returned by the server. If so, don't fail but re-generate the auth.

wagnerand commented 1 year ago

@alexryd could you take a look at this, please?

vowchr commented 1 year ago

Is this project still alive? Many people are waiting for this fix here....

1onar commented 9 months ago

This issue persists.

@wagnerand you did edit "src/rpc/auth.ts" which doesn't exist in the original code. Does it work if i insert your "auth.ts" in the latest release or do i need to do other adjustments?

wagnerand commented 9 months ago

This issue persists.

@wagnerand you did edit "src/rpc/auth.ts" which doesn't exist in the original code. Does it work if i insert your "auth.ts" in the latest release or do i need to do other adjustments?

It does exist in the original code, as you can see from the patch view. I edited an existing file, no new files were added.

1onar commented 9 months ago

It does exist in the original code, as you can see from the patch view. I edited an existing file, no new files were added.

Yes it does in node-shellies-ng but you did answer in an issue homebridge-shelly-ng that you fixed it. But the homebridge code doesnt contain the „auth.ts“ file.

wagnerand commented 9 months ago

Please see the pull request diff view: https://github.com/alexryd/node-shellies-ng/pull/3/files. node-shellies-ng is a dependency of homebdrige-shelly-ng and the fix for https://github.com/alexryd/homebridge-shelly-ng/issues/37 is this PR.

1onar commented 9 months ago

Sorry, now i get it and found it in the homebridge files. Thank you!

7baumann commented 9 months ago

Have you thought about opening a pull request on one of the active forks of the plugin like homebridge-shelly-ng-ul, homebridge-shelly-ng-infister, homebridge-linusne-shelly-ng or @lukyer/homebridge-shelly-ng, as none of them seem to have included the fix?

It would be nice to be able to use the plugin with authentification.

asameli commented 8 months ago

Gents, is anyone capable to fix this. Or did anyone find another project with this fix included?

7baumann commented 8 months ago

Gents, is anyone capable to fix this. Or did anyone find another project with this fix included?

Well, I think for the time being you have 4 options:

For my part, I did the latter. My homebridge is running on my synology NAS, so I ssh-ed into it and updated the source by hand. This is quite dirty, but seemed to be the most viable option. As new versions of the plugin are not to be expected, and if so hopefully with this fix, overwriting of the change should not be a problem. But I see the point that this only works for me and doesn't solve it for the community and is problematic in its nature as I am tempering with my prod-environment, so I am not recommending it. It is just what I thought for me was the best short-time solution.

EDIT: Oh, and I checked the other forks beforehand: None is including this fix.

nscheffer commented 8 months ago

hi @7baumann, Sorry I am a beginner, how do you hard-fix in your prod-environment ? Many thanks in advance and merry Christmas ...

7baumann commented 8 months ago

@nscheffer Sorry, but it is probably not feasable and/or wise for you to try to fix this by hand, if you do not know how to open a shell on the machine you are running homebridge on as well as update the file by hand. This is specific to your homebridge installation and so for you I think there is only one useful option:

Remove the password of your shelly for the time being. Additionally, check if it is possible to block internet access for your shelly on your router. If your network is trustworthy, this might be a viable option.

nscheffer commented 8 months ago

@7baumann , Beginner as a developer but I know how to compile my own kernel on my raspberry to fine tune my Homebridge... I am just lost regarding which file to edit to apply the patch on my current homebridge instance.

I don't set any password on my shelly-ng and they are on their own vlan, but if I am blocking internet access I will loose the Shelly Control, I got more than 60 Shelly devices....

7baumann commented 8 months ago

First of all: If you don't have a password set for your shellys, this issue shouldn't concern you. The problem occurs only if you are connecting to your shellys with authentification.

Nevertheless, I will try to give you and others some hints. Hopefully this sets you on the right path: homebridge plugins are npm packages, running on a nodejs server. Nodejs can execute Javascript, but this plugin is written in Typescript. Therefore, the source code you can find on your machine is a compiled version, you must look for a file called auth.js.

This file is part of an npm package called shellies-ng, which is used by the node-shelly-ng plugin. Therefore, when you found your homebridge installation, there should be a node-modules-folder where your plugins live. Navigate to the node-shelly-ng plugin and find the node_modules folder in there. This should contain a folder shellies-ng, and there under rpc/auth.js you find the file you need to edit.

Thankfully, there is nothing typescript-specific to the changes of this commit, so you can just copy-paste those new lines from the commit. Be aware that the whole file is typescript-specific, so you cannot overwrite the whole file. Find those lines and edit them by hand.

I hope this helps a little.

EDIT: Concerning the internet connection: I assumed that you are using homekit to remotly control your shellys, as I do. So no direct internet connection is needed (homekit connects locally in your network to your homebridge and then to your shellys).

wagnerand commented 8 months ago

Can you please use a different communication channel? This PR contains more than enough off-topic "spam" already. Thanks!

cubi1337 commented 6 months ago

hi, added Fix to

https://github.com/cubi1337/homebridge-shelly-ds9