Skip to content

Commit

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

Fixes project-chip#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()`.
  • Loading branch information
kpschoedel committed Aug 5, 2022
1 parent 135017a commit ec195d8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 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,12 @@ 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 +114,9 @@ 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 ec195d8

Please sign in to comment.