GHLocalApi icon indicating copy to clipboard operation
GHLocalApi copied to clipboard

Connect a chromecast to a wifi network

Open kkhanh opened this issue 3 years ago • 9 comments

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 [email protected]

Regards,

kkhanh avatar Jun 04 '21 16:06 kkhanh

Hey, @thorleifjaocbsen figured out the connect wifi endpoint including the password encryption here: https://github.com/rithvikvibhu/GHLocalApi/issues/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.

rithvikvibhu avatar Jun 04 '21 17:06 rithvikvibhu

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 avatar Jun 14 '21 09:06 kkhanh

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

kkhanh avatar Jun 14 '21 09:06 kkhanh

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 avatar Dec 10 '21 04:12 interfect

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 avatar Dec 12 '21 14:12 interfect

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?).

interfect avatar Dec 12 '21 14:12 interfect

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,

leo5593 avatar Apr 19 '22 16:04 leo5593

@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?

interfect avatar May 04 '22 01:05 interfect

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,

lockness-Ko avatar Sep 08 '22 03:09 lockness-Ko