Skip to content

Commit 96c9357

Browse files
emargolisgharveymnturonvivien-appletcarmelveilleux
authored
[SVE2] Cherry Pick Matter Official CDs and CD Trusted Storage Implementation (#23239)
* Add missing pthread header (#22833) * [build] Fix #21255 - allow circular initialization of SimpleStateMachine test. (#22461) * [build] Fix #21255 - allow circular initialization of SimpleStateMachine test. * [build] Add comment per review feedback. * [Darwin][AttestationVerifier] Expose a mechanism to customise cd signing keys and use it in darwin (#22338) * Add AttestationTrustStore::GetCertificationDeclarationCert virtual method to allow controllers passing in some CD certs * Add cdCerts member to MTRControllerFactoryparams and override AttestationTrustStore::GetCertificationDeclarationCert * Implement ArrayTrustStore::GetCertificationDeclarationSigningKey and initialize the test ArrayTrustStore store with the test CD cert * Update the FileAttestationTrustStore to read a directory with der certs for certification declaration verification * Add credentials/development/cd-certs/ and update chip-tool to use it if desired * Update API to match conversation - Remove CD stuff from FileAttestationTrustStore - Refactor FileAttestationTrustStore to allow loading of any X.509 cert directory - Add a command line to chip-tool to disallow test keys (`only-allow-trusted-cd-keys`) - Add plumbing to enable CD keys lookup properly without mixing-up with PAA semantics - Add official CD verifying key and official SDK CD test key in the default CD trust store as-is * Update src/darwin to take into account the proposed changes * Add unit test for `CsaCdKeysTrustStore` Co-authored-by: Tennessee Carmel-Veilleux <tennessee.carmelveilleux@gmail.com> * [Attestation] Updated to Use CD Signed by a Valid CSA Cert (#22685) * Updated CSA Official CD Signing Certificates (#23027) * restyled. * Remove fixed versioning for git in cirque (#23257) Co-authored-by: Gene Harvey <gene.harvey@smartthings.com> Co-authored-by: Martin Turon <mturon@google.com> Co-authored-by: Vivien Nicolas <vnicolas@apple.com> Co-authored-by: Tennessee Carmel-Veilleux <tennessee.carmelveilleux@gmail.com> Co-authored-by: Andrei Litvin <andy314@gmail.com>
1 parent 14d321b commit 96c9357

34 files changed

+861
-171
lines changed
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIICBzCCAa2gAwIBAgIHY3NhY2RrMTAKBggqhkjOPQQDAjBSMQwwCgYDVQQKDAND
3+
U0ExLDAqBgNVBAMMI01hdHRlciBDZXJ0aWZpY2F0aW9uIGFuZCBUZXN0aW5nIENB
4+
MRQwEgYKKwYBBAGConwCAQwEQzVBMDAgFw0yMjEwMDMxOTI4NTVaGA8yMDcyMDky
5+
MDE5Mjg1NVowWDEMMAoGA1UECgwDQ1NBMTIwMAYDVQQDDClDZXJ0aWZpY2F0aW9u
6+
IERlY2xhcmF0aW9uIFNpZ25pbmcgS2V5IDAwMTEUMBIGCisGAQQBgqJ8AgEMBEM1
7+
QTAwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATN7uk+RPi3K+PRqcB+IZaLmv/z
8+
tAPwXhZp17Hlyu5vx3FLQufiNpXpLNdjVHOigK5ojze7lInhFim5uU/3sJkpo2Yw
9+
ZDASBgNVHRMBAf8ECDAGAQH/AgEAMA4GA1UdDwEB/wQEAwIBhjAdBgNVHQ4EFgQU
10+
/jQ/lZlHdjth7kU5ExM4SU/mfY4wHwYDVR0jBBgwFoAUl+Rp0MUEFMJvxwH3fpR3
11+
OQmN9qUwCgYIKoZIzj0EAwIDSAAwRQIgEDWOcdKsVGtUh3evHbBd1lq4aS7yQtOp
12+
6GrOQ3/zXBsCIQDxorh2RXSaI8m2RCcoWaiWa0nLzQepNm3C2jrQVJmC2Q==
13+
-----END CERTIFICATE-----
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIICCDCCAa2gAwIBAgIHY3NhY2RrMjAKBggqhkjOPQQDAjBSMQwwCgYDVQQKDAND
3+
U0ExLDAqBgNVBAMMI01hdHRlciBDZXJ0aWZpY2F0aW9uIGFuZCBUZXN0aW5nIENB
4+
MRQwEgYKKwYBBAGConwCAQwEQzVBMDAgFw0yMjEwMDMxOTM2NDZaGA8yMDcyMDky
5+
MDE5MzY0NlowWDEMMAoGA1UECgwDQ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pO1b9dkGF+rzTL1o2Yw
9+
ZDASBgNVHRMBAf8ECDAGAQH/AgEAMA4GA1UdDwEB/wQEAwIBhjAdBgNVHQ4EFgQU
10+
RxA158BOqqi+fE1ME+PkwgmVqEswHwYDVR0jBBgwFoAUl+Rp0MUEFMJvxwH3fpR3
11+
OQmN9qUwCgYIKoZIzj0EAwIDRwAwRAIgIFecbY+1mVVNqxH9+8IMB8+safdyIJU2
12+
AqqtZ/w7AkQCIHiVlYTaCnJsnW5/cvj9GfIv7Eb0cjdmcAkrYGbnPQzX
13+
-----END CERTIFICATE-----
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIICBjCCAa2gAwIBAgIHY3NhY2RrNDAKBggqhkjOPQQDAjBSMQwwCgYDVQQKDAND
3+
U0ExLDAqBgNVBAMMI01hdHRlciBDZXJ0aWZpY2F0aW9uIGFuZCBUZXN0aW5nIENB
4+
MRQwEgYKKwYBBAGConwCAQwEQzVBMDAgFw0yMjEwMDMxOTQzMjFaGA8yMDcyMDky
5+
MDE5NDMyMVowWDEMMAoGA1UECgwDQ1NBMTIwMAYDVQQDDClDZXJ0aWZpY2F0aW9u
6+
IERlY2xhcmF0aW9uIFNpZ25pbmcgS2V5IDAwNDEUMBIGCisGAQQBgqJ8AgEMBEM1
7+
QTAwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAR8/I2IEKic9PoZF3jyr+x4+FF6
8+
l6Plf8ITutiI42EedP+2hL3rqKaLJSNKXDWPNzurm20wThMG3XYgpSjRFhwLo2Yw
9+
ZDASBgNVHRMBAf8ECDAGAQH/AgEAMA4GA1UdDwEB/wQEAwIBhjAdBgNVHQ4EFgQU
10+
9oYDo2kumBByQZ6h4as4VL13ldMwHwYDVR0jBBgwFoAUl+Rp0MUEFMJvxwH3fpR3
11+
OQmN9qUwCgYIKoZIzj0EAwIDRwAwRAIgLqAfkbtLYYdmQsnbn0CWv3G1/lbE36nz
12+
HbLbW5t6PY4CIE8oyIHsVhNSTPcb3mwRp+Vxhs8tKhbAdwv5BGgDaAHj
13+
-----END CERTIFICATE-----
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIICBzCCAa2gAwIBAgIHY3NhY2RrNTAKBggqhkjOPQQDAjBSMQwwCgYDVQQKDAND
3+
U0ExLDAqBgNVBAMMI01hdHRlciBDZXJ0aWZpY2F0aW9uIGFuZCBUZXN0aW5nIENB
4+
MRQwEgYKKwYBBAGConwCAQwEQzVBMDAgFw0yMjEwMDMxOTQ3MTVaGA8yMDcyMDky
5+
MDE5NDcxNVowWDEMMAoGA1UECgwDQ1NBMTIwMAYDVQQDDClDZXJ0aWZpY2F0aW9u
6+
IERlY2xhcmF0aW9uIFNpZ25pbmcgS2V5IDAwNTEUMBIGCisGAQQBgqJ8AgEMBEM1
7+
QTAwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARDilLGYqKm1yZH+V63UxNu5K4P
8+
2zqpwWkxQms9CGf5EDrn16G4h+n4E6byb3a7zak1k3h8EneMqPKXXcRaIEL5o2Yw
9+
ZDASBgNVHRMBAf8ECDAGAQH/AgEAMA4GA1UdDwEB/wQEAwIBhjAdBgNVHQ4EFgQU
10+
Y38mNK1i6v5q9mLvuW9v0vy//C8wHwYDVR0jBBgwFoAUl+Rp0MUEFMJvxwH3fpR3
11+
OQmN9qUwCgYIKoZIzj0EAwIDSAAwRQIhAM1HQpvkHKxLJByWaSYAPRZgh3Bis18W
12+
AViq7c/mtzEAAiBZO0lVe6Qo9iQPIBWZaVx/S/YSNO9uKNa/pvFu3V+nIg==
13+
-----END CERTIFICATE-----
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIICATCCAaegAwIBAgIHY3Nhcm9vdDAKBggqhkjOPQQDAjBSMQwwCgYDVQQKDAND
3+
U0ExLDAqBg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L+V1oeWXgNrUhxRA35rjO3vyh60QEZp
7+
T6CIgu7WUZ3suqNmMGQwEgYDVR0TAQH/BAgwBgEB/wIBATAOBgNVHQ8BAf8EBAMC
8+
AQYwHQYDVR0OBBYEFGL6gjNZrPqplj4c+hQK3fUE83FgMB8GA1UdIwQYMBaAFGL6
9+
gjNZrPqplj4c+hQK3fUE83FgMAoGCCqGSM49BAMCA0cAMEQCICxUXOTkV9im8NnZ
10+
u+vW7OHd/n+MbZps83UyH8b6xxOEAiBUB3jodDlyUn7t669YaGIgtUB48s1OYqdq
11+
58u5L/VMiw==
12+
-----END CERTIFICATE-----

examples/chip-tool/commands/common/CHIPCommand.cpp

+56-32
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,47 @@ std::set<CHIPCommand *> CHIPCommand::sDeferredCleanups;
3636

3737
using DeviceControllerFactory = chip::Controller::DeviceControllerFactory;
3838

39-
constexpr chip::FabricId kIdentityNullFabricId = chip::kUndefinedFabricId;
40-
constexpr chip::FabricId kIdentityAlphaFabricId = 1;
41-
constexpr chip::FabricId kIdentityBetaFabricId = 2;
42-
constexpr chip::FabricId kIdentityGammaFabricId = 3;
43-
constexpr chip::FabricId kIdentityOtherFabricId = 4;
44-
constexpr const char * kTrustStorePathVariable = "CHIPTOOL_PAA_TRUST_STORE_PATH";
45-
46-
const chip::Credentials::AttestationTrustStore * CHIPCommand::sPaaTrustStore = nullptr;
39+
constexpr chip::FabricId kIdentityNullFabricId = chip::kUndefinedFabricId;
40+
constexpr chip::FabricId kIdentityAlphaFabricId = 1;
41+
constexpr chip::FabricId kIdentityBetaFabricId = 2;
42+
constexpr chip::FabricId kIdentityGammaFabricId = 3;
43+
constexpr chip::FabricId kIdentityOtherFabricId = 4;
44+
constexpr const char * kPAATrustStorePathVariable = "CHIPTOOL_PAA_TRUST_STORE_PATH";
45+
constexpr const char * kCDTrustStorePathVariable = "CHIPTOOL_CD_TRUST_STORE_PATH";
46+
47+
const chip::Credentials::AttestationTrustStore * CHIPCommand::sTrustStore = nullptr;
4748
chip::Credentials::GroupDataProviderImpl CHIPCommand::sGroupDataProvider{ kMaxGroupsPerFabric, kMaxGroupKeysPerFabric };
4849

4950
namespace {
50-
const chip::Credentials::AttestationTrustStore * GetTestFileAttestationTrustStore(const char * paaTrustStorePath)
51+
const CHIP_ERROR GetAttestationTrustStore(const char * paaTrustStorePath,
52+
const chip::Credentials::AttestationTrustStore ** trustStore)
5153
{
54+
if (paaTrustStorePath == nullptr)
55+
{
56+
paaTrustStorePath = getenv(kPAATrustStorePathVariable);
57+
}
58+
59+
if (paaTrustStorePath == nullptr)
60+
{
61+
*trustStore = chip::Credentials::GetTestAttestationTrustStore();
62+
return CHIP_NO_ERROR;
63+
}
64+
5265
static chip::Credentials::FileAttestationTrustStore attestationTrustStore{ paaTrustStorePath };
5366

54-
if (attestationTrustStore.IsInitialized())
67+
if (paaTrustStorePath != nullptr && attestationTrustStore.paaCount() == 0)
5568
{
56-
return &attestationTrustStore;
69+
ChipLogError(chipTool, "No PAAs found in path: %s", paaTrustStorePath);
70+
ChipLogError(chipTool,
71+
"Please specify a valid path containing trusted PAA certificates using "
72+
"the argument [--paa-trust-store-path paa/file/path] "
73+
"or environment variable [%s=paa/file/path]",
74+
kPAATrustStorePathVariable);
75+
return CHIP_ERROR_INVALID_ARGUMENT;
5776
}
5877

59-
return nullptr;
78+
*trustStore = &attestationTrustStore;
79+
return CHIP_NO_ERROR;
6080
}
6181
} // namespace
6282

@@ -103,29 +123,33 @@ CHIP_ERROR CHIPCommand::MaybeSetUpStack()
103123
factoryInitParams.listenPort = port;
104124
ReturnLogErrorOnFailure(DeviceControllerFactory::GetInstance().Init(factoryInitParams));
105125

106-
if (!mPaaTrustStorePath.HasValue())
126+
ReturnErrorOnFailure(GetAttestationTrustStore(mPaaTrustStorePath.ValueOr(nullptr), &sTrustStore));
127+
128+
ReturnLogErrorOnFailure(InitializeCommissioner(kIdentityNull, kIdentityNullFabricId));
129+
130+
// After initializing first commissioner, add the additional CD certs once
107131
{
108-
char * const trust_store_path = getenv(kTrustStorePathVariable);
109-
if (trust_store_path != nullptr)
132+
const char * cdTrustStorePath = mCDTrustStorePath.ValueOr(nullptr);
133+
if (cdTrustStorePath == nullptr)
110134
{
111-
mPaaTrustStorePath.SetValue(trust_store_path);
135+
cdTrustStorePath = getenv(kCDTrustStorePathVariable);
112136
}
113-
}
114-
sPaaTrustStore = mPaaTrustStorePath.HasValue() ? GetTestFileAttestationTrustStore(mPaaTrustStorePath.Value())
115-
: chip::Credentials::GetTestAttestationTrustStore();
116-
;
117-
if (mPaaTrustStorePath.HasValue() && sPaaTrustStore == nullptr)
118-
{
119-
ChipLogError(chipTool, "No PAAs found in path: %s", mPaaTrustStorePath.Value());
120-
ChipLogError(chipTool,
121-
"Please specify a valid path containing trusted PAA certificates using"
122-
"the argument [--paa-trust-store-path paa/file/path]"
123-
"or environment variable [%s=paa/file/path]",
124-
kTrustStorePathVariable);
125-
return CHIP_ERROR_INVALID_ARGUMENT;
126-
}
127137

128-
ReturnLogErrorOnFailure(InitializeCommissioner(kIdentityNull, kIdentityNullFabricId));
138+
auto additionalCdCerts = chip::Credentials::LoadAllX509DerCerts(cdTrustStorePath);
139+
if (cdTrustStorePath != nullptr && additionalCdCerts.size() == 0)
140+
{
141+
ChipLogError(chipTool, "Warning: no CD signing certs found in path: %s, only defaults will be used", cdTrustStorePath);
142+
ChipLogError(chipTool,
143+
"Please specify a path containing trusted CD verifying key certificates using "
144+
"the argument [--cd-trust-store-path cd/file/path] "
145+
"or environment variable [%s=cd/file/path]",
146+
kCDTrustStorePathVariable);
147+
}
148+
ReturnErrorOnFailure(mCredIssuerCmds->AddAdditionalCDVerifyingCerts(additionalCdCerts));
149+
}
150+
bool allowTestCdSigningKey = !mOnlyAllowTrustedCdKeys.ValueOr(false);
151+
mCredIssuerCmds->SetCredentialIssuerOption(CredentialIssuerCommands::CredentialIssuerOptions::kAllowTestCdSigningKey,
152+
allowTestCdSigningKey);
129153

130154
return CHIP_NO_ERROR;
131155
}
@@ -343,7 +367,7 @@ CHIP_ERROR CHIPCommand::InitializeCommissioner(std::string key, chip::FabricId f
343367
std::unique_ptr<ChipDeviceCommissioner> commissioner = std::make_unique<ChipDeviceCommissioner>();
344368
chip::Controller::SetupParams commissionerParams;
345369

346-
ReturnLogErrorOnFailure(mCredIssuerCmds->SetupDeviceAttestation(commissionerParams, sPaaTrustStore));
370+
ReturnLogErrorOnFailure(mCredIssuerCmds->SetupDeviceAttestation(commissionerParams, sTrustStore));
347371

348372
VerifyOrReturnError(noc.Alloc(chip::Controller::kMaxCHIPDERCertLength), CHIP_ERROR_NO_MEMORY);
349373
VerifyOrReturnError(icac.Alloc(chip::Controller::kMaxCHIPDERCertLength), CHIP_ERROR_NO_MEMORY);

examples/chip-tool/commands/common/CHIPCommand.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,17 @@ class CHIPCommand : public Command
6565
AddArgument("paa-trust-store-path", &mPaaTrustStorePath,
6666
"Path to directory holding PAA certificate information. Can be absolute or relative to the current working "
6767
"directory.");
68+
AddArgument("cd-trust-store-path", &mCDTrustStorePath,
69+
"Path to directory holding CD certificate information. Can be absolute or relative to the current working "
70+
"directory.");
6871
AddArgument("commissioner-name", &mCommissionerName,
6972
"Name of fabric to use. Valid values are \"alpha\", \"beta\", \"gamma\", and integers greater than or equal to "
7073
"4. The default if not specified is \"alpha\".");
7174
AddArgument("commissioner-nodeid", 0, UINT64_MAX, &mCommissionerNodeId,
7275
"The node id to use for chip-tool. If not provided, kTestControllerNodeId (112233, 0x1B669) will be used.");
76+
AddArgument("only-allow-trusted-cd-keys", 0, 1, &mOnlyAllowTrustedCdKeys,
77+
"Only allow trusted CD verifying keys (disallow test keys). If not provided or 0 (\"false\"), untrusted CD "
78+
"verifying keys are allowed. If 1 (\"true\"), test keys are disallowed.");
7379
#if CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
7480
AddArgument("trace_file", &mTraceFile);
7581
AddArgument("trace_log", 0, 1, &mTraceLog);
@@ -153,10 +159,12 @@ class CHIPCommand : public Command
153159
chip::Optional<chip::NodeId> mCommissionerNodeId;
154160
chip::Optional<uint16_t> mBleAdapterId;
155161
chip::Optional<char *> mPaaTrustStorePath;
162+
chip::Optional<char *> mCDTrustStorePath;
163+
chip::Optional<bool> mOnlyAllowTrustedCdKeys;
156164

157165
// Cached trust store so commands other than the original startup command
158166
// can spin up commissioners as needed.
159-
static const chip::Credentials::AttestationTrustStore * sPaaTrustStore;
167+
static const chip::Credentials::AttestationTrustStore * sTrustStore;
160168

161169
static void RunQueuedCommand(intptr_t commandArg);
162170

examples/chip-tool/commands/common/CredentialIssuerCommands.h

+30
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <credentials/attestation_verifier/DeviceAttestationVerifier.h>
2424
#include <lib/core/CHIPCore.h>
2525
#include <lib/core/CHIPPersistentStorageDelegate.h>
26+
#include <vector>
2627

2728
class CredentialIssuerCommands
2829
{
@@ -54,6 +55,16 @@ class CredentialIssuerCommands
5455
virtual CHIP_ERROR SetupDeviceAttestation(chip::Controller::SetupParams & setupParams,
5556
const chip::Credentials::AttestationTrustStore * trustStore) = 0;
5657

58+
/**
59+
* @brief Add a list of additional non-default CD verifying keys (by certificate)
60+
*
61+
* Must be called AFTER SetupDeviceAttestation.
62+
*
63+
* @param additionalCdCerts - vector of X.509 DER verifying cert bodies
64+
* @return CHIP_NO_ERROR on succes, another CHIP_ERROR on internal failures.
65+
*/
66+
virtual CHIP_ERROR AddAdditionalCDVerifyingCerts(const std::vector<std::vector<uint8_t>> & additionalCdCerts) = 0;
67+
5768
virtual chip::Controller::OperationalCredentialsDelegate * GetCredentialIssuer() = 0;
5869

5970
/**
@@ -74,4 +85,23 @@ class CredentialIssuerCommands
7485
virtual CHIP_ERROR GenerateControllerNOCChain(chip::NodeId nodeId, chip::FabricId fabricId, const chip::CATValues & cats,
7586
chip::Crypto::P256Keypair & keypair, chip::MutableByteSpan & rcac,
7687
chip::MutableByteSpan & icac, chip::MutableByteSpan & noc) = 0;
88+
89+
// All options must start false
90+
enum CredentialIssuerOptions : uint8_t
91+
{
92+
kAllowTestCdSigningKey = 1, // If set, allow development/test SDK CD verifying key to be used
93+
};
94+
95+
virtual void SetCredentialIssuerOption(CredentialIssuerOptions option, bool isEnabled)
96+
{
97+
// Do nothing
98+
(void) option;
99+
(void) isEnabled;
100+
}
101+
102+
virtual bool GetCredentialIssuerOption(CredentialIssuerOptions option)
103+
{
104+
// All options always start false
105+
return false;
106+
}
77107
};

examples/chip-tool/commands/example/ExampleCredentialIssuerCommands.h

+50-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class ExampleCredentialIssuerCommands : public CredentialIssuerCommands
3737
{
3838
chip::Credentials::SetDeviceAttestationCredentialsProvider(chip::Credentials::Examples::GetExampleDACProvider());
3939

40-
setupParams.deviceAttestationVerifier = chip::Credentials::GetDefaultDACVerifier(trustStore);
40+
mDacVerifier = chip::Credentials::GetDefaultDACVerifier(trustStore);
41+
setupParams.deviceAttestationVerifier = mDacVerifier;
42+
mDacVerifier->EnableCdTestKeySupport(mAllowTestCdSigningKey);
4143

4244
return CHIP_NO_ERROR;
4345
}
@@ -49,6 +51,53 @@ class ExampleCredentialIssuerCommands : public CredentialIssuerCommands
4951
return mOpCredsIssuer.GenerateNOCChainAfterValidation(nodeId, fabricId, cats, keypair.Pubkey(), rcac, icac, noc);
5052
}
5153

54+
CHIP_ERROR AddAdditionalCDVerifyingCerts(const std::vector<std::vector<uint8_t>> & additionalCdCerts) override
55+
{
56+
VerifyOrReturnError(mDacVerifier != nullptr, CHIP_ERROR_INCORRECT_STATE);
57+
58+
for (const auto & cert : additionalCdCerts)
59+
{
60+
auto cdTrustStore = mDacVerifier->GetCertificationDeclarationTrustStore();
61+
VerifyOrReturnError(cdTrustStore != nullptr, CHIP_ERROR_INCORRECT_STATE);
62+
ReturnErrorOnFailure(cdTrustStore->AddTrustedKey(chip::ByteSpan(cert.data(), cert.size())));
63+
}
64+
65+
return CHIP_NO_ERROR;
66+
}
67+
68+
void SetCredentialIssuerOption(CredentialIssuerOptions option, bool isEnabled) override
69+
{
70+
switch (option)
71+
{
72+
case CredentialIssuerOptions::kAllowTestCdSigningKey:
73+
mAllowTestCdSigningKey = isEnabled;
74+
if (mDacVerifier != nullptr)
75+
{
76+
mDacVerifier->EnableCdTestKeySupport(isEnabled);
77+
}
78+
79+
default:
80+
break;
81+
}
82+
}
83+
84+
bool GetCredentialIssuerOption(CredentialIssuerOptions option) override
85+
{
86+
switch (option)
87+
{
88+
case CredentialIssuerOptions::kAllowTestCdSigningKey:
89+
return mAllowTestCdSigningKey;
90+
default:
91+
return false;
92+
}
93+
}
94+
95+
protected:
96+
bool mUsesMaxSizedCerts = false;
97+
// Starts true for legacy purposes
98+
bool mAllowTestCdSigningKey = true;
99+
52100
private:
53101
chip::Controller::ExampleOperationalCredentialsIssuer mOpCredsIssuer;
102+
chip::Credentials::DeviceAttestationVerifier * mDacVerifier;
54103
};

examples/common/tracing/decoder/interaction_model/DecoderCustomLog.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <credentials/CertificationDeclaration.h>
3333
#include <credentials/DeviceAttestationConstructor.h>
3434
#include <credentials/DeviceAttestationVendorReserved.h>
35+
#include <credentials/attestation_verifier/DefaultDeviceAttestationVerifier.h>
3536

3637
#include <lib/core/CHIPTLV.h>
3738
#include <lib/support/TypeTraits.h>
@@ -66,13 +67,15 @@ CHIP_ERROR LogCertificationDeclaration(const ByteSpan & cd)
6667

6768
// TODO Add an option to load a TrustStore so the subjectKeyId can be extracted from the CMS envelope in order
6869
// to select the proper public key.
69-
ByteSpan cdContentOut;
70-
uint8_t pubKey[] = { 0x04, 0x3c, 0x39, 0x89, 0x22, 0x45, 0x2b, 0x55, 0xca, 0xf3, 0x89, 0xc2, 0x5b, 0xd1, 0xbc, 0xa4, 0x65,
71-
0x69, 0x52, 0xcc, 0xb9, 0x0e, 0x88, 0x69, 0x24, 0x9a, 0xd8, 0x47, 0x46, 0x53, 0x01, 0x4c, 0xbf, 0x95,
72-
0xd6, 0x87, 0x96, 0x5e, 0x03, 0x6b, 0x52, 0x1c, 0x51, 0x03, 0x7e, 0x6b, 0x8c, 0xed, 0xef, 0xca, 0x1e,
73-
0xb4, 0x40, 0x46, 0x69, 0x4f, 0xa0, 0x88, 0x82, 0xee, 0xd6, 0x51, 0x9d, 0xec, 0xba };
70+
ByteSpan kid;
71+
ReturnErrorOnFailure(Credentials::CMS_ExtractKeyId(cd, kid));
72+
73+
Crypto::P256PublicKey verifyingKey;
74+
Credentials::CsaCdKeysTrustStore cdKeysTrustStore;
75+
ReturnErrorOnFailure(cdKeysTrustStore.LookupVerifyingKey(kid, verifyingKey));
7476

75-
ReturnErrorOnFailure(Credentials::CMS_Verify(cd, Crypto::P256PublicKey(pubKey), cdContentOut));
77+
ByteSpan cdContentOut;
78+
ReturnErrorOnFailure(Credentials::CMS_Verify(cd, verifyingKey, cdContentOut));
7679

7780
constexpr uint8_t kTag_FormatVersion = 0; /**< [ unsigned int ] Format version. */
7881
constexpr uint8_t kTag_VendorId = 1; /**< [ unsigned int ] Vedor identifier. */

0 commit comments

Comments
 (0)