Skip to content

Commit

Permalink
Fix broken PaseVerifier codepath and add test (#20969)
Browse files Browse the repository at this point in the history
* Fix broken PaseVerifier codepath and add test

* fix formatting

* correct indentations and newline
  • Loading branch information
ajwak authored and web-flow committed Jul 20, 2022
1 parent 30a0dae commit 3c43c3f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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 <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@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());
}
}
1 change: 1 addition & 0 deletions src/controller/java/AndroidDeviceControllerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ CHIP_ERROR N2J_PaseVerifierParams(JNIEnv * env, jlong setupPincode, jbyteArray p
SuccessOrExit(err);

env->ExceptionClear();
constructor = env->GetMethodID(paramsClass, "<init>", "(JI[B)V");
constructor = env->GetMethodID(paramsClass, "<init>", "(J[B)V");
VerifyOrExit(constructor != nullptr, err = CHIP_JNI_ERROR_METHOD_NOT_FOUND);

outParams = (jobject) env->NewObject(paramsClass, constructor, setupPincode, paseVerifier);
Expand Down

0 comments on commit 3c43c3f

Please sign in to comment.