Skip to content

Commit 8be890b

Browse files
authored
controller/python: add device attestation revocation support (#37134)
* src/credentials: add an API to DeviceAttestationVerifier interface to set the revocation delegate * controller/python: add device attestation revocation support - Added the cli option to matter testing framework for setting the dac revocation set path - Added the required changes in the python bindings - Added an API to the python controller to set the dac revocation set path. * rename TrySettingRevocationDelegate to SetRevocationDelegate
1 parent d7c1270 commit 8be890b

File tree

7 files changed

+68
-3
lines changed

7 files changed

+68
-3
lines changed

src/controller/python/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ shared_library("ChipDeviceCtrl") {
126126
"${chip_root}/src/app/icd/client:handler",
127127
"${chip_root}/src/app/server",
128128
"${chip_root}/src/credentials:default_attestation_verifier",
129+
"${chip_root}/src/credentials:test_dac_revocation_delegate",
129130
"${chip_root}/src/lib",
130131
"${chip_root}/src/lib/core",
131132
"${chip_root}/src/lib/dnssd",

src/controller/python/OpCredsBinding.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <credentials/attestation_verifier/DefaultDeviceAttestationVerifier.h>
4545
#include <credentials/attestation_verifier/DeviceAttestationVerifier.h>
4646
#include <credentials/attestation_verifier/FileAttestationTrustStore.h>
47+
#include <credentials/attestation_verifier/TestDACRevocationDelegateImpl.h>
4748

4849
using namespace chip;
4950

@@ -61,6 +62,15 @@ const chip::Credentials::AttestationTrustStore * GetTestFileAttestationTrustStor
6162
return &attestationTrustStore;
6263
}
6364

65+
Credentials::DeviceAttestationRevocationDelegate * GetTestAttestationRevocationDelegate(const char * dacRevocationSetPath)
66+
{
67+
VerifyOrReturnValue(dacRevocationSetPath != nullptr, nullptr);
68+
69+
static Credentials::TestDACRevocationDelegateImpl testDacRevocationDelegate;
70+
testDacRevocationDelegate.SetDeviceAttestationRevocationSetPath(dacRevocationSetPath);
71+
return &testDacRevocationDelegate;
72+
}
73+
6474
chip::Python::PlaceholderOperationalCredentialsIssuer sPlaceholderOperationalCredentialsIssuer;
6575
} // namespace
6676

@@ -700,4 +710,15 @@ PyChipError pychip_GetCompletionError()
700710
return ToPyChipError(sTestCommissioner.GetCompletionError());
701711
}
702712

713+
PyChipError pychip_DeviceController_SetDACRevocationSetPath(const char * dacRevocationSetPath)
714+
{
715+
Credentials::DeviceAttestationRevocationDelegate * dacRevocationDelegate =
716+
GetTestAttestationRevocationDelegate(dacRevocationSetPath);
717+
VerifyOrReturnError(dacRevocationDelegate != nullptr, ToPyChipError(CHIP_ERROR_INVALID_ARGUMENT));
718+
719+
Credentials::DeviceAttestationVerifier * dacVerifier = Credentials::GetDeviceAttestationVerifier();
720+
VerifyOrReturnError(dacVerifier != nullptr, ToPyChipError(CHIP_ERROR_INCORRECT_STATE));
721+
722+
return ToPyChipError(dacVerifier->SetRevocationDelegate(dacRevocationDelegate));
723+
}
703724
} // extern "C"

src/controller/python/chip/ChipDeviceCtrl.py

+15
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,9 @@ def _InitLib(self):
20102010
self._dmLib.pychip_DeviceController_SetTermsAcknowledgements.restype = PyChipError
20112011
self._dmLib.pychip_DeviceController_SetTermsAcknowledgements.argtypes = [c_uint16, c_uint16]
20122012

2013+
self._dmLib.pychip_DeviceController_SetDACRevocationSetPath.restype = PyChipError
2014+
self._dmLib.pychip_DeviceController_SetDACRevocationSetPath.argtypes = [c_char_p]
2015+
20132016

20142017
class ChipDeviceController(ChipDeviceControllerBase):
20152018
''' The ChipDeviceCommissioner binding, named as ChipDeviceController
@@ -2308,6 +2311,18 @@ async def IssueNOCChain(self, csr: Clusters.OperationalCredentials.Commands.CSRR
23082311

23092312
return await asyncio.futures.wrap_future(ctx.future)
23102313

2314+
def SetDACRevocationSetPath(self, dacRevocationSetPath: typing.Optional[str]):
2315+
''' Set the path to the device attestation revocation set JSON file.
2316+
2317+
Args:
2318+
dacRevocationSetPath: Path to the JSON file containing the device attestation revocation set
2319+
'''
2320+
self.CheckIsActive()
2321+
self._ChipStack.Call(
2322+
lambda: self._dmLib.pychip_DeviceController_SetDACRevocationSetPath(
2323+
c_char_p(str.encode(dacRevocationSetPath) if dacRevocationSetPath else None))
2324+
).raise_on_error()
2325+
23112326

23122327
class BareChipDeviceController(ChipDeviceControllerBase):
23132328
''' A bare device controller without AutoCommissioner support.

src/controller/python/chip/FabricAdmin.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ def __init__(self, certificateAuthority: CertificateAuthority.CertificateAuthori
6464
self._activeControllers: List[ChipDeviceCtrl.ChipDeviceController] = []
6565

6666
def NewController(self, nodeId: Optional[int] = None, paaTrustStorePath: str = "",
67-
useTestCommissioner: bool = False, catTags: List[int] = [], keypair: p256keypair.P256Keypair = None):
67+
useTestCommissioner: bool = False, catTags: List[int] = [], keypair: p256keypair.P256Keypair = None,
68+
dacRevocationSetPath: str = ""):
6869
''' Create a new chip.ChipDeviceCtrl.ChipDeviceController instance on this fabric.
6970
7071
When vending ChipDeviceController instances on a given fabric, each controller instance
@@ -77,6 +78,8 @@ def NewController(self, nodeId: Optional[int] = None, paaTrustStorePath: str = "
7778
paaTrustStorePath: Path to the PAA trust store. If one isn't provided, a suitable default is selected.
7879
useTestCommissioner: If a test commmisioner is to be created.
7980
catTags: A list of 32-bit CAT tags that will added to the NOC generated for this controller.
81+
keypair: A keypair to be used for the controller. If one isn't provided, a new one is generated.
82+
dacRevocationSetPath: Path to the device attestation revocation set JSON file.
8083
'''
8184
if (not (self._isActive)):
8285
raise RuntimeError(
@@ -107,6 +110,9 @@ def NewController(self, nodeId: Optional[int] = None, paaTrustStorePath: str = "
107110
catTags=catTags,
108111
keypair=keypair)
109112

113+
if dacRevocationSetPath and len(dacRevocationSetPath) > 0:
114+
controller.SetDACRevocationSetPath(dacRevocationSetPath)
115+
110116
self._activeControllers.append(controller)
111117
return controller
112118

src/credentials/attestation_verifier/DefaultDeviceAttestationVerifier.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ class DefaultDACVerifier : public DeviceAttestationVerifier
8383

8484
CsaCdKeysTrustStore * GetCertificationDeclarationTrustStore() override { return &mCdKeysTrustStore; }
8585

86-
void SetRevocationDelegate(DeviceAttestationRevocationDelegate * revocationDelegate)
86+
CHIP_ERROR SetRevocationDelegate(DeviceAttestationRevocationDelegate * revocationDelegate) override
8787
{
8888
mRevocationDelegate = revocationDelegate;
89+
return CHIP_NO_ERROR;
8990
}
9091

9192
protected:

src/credentials/attestation_verifier/DeviceAttestationVerifier.h

+15
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ class ArrayAttestationTrustStore : public AttestationTrustStore
260260
const size_t mNumCerts;
261261
};
262262

263+
// forward declaration
264+
class DeviceAttestationRevocationDelegate;
265+
263266
class DeviceAttestationVerifier
264267
{
265268
public:
@@ -410,6 +413,18 @@ class DeviceAttestationVerifier
410413
void EnableCdTestKeySupport(bool enabled) { mEnableCdTestKeySupport = enabled; }
411414
bool IsCdTestKeySupported() const { return mEnableCdTestKeySupport; }
412415

416+
/**
417+
* @brief Try to set the revocation delegate.
418+
*
419+
* @param[in] revocationDelegate The revocation delegate to set.
420+
*
421+
* @return CHIP_NO_ERROR on success, CHIP_ERROR_NOT_IMPLEMENTED if the revocation delegate is not supported.
422+
*/
423+
virtual CHIP_ERROR SetRevocationDelegate(DeviceAttestationRevocationDelegate * revocationDelegate)
424+
{
425+
return CHIP_ERROR_NOT_IMPLEMENTED;
426+
}
427+
413428
protected:
414429
CHIP_ERROR ValidateAttestationSignature(const Crypto::P256PublicKey & pubkey, const ByteSpan & attestationElements,
415430
const ByteSpan & attestationChallenge, const Crypto::P256ECDSASignature & signature);

src/python_testing/matter_testing_infrastructure/chip/testing/matter_testing.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,8 @@ class MatterTestConfig:
675675
# Accepted Terms and Conditions if used
676676
tc_version_to_simulate: int = None
677677
tc_user_response_to_simulate: int = None
678+
# path to device attestation revocation set json file
679+
dac_revocation_set_path: Optional[pathlib.Path] = None
678680

679681

680682
class ClusterMapper:
@@ -1949,6 +1951,7 @@ def convert_args_to_matter_config(args: argparse.Namespace) -> MatterTestConfig:
19491951

19501952
config.tc_version_to_simulate = args.tc_version_to_simulate
19511953
config.tc_user_response_to_simulate = args.tc_user_response_to_simulate
1954+
config.dac_revocation_set_path = args.dac_revocation_set_path
19521955

19531956
# Accumulate all command-line-passed named args
19541957
all_global_args = []
@@ -1984,6 +1987,8 @@ def parse_matter_test_args(argv: Optional[List[str]] = None) -> MatterTestConfig
19841987
paa_path_default = get_default_paa_trust_store(pathlib.Path.cwd())
19851988
basic_group.add_argument('--paa-trust-store-path', action="store", type=pathlib.Path, metavar="PATH", default=paa_path_default,
19861989
help="PAA trust store path (default: %s)" % str(paa_path_default))
1990+
basic_group.add_argument('--dac-revocation-set-path', action="store", type=pathlib.Path, metavar="PATH",
1991+
help="Path to JSON file containing the device attestation revocation set.")
19871992
basic_group.add_argument('--ble-interface-id', action="store", type=int,
19881993
metavar="INTERFACE_ID", help="ID of BLE adapter (from hciconfig)")
19891994
basic_group.add_argument('-N', '--controller-node-id', type=int_decimal_or_hex,
@@ -2506,7 +2511,8 @@ def run_tests_no_exit(test_class: MatterBaseTest, matter_test_config: MatterTest
25062511
default_controller = stack.certificate_authorities[0].adminList[0].NewController(
25072512
nodeId=matter_test_config.controller_node_id,
25082513
paaTrustStorePath=str(matter_test_config.paa_trust_store_path),
2509-
catTags=matter_test_config.controller_cat_tags
2514+
catTags=matter_test_config.controller_cat_tags,
2515+
dacRevocationSetPath=str(matter_test_config.dac_revocation_set_path),
25102516
)
25112517
test_config.user_params["default_controller"] = stash_globally(default_controller)
25122518

0 commit comments

Comments
 (0)