From 6cba697dcd1ea22adf8eed4c51e3b08d0660ac52 Mon Sep 17 00:00:00 2001 From: Riko Date: Sun, 8 Nov 2026 00:06:50 -0800 Subject: [PATCH] Clink: declare AUTH version 0x0701 and accept 2.x/3.x/4.x replies CarWith declares 0x0701 in its AUTH request (0x0501 in 2.x) and head units reply 0x0901. Send 0x0701 from the Kotlin and Rust sources and accept the known reply versions; keep the oracle transcript tests by comparing every field except the request version. --- .../openxplay/stream/clink/protocol/Auth.kt | 4 ++-- .../org/openxplay/stream/clink/AuthTest.kt | 13 ++++++++----- .../stream/clink/SimulatedHeadUnit.kt | 2 +- rust/oxp-clink/src/protocol/auth.rs | 4 ++-- rust/oxp-clink/tests/auth.rs | 18 ++++++++++++++---- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/kotlin/clink/src/main/kotlin/org/openxplay/stream/clink/protocol/Auth.kt b/kotlin/clink/src/main/kotlin/org/openxplay/stream/clink/protocol/Auth.kt index ab77fbf..628115c 100644 --- a/kotlin/clink/src/main/kotlin/org/openxplay/stream/clink/protocol/Auth.kt +++ b/kotlin/clink/src/main/kotlin/org/openxplay/stream/clink/protocol/Auth.kt @@ -120,7 +120,7 @@ public class Auth( val signature = Signature.getInstance("SHA256withECDSA").run { initSign(identity.pair.private, random); update(raw + nonce); sign() } - val values = mutableMapOf(1 to FieldValue.Varint(1uL), + val values = mutableMapOf(1 to FieldValue.Varint(0x0701uL), 4 to FieldValue.Bytes(raw), 5 to FieldValue.Bytes(signature), 6 to FieldValue.Bytes(nonce), 7 to FieldValue.Bytes(deviceId.toByteArray()), 8 to FieldValue.Bytes(name.toByteArray()), 9 to FieldValue.Varint(if (confirmed) 1uL else 0uL)) @@ -136,7 +136,7 @@ public class Auth( require(frame.category == 3 && frame.method == 2 && frame.kind == 2 && frame.sequence == sequence) require(frame.source == 0 && frame.format == 1) { "invalid_auth_header" } val f = Fields.decode(frame.body) - require(f.number(1) == 1uL || f.number(1) == 0x0901uL) { "auth_version_unsupported" } + require(f.number(1) in setOf(1uL, 0x0501uL, 0x0701uL, 0x0901uL)) { "auth_version_unsupported" } val result = f.number(7) if (result != 0uL) { agreement = null diff --git a/kotlin/clink/src/test/kotlin/org/openxplay/stream/clink/AuthTest.kt b/kotlin/clink/src/test/kotlin/org/openxplay/stream/clink/AuthTest.kt index a8fdde6..5dad3ef 100644 --- a/kotlin/clink/src/test/kotlin/org/openxplay/stream/clink/AuthTest.kt +++ b/kotlin/clink/src/test/kotlin/org/openxplay/stream/clink/AuthTest.kt @@ -34,7 +34,8 @@ class AuthTest { val actual = Fields.decode(frame.body) val expected = Fields.decode(vector("m1")) assertEquals(expected.numbers, actual.numbers) - for (id in expected.numbers - 5) when (val field = expected[id]) { + assertEquals(0x0701uL, actual.number(1)) + for (id in expected.numbers - setOf(1, 5)) when (val field = expected[id]) { is FieldValue.Varint -> assertEquals(field.value, actual.number(id)) is FieldValue.Bytes -> assertContentEquals(field.value, actual.bytes(id)) null -> error("missing fixture field") @@ -47,9 +48,11 @@ class AuthTest { }) } @Test fun fullResponseVersionsProduceOracleKeyAndSealedIpv4() { - for (fixture in listOf("m2", "m2_0901")) { + val base = Fields.decode(vector("m2")) + for (version in listOf(1uL, 0x0501uL, 0x0701uL, 0x0901uL)) { + val body = Fields(base.numbers.associateWith { if (it == 1) FieldValue.Varint(version) else base[it]!! }).encode() val auth = client(); start(auth) - val output = auth.receive(response(vector(fixture)), 125) + val output = auth.receive(response(body), 125) assertContentEquals(vector("session_key"), output.sessionKey) val confirm = output.frames.single() assertEquals(3, confirm.method); assertEquals(0, confirm.kind); assertEquals(8L, confirm.sequence) @@ -67,7 +70,7 @@ class AuthTest { val fields = Fields.decode(request.body) val expected = Fields.decode(vector("m1_quick")) assertEquals(expected.numbers, fields.numbers) - assertNull(fields[2]); assertNull(fields[3]); assertEquals(1uL, fields.number(9)) + assertNull(fields[2]); assertNull(fields[3]); assertEquals(1uL, fields.number(9)); assertEquals(0x0701uL, fields.number(1)) for (id in listOf(4, 6, 7, 8)) assertContentEquals(expected.bytes(id), fields.bytes(id)) // Same oracle car signature transcript; quick responses may omit identity and proof entirely. val full = Fields.decode(vector("m2")) @@ -77,7 +80,7 @@ class AuthTest { @Test fun resultCodesAllowExplicitFreshRetry() { val cases = mapOf(1uL to AuthResult.PIN_REQUIRED, 2uL to AuthResult.CONFIRMATION_REQUIRED, 3uL to AuthResult.INTERNAL_ERROR, 4uL to AuthResult.REJECTED, ULong.MAX_VALUE to AuthResult.REJECTED) - for (version in listOf(1uL, 0x0901uL)) for ((code, expected) in cases) { + for (version in listOf(1uL, 0x0501uL, 0x0701uL, 0x0901uL)) for ((code, expected) in cases) { val auth = client(); start(auth) val body = Fields(mapOf(1 to FieldValue.Varint(version), 7 to FieldValue.Varint(code))).encode() val output = auth.receive(response(body), 125) diff --git a/kotlin/clink/src/testFixtures/kotlin/org/openxplay/stream/clink/SimulatedHeadUnit.kt b/kotlin/clink/src/testFixtures/kotlin/org/openxplay/stream/clink/SimulatedHeadUnit.kt index 920f65c..2b2fe75 100644 --- a/kotlin/clink/src/testFixtures/kotlin/org/openxplay/stream/clink/SimulatedHeadUnit.kt +++ b/kotlin/clink/src/testFixtures/kotlin/org/openxplay/stream/clink/SimulatedHeadUnit.kt @@ -199,7 +199,7 @@ public class SimulatedHeadUnit( val input = DataInputStream(socket.getInputStream()) val request = readFrame(input) require(request.source == 1 && request.format == 1 && request.category == 3 && request.method == 1 && request.kind == 1) - val f = Fields.decode(request.body); require(f.number(1) == 1uL && f.number(9) <= 1uL) + val f = Fields.decode(request.body); require(f.number(1) in setOf(1uL, 0x0501uL, 0x0701uL) && f.number(9) <= 1uL) require(f.bytes(7).isNotEmpty() && f.bytes(8).isNotEmpty()) val agreement = f.bytes(4, 64); val nonce = f.bytes(6, 32) val phone = if (2 in f.numbers) f.bytes(2, 64).also { diff --git a/rust/oxp-clink/src/protocol/auth.rs b/rust/oxp-clink/src/protocol/auth.rs index 1d88a39..aa67f13 100644 --- a/rust/oxp-clink/src/protocol/auth.rs +++ b/rust/oxp-clink/src/protocol/auth.rs @@ -158,7 +158,7 @@ impl Auth { let signing = SigningKey::from(&self.identity.secret); let signature: Signature = signing.sign_with_rng(&mut OsRng, &transcript); let mut values = std::collections::BTreeMap::from([ - (1, V::Varint(1)), + (1, V::Varint(0x0701)), (4, V::Bytes(ep)), (5, V::Bytes(signature.to_der().as_bytes().to_vec())), (6, V::Bytes(nonce.to_vec())), @@ -218,7 +218,7 @@ impl Auth { )?; let f = Fields::decode(&frame.body)?; require( - [1, 0x0901].contains(&f.number(1)?), + [1, 0x0501, 0x0701, 0x0901].contains(&f.number(1)?), "auth_version_unsupported", )?; let result = f.number(7)?; diff --git a/rust/oxp-clink/tests/auth.rs b/rust/oxp-clink/tests/auth.rs index 6aa6461..a35d26c 100644 --- a/rust/oxp-clink/tests/auth.rs +++ b/rust/oxp-clink/tests/auth.rs @@ -66,9 +66,13 @@ fn full_request_matches_oracle_and_signature_transcript() { let actual = Fields::decode(&request.body).unwrap(); let mut expected = Fields::decode(&vector("m1")).unwrap(); let signature = actual.bytes(5).unwrap().to_vec(); + let version = actual.number(1).unwrap(); let mut compare = actual; + compare.0.remove(&1); compare.0.remove(&5); + expected.0.remove(&1); expected.0.remove(&5); + assert_eq!(0x0701, version); assert_eq!(expected, compare); let verifying = VerifyingKey::from(decode_public(&vector("identity_public")).unwrap()); verifying @@ -80,10 +84,12 @@ fn full_request_matches_oracle_and_signature_transcript() { } #[test] fn full_response_versions_oracle_key_confirm_ipv4_and_complete() { - for fixture in ["m2", "m2_0901"] { + for version in [1, 0x0501, 0x0701, 0x0901] { + let mut reply = Fields::decode(&vector("m2")).unwrap(); + reply.0.insert(1, FieldValue::Varint(version)); let mut auth = client(None); start(&mut auth, false, false); - let out = auth.receive(&response(vector(fixture)), 125).unwrap(); + let out = auth.receive(&response(reply.encode().unwrap()), 125).unwrap(); assert_eq!(vector("session_key"), out.session_key.unwrap()); let confirm = &out.frames[0]; assert_eq!((3, 0, 8), (confirm.method, confirm.kind, confirm.sequence)); @@ -103,7 +109,7 @@ fn full_response_versions_oracle_key_confirm_ipv4_and_complete() { .unwrap() .to_vec() ))); - assert!(auth.receive(&response(vector(fixture)), 126).is_err()); + assert!(auth.receive(&response(reply.encode().unwrap()), 126).is_err()); } } #[test] @@ -120,8 +126,12 @@ fn quick_reconnect_omits_identity_proof_and_confirms() { assert!(!actual.0.contains_key(&3)); assert_eq!(1, actual.number(9).unwrap()); let mut expected = Fields::decode(&vector("m1_quick")).unwrap(); + let version = actual.number(1).unwrap(); + actual.0.remove(&1); actual.0.remove(&5); + expected.0.remove(&1); expected.0.remove(&5); + assert_eq!(0x0701, version); assert_eq!(expected, actual); let mut response_fields = Fields::decode(&vector("m2")).unwrap(); response_fields.0.remove(&2); @@ -136,7 +146,7 @@ fn quick_reconnect_omits_identity_proof_and_confirms() { } #[test] fn result_codes_allow_fresh_explicit_retry() { - for version in [1, 0x0901] { + for version in [1, 0x0501, 0x0701, 0x0901] { for (code, expected) in [ (1, AuthResult::PinRequired), (2, AuthResult::ConfirmationRequired),