TeslaVehicleCommand 1.0.1
dotnet add package TeslaVehicleCommand --version 1.0.1
NuGet\Install-Package TeslaVehicleCommand -Version 1.0.1
<PackageReference Include="TeslaVehicleCommand" Version="1.0.1" />
<PackageVersion Include="TeslaVehicleCommand" Version="1.0.1" />
<PackageReference Include="TeslaVehicleCommand" />
paket add TeslaVehicleCommand --version 1.0.1
#r "nuget: TeslaVehicleCommand, 1.0.1"
#:package TeslaVehicleCommand@1.0.1
#addin nuget:?package=TeslaVehicleCommand&version=1.0.1
#tool nuget:?package=TeslaVehicleCommand&version=1.0.1
TeslaVehicleCommand
TeslaVehicleCommand is a .NET 8 library enabling secure, low‑level communication and command execution on Tesla vehicles via the official Tesla API.
Features
- Secure Session Establishment: Implements ECDH handshake and HMAC‑based message authentication using BouncyCastle to derive shared keys and verify integrity.
- DomainSession: Manages per‑domain session metadata (Handle, Counter, Epoch, ClockTime) and provides HMAC signing for Protobuf messages.
- SessionManager: Orchestrates multiple DomainSession instances (e.g., Infotainment, VehicleSecurity), handles handshake requests, and attaches signatures to
RoutableMessageobjects. - Protocol Buffers: Leverages
Google.Protobuffor efficient serialization of commands and responses. - Easy Integration: Designed to plug into existing Tesla API workflows (e.g., TeslaAPI, _Helpers).
Installation
Install via NuGet Package Manager:
dotnet add package TeslaVehicleCommand
Or search and install in Visual Studio:
Tools > NuGet Package Manager > Manage NuGet Packages for Solution...
Usage Example: Open Rear Trunk
Below is a minimal console app demonstrating how to initialize a session and send a command to open the Tesla’s rear trunk.
using TeslaVehicleCommand;
using TeslaProtobuf.Vcsec;
using TeslaProtobuf.Universalmessage;
using _Helpers;
using Google.Protobuf;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.OpenSsl;
using TeslaAPILib;
// Load your Tesla OAuth token and VIN
string token = "<YOUR_OAUTH_TOKEN>";
string vin = "<YOUR_VIN>";
// Initialize TeslaAPI client
var apiClient = new TeslaAPI(token);
// Load client's asymmetric key pair from PEM
AsymmetricCipherKeyPair clientKeyPair;
using (var reader = File.OpenText("path/to/client.key"))
{
clientKeyPair = (AsymmetricCipherKeyPair)new PemReader(reader).ReadObject();
}
// Create SessionManager and start handshake
var sessionManager = new SessionManager(clientKeyPair, apiClient);
await sessionManager.StartSession(vin);
// Build a ClosureMoveRequest to open the rear trunk
var command = new UnsignedMessage();
command.ClosureMoveRequest = new ClosureMoveRequest
{
RearTrunk = ClosureMoveType_E.ClosureMoveTypeOpen
};
// Wrap it in a RoutableMessage
var message = new RoutableMessage
{
ToDestination = new Destination { Domain = Domain.VehicleSecurity },
FromDestination = new Destination { RoutingAddress = ByteString.CopyFrom(RandomGenerator.Get()) },
ProtobufMessageAsBytes = command.ToByteString(),
Uuid = ByteString.CopyFrom(RandomGenerator.Get())
};
// Sign and send the message
sessionManager.SignRoutableMessage(message, Domain.VehicleSecurity);
string response64 = await apiClient.SendSignedCommandToVehicle(vin, message.ToByteString().ToBase64());
// Handle response
var response = RoutableMessage.Parser.ParseFrom(Convert.FromBase64String(response64));
// Check response.SignedMessageStatus.OperationStatus...
API Reference
DomainSession
- Constructor:
DomainSession(RoutableMessage response, string vin, AsymmetricCipherKeyPair clientKey, Domain domain) - SignHMAC(ByteString protobufMessageAsBytes): Returns HMAC tag for the given Protobuf payload.
SessionManager
- Constructor:
SessionManager(AsymmetricCipherKeyPair clientKey, TeslaAPI teslaApi) - StartSession(string vin): Performs handshake to establish sessions for all supported domains.
- SignRoutableMessage(RoutableMessage message, Domain domain): Attaches HMAC signature data to the message for the specified domain.
Dependencies
Target Framework
- .NET 8.0
License
This project is licensed under the MIT License. See the LICENSE file for details.
For more information, visit the TeslaVehicleCommand GitHub repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- BouncyCastle.Cryptography (>= 2.5.1)
- Google.Protobuf (>= 3.30.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.