Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Attestation trust store bridge #24381

Closed
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
11b5724
[Android] Added mechanism to override device attestation failure base…
panliming-tuya Oct 13, 2022
ea40f1a
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Oct 14, 2022
5ed16c0
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Oct 14, 2022
d36248a
platform jar keep name of method parameters
panliming-tuya Oct 14, 2022
1c38401
Restyled by whitespace
restyled-commits Oct 14, 2022
587ac5f
Restyled by google-java-format
restyled-commits Oct 14, 2022
66bedd6
Restyled by clang-format
restyled-commits Oct 14, 2022
d9be2ba
Restyled by gn
restyled-commits Oct 14, 2022
afdf205
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Oct 16, 2022
e8f0495
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Oct 18, 2022
640ddbd
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Oct 18, 2022
3c4f499
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Oct 20, 2022
48ce640
fix copyright
panliming-tuya Oct 20, 2022
eb95edd
Merge branch 'additional-verification-after-attestation' of https://g…
panliming-tuya Oct 20, 2022
5e8723b
fix and modify comments
panliming-tuya Oct 20, 2022
79024b4
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Oct 21, 2022
2270c9d
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Oct 28, 2022
47f079e
Use setters instead of adding parameters to methods
panliming-tuya Oct 28, 2022
27a3862
fix NetworkCredentials NPE
panliming-tuya Oct 28, 2022
beb066a
Do not expose deviceController raw pointer
panliming-tuya Oct 28, 2022
f9d3dd5
add sample
panliming-tuya Oct 28, 2022
9e6a181
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Nov 2, 2022
38b0c0c
Create AttestationTrustStoreBridge when we know we have PAA certs.
panliming-tuya Nov 3, 2022
0ee733e
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Nov 3, 2022
8481cde
fix jni method
panliming-tuya Nov 3, 2022
e6211db
fix certs loss of scope and add some comments
panliming-tuya Nov 7, 2022
3bacfe3
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Nov 7, 2022
3b40467
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Nov 8, 2022
b26afb9
implement destructor
panliming-tuya Nov 8, 2022
27584d6
fix destructor crash
panliming-tuya Nov 8, 2022
a654ede
revoke vscode setting change
panliming-tuya Nov 8, 2022
6db2e8b
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Nov 9, 2022
52c5c30
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Nov 15, 2022
4958adb
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Nov 18, 2022
213164e
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Nov 18, 2022
a610fa5
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Nov 21, 2022
59c8ca6
Restyled by whitespace
panliming-tuya Nov 21, 2022
3811015
Restyled by google-java-format
panliming-tuya Nov 21, 2022
8c01083
Restyled by clang-format
panliming-tuya Nov 21, 2022
5dcbae5
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Dec 13, 2022
8837adf
fix conflict
panliming-tuya Dec 15, 2022
212dc10
add unit of failSafeExpiryTimeout
panliming-tuya Dec 15, 2022
9d41d26
add sample code
panliming-tuya Dec 15, 2022
37f760a
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Dec 15, 2022
747645d
Restyled by whitespace
panliming-tuya Dec 15, 2022
17348b2
Restyled by google-java-format
panliming-tuya Dec 15, 2022
e5972ae
Restyled by clang-format
panliming-tuya Dec 15, 2022
9d915df
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Dec 19, 2022
993b5cf
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Jan 4, 2023
f069618
fix comments
panliming-tuya Jan 4, 2023
f485757
remove android attestation trust store
panliming-tuya Jan 4, 2023
c027231
Merge branch 'master' into additional-verification-after-attestation
panliming-tuya Jan 4, 2023
2b094c8
restyle
panliming-tuya Jan 4, 2023
a870918
[android] support attestation trust store delegate
panliming-tuya Jan 5, 2023
b76318b
restyled.
panliming-tuya Jan 5, 2023
af9da6d
fix jni crash
panliming-tuya Jan 6, 2023
d764674
Modify the timing of setting the Attestation trust store
panliming-tuya Jan 10, 2023
73c27a1
fix conflict
panliming-tuya Jan 12, 2023
731c941
setAttestationTrustStoreDelegate add comments
panliming-tuya Jan 12, 2023
b0b7e1c
Remove redundant variables
panliming-tuya Jan 13, 2023
7de0a34
Release jni class references
panliming-tuya Jan 13, 2023
d3a8940
Merge branch 'attestation-store-bridge' of https://github.com/panlimi…
panliming-tuya Jan 13, 2023
4ed1234
Fix objects leak when calling 'setAttestationTrustStoreDelegate' twice
panliming-tuya Jan 13, 2023
a8b9a86
Remove unused include
panliming-tuya Jan 17, 2023
f2d3c35
Modify private to protected
panliming-tuya Jan 17, 2023
7e29657
Optimize variable initialization
panliming-tuya Jan 17, 2023
4c219c2
fix compile error
panliming-tuya Jan 18, 2023
67dc3cf
Moving the alloc of AttestationTrustStoreBridge before clear
panliming-tuya Jan 18, 2023
454d160
Merge branch 'master' into attestation-store-bridge
panliming-tuya Jan 18, 2023
3f82e30
Add Android example
panliming-tuya Jan 19, 2023
6541582
Merge branch 'attestation-store-bridge' of https://github.com/panlimi…
panliming-tuya Jan 19, 2023
3ede0b5
Merge branch 'master' into attestation-store-bridge
panliming-tuya Jan 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/controller/java/AndroidDeviceControllerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ AndroidDeviceControllerWrapper::~AndroidDeviceControllerWrapper()
delete mDeviceAttestationDelegateBridge;
mDeviceAttestationDelegateBridge = nullptr;
}
if (mDeviceAttestationVerifier != nullptr)
{
delete mDeviceAttestationVerifier;
mDeviceAttestationVerifier = nullptr;
}
if (mAttestationTrustStoreBridge != nullptr)
{
delete mAttestationTrustStoreBridge;
mAttestationTrustStoreBridge = nullptr;
}
Comment on lines +70 to +79
Copy link
Contributor

@tcarmelveilleux tcarmelveilleux Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes it was new'ed which it doesn't have to be. We should not delete unless we know it was allocated dynamically with new.

The pattern used by previous code:

if (mDeviceAttestationDelegateBridge != nullptr)
    {
        delete mDeviceAttestationDelegateBridge;
        mDeviceAttestationDelegateBridge = nullptr;
    }

is also problematic, unless the API clearly states the requirement that the arguments must be allocated with new and ownership is transfered to the class.

Suggest using std::unique_ptr instead if ownership transfer is desired. It would make it clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with that, using std::unique_ptr could make it clearer.

However, it requires all platforms AttestationTrustStore * and DeviceAttestationVerifier * to be modified into smart pointers.

Could we fix it in following PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now the issue is that you force a new being done outside, which is not guaranteed to be done by all...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK,I will fix it. Due to the need to modify the code for multiple platforms, I need to work with other teams in my company, which will take some time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

void AndroidDeviceControllerWrapper::SetJavaObjectRef(JavaVM * vm, jobject obj)
Expand Down Expand Up @@ -158,7 +168,7 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(
// Initialize device attestation verifier
// TODO: Replace testingRootStore with a AttestationTrustStore that has the necessary official PAA roots available
const chip::Credentials::AttestationTrustStore * testingRootStore = chip::Credentials::GetTestAttestationTrustStore();
SetDeviceAttestationVerifier(GetDefaultDACVerifier(testingRootStore));
chip::Credentials::SetDeviceAttestationVerifier(GetDefaultDACVerifier(testingRootStore));

chip::Controller::FactoryInitParams initParams;
chip::Controller::SetupParams setupParams;
Expand Down
37 changes: 36 additions & 1 deletion src/controller/java/AndroidDeviceControllerWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#endif // JAVA_MATTER_CONTROLLER_TEST

#include "AndroidOperationalCredentialsIssuer.h"
#include "AttestationTrustStoreBridge.h"
#include "DeviceAttestationDelegateBridge.h"

/**
Expand Down Expand Up @@ -196,6 +197,38 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel
}
}

void SetAttestationTrustStoreBridge(AttestationTrustStoreBridge * attestationTrustStoreBridge)
{
mAttestationTrustStoreBridge = attestationTrustStoreBridge;
}

AttestationTrustStoreBridge * GetAttestationTrustStoreBridge() { return mAttestationTrustStoreBridge; }

void ClearAttestationTrustStoreBridge()
{
if (mAttestationTrustStoreBridge != nullptr)
{
delete mAttestationTrustStoreBridge;
mAttestationTrustStoreBridge = nullptr;
}
}

void SetDeviceAttestationVerifier(chip::Credentials::DeviceAttestationVerifier * deviceAttestationVerifier)
{
mDeviceAttestationVerifier = deviceAttestationVerifier;
}

chip::Credentials::DeviceAttestationVerifier * GetDeviceAttestationVerifier() { return mDeviceAttestationVerifier; }

void ClearDeviceAttestationVerifier()
{
if (mDeviceAttestationVerifier != nullptr)
{
delete mDeviceAttestationVerifier;
mDeviceAttestationVerifier = nullptr;
}
}

private:
using ChipDeviceControllerPtr = std::unique_ptr<chip::Controller::DeviceCommissioner>;

Expand Down Expand Up @@ -232,7 +265,9 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel

chip::Credentials::PartialDACVerifier mPartialDACVerifier;

DeviceAttestationDelegateBridge * mDeviceAttestationDelegateBridge = nullptr;
DeviceAttestationDelegateBridge * mDeviceAttestationDelegateBridge = nullptr;
AttestationTrustStoreBridge * mAttestationTrustStoreBridge = nullptr;
chip::Credentials::DeviceAttestationVerifier * mDeviceAttestationVerifier = nullptr;

AndroidDeviceControllerWrapper(ChipDeviceControllerPtr controller,
#ifdef JAVA_MATTER_CONTROLLER_TEST
Expand Down
93 changes: 93 additions & 0 deletions src/controller/java/AttestationTrustStoreBridge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
*
* Copyright (c) 2023 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "AttestationTrustStoreBridge.h"
#include <credentials/CHIPCert.h>
#include <lib/support/CHIPJNIError.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/JniReferences.h>
#include <lib/support/JniTypeWrappers.h>
#include <lib/support/logging/CHIPLogging.h>

using namespace chip;

AttestationTrustStoreBridge::~AttestationTrustStoreBridge()
{
if (mAttestationTrustStoreDelegate != nullptr)
{
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread"));
env->DeleteGlobalRef(mAttestationTrustStoreDelegate);
mAttestationTrustStoreDelegate = nullptr;
}
}

CHIP_ERROR AttestationTrustStoreBridge::GetProductAttestationAuthorityCert(const chip::ByteSpan & skid,
chip::MutableByteSpan & outPaaDerBuffer) const
{
constexpr size_t paaCertAllocatedLen = chip::Credentials::kMaxDERCertLength;
Platform::ScopedMemoryBuffer<uint8_t> paaCert;
MutableByteSpan paaDerBuffer;

VerifyOrReturnError(paaCert.Alloc(paaCertAllocatedLen), CHIP_ERROR_NO_MEMORY);

VerifyOrReturnError(skid.size() == chip::Crypto::kSubjectKeyIdentifierLength, CHIP_ERROR_INVALID_ARGUMENT);

paaDerBuffer = MutableByteSpan(paaCert.Get(), paaCertAllocatedLen);
panliming-tuya marked this conversation as resolved.
Show resolved Hide resolved
ReturnErrorOnFailure(GetPaaCertFromJava(skid, paaDerBuffer));

uint8_t skidBuf[chip::Crypto::kSubjectKeyIdentifierLength] = { 0 };
chip::MutableByteSpan candidateSkidSpan{ skidBuf };
VerifyOrReturnError(CHIP_NO_ERROR == chip::Crypto::ExtractSKIDFromX509Cert(paaDerBuffer, candidateSkidSpan),
CHIP_ERROR_INTERNAL);

// Make sure the skid of the paa cert is match.
if (skid.data_equal(candidateSkidSpan))
{
// Found a match
return CopySpanToMutableSpan(paaDerBuffer, outPaaDerBuffer);
}
return CHIP_ERROR_CA_CERT_NOT_FOUND;
}

CHIP_ERROR AttestationTrustStoreBridge::GetPaaCertFromJava(const chip::ByteSpan & skid,
chip::MutableByteSpan & outPaaDerBuffer) const
{
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
jclass attestationTrustStoreDelegateCls = nullptr;
jbyteArray javaSkid = nullptr;
jmethodID getProductAttestationAuthorityCertMethod = nullptr;

JniReferences::GetInstance().GetClassRef(env, "chip/devicecontroller/AttestationTrustStoreDelegate",
panliming-tuya marked this conversation as resolved.
Show resolved Hide resolved
attestationTrustStoreDelegateCls);
VerifyOrReturnError(attestationTrustStoreDelegateCls != nullptr, CHIP_JNI_ERROR_TYPE_NOT_FOUND);
JniClass attestationTrustStoreDelegateJniCls(attestationTrustStoreDelegateCls);

JniReferences::GetInstance().FindMethod(env, mAttestationTrustStoreDelegate, "getProductAttestationAuthorityCert", "([B)[B",
&getProductAttestationAuthorityCertMethod);
VerifyOrReturnError(getProductAttestationAuthorityCertMethod != nullptr, CHIP_JNI_ERROR_METHOD_NOT_FOUND);

JniReferences::GetInstance().N2J_ByteArray(env, skid.data(), static_cast<jsize>(skid.size()), javaSkid);
VerifyOrReturnError(javaSkid != nullptr, CHIP_ERROR_NO_MEMORY);

jbyteArray javaPaaCert =
(jbyteArray) env->CallObjectMethod(mAttestationTrustStoreDelegate, getProductAttestationAuthorityCertMethod, javaSkid);
JniByteArray paaCertBytes(env, javaPaaCert);
CopySpanToMutableSpan(paaCertBytes.byteSpan(), outPaaDerBuffer);

return CHIP_NO_ERROR;
}
37 changes: 37 additions & 0 deletions src/controller/java/AttestationTrustStoreBridge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
*
* Copyright (c) 2023 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <credentials/attestation_verifier/DeviceAttestationVerifier.h>
#include <lib/support/JniReferences.h>
#include <vector>
panliming-tuya marked this conversation as resolved.
Show resolved Hide resolved

class AttestationTrustStoreBridge : public chip::Credentials::AttestationTrustStore
{
public:
AttestationTrustStoreBridge(jobject attestationTrustStoreDelegate) :
mAttestationTrustStoreDelegate(attestationTrustStoreDelegate)
{}
~AttestationTrustStoreBridge();

CHIP_ERROR GetProductAttestationAuthorityCert(const chip::ByteSpan & skid,
panliming-tuya marked this conversation as resolved.
Show resolved Hide resolved
chip::MutableByteSpan & outPaaDerBuffer) const override;

private:
panliming-tuya marked this conversation as resolved.
Show resolved Hide resolved
jobject mAttestationTrustStoreDelegate = nullptr;

CHIP_ERROR GetPaaCertFromJava(const chip::ByteSpan & skid, chip::MutableByteSpan & outPaaDerBuffer) const;
};
3 changes: 3 additions & 0 deletions src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ shared_library("jni") {
"AndroidDeviceControllerWrapper.h",
"AndroidOperationalCredentialsIssuer.cpp",
"AndroidOperationalCredentialsIssuer.h",
"AttestationTrustStoreBridge.cpp",
"AttestationTrustStoreBridge.h",
"BaseCHIPCluster-JNI.cpp",
"CHIPAttributeTLVValueDecoder.h",
"CHIPDefaultCallbacks.cpp",
Expand Down Expand Up @@ -104,6 +106,7 @@ android_library("java") {
"src/chip/clusterinfo/DelegatedClusterCallback.java",
"src/chip/clusterinfo/InteractionInfo.java",
"src/chip/devicecontroller/AttestationInfo.java",
"src/chip/devicecontroller/AttestationTrustStoreDelegate.java",
"src/chip/devicecontroller/CSRInfo.java",
"src/chip/devicecontroller/ChipClusterException.java",
"src/chip/devicecontroller/ChipCommandType.java",
Expand Down
63 changes: 63 additions & 0 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,37 @@ JNI_METHOD(void, setDeviceAttestationDelegate)
}
}

JNI_METHOD(void, setAttestationTrustStoreDelegate)
(JNIEnv * env, jobject self, jlong handle, jobject attestationTrustStoreDelegate)
{
chip::DeviceLayer::StackLock lock;
CHIP_ERROR err = CHIP_NO_ERROR;
AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle);

ChipLogProgress(Controller, "setAttestationTrustStoreDelegate() called");

if (attestationTrustStoreDelegate != nullptr)
{
wrapper->ClearAttestationTrustStoreBridge();
jobject attestationTrustStoreDelegateRef = env->NewGlobalRef(attestationTrustStoreDelegate);
wrapper->SetAttestationTrustStoreBridge(new AttestationTrustStoreBridge(attestationTrustStoreDelegateRef));
panliming-tuya marked this conversation as resolved.
Show resolved Hide resolved
VerifyOrExit(wrapper->GetAttestationTrustStoreBridge() != nullptr, err = CHIP_ERROR_NO_MEMORY);
panliming-tuya marked this conversation as resolved.
Show resolved Hide resolved

wrapper->ClearDeviceAttestationVerifier();
wrapper->SetDeviceAttestationVerifier(new Credentials::DefaultDACVerifier(wrapper->GetAttestationTrustStoreBridge()));
panliming-tuya marked this conversation as resolved.
Show resolved Hide resolved
VerifyOrExit(wrapper->GetDeviceAttestationVerifier() != nullptr, err = CHIP_ERROR_NO_MEMORY);

wrapper->Controller()->SetDeviceAttestationVerifier(wrapper->GetDeviceAttestationVerifier());
}

exit:
if (err != CHIP_NO_ERROR)
{
ChipLogError(Controller, "Failed to set device attestation delegate.");
JniReferences::GetInstance().ThrowError(env, sChipDeviceControllerExceptionCls, err);
}
}

JNI_METHOD(void, commissionDevice)
(JNIEnv * env, jobject self, jlong handle, jlong deviceId, jbyteArray csrNonce, jobject networkCredentials)
{
Expand Down Expand Up @@ -730,6 +761,38 @@ JNI_METHOD(jbyteArray, convertX509CertToMatterCert)
return outJbytes;
}

JNI_METHOD(jbyteArray, extractSkidFromPaaCert)
(JNIEnv * env, jobject self, jbyteArray paaCert)
{
uint32_t allocatedCertLength = chip::Credentials::kMaxCHIPCertLength;
chip::Platform::ScopedMemoryBuffer<uint8_t> outBuf;
jbyteArray outJbytes = nullptr;
JniByteArray paaCertBytes(env, paaCert);

CHIP_ERROR err = CHIP_NO_ERROR;
VerifyOrExit(outBuf.Alloc(allocatedCertLength), err = CHIP_ERROR_NO_MEMORY);
{
MutableByteSpan outBytes(outBuf.Get(), allocatedCertLength);

err = chip::Crypto::ExtractSKIDFromX509Cert(paaCertBytes.byteSpan(), outBytes);
SuccessOrExit(err);

VerifyOrExit(chip::CanCastTo<uint32_t>(outBytes.size()), err = CHIP_ERROR_INTERNAL);

err = JniReferences::GetInstance().N2J_ByteArray(env, outBytes.data(), static_cast<uint32_t>(outBytes.size()), outJbytes);
SuccessOrExit(err);
}

exit:
if (err != CHIP_NO_ERROR)
{
ChipLogError(Controller, "Failed to extract skid frome X509 cert. Err = %" CHIP_ERROR_FORMAT, err.Format());
JniReferences::GetInstance().ThrowError(env, sChipDeviceControllerExceptionCls, err);
}

return outJbytes;
}

JNI_METHOD(void, unpairDevice)(JNIEnv * env, jobject self, jlong handle, jlong deviceId)
{
chip::DeviceLayer::StackLock lock;
Expand Down
3 changes: 3 additions & 0 deletions src/controller/java/DeviceAttestationDelegateBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,14 @@ void DeviceAttestationDelegateBridge::OnDeviceAttestationCompleted(
env, "chip/devicecontroller/DeviceAttestationDelegate$DeviceAttestationCompletionCallback", completionCallbackCls);
VerifyOrReturn(completionCallbackCls != nullptr,
ChipLogError(Controller, "Could not find device attestation completion callback class."));
JniClass completionCallbackJniCls(completionCallbackCls);
yufengwangca marked this conversation as resolved.
Show resolved Hide resolved

jclass failureCallbackCls = nullptr;
JniReferences::GetInstance().GetClassRef(
env, "chip/devicecontroller/DeviceAttestationDelegate$DeviceAttestationFailureCallback", failureCallbackCls);
VerifyOrReturn(failureCallbackCls != nullptr,
ChipLogError(Controller, "Could not find device attestation failure callback class."));
JniClass failureCallbackJniCls(failureCallbackCls);
yufengwangca marked this conversation as resolved.
Show resolved Hide resolved

if (env->IsInstanceOf(mDeviceAttestationDelegate, completionCallbackCls))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package chip.devicecontroller;

import javax.annotation.Nullable;

/**
* Delegate for attestation trust store for device attestation verifiers.
*
* <p>API is synchronous. This implementation will replace the built-in attestation trust store,
* please make sure you have the required paa certificate before commissioning.
*/
public interface AttestationTrustStoreDelegate {
/**
* Look-up a product attestation authority (PAA) cert by subject key identifier (SKID).
*
* <p>The implementations of this interface must have access to a set of PAAs to trust.
*
* <p>Interface is synchronous, and therefore this should not be used unless to expose a PAA store
* that is both fully local and quick to access.
*
* @param skid Buffer containing the subject key identifier (SKID) of the PAA to look-up
* @return If found, the result should return paa cert in x.509 format, if not found, return null.
*/
@Nullable
byte[] getProductAttestationAuthorityCert(byte[] skid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ public void setDeviceAttestationFailureCallback(
setDeviceAttestationDelegate(deviceControllerPtr, failSafeExpiryTimeoutSecs, failureCallback);
}

/**
* Set delegate for attestation trust store for device attestation verifiers.
*
* <p>It will replace the built-in attestation trust store, please make sure you have the required
* paa certificate before commissioning.
*
* @param attestationTrustStoreDelegate Delegate for attestation trust store
*/
public void setAttestationTrustStoreDelegate(
AttestationTrustStoreDelegate attestationTrustStoreDelegate) {
setAttestationTrustStoreDelegate(deviceControllerPtr, attestationTrustStoreDelegate);
}

public void pairDevice(
BluetoothGatt bleServer,
int connId,
Expand Down Expand Up @@ -626,6 +639,14 @@ public void readPath(
*/
public native byte[] convertX509CertToMatterCert(byte[] x509Cert);

/**
* Extract skid from paa cert.
*
panliming-tuya marked this conversation as resolved.
Show resolved Hide resolved
* @param paaCert The product attestation authority (PAA) cert
* @return The subject key identifier (SKID)
*/
public native byte[] extractSkidFromPaaCert(byte[] paaCert);

/**
* Generates a new PASE verifier for the given setup PIN code.
*
Expand Down Expand Up @@ -670,6 +691,9 @@ private native void read(
private native void setDeviceAttestationDelegate(
long deviceControllerPtr, int failSafeExpiryTimeoutSecs, DeviceAttestationDelegate delegate);

private native void setAttestationTrustStoreDelegate(
long deviceControllerPtr, AttestationTrustStoreDelegate delegate);

private native void pairDevice(
long deviceControllerPtr,
long deviceId,
Expand Down