Skip to content

Commit

Permalink
v0.8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Oct 9, 2024
1 parent 74f91ae commit 6086e84
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tesla_fleet_api/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from enum import Enum
import logging

VERSION = "0.8.2"
VERSION = "0.8.3"
LOGGER = logging.getLogger(__package__)
SERVERS = {
"na": "https://fleet-api.prd.na.vn.cloud.tesla.com",
Expand Down
15 changes: 10 additions & 5 deletions tesla_fleet_api/teslafleetapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TeslaFleetApi:
session: aiohttp.ClientSession
headers: dict[str, str]
refresh_hook: Awaitable | None = None
_private_key: ec.EllipticCurvePrivateKey | None = None
private_key: ec.EllipticCurvePrivateKey | None = None

def __init__(
self,
Expand Down Expand Up @@ -164,11 +164,11 @@ async def products(self) -> dict[str, Any]:
async def get_private_key(self, path: str = "private_key.pem") -> ec.EllipticCurvePrivateKey:
"""Get or create the private key."""
if not exists(path):
self._private_key = ec.generate_private_key(
self.private_key = ec.generate_private_key(
ec.SECP256R1(), default_backend()
)
# save the key
pem = self._private_key.private_bytes(
pem = self.private_key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.TraditionalOpenSSL,
encryption_algorithm=serialization.NoEncryption(),
Expand All @@ -189,5 +189,10 @@ async def get_private_key(self, path: str = "private_key.pem") -> ec.EllipticCur

if not isinstance(value, ec.EllipticCurvePrivateKey):
raise AssertionError("Loaded key is not an EllipticCurvePrivateKey")
self._private_key = value
return self._private_key
self.private_key = value
return self.private_key

@property
def has_private_key(self) -> bool:
"""Check if the private key has been set."""
return self.private_key is not None
12 changes: 6 additions & 6 deletions tesla_fleet_api/vehiclesigned.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def tag(
class VehicleSigned(VehicleSpecific):
"""Class describing the Tesla Fleet API vehicle endpoints and commands for a specific vehicle with command signing."""

_private_key: ec.EllipticCurvePrivateKey
private_key: ec.EllipticCurvePrivateKey
_public_key: bytes
_from_destination: bytes
_sessions: dict[int, Session]
Expand All @@ -164,13 +164,13 @@ def __init__(
):
super().__init__(parent, vin)
if key:
self._private_key = key
elif parent._parent._private_key:
self._private_key = parent._parent._private_key
self.private_key = key
elif parent._parent.private_key:
self.private_key = parent._parent.private_key
else:
raise ValueError("No private key.")

self._public_key = self._private_key.public_key().public_bytes(
self._public_key = self.private_key.public_key().public_bytes(
encoding=Encoding.X962, format=PublicFormat.UncompressedPoint
)
self._from_destination = randbytes(16)
Expand Down Expand Up @@ -200,7 +200,7 @@ async def _handshake(self, domain: int) -> None:
vehicle_public_key = info.publicKey

# Derive shared key from private key _key and vehicle public key
shared = self._private_key.exchange(
shared = self.private_key.exchange(
ec.ECDH(),
ec.EllipticCurvePublicKey.from_encoded_point(
ec.SECP256R1(), vehicle_public_key
Expand Down

0 comments on commit 6086e84

Please sign in to comment.