Skip to content

Commit 8a0cb64

Browse files
luoji-nxp“nxf90552”
authored and
“nxf90552”
committed
Support device attestation based on Trusty OS
read all device attestation credentials from secure storage which is managed by TEE (Trusty OS), all credentials should be provisioned in bootloader stage. Change-Id: I59f144b92c3dfde2ab167d9f0f7f62508ed47354 Signed-off-by: Ji Luo <ji.luo@nxp.com> Reviewed-on: http://androidsource.nxp.com/project/21250 Reviewed-by: Elven Wang <elven.wang@nxp.com> Reviewed-on: http://androidsource.nxp.com/project/23004
1 parent 7815166 commit 8a0cb64

File tree

5 files changed

+196
-0
lines changed

5 files changed

+196
-0
lines changed

examples/platform/linux/AppMain.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@
126126
#include <platform/Linux/NetworkCommissioningDriver.h>
127127
#endif // CHIP_DEVICE_LAYER_TARGET_LINUX
128128

129+
#if CHIP_ATTESTATION_TRUSTY_OS
130+
#include "DeviceAttestationCreds.h"
131+
using namespace chip::Credentials::Trusty;
132+
#endif
133+
129134
using namespace chip;
130135
using namespace chip::ArgParser;
131136
using namespace chip::Credentials;
@@ -710,7 +715,11 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)
710715
PrintOnboardingCodes(LinuxDeviceOptions::GetInstance().payload);
711716

712717
// Initialize device attestation config
718+
#if CHIP_ATTESTATION_TRUSTY_OS
719+
SetDeviceAttestationCredentialsProvider(&TrustyDACProvider::GetTrustyDACProvider());
720+
#else
713721
SetDeviceAttestationCredentialsProvider(LinuxDeviceOptions::GetInstance().dacProvider);
722+
#endif
714723

715724
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
716725
ChipLogProgress(AppServer, "Starting commissioner");

examples/platform/linux/BUILD.gn

+18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import("${chip_root}/src/app/icd/icd.gni")
1919
import("${chip_root}/src/lib/core/core.gni")
2020
import("${chip_root}/src/lib/lib.gni")
2121
import("${chip_root}/src/tracing/tracing_args.gni")
22+
import("${chip_root}/src/lib/trusty.gni")
2223

2324
if (current_os != "nuttx") {
2425
import("//build_overrides/jsoncpp.gni")
@@ -96,6 +97,13 @@ source_set("app-main") {
9697
"testing/CustomCSRResponseOperationalKeyStore.h",
9798
]
9899

100+
if (chip_with_trusty_os == 1) {
101+
sources += [
102+
"DeviceAttestationCreds.cpp",
103+
"DeviceAttestationCreds.h",
104+
]
105+
}
106+
99107
public_deps = [
100108
":boolean-state-configuration-test-event-trigger",
101109
":commissioner-main",
@@ -122,6 +130,16 @@ source_set("app-main") {
122130
public_deps += [ jsoncpp_root ]
123131
}
124132

133+
if (chip_with_trusty_os == 1) {
134+
public_deps += [ "${chip_root}/third_party/libtrustymatter" ]
135+
}
136+
137+
if (chip_with_trusty_os == 1) {
138+
defines += [ "CHIP_ATTESTATION_TRUSTY_OS=1" ]
139+
} else {
140+
defines += [ "CHIP_ATTESTATION_TRUSTY_OS=0" ]
141+
}
142+
125143
if (chip_enable_pw_rpc) {
126144
defines += [ "PW_RPC_ENABLED" ]
127145
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
*
3+
* Copyright (c) 2021-2022 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
* Copyright 2023 NXP
18+
*/
19+
#include "DeviceAttestationCreds.h"
20+
21+
#include <crypto/CHIPCryptoPAL.h>
22+
#include <lib/core/CHIPError.h>
23+
#include <lib/support/Span.h>
24+
#include <trusty_matter.h>
25+
26+
using namespace matter;
27+
28+
namespace chip {
29+
namespace Credentials {
30+
namespace Trusty {
31+
32+
CHIP_ERROR TrustyDACProvider::GetDeviceAttestationCert(MutableByteSpan & out_dac_buffer)
33+
{
34+
size_t out_size = 0;
35+
int rc;
36+
37+
rc = trusty_matter.ExportDACCert(out_dac_buffer.data(), out_dac_buffer.size(), out_size);
38+
if (rc == 0) {
39+
out_dac_buffer.reduce_size(out_size);
40+
return CHIP_NO_ERROR;
41+
} else
42+
return CHIP_ERROR_CERT_LOAD_FAILED;
43+
}
44+
45+
CHIP_ERROR TrustyDACProvider::GetProductAttestationIntermediateCert(MutableByteSpan & out_pai_buffer)
46+
{
47+
size_t out_size = 0;
48+
int rc;
49+
50+
rc = trusty_matter.ExportPAICert(out_pai_buffer.data(), out_pai_buffer.size(), out_size);
51+
if (rc == 0) {
52+
out_pai_buffer.reduce_size(out_size);
53+
return CHIP_NO_ERROR;
54+
} else
55+
return CHIP_ERROR_CERT_LOAD_FAILED;
56+
}
57+
58+
CHIP_ERROR TrustyDACProvider::GetCertificationDeclaration(MutableByteSpan & out_cd_buffer)
59+
{
60+
size_t out_size = 0;
61+
int rc;
62+
63+
rc = trusty_matter.ExportCDCert(out_cd_buffer.data(), out_cd_buffer.size(), out_size);
64+
if (rc == 0) {
65+
out_cd_buffer.reduce_size(out_size);
66+
return CHIP_NO_ERROR;
67+
} else
68+
return CHIP_ERROR_CERT_LOAD_FAILED;
69+
}
70+
71+
CHIP_ERROR TrustyDACProvider::GetFirmwareInformation(MutableByteSpan & out_firmware_info_buffer)
72+
{
73+
// TODO: We need a real example FirmwareInformation to be populated.
74+
out_firmware_info_buffer.reduce_size(0);
75+
76+
return CHIP_NO_ERROR;
77+
}
78+
79+
CHIP_ERROR TrustyDACProvider::SignWithDeviceAttestationKey(const ByteSpan & message_to_sign,
80+
MutableByteSpan & out_signature_buffer)
81+
{
82+
int rc = 0;
83+
size_t out_size = 0;
84+
85+
VerifyOrReturnError(IsSpanUsable(out_signature_buffer), CHIP_ERROR_INVALID_ARGUMENT);
86+
VerifyOrReturnError(IsSpanUsable(message_to_sign), CHIP_ERROR_INVALID_ARGUMENT);
87+
88+
rc = trusty_matter.SignWithDACKey(message_to_sign.data(), message_to_sign.size(),
89+
out_signature_buffer.data(), out_signature_buffer.size(), out_size);
90+
if (rc == 0) {
91+
out_signature_buffer.reduce_size(out_size);
92+
return CHIP_NO_ERROR;
93+
} else
94+
return CHIP_ERROR_CERT_LOAD_FAILED;
95+
}
96+
97+
TrustyDACProvider & TrustyDACProvider::GetTrustyDACProvider()
98+
{
99+
static TrustyDACProvider trusty_dac_provider;
100+
101+
return trusty_dac_provider;
102+
}
103+
104+
} // namespace Trusty
105+
} // namespace Credentials
106+
} // namespace chip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2023 NXP
3+
*
4+
* Copyright (c) 2021 Project CHIP Authors
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
#pragma once
19+
20+
#include <credentials/DeviceAttestationCredsProvider.h>
21+
#include <trusty_matter.h>
22+
23+
using namespace matter;
24+
25+
namespace chip {
26+
namespace Credentials {
27+
namespace Trusty {
28+
29+
class TrustyDACProvider : public DeviceAttestationCredentialsProvider
30+
{
31+
public:
32+
static TrustyDACProvider & GetTrustyDACProvider();
33+
34+
CHIP_ERROR GetCertificationDeclaration(MutableByteSpan & out_cd_buffer) override;
35+
CHIP_ERROR GetFirmwareInformation(MutableByteSpan & out_firmware_info_buffer) override;
36+
CHIP_ERROR GetDeviceAttestationCert(MutableByteSpan & out_dac_buffer) override;
37+
CHIP_ERROR GetProductAttestationIntermediateCert(MutableByteSpan & out_pai_buffer) override;
38+
CHIP_ERROR SignWithDeviceAttestationKey(const ByteSpan & message_to_sign, MutableByteSpan & out_signature_buffer) override;
39+
40+
private:
41+
TrustyMatter trusty_matter;
42+
};
43+
44+
} // namespace Trusty
45+
} // namespace Credentials
46+
} // namespace chip

src/lib/trusty.gni

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2023 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
declare_args() {
16+
chip_with_trusty_os = 0
17+
}

0 commit comments

Comments
 (0)