Skip to content

Commit

Permalink
Update cryptography dependency constraints and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
natekspencer committed Feb 2, 2024
1 parent 719439a commit 0757cf0
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 31 deletions.
67 changes: 38 additions & 29 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ packages = [
[tool.poetry.dependencies]
python = ">=3.9, <3.13"
aiohttp = ">=3.0.0"
cryptography = "^41.0.1"
cryptography = ">=41.0.1, <43.0"
backports-strenum = { version = "^1.2.4", python = "<3.11" }
bleak = { version = "^0.21", optional = true }
dbus-fast = {version = "^2.11.0", optional = true, platform = "linux"}
Expand Down
2 changes: 1 addition & 1 deletion src/rivian/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get_message_signature(secret_key: bytes, message: bytes) -> str:


def get_secret_key(private_key_str: str, public_key_str: str) -> bytes:
"""Get HKDF derived secrety key from private/public key pair."""
"""Get HKDF derived secret key from private/public key pair."""
private_key = decode_private_key(private_key_str)
public_key = decode_public_key(public_key_str)
secret = private_key.exchange(ec.ECDH(), public_key)
Expand Down
35 changes: 35 additions & 0 deletions tests/utils_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Test utils module."""

from __future__ import annotations

import time

from rivian import VehicleCommand, utils

PHONE_NONCE = bytes.fromhex("e4e9b1f0abba398bdfe5b2d90cba16ad")
PRIVATE_KEY = "LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JR0hBZ0VBTUJNR0J5cUdTTTQ5QWdFR0NDcUdTTTQ5QXdFSEJHMHdhd0lCQVFRZ0tzMzNEek8rbjBZbVI1RFUKNUFIb2N6cUw1RlBXdUZSZ2E4ano1QVZmbWl5aFJBTkNBQVRIL2lQSmxtbTh5RjdsUFJOYlcvZFFDTDJseVpjWQo4U0dKcGpNQ1k4WkhCa0xXV3hoSTZ6RVFTdW5QaUM0Vy9zYUpPVW5EVm15N1Vkbm1EOCtzOCtFNAotLS0tLUVORCBQUklWQVRFIEtFWS0tLS0tCg=="
VEHICLE_KEY = "04334cc40a88768920b54bdfdcd38238df2ec65ce3605a1d343ef2ab8c1a1daa0545cbb804ebf3ab89826924ea3011352b1d23957a52de0acd5a326078d222d31c"


def test_generate_key_pair() -> None:
"""Test generating an ECDH public-private key pair."""
public_key, private_key = utils.generate_key_pair()
assert public_key, private_key


def test_generate_ble_command_hmac() -> None:
"""Test generating a BLE command HMAC."""
hmac = utils.generate_ble_command_hmac(PHONE_NONCE, VEHICLE_KEY, PRIVATE_KEY)
assert hmac == bytes.fromhex(
"935bde3fe77d5501635e16e2a9f2e867038e6a2bd6c5936d0b315ab38e0993dd"
)


def test_generate_vehicle_command_hmac() -> None:
"""Test generating a vehicle command HMAC."""
command = str(VehicleCommand.WAKE_VEHICLE)
timestamp = "1707000000"
hmac = utils.generate_vehicle_command_hmac(
command, timestamp, VEHICLE_KEY, PRIVATE_KEY
)
assert hmac == "2a68bdda69ff8643e37bac595905f6a481435e00bb63bdd415ecbb425a5bb598"

0 comments on commit 0757cf0

Please sign in to comment.