Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Add CSR Element validate API #31852

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,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
Loading