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

[SE05x] Logic to track signature calls for attestation is removed #23207

Merged
Merged
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7231c11
added readme for se05x example
sujaygkulkarni-nxp Oct 11, 2022
b74254a
changed device attestation - Logic to track attestation calls removed
sujaygkulkarni-nxp Oct 11, 2022
002d15e
updated simw build files
sujaygkulkarni-nxp Oct 11, 2022
1ba6a90
reverting changes
sujaygkulkarni-nxp Oct 11, 2022
f37cac5
reverting changes
sujaygkulkarni-nxp Oct 11, 2022
8e71d94
using chip_device_platform
sujaygkulkarni-nxp Oct 11, 2022
10044e2
updated simw package repo
sujaygkulkarni-nxp Oct 16, 2022
7ac71a6
restyler-diff
sujaygkulkarni-nxp Oct 16, 2022
fe6df6b
restyler-diff
sujaygkulkarni-nxp Oct 16, 2022
f20f459
Merge branch 'project-chip:master' into feature/se05x-t4t-support
sujaygkulkarni-nxp Oct 16, 2022
02ea2de
updated simw-repo submodule
sujaygkulkarni-nxp Oct 17, 2022
c8aafde
updated device attestation provider to handle TLV errors
sujaygkulkarni-nxp Oct 21, 2022
68001b8
Merge branch 'project-chip:master' into feature/se05x-t4t-support
sujaygkulkarni-nxp Oct 21, 2022
bb6be75
removed extra semicolon
sujaygkulkarni-nxp Oct 22, 2022
d5f853c
updated comments in DAC provider
sujaygkulkarni-nxp Oct 22, 2022
df6e526
making only TAG3 optional
sujaygkulkarni-nxp Oct 22, 2022
23c796f
spell check
sujaygkulkarni-nxp Oct 22, 2022
4ac60ce
updated comments
sujaygkulkarni-nxp Oct 22, 2022
f98c799
Update examples/platform/nxp/se05x/DeviceAttestationSe05xCredsExample…
sujaygkulkarni-nxp Oct 25, 2022
cc53d45
Merge branch 'master' into feature/se05x-t4t-support
sujaygkulkarni-nxp Oct 25, 2022
ccb2cb2
restyle-diff
sujaygkulkarni-nxp Oct 25, 2022
c2869e5
Merge branch 'master' into feature/se05x-t4t-support
sujaygkulkarni-nxp Oct 26, 2022
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
179 changes: 75 additions & 104 deletions examples/platform/nxp/se05x/DeviceAttestationSe05xCredsExample_v2.cpp
Original file line number Diff line number Diff line change
@@ -37,23 +37,25 @@
/* Device attestation key ids */
#define DEV_ATTESTATION_KEY_SE05X_ID 0x7D300000
#define DEV_ATTESTATION_CERT_SE05X_ID 0x7D300001
#define CERT_DECLARATION_DATA_SE05X_ID 0x7D300002

/* Device attestation key ids (Used with internal sign) */
#define CD_DEV_ATTESTATION_KEY_SE05X_ID 0x7D300002
#define NOCSR_DEV_ATTESTATION_KEY_SE05X_ID 0x7D300004

/* Device attestation data ids (for Cert decl) */
#define CD_CERT_DECLARATION_DATA_SE05X_ID 0x7D300009
#define CD_ATTEST_NONCE_DATA_SE05X_ID 0x7D30000C
#define CD_TIME_STAMP_LEN_SE05X_ID 0x7D30000E
#define CD_TIME_STAMP_DATA_SE05X_ID 0x7D30000F
#define CD_ATTEST_CHALLENGE_SE05X_ID 0x7D300011

/* Device attestation data ids (for CSR) */
#define NOCSR_CSR_LEN_SE05X_ID 0x7D300014
#define NOCSR_CSR_DATA_SE05X_ID 0x7D300015
#define NOCSR_CSR_NONCE_DATA_SE05X_ID 0x7D300018
#define NOCSR_ATTEST_CHALLENGE_SE05X_ID 0x7D30001A
#define DEV_ATTESTATION_KEY_SE05X_ID_IS 0x7D300003
#define DEV_ATTESTATION_KEY_SE05X_ID_IS_TBS 0x7D300004

#define TAG1_ID 0x7D300005
#define TAG1_LEN_ID 0x7D300006
#define TAG1_VALUE_ID 0x7D300007
#define TAG2_ID 0x7D300008
#define TAG2_LEN_ID 0x7D300009
#define TAG2_VALUE_ID 0x7D30000A
#define TAG3_ID 0x7D30000B
#define TAG3_LEN_ID 0x7D30000C
#define TAG3_VALUE_ID 0x7D30000D
#define ATTEST_CHALLENGE_ID 0x7D30000E

#define START_CONTAINER_SE05X_ID 0x7D30000F
#define END_CONTAINER_SE05X_ID 0x7D300010

extern CHIP_ERROR se05xGetCertificate(uint32_t keyId, uint8_t * buf, size_t * buflen);
extern CHIP_ERROR se05xSetCertificate(uint32_t keyId, const uint8_t * buf, size_t buflen);
@@ -150,7 +152,7 @@ CHIP_ERROR ExampleSe05xDACProviderv2::GetCertificationDeclaration(MutableByteSpa
#else
size_t buflen = out_cd_buffer.size();
ChipLogDetail(Crypto, "Get certificate declaration from se05x");
ReturnErrorOnFailure(se05xGetCertificate(CD_CERT_DECLARATION_DATA_SE05X_ID, out_cd_buffer.data(), &buflen));
ReturnErrorOnFailure(se05xGetCertificate(CERT_DECLARATION_DATA_SE05X_ID, out_cd_buffer.data(), &buflen));
out_cd_buffer.reduce_size(buflen);
return CHIP_NO_ERROR;
#endif
@@ -178,108 +180,77 @@ CHIP_ERROR ExampleSe05xDACProviderv2::SignWithDeviceAttestationKey(const ByteSpa

msg_reader.Init(message_to_sign);

/* To be removed. Use common key id to sign message */
static bool sign_cert_decl_attest = 1;

if (sign_cert_decl_attest)
{
/* Check if certificate declaration tag is present and Skip certificate declaration tag */
ReturnErrorOnFailure(TLV::Utilities::Find(msg_reader, TLV::ContextTag(1), tagReader));

ReturnErrorOnFailure(TLV::Utilities::Find(msg_reader, TLV::ContextTag(2), tagReader));
uint8_t attlen = tagReader.GetLength();
VerifyOrReturnError(attlen > 0, CHIP_ERROR_INVALID_TLV_TAG);
/* Get attestation nonce */
ByteSpan attest_nonce;
ReturnErrorOnFailure(tagReader.Get(attest_nonce));
/* Set attestation nonce */
VerifyOrReturnError(CHIP_NO_ERROR ==
se05xSetCertificate(CD_ATTEST_NONCE_DATA_SE05X_ID, attest_nonce.data(), attest_nonce.size()),
CHIP_ERROR_INTERNAL);
uint16_t taglen = 0;
ByteSpan tagvalue;
uint8_t tempBuf[2] = {
0,
};

ReturnErrorOnFailure(TLV::Utilities::Find(msg_reader, TLV::ContextTag(3), tagReader));
uint8_t tslen = tagReader.GetLength();
if (tslen > 0)
{
ByteSpan time_stamp;
ReturnErrorOnFailure(tagReader.Get(time_stamp));
/* Set time stamp data */
VerifyOrReturnError(CHIP_NO_ERROR ==
se05xSetCertificate(CD_TIME_STAMP_DATA_SE05X_ID, time_stamp.data(), time_stamp.size()),
CHIP_ERROR_INTERNAL);
}
/* Set time stamp length */
VerifyOrReturnError(CHIP_NO_ERROR == se05xSetCertificate(CD_TIME_STAMP_LEN_SE05X_ID, &tslen, 1), CHIP_ERROR_INTERNAL);
tempBuf[0] = (uint8_t) TLV::TLVElementType::Structure;
VerifyOrReturnError(CHIP_NO_ERROR == se05xSetCertificate(START_CONTAINER_SE05X_ID, tempBuf, 1), CHIP_ERROR_INTERNAL);

if ((tagReader.GetRemainingLength() + 1 /* End container */) >= 16)
for (int i = 1; i <= 3; i++)
{
if (TLV::Utilities::Find(msg_reader, TLV::ContextTag(i), tagReader) == CHIP_NO_ERROR)
{
/* Set attestation challenge */
VerifyOrReturnError(CHIP_NO_ERROR ==
se05xSetCertificate(CD_ATTEST_CHALLENGE_SE05X_ID, (message_to_sign.end() - 16), 16),
CHIP_ERROR_INTERNAL);
taglen = tagReader.GetLength();
tempBuf[0] = tagReader.GetControlByte();
;
tempBuf[1] = i;
VerifyOrReturnError(CHIP_NO_ERROR == se05xSetCertificate(TAG1_ID + (3 * (i - 1)), tempBuf, 2), CHIP_ERROR_INTERNAL);
if (taglen > 256)
{
tempBuf[0] = taglen & 0xFF;
tempBuf[1] = (taglen >> 8) & 0xFF;
VerifyOrReturnError(CHIP_NO_ERROR == se05xSetCertificate(TAG1_LEN_ID + (3 * (i - 1)), tempBuf, 2),
CHIP_ERROR_INTERNAL);
}
else
{
tempBuf[0] = taglen;
VerifyOrReturnError(CHIP_NO_ERROR == se05xSetCertificate(TAG1_LEN_ID + (3 * (i - 1)), tempBuf, 1),
CHIP_ERROR_INTERNAL);
}
if (taglen > 0)
{
ReturnErrorOnFailure(tagReader.Get(tagvalue));
VerifyOrReturnError(CHIP_NO_ERROR == se05xSetCertificate(TAG1_VALUE_ID + (3 * (i - 1)), tagvalue.data(), taglen),
CHIP_ERROR_INTERNAL);
}
}
}
else
{
ReturnErrorOnFailure(TLV::Utilities::Find(msg_reader, TLV::ContextTag(1), tagReader));
uint8_t csrlen = tagReader.GetLength();
VerifyOrReturnError(csrlen > 0, CHIP_ERROR_INVALID_TLV_TAG);
ByteSpan csr_data;
/* Get nocsr */
ReturnErrorOnFailure(tagReader.Get(csr_data));
/* Set nocsr length */
VerifyOrReturnError(CHIP_NO_ERROR == se05xSetCertificate(NOCSR_CSR_LEN_SE05X_ID, &csrlen, 1), CHIP_ERROR_INTERNAL);
/* Set nocsr data */
se05x_delete_key(NOCSR_CSR_DATA_SE05X_ID);
VerifyOrReturnError(CHIP_NO_ERROR == se05xSetCertificate(NOCSR_CSR_DATA_SE05X_ID, csr_data.data(), csr_data.size()),
CHIP_ERROR_INTERNAL);

ReturnErrorOnFailure(TLV::Utilities::Find(msg_reader, TLV::ContextTag(2), tagReader));
uint8_t noncelen = tagReader.GetLength();
VerifyOrReturnError(noncelen > 0, CHIP_ERROR_INVALID_TLV_TAG);
/* Get nocsr nonce */
ByteSpan nocsr_nonce;
ReturnErrorOnFailure(tagReader.Get(nocsr_nonce));
/* Set nocsr nonce data */
VerifyOrReturnError(CHIP_NO_ERROR ==
se05xSetCertificate(NOCSR_CSR_NONCE_DATA_SE05X_ID, nocsr_nonce.data(), nocsr_nonce.size()),
CHIP_ERROR_INTERNAL);
tempBuf[0] = (uint8_t) TLV::TLVElementType::EndOfContainer;
VerifyOrReturnError(CHIP_NO_ERROR == se05xSetCertificate(END_CONTAINER_SE05X_ID, tempBuf, 1), CHIP_ERROR_INTERNAL);

if ((tagReader.GetRemainingLength() + 1 /* End container */) >= 16)
{
/* Set attestation challenge */
VerifyOrReturnError(CHIP_NO_ERROR ==
se05xSetCertificate(NOCSR_ATTEST_CHALLENGE_SE05X_ID, (message_to_sign.end() - 16), 16),
CHIP_ERROR_INTERNAL);
}
if ((tagReader.GetRemainingLength() + 1 /* End container */) >= 16)
{
/* Set attestation challenge */
VerifyOrReturnError(CHIP_NO_ERROR == se05xSetCertificate(ATTEST_CHALLENGE_ID, (message_to_sign.end() - 16), 16),
CHIP_ERROR_INTERNAL);
}

uint8_t signature_se05x[Crypto::kMax_ECDSA_Signature_Length_Der] = { 0 };
size_t signature_se05x_len = sizeof(signature_se05x);

if (sign_cert_decl_attest)
{
err = se05xPerformInternalSign(CD_DEV_ATTESTATION_KEY_SE05X_ID, signature_se05x, &signature_se05x_len);
se05x_delete_key(CD_ATTEST_NONCE_DATA_SE05X_ID);
se05x_delete_key(CD_TIME_STAMP_LEN_SE05X_ID);
se05x_delete_key(CD_TIME_STAMP_DATA_SE05X_ID);
se05x_delete_key(CD_ATTEST_CHALLENGE_SE05X_ID);
sign_cert_decl_attest = 0;
}
else
{
err = se05xPerformInternalSign(NOCSR_DEV_ATTESTATION_KEY_SE05X_ID, signature_se05x, &signature_se05x_len);
se05x_delete_key(NOCSR_CSR_LEN_SE05X_ID);
se05x_delete_key(NOCSR_CSR_DATA_SE05X_ID);
se05x_delete_key(NOCSR_CSR_NONCE_DATA_SE05X_ID);
se05x_delete_key(NOCSR_ATTEST_CHALLENGE_SE05X_ID);
sign_cert_decl_attest = 1;
}

err = se05xPerformInternalSign(DEV_ATTESTATION_KEY_SE05X_ID_IS, signature_se05x, &signature_se05x_len);
ReturnErrorOnFailure(err);

return chip::Crypto::EcdsaAsn1SignatureToRaw(chip::Crypto::kP256_FE_Length, ByteSpan{ signature_se05x, signature_se05x_len },
out_signature_buffer);
err = chip::Crypto::EcdsaAsn1SignatureToRaw(chip::Crypto::kP256_FE_Length, ByteSpan{ signature_se05x, signature_se05x_len },
out_signature_buffer);

se05x_delete_key(TAG1_ID);
se05x_delete_key(TAG1_LEN_ID);
se05x_delete_key(TAG1_VALUE_ID);
se05x_delete_key(TAG2_ID);
se05x_delete_key(TAG2_LEN_ID);
se05x_delete_key(TAG2_VALUE_ID);
se05x_delete_key(TAG3_ID);
se05x_delete_key(TAG3_LEN_ID);
se05x_delete_key(TAG3_VALUE_ID);
se05x_delete_key(ATTEST_CHALLENGE_ID);

return err;
}

} // namespace
5 changes: 5 additions & 0 deletions examples/platform/nxp/se05x/linux/AppMain.cpp
Original file line number Diff line number Diff line change
@@ -78,6 +78,7 @@

#if CHIP_CRYPTO_HSM
#include "DeviceAttestationSe05xCredsExample.h"
#include "se05x_t4t_utils.h"
#include <crypto/hsm/CHIPCryptoPALHsm.h>
#include <crypto/hsm/nxp/PersistentStorageOperationalKeystoreHSM.h>
#endif
@@ -367,6 +368,10 @@ void ChipLinuxAppMainLoop()
#else
static chip::CommonCaseDeviceServerInitParams initParams;
#endif

#if CHIP_CRYPTO_HSM
VerifyOrDie(se05x_enable_contactless_interface() == 0);
#endif
VerifyOrDie(initParams.InitializeStaticResourcesBeforeServerInit() == CHIP_NO_ERROR);

#if defined(ENABLE_CHIP_SHELL)
4 changes: 4 additions & 0 deletions examples/thermostat/nxp/linux-se05x/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
To cross-compile this example on x64 host and run on **NXP i.MX 8M Mini**
**EVK**, see the associated
[README document](../../../../../docs/guides/nxp_imx8m_linux_examples.md) for
details.
1 change: 0 additions & 1 deletion examples/thermostat/nxp/linux-se05x/args.gni
Original file line number Diff line number Diff line change
@@ -15,4 +15,3 @@
import("//build_overrides/chip.gni")
import("${chip_root}/config/standalone/args.gni")
chip_with_se05x = 1
host = "host_linux"
14 changes: 10 additions & 4 deletions third_party/simw-top-mini/BUILD.gn
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
# limitations under the License.

import("//build_overrides/chip.gni")
import("${chip_root}/src/platform/device.gni")
import("${chip_root}/third_party/simw-top-mini/simw_config.gni")

config("se05x_config") {
@@ -26,14 +27,18 @@ config("se05x_config") {

#defines += ["FLOW_VERBOSE"]

if (host == "host_k32w") {
if (chip_device_platform == "k32w0") {
defines += [
"AX_EMBEDDED",
"LPC_K32W",
"SDK_OS_FREE_RTOS=1",
]
}

if (chip_rpi_se05x_t4t_demo == 1) {
defines += [ "CHIP_RPI_SE05X_T4T_DEMO" ]
}

include_dirs = [
"${chip_root}/third_party/simw-top-mini/repo",
"${chip_root}/third_party/simw-top-mini/repo/sss/inc",
@@ -49,7 +54,7 @@ config("se05x_config") {
"${chip_root}/third_party/simw-top-mini/repo/hostlib/hostLib/platform/inc",
"${chip_root}/third_party/simw-top-mini/repo/hostlib/hostLib/libCommon/smCom",
]
if (host == "host_k32w") {
if (chip_device_platform == "k32w0") {
include_dirs += [
"${chip_root}/third_party/simw-top-mini/repo/demos/ksdk/common/boards/DK6/wireless_examples/chip",
"${chip_root}/third_party/simw-top-mini/repo/demos/ksdk/common/freertos/boards/DK6",
@@ -66,6 +71,7 @@ source_set("se05x") {
"${chip_root}/third_party/simw-top-mini/repo/hostlib/hostLib/libCommon/infra/sm_printf.c",
"${chip_root}/third_party/simw-top-mini/repo/hostlib/hostLib/libCommon/log/nxLog.c",
"${chip_root}/third_party/simw-top-mini/repo/hostlib/hostLib/libCommon/smCom/smCom.c",
"${chip_root}/third_party/simw-top-mini/repo/hostlib/hostLib/platform/generic/se05x_t4t_utils.cpp",
"${chip_root}/third_party/simw-top-mini/repo/hostlib/hostLib/platform/rsp/se05x_reset.c",
"${chip_root}/third_party/simw-top-mini/repo/hostlib/hostLib/se05x/src/se05x_ECC_curves.c",
"${chip_root}/third_party/simw-top-mini/repo/hostlib/hostLib/se05x/src/se05x_mw.c",
@@ -93,12 +99,12 @@ source_set("se05x") {
"${chip_root}/third_party/simw-top-mini/repo/hostlib/hostLib/libCommon/smCom/smComT1oI2C.c",
]

if (host == "host_k32w") {
if (chip_device_platform == "k32w0") {
sources += [
"${chip_root}/third_party/simw-top-mini/repo/hostlib/hostLib/platform/ksdk/i2c_dk6.c",
"${chip_root}/third_party/simw-top-mini/repo/hostlib/hostLib/platform/ksdk/timer_kinetis_freertos.c",
]
} else if (host == "host_linux") {
} else if (chip_device_platform == "linux") {
sources += [
"${chip_root}/third_party/simw-top-mini/repo/hostlib/hostLib/platform/generic/sm_timer.c",
"${chip_root}/third_party/simw-top-mini/repo/hostlib/hostLib/platform/linux/i2c_a7.c",
3 changes: 1 addition & 2 deletions third_party/simw-top-mini/simw_config.gni
Original file line number Diff line number Diff line change
@@ -15,6 +15,5 @@
# Configuration file

declare_args() {
# possible values host_k32w, host_linux
host = "host_k32w"
chip_rpi_se05x_t4t_demo = 0
}