From 7c67aa1cc3f8a7c11935a8fb426f0aa6ce06b418 Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Tue, 29 Oct 2024 21:13:56 -0700 Subject: [PATCH] [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 --- src/controller/java/AndroidDeviceControllerWrapper.cpp | 8 +------- src/controller/java/AndroidDeviceControllerWrapper.h | 7 ++----- src/controller/java/BUILD.gn | 2 ++ .../android => controller/java}/CHIPP256KeypairBridge.cpp | 3 +-- .../android => controller/java}/CHIPP256KeypairBridge.h | 0 src/platform/android/BUILD.gn | 2 -- 6 files changed, 6 insertions(+), 16 deletions(-) rename src/{platform/android => controller/java}/CHIPP256KeypairBridge.cpp (98%) rename src/{platform/android => controller/java}/CHIPP256KeypairBridge.h (100%) diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index ba0342629a73df..7f821fefc0c9ac 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -42,9 +42,7 @@ #include #include #include -#ifndef JAVA_MATTER_CONTROLLER_TEST -#include -#endif // JAVA_MATTER_CONTROLLER_TEST + using namespace chip; using namespace chip::Controller; using namespace chip::Credentials; @@ -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) { @@ -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(); @@ -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"); diff --git a/src/controller/java/AndroidDeviceControllerWrapper.h b/src/controller/java/AndroidDeviceControllerWrapper.h index 02d50499bbbcda..93374a1e0f1795 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.h +++ b/src/controller/java/AndroidDeviceControllerWrapper.h @@ -28,19 +28,18 @@ #include #include #include +#include #include #include #include #include #include #include - #ifdef JAVA_MATTER_CONTROLLER_TEST #include #include #else #include -#include #endif // JAVA_MATTER_CONTROLLER_TEST #include "AndroidCheckInDelegate.h" @@ -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 @@ -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); @@ -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. diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index 480e30f704ab29..2ae828ad09c47e 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -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", 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 a6be8799ab7b96..a73eb417203c10 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 #include #include -#include #include #include 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 640b52490078eb..9893907f8588ba 100644 --- a/src/platform/android/BUILD.gn +++ b/src/platform/android/BUILD.gn @@ -64,8 +64,6 @@ static_library("android") { "BleConnectCallback-JNI.cpp", "BlePlatformConfig.h", "CHIPDevicePlatformEvent.h", - "CHIPP256KeypairBridge.cpp", - "CHIPP256KeypairBridge.h", "CommissionableDataProviderImpl.cpp", "CommissionableDataProviderImpl.h", "ConfigurationManagerImpl.cpp",