Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect a chromecast to a wifi network #88

Open
kkhanh opened this issue Jun 4, 2021 · 9 comments
Open

Connect a chromecast to a wifi network #88

kkhanh opened this issue Jun 4, 2021 · 9 comments

Comments

@kkhanh
Copy link

kkhanh commented Jun 4, 2021

Hi,

First of all, thank you @rithvikvibhu for your work.

I would like to know if you or anyone else has made any progress regarding the "enc_passwd" parameter.

We have built a solution around the chromecast and to speed up the configuration, my company is willing to reward 750€ the person who can successfully connect a chromecast to a WPA2 network using the /connect_wifi endpoint or any workaround. There will also be an additionnal reward if you can connect the chromecast to a Google account and change the screen saver settings (hide weather, hide time, change background screen through Google photos)

You can contact us at skyproo@gmail.com

Regards,

@rithvikvibhu
Copy link
Owner

Hey, @thorleifjaocbsen figured out the connect wifi endpoint including the password encryption here: #68

I kinda missed (forgot about) that issue and was marked closed by the bot before it was added to the docs - will get to it soon.

I don't have a chromecast to check the Google account linking, but feel free to rename this issue to mention the reward and I'll leave it open here in case anyone is interested.

@kkhanh
Copy link
Author

kkhanh commented Jun 14, 2021

Hi,
Thanks for the help. We can confirm it is working.
We are still interested in linking a chromecast to a Google account and a way to change the settings listed above.

@kkhanh
Copy link
Author

kkhanh commented Jun 14, 2021

I forgot to mention you need to call /setup/save_wifi with this data {"keep_hotspot_until_connected": true} otherwise it will fail.

@interfect
Copy link

I had trouble applying the API docs without the Curl command examples, so I've turned these learnings into a Bash script that can set up your Chromecast for you: https://gist.github.com/interfect/5f68381d55658d334e2bc4619d796476

Download it, make it executable, get a connection over which you can talk to the Chromecast by IP, and then do something like:

CHROMECAST_IP=192.168.0.100 WIFI_SSID="foobar" WIFI_PASSWORD="hackme" ./castanet.sh

Not sure how to connect it to a Google account or tinker with the screensaver though.

@interfect
Copy link

Reports of my script working may have been greatly exaggerated.

I can get the device to join the wifi network, and somehow the first time I did it I got it to actually save the network details and reconnect after a reboot. But then it eventually dropped off the network the next day, and now, when I have it hooked up to the TV, when I tell it to join the network it joins and displays a "Connecting to" screen that won't go away on its own. I can talk to it over wifi and even cast to it, but even if it is playing something, it decides after a couple minutes that the wifi network is Bad Actually and disconnects and forgets it.

I think it is waiting for something else that the app would usually do, but I don't know what that is or how to emulate it. It isn't just "cast something to the device". My best theory right now is that it might be "set_eureka_info", since that's something I manually called on the day I wrote the script and not since, but even that didn't get it to stay on the network indefinitely since it eventually left the next day.

@interfect
Copy link

OK I read @kkhanh's comment again and noticed the save_wifi endpoint was mentioned, not connect_wifi. And according to http://blog.brokennetwork.ca/2019/05/setting-up-google-chromecast-without.html?m=1 that call is both essential and not documented in this repo. I will try adding it to the script (and maybe the repo?).

@leo5593
Copy link

leo5593 commented Apr 19, 2022

Hello,

@interfect Thank you very much for the script with the save_wifi, i was missing this part to finalize the connection to an open network.

I still have trouble with secured network. Nodejs is not happy with crypto.constants.RSA_PKCS1_PADDING.

internal/crypto/cipher.js:63
    return method(data, format, type, passphrase, buffer, padding, oaepHash,
           ^

Error: error:0408F08D:rsa routines:pkey_rsa_ctrl:invalid padding mode
    at Object.publicEncrypt (internal/crypto/cipher.js:63:12)
    at Object.<anonymous> (/home/nico/Dev/Chromecast/enckey.js:21:30)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47 {
  opensslErrorStack: [
    'error:06089093:digital envelope routines:EVP_PKEY_CTX_ctrl:command not supported'
  ],
  library: 'rsa routines',
  function: 'pkey_rsa_ctrl',
  reason: 'invalid padding mode',
  code: 'ERR_OSSL_RSA_INVALID_PADDING_MODE'
}

Removing the padding configuration gives an output for the encrypted password but the POST request return an internal server error.

curl -v --insecure --tlsv1.2 --tls-max 1.2 -H 'content-type: application/json' -d '{"ssid": "TestCast", "wpa_auth": 7, "wpa_cipher": 4, "enc_passwd": "KI1z4GA69ZLSYD6doPYi6c+gUXFOH/yKbfBlErxrP153OgaQCCf/KLXLxjlBc4iJr5sSw16KJS7OoBPCBgV9lirX5NU9W0hMxqwXE2oyT9vparTPh3vs0DoQOa35cNutLqm6oR/tEvbS28iCwZqfiGRXDPfdth0oNls1GfkcBdxvupRJWeBfazAJ+f+T+7on7ObnNaq+eaSsDEsuJIjtMYNaAtX4SnqF28tzSPs5XHnoF7Cv/1DSS5uRNNwOsXzrPdLyeR19ovHr8CbhNMYXAqqQ4QxPfAZqlp+BiZAn0XDtDvXuaQ6GN59FaF0kE7ClW+snWa6iFIMdRV3yyW8LEA=="}' https://192.168.41.68:8443/setup/connect_wifi

> POST /setup/connect_wifi HTTP/1.1
> Host: 192.168.41.68:8443
> User-Agent: curl/7.68.0
> Accept: */*
> content-type: application/json
> Content-Length: 414
>
< HTTP/1.1 500 Internal Server Error
< Access-Control-Allow-Headers:Content-Type
< Cache-Control:no-cache
< Content-Length:0
<

This is may be related to a nodejs version ? What was your nodejs to tested with ?

Regards,

@interfect
Copy link

@leo5593 I think this is related to a somewhat-nonsensical combination of cryptography options being specified: I would give a hash function to use for padding, and then specify a padding method that doesn't use a hash function.

I don't quite remember the Node version it worked on, but it clearly doesn't work on some Node versions and/or some versions of the backing system crypto libraries.

I've updated the gist as suggested in https://gist.github.com/interfect/5f68381d55658d334e2bc4619d796476?permalink_comment_id=4133830#gistcomment-4133830 to stop passing the hash function that shouldn't have been being used anyway. Maybe try it again now?

@lockness-Ko
Copy link

This still gives a 500 internal server error (even with bssid supplied). I'm doing some further testing to see if I can get more info. My thoughts is that it's not the node js implementation,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants
@interfect @rithvikvibhu @kkhanh @lockness-Ko @leo5593 and others