﻿# All-Devices Providers

This directory contains `all-devices-app` providers that implement or wrap core
Matter SDK provider interfaces.

They provide clean separation between the application data model, POSIX test
simulator overrides (such as dynamic CLI options), and platform hardware
delegates.

---

## Provider Overview

| Provider Class                                                                                         | Base SDK Interface                                                                                                        | Description                                                                                                                                                                                                                                                      |
| :----------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`AllDevicesExampleDACProvider`](https://github.com/project-chip/connectedhomeip/blob/master/examples/all-devices-app/src/credentials/DeviceAttestationCredsProvider.h) | Handles Device Attestation Credentials (DAC, PAI, CD, and DAC private key signing). In POSIX test/simulation environments, supports loading test credentials from a JSON vector file (`--dac_provider <path>`), falling back to default SDK example credentials. |
| [`AllDevicesExampleDeviceInfoProviderImpl`](https://github.com/project-chip/connectedhomeip/blob/master/examples/all-devices-app/src/platform/DeviceInfoProvider.h)                                  | Provides fixed labels, user labels, supported locales, and calendar types across dynamic endpoints in `all-devices-app`.                                                                                                                                         |
| [`AllDevicesExampleDeviceInstanceInfoProviderImpl`](https://github.com/project-chip/connectedhomeip/blob/master/examples/all-devices-app/src/platform/DeviceInstanceInfoProvider.h)                  | Wraps the underlying platform `DeviceInstanceInfoProvider` delegate and overrides Vendor ID and Product ID when custom `--vendor-id` and `--product-id` CLI options are passed.                                                                                  |

---

## DAC Test Vector JSON Schema

When supplying a custom test vector file via `--dac_provider <path>`, the JSON
file is parsed by `TestHarnessDACProvider`
(`src/app/tests/suites/credentials/TestHarnessDACProvider.cpp`).

The supported JSON keys are:

| JSON Key                    | Type                    | Description                                                                           |
| :-------------------------- | :---------------------- | :------------------------------------------------------------------------------------ |
| `dac_cert`                  | Hex String              | DER-encoded Device Attestation Certificate (DAC).                                     |
| `dac_private_key`           | Hex String              | 32-byte P-256 ECDSA private key scalar used to sign the device attestation challenge. |
| `dac_public_key`            | Hex String _(Optional)_ | 65-byte uncompressed P-256 public key corresponding to `dac_private_key`.             |
| `pai_cert`                  | Hex String              | DER-encoded Product Attestation Intermediate (PAI) certificate.                       |
| `certification_declaration` | Hex String              | CMS-signed DER-encoded Certification Declaration (CD) payload.                        |
| `firmware_information`      | Hex String _(Optional)_ | Optional firmware information payload.                                                |
| `basic_info_pid`            | Integer _(Optional)_    | Expected Product ID matching the test vector.                                         |
| `description`               | String _(Optional)_     | Human-readable description of the test scenario.                                      |
| `is_success_case`           | Boolean _(Optional)_    | Indicates whether the test vector is expected to pass or fail attestation.            |

### Pre-Existing Test Vectors

Pre-existing test vector JSON files are available in the Matter SDK repository
under:
[`credentials/development/attestation/`](https://github.com/project-chip/connectedhomeip/blob/master/credentials/development/attestation)

Examples:

-   **Test Credentials for VID=0xFFF1 PID=0x8000**:
    `credentials/development/attestation/TestCredentials-FFF1-8000.json`
-   **Test Credentials for VID=0xFFF2 PID=0x8001**:
    `credentials/development/attestation/TestCredentials-FFF2-8001.json`

Example invocation:

```bash
./out/linux-x64-all-devices-clang/all-devices-app \
  --dac_provider credentials/development/attestation/TestCredentials-FFF1-8000.json \
  --vendor-id 0xFFF1 \
  --product-id 0x8000
```

---

## Production vs. Simulation Usage

### 1. Device Attestation Credentials (DAC)

In real commercial products, DAC private keys must never be stored in plaintext
JSON files or memory accessible to user space.

-   **Simulation / Test Harnesses (POSIX)**: The POSIX entrypoint
    ([`posix/main.cpp`](https://github.com/project-chip/connectedhomeip/blob/master/examples/all-devices-app/posix/main.cpp)) initializes
    `AllDevicesExampleDACProvider` with `AppOptions::GetConfig().dacProvider` to
    allow test runners (such as WOCA and Python certification scripts) to supply
    test vectors dynamically.
-   **Embedded MCUs (ESP32, Silicon Labs, Nordic)**: Hardware platforms
    initialize a `FactoryDataProvider` (which reads from secure flash or NVM)
    and register it at boot.
-   **Commercial Linux Gateways**: Real products replace
    `AllDevicesExampleDACProvider` with a provider that delegates signing
    directly to a Hardware Secure Element (e.g., `ATECC608`, NXP `SE050`), TPM,
    or platform Secure Enclave / TrustZone
    ([`TrustyDACProvider`](https://github.com/project-chip/connectedhomeip/blob/master/src/platform/Linux/DeviceAttestationCredsTrusty.h)).

### 2. Device Instance Info

`AllDevicesExampleDeviceInstanceInfoProviderImpl` demonstrates the decorator
pattern: it intercepts basic info queries to allow CLI customization during
development while forwarding hardware-level queries (such as rotating device ID,
serial numbers, and manufacturing dates) to the underlying platform delegate.
