[Java][Controller] Add custom cert support for java controller (#33342)
* add custom cert support for java controller
* Restyled by clang-format
* Restyled by gn
---------
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp
index ba03426..7f821fe 100644
--- a/src/controller/java/AndroidDeviceControllerWrapper.cpp
+++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp
@@ -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;
@@ -54,13 +52,11 @@
{
mController->Shutdown();
-#ifndef JAVA_MATTER_CONTROLLER_TEST
if (mKeypairBridge != nullptr)
{
chip::Platform::Delete(mKeypairBridge);
mKeypairBridge = nullptr;
}
-#endif // JAVA_MATTER_CONTROLLER_TEST
if (mDeviceAttestationDelegateBridge != nullptr)
{
@@ -298,7 +294,6 @@
// 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();
@@ -335,7 +330,6 @@
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");
diff --git a/src/controller/java/AndroidDeviceControllerWrapper.h b/src/controller/java/AndroidDeviceControllerWrapper.h
index 02d5049..93374a1 100644
--- a/src/controller/java/AndroidDeviceControllerWrapper.h
+++ b/src/controller/java/AndroidDeviceControllerWrapper.h
@@ -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"
@@ -71,7 +70,6 @@
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
@@ -85,7 +83,6 @@
}
return mKeypairBridge;
}
-#endif // JAVA_MATTER_CONTROLLER_TEST
void CallJavaIntMethod(const char * methodName, jint argument);
void CallJavaLongMethod(const char * methodName, jlong argument);
@@ -235,12 +232,12 @@
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.
diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn
index 480e30f..2ae828a 100644
--- a/src/controller/java/BUILD.gn
+++ b/src/controller/java/BUILD.gn
@@ -136,6 +136,8 @@
"AttestationTrustStoreBridge.cpp",
"AttestationTrustStoreBridge.h",
"CHIPDeviceController-JNI.cpp",
+ "CHIPP256KeypairBridge.cpp",
+ "CHIPP256KeypairBridge.h",
"DeviceAttestation-JNI.cpp",
"DeviceAttestationDelegateBridge.cpp",
"DeviceAttestationDelegateBridge.h",
diff --git a/src/platform/android/CHIPP256KeypairBridge.cpp b/src/controller/java/CHIPP256KeypairBridge.cpp
similarity index 98%
rename from src/platform/android/CHIPP256KeypairBridge.cpp
rename to src/controller/java/CHIPP256KeypairBridge.cpp
index a6be879..a73eb41 100644
--- a/src/platform/android/CHIPP256KeypairBridge.cpp
+++ b/src/controller/java/CHIPP256KeypairBridge.cpp
@@ -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"
@@ -26,7 +26,6 @@
#include <cstdint>
#include <cstdlib>
#include <jni.h>
-#include <platform/PlatformManager.h>
#include <string.h>
#include <type_traits>
diff --git a/src/platform/android/CHIPP256KeypairBridge.h b/src/controller/java/CHIPP256KeypairBridge.h
similarity index 100%
rename from src/platform/android/CHIPP256KeypairBridge.h
rename to src/controller/java/CHIPP256KeypairBridge.h
diff --git a/src/platform/android/BUILD.gn b/src/platform/android/BUILD.gn
index 640b524..9893907 100644
--- a/src/platform/android/BUILD.gn
+++ b/src/platform/android/BUILD.gn
@@ -64,8 +64,6 @@
"BleConnectCallback-JNI.cpp",
"BlePlatformConfig.h",
"CHIPDevicePlatformEvent.h",
- "CHIPP256KeypairBridge.cpp",
- "CHIPP256KeypairBridge.h",
"CommissionableDataProviderImpl.cpp",
"CommissionableDataProviderImpl.h",
"ConfigurationManagerImpl.cpp",