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

Adding preprocessor checks before using DevelopmentCerts:kDac* constants #25467

Closed

Conversation

sharadb-amazon
Copy link
Contributor

@sharadb-amazon sharadb-amazon commented Mar 3, 2023

Fixes #25388

Change summary

This change adds a necessary preprocessor check in src/credentials/examples/DeviceAttestationCredsExample.cpp to allow the code to build if CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID is set to a value outside of the range of test values i.e. [0x8000, 0x801F]. (see src/credentials/examples/ExampleDACs.cpp) If we do not make this change, we end up with compilation failures like this when building an app (say the tv-casting-app) if the product id is outside the test range:

Undefined symbols for architecture arm64:
  "chip::DevelopmentCerts::kDacPublicKey", referenced from:
      chip::Credentials::Examples::(anonymous namespace)::ExampleDACProvider::SignWithDeviceAttestationKey(chip::Span<unsigned char const> const&, chip::Span<unsigned char>&) in libTvCastingCommon.a(libCredentials.DeviceAttestationCredsExample.cpp.o)
  "chip::DevelopmentCerts::kDacPrivateKey", referenced from:
      chip::Credentials::Examples::(anonymous namespace)::ExampleDACProvider::SignWithDeviceAttestationKey(chip::Span<unsigned char const> const&, chip::Span<unsigned char>&) in libTvCastingCommon.a(libCredentials.DeviceAttestationCredsExample.cpp.o)
  "chip::DevelopmentCerts::kDacCert", referenced from:
      chip::Credentials::Examples::(anonymous namespace)::ExampleDACProvider::GetDeviceAttestationCert(chip::Span<unsigned char>&) in libTvCastingCommon.a(libCredentials.DeviceAttestationCredsExample.cpp.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Testing

Successfully able to build the tv-casting-app with a CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID set to a value outside the range of test values, like 0x7FFF.

@@ -52,7 +52,11 @@ class ExampleDACProvider : public DeviceAttestationCredentialsProvider

CHIP_ERROR ExampleDACProvider::GetDeviceAttestationCert(MutableByteSpan & out_dac_buffer)
{
#if 0x8000 <= CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID && CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID <= 0x801F
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of hardcoding the 0x8000 here, can we define the CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID_MIN/MAX or something in the ExampleDACs.h file?

It'd be nicer to have the control of the range specified close to where they're defined otherwise if we add additional product identifiers here you'd need to know to look at this spot too otherwise it won't work and you'd be wondering why

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, wouldn't it be better to simply add a GN switch not to compile ExampleDACProvider if you use a non-default product ID? This class is only for test purposes so it shouldn't be used if you have your own DAC. Btw, why is the linker error occuring? Is ExampleDACProvider instantiated in your application? Wouldn't removing ExampleDACProvider from the application be enough to resolve it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, in this PR: #25953

Closing this one.

Copy link
Contributor

@andy31415 andy31415 left a comment

Choose a reason for hiding this comment

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

It seems like this should be some GN compile flag deciding if example is compiled in or not. I.e. compilation should just not try to compile in instead of getting some link error.

@pullapprove pullapprove bot requested review from joonhaengHeo and younghak-hwang and removed request for pjzander-signify March 14, 2023 17:35
@sharadb-amazon
Copy link
Contributor Author

It seems like this should be some GN compile flag deciding if example is compiled in or not. I.e. compilation should just not try to compile in instead of getting some link error.

Done, in this PR: #25953

Closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Compilation error on defining CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID outside test value range
4 participants