Line data Source code
1 : /*
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 : #include "DeviceAttestationCredsProvider.h"
18 :
19 : namespace chip {
20 : namespace Credentials {
21 :
22 : namespace {
23 :
24 : // Version to have a default placeholder so the getter never
25 : // returns `nullptr` by default.
26 : class UnimplementedDACProvider : public DeviceAttestationCredentialsProvider
27 : {
28 : public:
29 0 : CHIP_ERROR GetCertificationDeclaration(MutableByteSpan & out_cd_buffer) override
30 : {
31 : (void) out_cd_buffer;
32 0 : return CHIP_ERROR_NOT_IMPLEMENTED;
33 : }
34 :
35 0 : CHIP_ERROR GetFirmwareInformation(MutableByteSpan & out_firmware_info_buffer) override
36 : {
37 : (void) out_firmware_info_buffer;
38 0 : return CHIP_ERROR_NOT_IMPLEMENTED;
39 : }
40 :
41 1 : CHIP_ERROR GetDeviceAttestationCert(MutableByteSpan & out_dac_buffer) override
42 : {
43 : (void) out_dac_buffer;
44 1 : return CHIP_ERROR_NOT_IMPLEMENTED;
45 : }
46 :
47 0 : CHIP_ERROR GetProductAttestationIntermediateCert(MutableByteSpan & out_pai_buffer) override
48 : {
49 : (void) out_pai_buffer;
50 0 : return CHIP_ERROR_NOT_IMPLEMENTED;
51 : }
52 :
53 0 : CHIP_ERROR SignWithDeviceAttestationKey(const ByteSpan & message_to_sign, MutableByteSpan & out_signature_buffer) override
54 : {
55 : (void) message_to_sign;
56 : (void) out_signature_buffer;
57 0 : return CHIP_ERROR_NOT_IMPLEMENTED;
58 : }
59 : };
60 :
61 : // Default to avoid nullptr on getter and cleanly handle new products/clients before
62 : // they provide their own.
63 : UnimplementedDACProvider gDefaultDACProvider;
64 :
65 : DeviceAttestationCredentialsProvider * gDacProvider = &gDefaultDACProvider;
66 :
67 : } // namespace
68 :
69 2 : DeviceAttestationCredentialsProvider * GetDeviceAttestationCredentialsProvider()
70 : {
71 2 : return gDacProvider;
72 : }
73 :
74 1 : void SetDeviceAttestationCredentialsProvider(DeviceAttestationCredentialsProvider * provider)
75 : {
76 1 : if (provider == nullptr)
77 : {
78 0 : return;
79 : }
80 :
81 1 : gDacProvider = provider;
82 : }
83 :
84 0 : bool IsDeviceAttestationCredentialsProviderSet()
85 : {
86 0 : return (gDacProvider != &gDefaultDACProvider);
87 : }
88 :
89 : } // namespace Credentials
90 : } // namespace chip
|