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

Add support for Command signing #5

Open
tadly opened this issue Oct 4, 2024 · 16 comments
Open

Add support for Command signing #5

tadly opened this issue Oct 4, 2024 · 16 comments
Assignees
Labels
question Further information is requested

Comments

@tadly
Copy link

tadly commented Oct 4, 2024

Discussions aren't enabled and there's no issue for this yet so here I go...

Home-Assistant just added a bunch of features to the tesla integration which is based on this module.
For my m3 highland, command signing seems to be required.

Are there plans on adding support for this?

I don't know how difficult this would be so excuse me if I sound ignorant.

@Bre77
Copy link
Contributor

Bre77 commented Oct 5, 2024

Yes there are plans to do this, but it is very difficult, and it will take time. I will also need a way to install a private key on vehicles, which is likely going to require a bluetooth implementation, which I have also started for Home Assistant.

@Bre77 Bre77 added documentation Improvements or additions to documentation question Further information is requested and removed documentation Improvements or additions to documentation labels Oct 5, 2024
@Bre77 Bre77 self-assigned this Oct 5, 2024
@tadly
Copy link
Author

tadly commented Oct 7, 2024

Did a quick google to get a better understanding on the whole key topic.
We would need to install the public-key part (not private) on the vehicle. This medium articel outlines it quite well.

For protocol, the relevant part of the article:

Step 1 :: Generate the private key
openssl ecparam -genkey -name prime256v1 -noout > private.pem

Step 2 :: Generate the public key
openssl ec -in private.pem -pubout > public.pem

Step 3 :: Add the public key with the car
./tesla-control -vin {VIN} -ble add-key-request {path_to_the_public_key_along_with_the_public_key_file_name} {ROLE} {FORM_FACTOR}

VIN — Vehicle Identification Number
ROLE — One of: owner, driver
FORM_FACTOR — One of: nfc_card, ios_device, android_device, cloud_key

A sample command to add a BLE key looks like the below -
./tesla-control -vin 7ABCGDEE123ABC555 -ble add-key-request public.pem owner cloud_key

When the command is issued, a successful request will return the following response.
Sent add-key request to 7ABCGDEE123ABC555. Confirm by tapping NFC card on center console.

@Bre77
Copy link
Contributor

Bre77 commented Oct 7, 2024

Did a quick google to get a better understanding on the whole key topic.
We would need to install the public-key part (not private) on the vehicle. This medium articel outlines it quite well.

Yes, but that's written in Go and the only Python implementation hasn't been updated for ~2 years and no longer works. I've spent most of the day today working on it and while I can get the public key installed that's about as far as I have it working.

I may just give up on the Bluetooth implementation and resort to giving people instructions to use Tesla's tools.

@tadly
Copy link
Author

tadly commented Oct 7, 2024

Oh I see. You wanted it to be part of this project (makes sense).
For a first iteration, just to get command signing to work, relying on Tesla's tool wouldn't be that bad IMO.
Key-generation and installation needs to be done only once so... :)

@Bre77
Copy link
Contributor

Bre77 commented Oct 7, 2024

Well the bluetooth side will live in https://github.com/Teslemetry/python_tesla_bluetooth but it creates the private key that this library could then use.

So really now the biggest blocker is that the only command signing implementation ive seen that works is either in C# or Go, and I need it in Python. It'll be the next thing I try attempt.

@tadly
Copy link
Author

tadly commented Oct 7, 2024

Mind sharing the go project?
Translating the logic to python shouldn't be that hard I think. Maybe I can help :)

@Bre77
Copy link
Contributor

Bre77 commented Oct 7, 2024

https://github.com/teslamotors/vehicle-command/blob/main/cmd/tesla-http-proxy/main.go

I have started the library side implementation here: https://github.com/Teslemetry/python-tesla-fleet-api/blob/main/tesla_fleet_api/vehiclesigned.py

@Bre77
Copy link
Contributor

Bre77 commented Oct 7, 2024

I got pretty close to a working implementation on flash_lights tonight. Just the HMAC signature to go, so it's realistic that I could get this in for 2024.11

@Bre77
Copy link
Contributor

Bre77 commented Oct 8, 2024

IT WORKS
a74041e

@tadly
Copy link
Author

tadly commented Oct 8, 2024

I love how you went from

...but it is very difficult, and it will take time

to

IT WORKS

in just 3 days.
Thank you so much for this. Gets me really excited to finally automate some stuff with my tesla

@Bre77
Copy link
Contributor

Bre77 commented Oct 8, 2024

I suffer from shiny object syndrome. I started making progress and felt like It was actually acheivable. I have working:

  • Lock
  • Unlock
  • Frunk
  • Trunk
  • Charge Port Open/Close
  • Flash Lights
  • Remote drive

Just the matter of writting all the protobuf defintions for the other Infotainment commands and then a lot of exception handling.

@tadly
Copy link
Author

tadly commented Oct 9, 2024

I suffer from shiny object syndrome.

Sounds to me like you got into some kind of flow. I love when that happens :)

Given the commit history, you've been chipping away.
Congrats on getting all that figured out and thanks again for doing so. Really appreciate it man :)

@gabriele-latino
Copy link

Hi @Bre77, maybe I missed something...
I just installed 2024.11.0 but I'm still in the loop of the command signing issue... there is a way to configure it to have some commands working?
Thanks a lot for your effort

@tadly
Copy link
Author

tadly commented Nov 7, 2024

Pretty sure this didn't make it into the 2024.11 release as the aktual implementation in HA happend 2 days ago (See home-assistant/core#128407)

Should be part of 2024.12 I think

@gabriele-latino
Copy link

So there is no hope that it will be introduced in 2024.11.x? :(

@Bre77
Copy link
Contributor

Bre77 commented Nov 8, 2024

So there is no hope that it will be introduced in 2024.11.x? :(

Home Assistant does not release new features in .x releases, only in the monthly x.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants