From 23ae661a3ef514642c488be8de301b860642d077 Mon Sep 17 00:00:00 2001 From: Amon Al-Khatib Date: Tue, 19 Jul 2022 16:24:35 -0700 Subject: [PATCH 1/3] Fix broken PaseVerifier codepath and add test --- .../chiptool/CHIPDeviceControllerTest.java | 42 +++++++++++++++++++ .../java/AndroidDeviceControllerWrapper.cpp | 1 + .../java/CHIPDeviceController-JNI.cpp | 2 +- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/android/CHIPTool/app/src/androidTest/java/com/google/chip/chiptool/CHIPDeviceControllerTest.java diff --git a/src/android/CHIPTool/app/src/androidTest/java/com/google/chip/chiptool/CHIPDeviceControllerTest.java b/src/android/CHIPTool/app/src/androidTest/java/com/google/chip/chiptool/CHIPDeviceControllerTest.java new file mode 100644 index 00000000000000..259b309ebcfb4b --- /dev/null +++ b/src/android/CHIPTool/app/src/androidTest/java/com/google/chip/chiptool/CHIPDeviceControllerTest.java @@ -0,0 +1,42 @@ +package com.google.chip.chiptool; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import android.content.Context; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import chip.devicecontroller.ChipDeviceController; +import chip.devicecontroller.PaseVerifierParams; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class CHIPDeviceControllerTest { + @Test + public void PaseVerifierTest() { + long deviceId = 123L; + long setupPincode = 808080L; + long iterations = 1000L; + byte[] randomSalt = "hEvzbU:%h)?aB,h7+9fn[Lf[BhYB!=TA".getBytes(); + + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + ChipDeviceController chipDeviceController = + ChipClient.INSTANCE.getDeviceController(appContext); + + PaseVerifierParams params = + chipDeviceController.computePaseVerifier(deviceId, setupPincode, iterations, randomSalt); + + assertNotNull(params); + assertEquals(params.getSetupPincode(), setupPincode); + assertNotNull(params.getPakeVerifier()); + } +} \ No newline at end of file diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index 9384f29d79b706..b3c969c2577b74 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -143,6 +143,7 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew( initParams.bleLayer = DeviceLayer::ConnectivityMgr().GetBleLayer(); #endif initParams.listenPort = listenPort; + setupParams.controllerVendorId = VendorId::NotSpecified; setupParams.pairingDelegate = wrapper.get(); setupParams.operationalCredentialsDelegate = opCredsIssuer; initParams.fabricIndependentStorage = wrapperStorage; diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 5499fee6909a75..9b39ed0748c8e5 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -1224,7 +1224,7 @@ CHIP_ERROR N2J_PaseVerifierParams(JNIEnv * env, jlong setupPincode, jbyteArray p SuccessOrExit(err); env->ExceptionClear(); - constructor = env->GetMethodID(paramsClass, "", "(JI[B)V"); + constructor = env->GetMethodID(paramsClass, "", "(J[B)V"); VerifyOrExit(constructor != nullptr, err = CHIP_JNI_ERROR_METHOD_NOT_FOUND); outParams = (jobject) env->NewObject(paramsClass, constructor, setupPincode, paseVerifier); From 360c6a0fc8c30aec7941cea0da96a527e09079a2 Mon Sep 17 00:00:00 2001 From: Amon Al-Khatib Date: Tue, 19 Jul 2022 17:11:38 -0700 Subject: [PATCH 2/3] fix formatting --- .../google/chip/chiptool/CHIPDeviceControllerTest.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/android/CHIPTool/app/src/androidTest/java/com/google/chip/chiptool/CHIPDeviceControllerTest.java b/src/android/CHIPTool/app/src/androidTest/java/com/google/chip/chiptool/CHIPDeviceControllerTest.java index 259b309ebcfb4b..aa444ef422304d 100644 --- a/src/android/CHIPTool/app/src/androidTest/java/com/google/chip/chiptool/CHIPDeviceControllerTest.java +++ b/src/android/CHIPTool/app/src/androidTest/java/com/google/chip/chiptool/CHIPDeviceControllerTest.java @@ -4,15 +4,12 @@ import static org.junit.Assert.assertNotNull; import android.content.Context; - import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.platform.app.InstrumentationRegistry; - -import org.junit.Test; -import org.junit.runner.RunWith; - import chip.devicecontroller.ChipDeviceController; import chip.devicecontroller.PaseVerifierParams; +import org.junit.Test; +import org.junit.runner.RunWith; /** * Instrumented test, which will execute on an Android device. @@ -29,8 +26,7 @@ public void PaseVerifierTest() { byte[] randomSalt = "hEvzbU:%h)?aB,h7+9fn[Lf[BhYB!=TA".getBytes(); Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - ChipDeviceController chipDeviceController = - ChipClient.INSTANCE.getDeviceController(appContext); + ChipDeviceController chipDeviceController = ChipClient.INSTANCE.getDeviceController(appContext); PaseVerifierParams params = chipDeviceController.computePaseVerifier(deviceId, setupPincode, iterations, randomSalt); From 4b0cbfde75c2d30f16a31e31ee68f2255892e71b Mon Sep 17 00:00:00 2001 From: Amon Al-Khatib Date: Tue, 19 Jul 2022 17:18:32 -0700 Subject: [PATCH 3/3] correct indentations and newline --- .../chiptool/CHIPDeviceControllerTest.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/android/CHIPTool/app/src/androidTest/java/com/google/chip/chiptool/CHIPDeviceControllerTest.java b/src/android/CHIPTool/app/src/androidTest/java/com/google/chip/chiptool/CHIPDeviceControllerTest.java index aa444ef422304d..a179e9234c8d73 100644 --- a/src/android/CHIPTool/app/src/androidTest/java/com/google/chip/chiptool/CHIPDeviceControllerTest.java +++ b/src/android/CHIPTool/app/src/androidTest/java/com/google/chip/chiptool/CHIPDeviceControllerTest.java @@ -18,21 +18,21 @@ */ @RunWith(AndroidJUnit4.class) public class CHIPDeviceControllerTest { - @Test - public void PaseVerifierTest() { - long deviceId = 123L; - long setupPincode = 808080L; - long iterations = 1000L; - byte[] randomSalt = "hEvzbU:%h)?aB,h7+9fn[Lf[BhYB!=TA".getBytes(); + @Test + public void PaseVerifierTest() { + long deviceId = 123L; + long setupPincode = 808080L; + long iterations = 1000L; + byte[] randomSalt = "hEvzbU:%h)?aB,h7+9fn[Lf[BhYB!=TA".getBytes(); - Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - ChipDeviceController chipDeviceController = ChipClient.INSTANCE.getDeviceController(appContext); + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + ChipDeviceController chipDeviceController = ChipClient.INSTANCE.getDeviceController(appContext); - PaseVerifierParams params = - chipDeviceController.computePaseVerifier(deviceId, setupPincode, iterations, randomSalt); + PaseVerifierParams params = + chipDeviceController.computePaseVerifier(deviceId, setupPincode, iterations, randomSalt); - assertNotNull(params); - assertEquals(params.getSetupPincode(), setupPincode); - assertNotNull(params.getPakeVerifier()); - } -} \ No newline at end of file + assertNotNull(params); + assertEquals(params.getSetupPincode(), setupPincode); + assertNotNull(params.getPakeVerifier()); + } +}