Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int, FieldValue>(1 to FieldValue.Varint(1uL),
val values = mutableMapOf<Int, FieldValue>(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))
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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"))
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions rust/oxp-clink/src/protocol/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Expand Down Expand Up @@ -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)?;
Expand Down
18 changes: 14 additions & 4 deletions rust/oxp-clink/tests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand All @@ -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]
Expand All @@ -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);
Expand All @@ -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),
Expand Down
Loading