Skip to content

Commit

Permalink
Surface a Java function to compute compressed fabric ID (#16256)
Browse files Browse the repository at this point in the history
Tested:
- Compiled and ran through commissioning, providing a real RCAC/NOC and
  verifying that the output matched the advertised operational instance
  name of the device.
  • Loading branch information
g-coppock authored and pull[bot] committed Jul 27, 2023
1 parent a56b92d commit 9cc67d8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
using namespace chip;
using namespace chip::Inet;
using namespace chip::Controller;
using namespace chip::Credentials;

#define JNI_METHOD(RETURN, METHOD_NAME) \
extern "C" JNIEXPORT RETURN JNICALL Java_chip_devicecontroller_ChipDeviceController_##METHOD_NAME
Expand Down Expand Up @@ -499,6 +500,29 @@ JNI_METHOD(jstring, getIpAddress)(JNIEnv * env, jobject self, jlong handle, jlon
return env->NewStringUTF(addrStr);
}

JNI_METHOD(jlong, generateCompressedFabricId)
(JNIEnv * env, jobject self, jbyteArray rcac, jbyteArray noc)
{
chip::DeviceLayer::StackLock lock;
CompressedFabricId compressedFabricId;
FabricId fabricId;
NodeId nodeId;
CHIP_ERROR err = CHIP_NO_ERROR;

chip::JniByteArray jniRcac(env, rcac);
chip::JniByteArray jniNoc(env, noc);
err = ExtractNodeIdFabricIdCompressedFabricIdFromOpCerts(jniRcac.byteSpan(), jniNoc.byteSpan(), compressedFabricId, fabricId,
nodeId);

if (err != CHIP_NO_ERROR)
{
ChipLogError(Controller, "Failed to extract compressed fabric ID.");
JniReferences::GetInstance().ThrowError(env, sChipDeviceControllerExceptionCls, err);
}

return static_cast<jlong>(compressedFabricId);
}

JNI_METHOD(jobject, getNetworkLocation)(JNIEnv * env, jobject self, jlong handle, jlong deviceId)
{
chip::DeviceLayer::StackLock lock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ public long getCompressedFabricId() {
return getCompressedFabricId(deviceControllerPtr);
}

/**
* Returns the compressed fabric ID based on the given root certificate and node operational
* credentials.
*
* @param rcac the root certificate (in Matter cert form)
* @param noc the NOC (in Matter cert form)
* @see #convertX509CertToMatterCert(byte[])
*/
public native long generateCompressedFabricId(byte[] rcac, byte[] noc);

public void updateDevice(long fabricId, long deviceId) {
updateDevice(deviceControllerPtr, fabricId, deviceId);
}
Expand Down

0 comments on commit 9cc67d8

Please sign in to comment.