Skip to content

Commit

Permalink
[Android] Add CSR Element validate API (#31852)
Browse files Browse the repository at this point in the history
* Add CSR Element validate API

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
joonhaengHeo and restyled-commits authored Feb 2, 2024
1 parent 691efa5 commit 69f96f7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,33 @@ JNI_METHOD(jobject, computePaseVerifier)
return nullptr;
}

JNI_METHOD(jbyteArray, validateAndExtractCSR)(JNIEnv * env, jclass clazz, jbyteArray jCsrElements, jbyteArray jCsrNonce)
{

chip::JniByteArray csrElements(env, jCsrElements);
chip::JniByteArray csrNonce(env, jCsrNonce);

chip::ByteSpan csrSpan;
chip::ByteSpan csrNonceSpan;
chip::ByteSpan vendor_reserved1, vendor_reserved2, vendor_reserved3;
CHIP_ERROR err = chip::Credentials::DeconstructNOCSRElements(csrElements.byteSpan(), csrSpan, csrNonceSpan, vendor_reserved1,
vendor_reserved2, vendor_reserved3);

VerifyOrReturnValue(err == CHIP_NO_ERROR, nullptr,
ChipLogError(Controller, "CsrElement decoding error: %" CHIP_ERROR_FORMAT, err.Format()));
VerifyOrReturnValue(csrNonceSpan.size() == Controller::kCSRNonceLength, nullptr,
ChipLogError(Controller, "csrNonce size is invalid"));

// Verify that Nonce matches with what we sent
VerifyOrReturnValue(csrNonceSpan.data_equal(csrNonce.byteSpan()), nullptr,
ChipLogError(Controller, "csrNonce is not matched!"));

jbyteArray javaCsr;
chip::JniReferences::GetInstance().N2J_ByteArray(chip::JniReferences::GetInstance().GetEnvForCurrentThread(), csrSpan.data(),
static_cast<jsize>(csrSpan.size()), javaCsr);
return javaCsr;
}

JNI_METHOD(jobject, getICDClientInfo)(JNIEnv * env, jobject self, jlong handle, jint jFabricIndex)
{
chip::DeviceLayer::StackLock lock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,8 @@ public void shutdownCommissioning() {
shutdownCommissioning(deviceControllerPtr);
}

public static native byte[] validateAndExtractCSR(byte[] csrElements, byte[] csrNonce);

private native PaseVerifierParams computePaseVerifier(
long deviceControllerPtr, long devicePtr, long setupPincode, long iterations, byte[] salt);

Expand Down

0 comments on commit 69f96f7

Please sign in to comment.