blob: a6735dcece15b2e6098807071867b893614a20cf [file] [log] [blame]
Tennessee Carmel-Veilleuxb0b53c82021-08-16 21:33:19 -04001/*
2 *
3 * Copyright (c) 2021 Project CHIP Authors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#pragma once
18
19#include <lib/core/CHIPError.h>
20#include <lib/support/Span.h>
21
22namespace chip {
23namespace Credentials {
24
25class DeviceAttestationCredentialsProvider
26{
27public:
28 DeviceAttestationCredentialsProvider() = default;
29 virtual ~DeviceAttestationCredentialsProvider() = default;
30
31 // Not copyable
Karsten Sperling38d6a482023-09-29 15:50:08 +130032 DeviceAttestationCredentialsProvider(const DeviceAttestationCredentialsProvider &) = delete;
Tennessee Carmel-Veilleuxb0b53c82021-08-16 21:33:19 -040033 DeviceAttestationCredentialsProvider & operator=(const DeviceAttestationCredentialsProvider &) = delete;
34
35 /**
36 * @brief Get the Certification Declaration body. Updates `out_cd_buffer`'s size on success
37 * to match the data size. If no Certification Declaration is available, sets
38 * `out_cd_buffer` to empty.
39 *
Tennessee Carmel-Veilleux8f86c432022-03-11 15:49:56 -050040 * @param[in,out] out_cd_buffer Buffer to receive the Certification Declaration body.
Tennessee Carmel-Veilleuxb0b53c82021-08-16 21:33:19 -040041 * @returns CHIP_NO_ERROR on success, CHIP_ERROR_BUFFER_TOO_SMALL if `out_cd_buffer`
42 * is too small, or another CHIP_ERROR from the underlying implementation
43 * if access fails.
44 */
45 virtual CHIP_ERROR GetCertificationDeclaration(MutableByteSpan & out_cd_buffer) = 0;
46
47 /**
48 * @brief Get the Firmware Information body. Updates `out_firmware_info_buffer`'s size
49 * on success to match the data size. If no Firmware Information is available,
50 * sets `out_firmware_info_buffer` to empty.
51 *
Tennessee Carmel-Veilleux8f86c432022-03-11 15:49:56 -050052 * @param[in,out] out_firmware_info_buffer Buffer to receive the Firmware Information body.
Tennessee Carmel-Veilleuxb0b53c82021-08-16 21:33:19 -040053 * @returns CHIP_NO_ERROR on success, CHIP_ERROR_BUFFER_TOO_SMALL if `out_firmware_info_buffer`
54 * is too small, or another CHIP_ERROR from the underlying implementation if access fails.
55 */
56 virtual CHIP_ERROR GetFirmwareInformation(MutableByteSpan & out_firmware_info_buffer) = 0;
57
58 /**
59 * @brief Get the Device Attestation Certificate in DER format. Updates `out_dac_buffer`'s
60 * size on success to match the data size. If no Device Attestation Certificate
61 * is available, sets `out_dac_buffer` to empty.
62 *
Tennessee Carmel-Veilleux8f86c432022-03-11 15:49:56 -050063 * @param[in,out] out_dac_buffer Buffer to receive the Device Attestation Certificate.
Tennessee Carmel-Veilleuxb0b53c82021-08-16 21:33:19 -040064 * @returns CHIP_NO_ERROR on success, CHIP_ERROR_BUFFER_TOO_SMALL if `out_dac_buffer`
65 * is too small, or another CHIP_ERROR from the underlying implementation if
66 * access fails.
67 */
68 virtual CHIP_ERROR GetDeviceAttestationCert(MutableByteSpan & out_dac_buffer) = 0;
69
70 /**
71 * @brief Get the PAI Certificate in DER format. Updates `out_pai_buffer`'s
72 * size on success to match the data size. If no PAI certificate
73 * is available, sets `out_pai_buffer` to empty.
74 *
Tennessee Carmel-Veilleux8f86c432022-03-11 15:49:56 -050075 * @param[in,out] out_pai_buffer Buffer to receive the PAI certificate.
Tennessee Carmel-Veilleuxb0b53c82021-08-16 21:33:19 -040076 * @returns CHIP_NO_ERROR on success, CHIP_ERROR_BUFFER_TOO_SMALL if `out_pai_buffer`
77 * is too small, or another CHIP_ERROR from the underlying implementation if
78 * access fails.
79 */
80 virtual CHIP_ERROR GetProductAttestationIntermediateCert(MutableByteSpan & out_pai_buffer) = 0;
81
82 /**
Tennessee Carmel-Veilleux81c7f2a2022-06-28 23:23:53 -040083 * @brief Signs a message using the device attestation private key
Tennessee Carmel-Veilleuxb0b53c82021-08-16 21:33:19 -040084 *
Tennessee Carmel-Veilleux81c7f2a2022-06-28 23:23:53 -040085 * @param[in] message_to_sign The message to sign using the attestation private key.
Tennessee Carmel-Veilleux8f86c432022-03-11 15:49:56 -050086 * @param[in,out] out_signature_buffer Buffer to receive the signature in raw <r,s> format.
Tennessee Carmel-Veilleux81c7f2a2022-06-28 23:23:53 -040087 * @returns CHIP_NO_ERROR on success, CHIP_ERROR_BUFFER_TOO_SMALL if `out_signature_buffer` is too small,
Tennessee Carmel-Veilleuxb0b53c82021-08-16 21:33:19 -040088 * or another CHIP_ERROR from the underlying implementation if signature fails.
89 */
Tennessee Carmel-Veilleux81c7f2a2022-06-28 23:23:53 -040090 virtual CHIP_ERROR SignWithDeviceAttestationKey(const ByteSpan & message_to_sign, MutableByteSpan & out_signature_buffer) = 0;
Tennessee Carmel-Veilleuxb0b53c82021-08-16 21:33:19 -040091};
92
93/**
94 * Instance getter for the global DeviceAttestationCredentialsProvider.
95 *
96 * Callers have to externally synchronize usage of this function.
97 *
98 * @return The global device attestation credentials provider. Assume never null.
99 */
100DeviceAttestationCredentialsProvider * GetDeviceAttestationCredentialsProvider();
101
102/**
103 * Instance setter for the global DeviceAttestationCredentialsProvider.
104 *
105 * Callers have to externally synchronize usage of this function.
106 *
107 * If the `provider` is nullptr, no change is done.
108 *
109 * @param[in] provider the DeviceAttestationCredentialsProvider to start returning with the getter
110 */
111void SetDeviceAttestationCredentialsProvider(DeviceAttestationCredentialsProvider * provider);
112
Hui.Li-TCL121263f2022-03-14 23:19:36 +0800113/**
114 * Check if Instance is prepared
115 */
116bool IsDeviceAttestationCredentialsProviderSet();
117
Tennessee Carmel-Veilleuxb0b53c82021-08-16 21:33:19 -0400118} // namespace Credentials
119} // namespace chip