From 7fde831b69d70785ff5d8116dba31a0213da23dd Mon Sep 17 00:00:00 2001 From: Amon Al-Khatib <108832650+ajwak@users.noreply.github.com> Date: Wed, 20 Jul 2022 06:33:15 +0000 Subject: [PATCH] Fix broken PaseVerifier codepath and add test (#20969) * Fix broken PaseVerifier codepath and add test * fix formatting * correct indentations and newline --- .../chiptool/CHIPDeviceControllerTest.java | 38 +++++++++++++++++++ .../java/AndroidDeviceControllerWrapper.cpp | 1 + .../java/CHIPDeviceController-JNI.cpp | 2 +- 3 files changed, 40 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..a179e9234c8d73 --- /dev/null +++ b/src/android/CHIPTool/app/src/androidTest/java/com/google/chip/chiptool/CHIPDeviceControllerTest.java @@ -0,0 +1,38 @@ +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 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. + * + * @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()); + } +} 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);