Skip to content

Commit 4422581

Browse files
[Android] Add to set CD trust keys (#31708)
* Add to set CD trust keys * Restyled by google-java-format * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 839c565 commit 4422581

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

src/controller/java/AndroidDeviceControllerWrapper.cpp

+25-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,8 @@ CHIP_ERROR AndroidDeviceControllerWrapper::UpdateDeviceAttestationDelegateBridge
543543
return err;
544544
}
545545

546-
CHIP_ERROR AndroidDeviceControllerWrapper::UpdateAttestationTrustStoreBridge(jobject attestationTrustStoreDelegate)
546+
CHIP_ERROR AndroidDeviceControllerWrapper::UpdateAttestationTrustStoreBridge(jobject attestationTrustStoreDelegate,
547+
jobject cdTrustKeys)
547548
{
548549
CHIP_ERROR err = CHIP_NO_ERROR;
549550

@@ -566,6 +567,29 @@ CHIP_ERROR AndroidDeviceControllerWrapper::UpdateAttestationTrustStoreBridge(job
566567
}
567568
mDeviceAttestationVerifier = deviceAttestationVerifier;
568569

570+
if (cdTrustKeys != nullptr)
571+
{
572+
WellKnownKeysTrustStore * cdTrustStore = mDeviceAttestationVerifier->GetCertificationDeclarationTrustStore();
573+
VerifyOrExit(cdTrustStore != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
574+
575+
jint size;
576+
err = JniReferences::GetInstance().GetListSize(cdTrustKeys, size);
577+
VerifyOrExit(err == CHIP_NO_ERROR, err = CHIP_ERROR_INVALID_ARGUMENT);
578+
579+
for (jint i = 0; i < size; i++)
580+
{
581+
jobject jTrustKey = nullptr;
582+
err = JniReferences::GetInstance().GetListItem(cdTrustKeys, i, jTrustKey);
583+
584+
VerifyOrExit(err == CHIP_NO_ERROR, err = CHIP_ERROR_INVALID_ARGUMENT);
585+
586+
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
587+
JniByteArray jniTrustKey(env, static_cast<jbyteArray>(jTrustKey));
588+
err = cdTrustStore->AddTrustedKey(jniTrustKey.byteSpan());
589+
VerifyOrExit(err == CHIP_NO_ERROR, err = CHIP_ERROR_INVALID_ARGUMENT);
590+
}
591+
}
592+
569593
mController->SetDeviceAttestationVerifier(mDeviceAttestationVerifier);
570594

571595
exit:

src/controller/java/AndroidDeviceControllerWrapper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel
202202
CHIP_ERROR UpdateDeviceAttestationDelegateBridge(jobject deviceAttestationDelegate, chip::Optional<uint16_t> expiryTimeoutSecs,
203203
bool shouldWaitAfterDeviceAttestation);
204204

205-
CHIP_ERROR UpdateAttestationTrustStoreBridge(jobject attestationTrustStoreDelegate);
205+
CHIP_ERROR UpdateAttestationTrustStoreBridge(jobject attestationTrustStoreDelegate, jobject cdTrustKeys);
206206

207207
CHIP_ERROR StartOTAProvider(jobject otaProviderDelegate);
208208

src/controller/java/CHIPDeviceController-JNI.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ JNI_METHOD(void, setDeviceAttestationDelegate)
533533
}
534534

535535
JNI_METHOD(void, setAttestationTrustStoreDelegate)
536-
(JNIEnv * env, jobject self, jlong handle, jobject attestationTrustStoreDelegate)
536+
(JNIEnv * env, jobject self, jlong handle, jobject attestationTrustStoreDelegate, jobject cdTrustKeys)
537537
{
538538
chip::DeviceLayer::StackLock lock;
539539
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -544,7 +544,7 @@ JNI_METHOD(void, setAttestationTrustStoreDelegate)
544544
if (attestationTrustStoreDelegate != nullptr)
545545
{
546546
jobject attestationTrustStoreDelegateRef = env->NewGlobalRef(attestationTrustStoreDelegate);
547-
err = wrapper->UpdateAttestationTrustStoreBridge(attestationTrustStoreDelegateRef);
547+
err = wrapper->UpdateAttestationTrustStoreBridge(attestationTrustStoreDelegateRef, cdTrustKeys);
548548
SuccessOrExit(err);
549549
}
550550

src/controller/java/src/chip/devicecontroller/ChipDeviceController.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import android.bluetooth.BluetoothGatt;
2121
import android.util.Log;
22+
import chip.devicecontroller.ChipDeviceController.CompletionListener;
2223
import chip.devicecontroller.GetConnectedDeviceCallbackJni.GetConnectedDeviceCallback;
2324
import chip.devicecontroller.model.AttributeWriteRequest;
2425
import chip.devicecontroller.model.ChipAttributePath;
@@ -117,10 +118,18 @@ public void setDeviceAttestationDelegate(
117118
* paa certificates before commissioning.
118119
*
119120
* @param attestationTrustStoreDelegate Delegate for attestation trust store
121+
* @param cdTrustKeys certification Declaration Trust Keys
120122
*/
123+
public void setAttestationTrustStoreDelegate(
124+
AttestationTrustStoreDelegate attestationTrustStoreDelegate,
125+
@Nullable List<byte[]> cdTrustKeys) {
126+
setAttestationTrustStoreDelegate(
127+
deviceControllerPtr, attestationTrustStoreDelegate, cdTrustKeys);
128+
}
129+
121130
public void setAttestationTrustStoreDelegate(
122131
AttestationTrustStoreDelegate attestationTrustStoreDelegate) {
123-
setAttestationTrustStoreDelegate(deviceControllerPtr, attestationTrustStoreDelegate);
132+
setAttestationTrustStoreDelegate(deviceControllerPtr, attestationTrustStoreDelegate, null);
124133
}
125134

126135
/**
@@ -1367,7 +1376,9 @@ private native void setDeviceAttestationDelegate(
13671376
long deviceControllerPtr, int failSafeExpiryTimeoutSecs, DeviceAttestationDelegate delegate);
13681377

13691378
private native void setAttestationTrustStoreDelegate(
1370-
long deviceControllerPtr, AttestationTrustStoreDelegate delegate);
1379+
long deviceControllerPtr,
1380+
AttestationTrustStoreDelegate delegate,
1381+
@Nullable List<byte[]> cdTrustKeys);
13711382

13721383
private native void startOTAProvider(long deviceControllerPtr, OTAProviderDelegate delegate);
13731384

0 commit comments

Comments
 (0)