Skip to content

Commit

Permalink
[Java][Controller] Add custom cert support for java controller (#33342)
Browse files Browse the repository at this point in the history
* add custom cert support for java controller

* Restyled by clang-format

* Restyled by gn

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Nov 7, 2024
1 parent ca6fc3e commit 7c67aa1
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 16 deletions.
8 changes: 1 addition & 7 deletions src/controller/java/AndroidDeviceControllerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
#include <lib/support/TestGroupData.h>
#include <lib/support/ThreadOperationalDataset.h>
#include <platform/KeyValueStoreManager.h>
#ifndef JAVA_MATTER_CONTROLLER_TEST
#include <platform/android/CHIPP256KeypairBridge.h>
#endif // JAVA_MATTER_CONTROLLER_TEST

using namespace chip;
using namespace chip::Controller;
using namespace chip::Credentials;
Expand All @@ -54,13 +52,11 @@ AndroidDeviceControllerWrapper::~AndroidDeviceControllerWrapper()
{
mController->Shutdown();

#ifndef JAVA_MATTER_CONTROLLER_TEST
if (mKeypairBridge != nullptr)
{
chip::Platform::Delete(mKeypairBridge);
mKeypairBridge = nullptr;
}
#endif // JAVA_MATTER_CONTROLLER_TEST

if (mDeviceAttestationDelegateBridge != nullptr)
{
Expand Down Expand Up @@ -298,7 +294,6 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(

// The lifetime of the ephemeralKey variable must be kept until SetupParams is saved.
Crypto::P256Keypair ephemeralKey;
#ifndef JAVA_MATTER_CONTROLLER_TEST
if (rootCertificate != nullptr && nodeOperationalCertificate != nullptr && keypairDelegate != nullptr)
{
CHIPP256KeypairBridge * nativeKeypairBridge = wrapper->GetP256KeypairBridge();
Expand Down Expand Up @@ -335,7 +330,6 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(
setupParams.controllerNOC = chip::ByteSpan(wrapper->mNocCertificate.data(), wrapper->mNocCertificate.size());
}
else
#endif // JAVA_MATTER_CONTROLLER_TEST
{
ChipLogProgress(Controller,
"No existing credentials provided: generating ephemeral local NOC chain with OperationalCredentialsIssuer");
Expand Down
7 changes: 2 additions & 5 deletions src/controller/java/AndroidDeviceControllerWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,18 @@
#include <app/icd/client/CheckInHandler.h>
#include <app/icd/client/DefaultICDClientStorage.h>
#include <controller/CHIPDeviceController.h>
#include <controller/java/CHIPP256KeypairBridge.h>
#include <credentials/GroupDataProviderImpl.h>
#include <credentials/PersistentStorageOpCertStore.h>
#include <credentials/attestation_verifier/DacOnlyPartialAttestationVerifier.h>
#include <crypto/RawKeySessionKeystore.h>
#include <lib/support/TimeUtils.h>
#include <platform/internal/DeviceNetworkInfo.h>

#ifdef JAVA_MATTER_CONTROLLER_TEST
#include <controller/ExampleOperationalCredentialsIssuer.h>
#include <controller/ExamplePersistentStorage.h>
#else
#include <platform/android/AndroidChipPlatform-JNI.h>
#include <platform/android/CHIPP256KeypairBridge.h>
#endif // JAVA_MATTER_CONTROLLER_TEST

#include "AndroidCheckInDelegate.h"
Expand Down Expand Up @@ -71,7 +70,6 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel
jobject JavaObjectRef() { return mJavaObjectRef.ObjectRef(); }
jlong ToJNIHandle();

#ifndef JAVA_MATTER_CONTROLLER_TEST
/**
* Returns a CHIPP256KeypairBridge which can be used to delegate signing operations
* to a KeypairDelegate in the Java layer. Note that this will always return a pointer
Expand All @@ -85,7 +83,6 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel
}
return mKeypairBridge;
}
#endif // JAVA_MATTER_CONTROLLER_TEST

void CallJavaIntMethod(const char * methodName, jint argument);
void CallJavaLongMethod(const char * methodName, jlong argument);
Expand Down Expand Up @@ -235,12 +232,12 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel

JavaVM * mJavaVM = nullptr;
chip::JniGlobalReference mJavaObjectRef;
CHIPP256KeypairBridge * mKeypairBridge = nullptr;
#ifdef JAVA_MATTER_CONTROLLER_TEST
ExampleOperationalCredentialsIssuerPtr mOpCredsIssuer;
PersistentStorage mExampleStorage;
#else
AndroidOperationalCredentialsIssuerPtr mOpCredsIssuer;
CHIPP256KeypairBridge * mKeypairBridge = nullptr;
#endif // JAVA_MATTER_CONTROLLER_TEST

// These fields allow us to release the string/byte array memory later.
Expand Down
2 changes: 2 additions & 0 deletions src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ shared_library("jni") {
"AttestationTrustStoreBridge.cpp",
"AttestationTrustStoreBridge.h",
"CHIPDeviceController-JNI.cpp",
"CHIPP256KeypairBridge.cpp",
"CHIPP256KeypairBridge.h",
"DeviceAttestation-JNI.cpp",
"DeviceAttestationDelegateBridge.cpp",
"DeviceAttestationDelegateBridge.h",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "platform/android/CHIPP256KeypairBridge.h"
#include "CHIPP256KeypairBridge.h"
#include "lib/core/CHIPError.h"
#include "lib/support/CHIPJNIError.h"
#include "lib/support/JniReferences.h"
Expand All @@ -26,7 +26,6 @@
#include <cstdint>
#include <cstdlib>
#include <jni.h>
#include <platform/PlatformManager.h>
#include <string.h>
#include <type_traits>

Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions src/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ static_library("android") {
"BleConnectCallback-JNI.cpp",
"BlePlatformConfig.h",
"CHIPDevicePlatformEvent.h",
"CHIPP256KeypairBridge.cpp",
"CHIPP256KeypairBridge.h",
"CommissionableDataProviderImpl.cpp",
"CommissionableDataProviderImpl.h",
"ConfigurationManagerImpl.cpp",
Expand Down

0 comments on commit 7c67aa1

Please sign in to comment.