tesla-fleet-api 0.8.1__py3-none-any.whl → 0.8.3__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- tesla_fleet_api/const.py +1 -1
- tesla_fleet_api/teslafleetapi.py +21 -17
- tesla_fleet_api/vehiclesigned.py +6 -9
- {tesla_fleet_api-0.8.1.dist-info → tesla_fleet_api-0.8.3.dist-info}/METADATA +1 -1
- {tesla_fleet_api-0.8.1.dist-info → tesla_fleet_api-0.8.3.dist-info}/RECORD +8 -8
- {tesla_fleet_api-0.8.1.dist-info → tesla_fleet_api-0.8.3.dist-info}/LICENSE +0 -0
- {tesla_fleet_api-0.8.1.dist-info → tesla_fleet_api-0.8.3.dist-info}/WHEEL +0 -0
- {tesla_fleet_api-0.8.1.dist-info → tesla_fleet_api-0.8.3.dist-info}/top_level.txt +0 -0
tesla_fleet_api/const.py
CHANGED
tesla_fleet_api/teslafleetapi.py
CHANGED
@@ -4,11 +4,11 @@ from json import dumps
|
|
4
4
|
from typing import Any, Awaitable
|
5
5
|
from os.path import exists
|
6
6
|
import aiohttp
|
7
|
+
import aiofiles
|
7
8
|
|
8
9
|
# cryptography
|
9
|
-
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
10
10
|
from cryptography.hazmat.primitives.asymmetric import ec
|
11
|
-
from cryptography.hazmat.primitives import
|
11
|
+
from cryptography.hazmat.primitives import serialization
|
12
12
|
from cryptography.hazmat.backends import default_backend
|
13
13
|
|
14
14
|
from .exceptions import raise_for_status, InvalidRegion, LibraryError, ResponseError
|
@@ -30,7 +30,7 @@ class TeslaFleetApi:
|
|
30
30
|
session: aiohttp.ClientSession
|
31
31
|
headers: dict[str, str]
|
32
32
|
refresh_hook: Awaitable | None = None
|
33
|
-
|
33
|
+
private_key: ec.EllipticCurvePrivateKey | None = None
|
34
34
|
|
35
35
|
def __init__(
|
36
36
|
self,
|
@@ -161,28 +161,27 @@ class TeslaFleetApi:
|
|
161
161
|
"api/1/products",
|
162
162
|
)
|
163
163
|
|
164
|
-
def
|
165
|
-
"""
|
164
|
+
async def get_private_key(self, path: str = "private_key.pem") -> ec.EllipticCurvePrivateKey:
|
165
|
+
"""Get or create the private key."""
|
166
166
|
if not exists(path):
|
167
|
-
self.
|
167
|
+
self.private_key = ec.generate_private_key(
|
168
168
|
ec.SECP256R1(), default_backend()
|
169
169
|
)
|
170
170
|
# save the key
|
171
|
-
pem = self.
|
171
|
+
pem = self.private_key.private_bytes(
|
172
172
|
encoding=serialization.Encoding.PEM,
|
173
173
|
format=serialization.PrivateFormat.TraditionalOpenSSL,
|
174
174
|
encryption_algorithm=serialization.NoEncryption(),
|
175
175
|
)
|
176
|
-
with open(path, "wb") as key_file:
|
177
|
-
key_file.write(pem)
|
178
|
-
return self._private_key
|
176
|
+
async with aiofiles.open(path, "wb") as key_file:
|
177
|
+
await key_file.write(pem)
|
179
178
|
else:
|
180
179
|
try:
|
181
|
-
with open(path, "rb") as key_file:
|
182
|
-
key_data = key_file.read()
|
183
|
-
|
184
|
-
|
185
|
-
|
180
|
+
async with aiofiles.open(path, "rb") as key_file:
|
181
|
+
key_data = await key_file.read()
|
182
|
+
value = serialization.load_pem_private_key(
|
183
|
+
key_data, password=None, backend=default_backend()
|
184
|
+
)
|
186
185
|
except FileNotFoundError:
|
187
186
|
raise FileNotFoundError(f"Private key file not found at {path}")
|
188
187
|
except PermissionError:
|
@@ -190,5 +189,10 @@ class TeslaFleetApi:
|
|
190
189
|
|
191
190
|
if not isinstance(value, ec.EllipticCurvePrivateKey):
|
192
191
|
raise AssertionError("Loaded key is not an EllipticCurvePrivateKey")
|
193
|
-
self.
|
194
|
-
|
192
|
+
self.private_key = value
|
193
|
+
return self.private_key
|
194
|
+
|
195
|
+
@property
|
196
|
+
def has_private_key(self) -> bool:
|
197
|
+
"""Check if the private key has been set."""
|
198
|
+
return self.private_key is not None
|
tesla_fleet_api/vehiclesigned.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
import base64
|
3
|
-
from dataclasses import dataclass
|
4
3
|
from random import randbytes
|
5
4
|
from typing import Any, TYPE_CHECKING
|
6
5
|
import time
|
@@ -155,7 +154,7 @@ class Session:
|
|
155
154
|
class VehicleSigned(VehicleSpecific):
|
156
155
|
"""Class describing the Tesla Fleet API vehicle endpoints and commands for a specific vehicle with command signing."""
|
157
156
|
|
158
|
-
|
157
|
+
private_key: ec.EllipticCurvePrivateKey
|
159
158
|
_public_key: bytes
|
160
159
|
_from_destination: bytes
|
161
160
|
_sessions: dict[int, Session]
|
@@ -165,13 +164,13 @@ class VehicleSigned(VehicleSpecific):
|
|
165
164
|
):
|
166
165
|
super().__init__(parent, vin)
|
167
166
|
if key:
|
168
|
-
self.
|
169
|
-
elif parent._parent.
|
170
|
-
self.
|
167
|
+
self.private_key = key
|
168
|
+
elif parent._parent.private_key:
|
169
|
+
self.private_key = parent._parent.private_key
|
171
170
|
else:
|
172
171
|
raise ValueError("No private key.")
|
173
172
|
|
174
|
-
self._public_key = self.
|
173
|
+
self._public_key = self.private_key.public_key().public_bytes(
|
175
174
|
encoding=Encoding.X962, format=PublicFormat.UncompressedPoint
|
176
175
|
)
|
177
176
|
self._from_destination = randbytes(16)
|
@@ -201,7 +200,7 @@ class VehicleSigned(VehicleSpecific):
|
|
201
200
|
vehicle_public_key = info.publicKey
|
202
201
|
|
203
202
|
# Derive shared key from private key _key and vehicle public key
|
204
|
-
shared = self.
|
203
|
+
shared = self.private_key.exchange(
|
205
204
|
ec.ECDH(),
|
206
205
|
ec.EllipticCurvePublicKey.from_encoded_point(
|
207
206
|
ec.SECP256R1(), vehicle_public_key
|
@@ -215,8 +214,6 @@ class VehicleSigned(VehicleSpecific):
|
|
215
214
|
delta=int(time.time()) - info.clock_time,
|
216
215
|
)
|
217
216
|
|
218
|
-
print(self._sessions[domain])
|
219
|
-
|
220
217
|
async def _sendVehicleSecurity(self, command: UnsignedMessage) -> dict[str, Any]:
|
221
218
|
"""Sign and send a message to Infotainment computer."""
|
222
219
|
if DOMAIN_VEHICLE_SECURITY not in self._sessions:
|
@@ -1,19 +1,19 @@
|
|
1
1
|
tesla_fleet_api/__init__.py,sha256=BVZUDsfaxT05tAfcMHHWiyFyXwmDOx_wP_IHZBscgho,729
|
2
2
|
tesla_fleet_api/charging.py,sha256=N_mc8axrXj3iduqLj_jCt4Vx86tHqe3xqQT4R1R7HvU,1689
|
3
|
-
tesla_fleet_api/const.py,sha256=
|
3
|
+
tesla_fleet_api/const.py,sha256=jPBw9t-WqBbyAuzvEL9mG6Z0dSmftr9nTDJXj7Y_PiU,9577
|
4
4
|
tesla_fleet_api/energy.py,sha256=S7D75MPuMVsHgkyUcFfMqjGCLZBM5YVFlWLEHbaX-zw,5957
|
5
5
|
tesla_fleet_api/energyspecific.py,sha256=UfeaGE59aoAa8UhpQCXUi0sOrNCA40xZlqwF73BXTVY,4254
|
6
6
|
tesla_fleet_api/exceptions.py,sha256=zl8m4Z51ihVD5cKYSZ8e6heerArF0j5isQmX-gSdkwM,15456
|
7
7
|
tesla_fleet_api/partner.py,sha256=1vIBUaxKLIfqcC0X6VXZN0dMAzj_CLNPUMjA6QVqZ1k,1223
|
8
8
|
tesla_fleet_api/ratecalculator.py,sha256=4lz8yruUeouHXh_3ezsXX-CTpIegp1T1J4VuRV_qdHA,1791
|
9
|
-
tesla_fleet_api/teslafleetapi.py,sha256=
|
9
|
+
tesla_fleet_api/teslafleetapi.py,sha256=vr6qRb1oa7Y4NtstGJoxRh7DbeZS1nw7AAaVgMINMXA,7375
|
10
10
|
tesla_fleet_api/teslafleetoauth.py,sha256=OY9yRQuokYo3ts0C8Qb6Z-o9NNAGHbX9F5mHfAh50fo,4121
|
11
11
|
tesla_fleet_api/teslafleetopensource.py,sha256=TJfVPcqJlA1b3kMoGuLr-g5Gn8UDyYsTZhjvGY1MtIk,2007
|
12
12
|
tesla_fleet_api/teslemetry.py,sha256=Rl73BWYYJk1UWIhCPwywcXGRlkATYZrPz3LP-Covppw,3272
|
13
13
|
tesla_fleet_api/tessie.py,sha256=4dBYxe1G2v9JvJGRbb01wXrAmvWT4jOfV4f_VQE_vkE,2302
|
14
14
|
tesla_fleet_api/user.py,sha256=TZE2oh-n5zrhKXmGRuiNL9voKVODD7rBhGE_IObYVGA,1179
|
15
15
|
tesla_fleet_api/vehicle.py,sha256=W5Y_ok5PK7jtXsenWpMWJTS4RpLhRW-1AlTPv1a6R6A,31765
|
16
|
-
tesla_fleet_api/vehiclesigned.py,sha256=
|
16
|
+
tesla_fleet_api/vehiclesigned.py,sha256=10O2IcQD336utDzUChFrtwNFxo2Q2ID41dn9k-Y6A-Q,39160
|
17
17
|
tesla_fleet_api/vehiclespecific.py,sha256=Nr4zZzfmIuw3RFYjQEX6c_xtYZgztMsN5ohVn-YEH0I,20600
|
18
18
|
tesla_fleet_api/pb2/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
19
19
|
tesla_fleet_api/pb2/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -25,8 +25,8 @@ tesla_fleet_api/pb2/signatures_pb2.py,sha256=5mdJUC8EC8kx1UxYrHK5XI3_7M6v7w2POH1
|
|
25
25
|
tesla_fleet_api/pb2/universal_message_pb2.py,sha256=F6-SkYXSuzWDsBvnGMg9k2pAIZv13v609qCPx7NSrdw,7254
|
26
26
|
tesla_fleet_api/pb2/vcsec_pb2.py,sha256=CMJ97e4Mm4p7NFcgybbCC2KJRcvtrcqmBy_pGycYhMo,26238
|
27
27
|
tesla_fleet_api/pb2/vehicle_pb2.py,sha256=P1V7Dqg3BBGZwODxTpZqtxLP6fGS_FNBqJcz_Fp0crs,2482
|
28
|
-
tesla_fleet_api-0.8.
|
29
|
-
tesla_fleet_api-0.8.
|
30
|
-
tesla_fleet_api-0.8.
|
31
|
-
tesla_fleet_api-0.8.
|
32
|
-
tesla_fleet_api-0.8.
|
28
|
+
tesla_fleet_api-0.8.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
29
|
+
tesla_fleet_api-0.8.3.dist-info/METADATA,sha256=n13nIO19R4285XWPBnX-cN6GWu4xbKNami9ccsjNOpo,3821
|
30
|
+
tesla_fleet_api-0.8.3.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
31
|
+
tesla_fleet_api-0.8.3.dist-info/top_level.txt,sha256=jeNbog_1saXBFrGpom9WyPWmilxsyP3szL_G7JLWQfM,16
|
32
|
+
tesla_fleet_api-0.8.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|