Skip to content

Commit

Permalink
add custom cert support for java controller
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google committed May 7, 2024
1 parent 36c76e6 commit 8e562de
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 @@ -40,9 +40,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 @@ -52,13 +50,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 @@ -296,7 +292,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 @@ -333,7 +328,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 @@ -34,13 +34,12 @@
#include <crypto/RawKeySessionKeystore.h>
#include <lib/support/TimeUtils.h>
#include <platform/internal/DeviceNetworkInfo.h>

#include <controller/java/CHIPP256KeypairBridge.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 @@ -231,12 +228,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 @@ -120,6 +120,8 @@ shared_library("jni") {
check_includes = false

sources = [
"CHIPP256KeypairBridge.cpp",
"CHIPP256KeypairBridge.h",
"AndroidCheckInDelegate.cpp",
"AndroidCheckInDelegate.h",
"AndroidClusterExceptions.cpp",
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 @@ -51,8 +51,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 8e562de

Please sign in to comment.