Skip to content

Commit

Permalink
chip-tool: add more flexibility in PAA root folder selection (#21691)
Browse files Browse the repository at this point in the history
* chip-tool: add more flexibility in PAA root folder selection

#### Problem

Fixes #21681 chip-tool: add more flexibility in PAA root folder selection

#### Change overview

If `--paa-trust-store-path` is not given, and the environment variable
`CHIPTOOL_PAA_TRUST_STORE_PATH` exists, use its value.

#### Testing

Manual confirmation of the logged `mPaaTrustStorePath.Value()`.

* restyled
  • Loading branch information
kpschoedel authored and pull[bot] committed Jul 19, 2023
1 parent 9b0cbb3 commit 1169447
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions examples/chip-tool/commands/common/CHIPCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ constexpr chip::FabricId kIdentityAlphaFabricId = 1;
constexpr chip::FabricId kIdentityBetaFabricId = 2;
constexpr chip::FabricId kIdentityGammaFabricId = 3;
constexpr chip::FabricId kIdentityOtherFabricId = 4;
constexpr const char * kTrustStorePathVariable = "CHIPTOOL_PAA_TRUST_STORE_PATH";

namespace {
const chip::Credentials::AttestationTrustStore * GetTestFileAttestationTrustStore(const char * paaTrustStorePath)
Expand Down Expand Up @@ -99,6 +100,14 @@ CHIP_ERROR CHIPCommand::MaybeSetUpStack()
factoryInitParams.listenPort = port;
ReturnLogErrorOnFailure(DeviceControllerFactory::GetInstance().Init(factoryInitParams));

if (!mPaaTrustStorePath.HasValue())
{
char * const trust_store_path = getenv(kTrustStorePathVariable);
if (trust_store_path != nullptr)
{
mPaaTrustStorePath.SetValue(trust_store_path);
}
}
const chip::Credentials::AttestationTrustStore * trustStore = mPaaTrustStorePath.HasValue()
? GetTestFileAttestationTrustStore(mPaaTrustStorePath.Value())
: chip::Credentials::GetTestAttestationTrustStore();
Expand All @@ -107,9 +116,10 @@ CHIP_ERROR CHIPCommand::MaybeSetUpStack()
{
ChipLogError(chipTool, "No PAAs found in path: %s", mPaaTrustStorePath.Value());
ChipLogError(chipTool,
"Please specify a valid path containing trusted PAA certificates using [--paa-trust-store-path paa/file/path] "
"argument");

"Please specify a valid path containing trusted PAA certificates using"
"the argument [--paa-trust-store-path paa/file/path]"
"or environment variable [%s=paa/file/path]",
kTrustStorePathVariable);
return CHIP_ERROR_INVALID_ARGUMENT;
}

Expand Down

0 comments on commit 1169447

Please sign in to comment.