-
Notifications
You must be signed in to change notification settings - Fork 615
feat(unitree): forward aes_128_key to WebRTC driver for G1 firmware >=1.5.1 #2117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mihai-chiorean
wants to merge
6
commits into
dimensionalOS:main
Choose a base branch
from
mihai-chiorean:feat/forward-aes-128-key
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f39ee53
feat(unitree): forward aes_128_key to WebRTC driver for G1 firmware >…
mihai-chiorean 20a9c44
Merge branch 'main' into feat/forward-aes-128-key
mihai-chiorean a98a5f8
feat(unitree): expose aes_128_key in G1 module configs + add unit tests
mihai-chiorean fceccd7
Update dimos/robot/unitree/connection.py
mihai-chiorean 6bff60d
feat(unitree): thread aes_128_key through Go2 connection
mihai-chiorean 24023e0
Merge branch 'main' into feat/forward-aes-128-key
mihai-chiorean File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Copyright 2025-2026 Dimensional Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Targeted test for go2.connection.make_connection's aes_128_key forwarding. | ||
|
|
||
| Pins the wiring added in PR #2117 so renaming the kwarg in either | ||
| UnitreeWebRTCConnection or make_connection without updating the other | ||
| fails loudly. The leaf (UnitreeWebRTCConnection.__init__) is exercised | ||
| in dimos/robot/unitree/test_connection.py — this file only covers the | ||
| go2-local routing. | ||
| """ | ||
|
|
||
| from types import SimpleNamespace | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| from dimos.robot.unitree.go2 import connection as go2_conn | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def stub_webrtc(monkeypatch: pytest.MonkeyPatch) -> MagicMock: | ||
| """Replace UnitreeWebRTCConnection in go2.connection with a MagicMock so | ||
| make_connection's webrtc branch is exercised without dialing out.""" | ||
| stub = MagicMock(name="UnitreeWebRTCConnection") | ||
| monkeypatch.setattr(go2_conn, "UnitreeWebRTCConnection", stub) | ||
| return stub | ||
|
|
||
|
|
||
| def test_make_connection_webrtc_forwards_aes_128_key(stub_webrtc: MagicMock) -> None: | ||
| """Webrtc branch must forward aes_128_key as a kwarg to UnitreeWebRTCConnection. | ||
|
|
||
| Guards the Go2 half of the PR #2117 fix: without this forwarding, Go2 | ||
| robots on firmware >=1.1.15 fail the WebRTC handshake even when a key | ||
| is provided in config. | ||
| """ | ||
| cfg = SimpleNamespace(unitree_connection_type="webrtc") | ||
| go2_conn.make_connection("192.168.123.161", cfg, aes_128_key="cafe" * 8) | ||
| stub_webrtc.assert_called_once_with("192.168.123.161", aes_128_key="cafe" * 8) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| # Copyright 2025-2026 Dimensional Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Unit tests for UnitreeWebRTCConnection's aes_128_key kwarg + env-var fallback. | ||
|
|
||
| Pure-Python tests — no hardware, no network. Mocks the LegionConnection driver | ||
| and the connect() side-effect so __init__ stays inside the kwarg-forwarding logic. | ||
| """ | ||
|
|
||
| from typing import Any | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| from dimos.robot.unitree import connection as conn_mod | ||
| from dimos.robot.unitree.connection import UnitreeWebRTCConnection | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def stub_legion(monkeypatch: pytest.MonkeyPatch) -> MagicMock: | ||
| """Replace LegionConnection in the module with a MagicMock and suppress | ||
| UnitreeWebRTCConnection.connect so __init__ doesn't try to dial out.""" | ||
| monkeypatch.setattr(UnitreeWebRTCConnection, "connect", lambda self: None) | ||
| legion = MagicMock(name="LegionConnection") | ||
| monkeypatch.setattr(conn_mod, "LegionConnection", legion) | ||
| return legion | ||
|
|
||
|
|
||
| def _aes_kwarg(legion: MagicMock) -> Any: | ||
| """Pull aes_128_key out of the LegionConnection call args, or None if absent.""" | ||
| _args, kwargs = legion.call_args | ||
| return kwargs.get("aes_128_key") | ||
|
|
||
|
|
||
| def test_aes_key_omitted_when_neither_kwarg_nor_env( | ||
| stub_legion: MagicMock, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| """Default behaviour: no kwarg, no env var → aes_128_key not forwarded. | ||
|
|
||
| Guarantees the call is byte-identical to the pre-PR behaviour for users | ||
| on G1 firmware <1.5.1 and all Go2 robots. | ||
| """ | ||
| monkeypatch.delenv("UNITREE_AES_128_KEY", raising=False) | ||
| UnitreeWebRTCConnection(ip="192.168.123.161") | ||
| assert _aes_kwarg(stub_legion) is None | ||
| assert "aes_128_key" not in stub_legion.call_args.kwargs | ||
|
|
||
|
|
||
| def test_aes_key_from_explicit_kwarg( | ||
| stub_legion: MagicMock, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| """Caller passes the key directly → forwarded verbatim.""" | ||
| monkeypatch.delenv("UNITREE_AES_128_KEY", raising=False) | ||
| UnitreeWebRTCConnection(ip="192.168.123.161", aes_128_key="aa" * 16) | ||
| assert _aes_kwarg(stub_legion) == "aa" * 16 | ||
|
|
||
|
|
||
| def test_aes_key_from_env_when_kwarg_none( | ||
| stub_legion: MagicMock, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| """Env-var fallback: kwarg unset → UNITREE_AES_128_KEY is used.""" | ||
| monkeypatch.setenv("UNITREE_AES_128_KEY", "bb" * 16) | ||
| UnitreeWebRTCConnection(ip="192.168.123.161") | ||
| assert _aes_kwarg(stub_legion) == "bb" * 16 | ||
|
|
||
|
|
||
| def test_explicit_kwarg_beats_env(stub_legion: MagicMock, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| """Precedence: explicit kwarg wins over UNITREE_AES_128_KEY env var.""" | ||
| monkeypatch.setenv("UNITREE_AES_128_KEY", "from-env") | ||
| UnitreeWebRTCConnection(ip="192.168.123.161", aes_128_key="from-kwarg") | ||
| assert _aes_kwarg(stub_legion) == "from-kwarg" | ||
|
|
||
|
|
||
| def test_empty_string_kwarg_falls_back_to_env_when_unset( | ||
| stub_legion: MagicMock, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| """Empty-string kwarg + unset env → final key is None, nothing forwarded. | ||
|
|
||
| Truthiness guard means `aes_128_key=""` falls through to the env-var | ||
| lookup just like `aes_128_key=None` would. With the env unset, the final | ||
| value is None and the kwarg is omitted from the LegionConnection call — | ||
| same byte-identical behaviour as the unset case. | ||
| """ | ||
| monkeypatch.delenv("UNITREE_AES_128_KEY", raising=False) | ||
| UnitreeWebRTCConnection(ip="192.168.123.161", aes_128_key="") | ||
| assert "aes_128_key" not in stub_legion.call_args.kwargs | ||
|
|
||
|
|
||
| def test_empty_string_kwarg_uses_env_when_set( | ||
| stub_legion: MagicMock, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| """Empty-string kwarg + set env → env value wins. | ||
|
|
||
| Guards against the bug greptile flagged on PR #2117: a YAML/JSON config | ||
| serialising `aes_128_key: ""` instead of `null` MUST still allow the env | ||
| var to provide the real key. Otherwise the connection silently fails on | ||
| G1 firmware >=1.5.1 (and Go2 firmware >=1.1.15) with | ||
| 'RSA key format is not supported'. | ||
| """ | ||
| monkeypatch.setenv("UNITREE_AES_128_KEY", "cc" * 16) | ||
| UnitreeWebRTCConnection(ip="192.168.123.161", aes_128_key="") | ||
| assert _aes_kwarg(stub_legion) == "cc" * 16 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also include GO2 firmware 1.1.15 as it has the same issue and this should fix it for the GO2 too !