TeslaVehicleCommand 1.0.1

dotnet add package TeslaVehicleCommand --version 1.0.1
                    
NuGet\Install-Package TeslaVehicleCommand -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TeslaVehicleCommand" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TeslaVehicleCommand" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="TeslaVehicleCommand" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TeslaVehicleCommand --version 1.0.1
                    
#r "nuget: TeslaVehicleCommand, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TeslaVehicleCommand@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TeslaVehicleCommand&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=TeslaVehicleCommand&version=1.0.1
                    
Install as a Cake Tool

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 RoutableMessage objects.
  • Protocol Buffers: Leverages Google.Protobuf for 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 196 6/16/2025
1.0.0 191 6/16/2025