Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2022 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 : #include <platform/CommissionableDataProvider.h>
22 :
23 : namespace chip {
24 : namespace DeviceLayer {
25 :
26 : /**
27 : * @brief Version of a CommissionableDataProvider with just enough
28 : * support for basic tests of the minimum required CommissionableDataProvider
29 : * features, using a default passcode and discriminator.
30 : */
31 : class TestOnlyCommissionableDataProvider : public CommissionableDataProvider
32 : {
33 : public:
34 2 : TestOnlyCommissionableDataProvider() {}
35 :
36 8 : CHIP_ERROR GetSetupDiscriminator(uint16_t & setupDiscriminator) override
37 : {
38 8 : constexpr uint16_t kDefaultTestDiscriminator = 3840;
39 8 : setupDiscriminator = kDefaultTestDiscriminator;
40 8 : return CHIP_NO_ERROR;
41 : }
42 :
43 0 : CHIP_ERROR SetSetupDiscriminator(uint16_t setupDiscriminator) override
44 : {
45 : (void) setupDiscriminator;
46 0 : return CHIP_ERROR_NOT_IMPLEMENTED;
47 : }
48 :
49 5 : CHIP_ERROR GetSpake2pIterationCount(uint32_t & iterationCount) override
50 : {
51 5 : constexpr uint32_t kDefaultTestVerifierIterationCount = 1000;
52 5 : iterationCount = kDefaultTestVerifierIterationCount;
53 5 : return CHIP_NO_ERROR;
54 : }
55 :
56 5 : CHIP_ERROR GetSpake2pSalt(MutableByteSpan & saltBuf) override
57 : {
58 5 : const uint8_t kDefaultTestVerifierSalt[16] = {
59 : 0x53, 0x50, 0x41, 0x4b, 0x45, 0x32, 0x50, 0x20, 0x4b, 0x65, 0x79, 0x20, 0x53, 0x61, 0x6c, 0x74,
60 : };
61 :
62 5 : size_t saltLen = sizeof(kDefaultTestVerifierSalt);
63 5 : if (saltBuf.size() < saltLen)
64 : {
65 0 : return CHIP_ERROR_BUFFER_TOO_SMALL;
66 : }
67 5 : memcpy(saltBuf.data(), &kDefaultTestVerifierSalt[0], saltLen);
68 5 : saltBuf.reduce_size(saltLen);
69 5 : return CHIP_NO_ERROR;
70 : }
71 :
72 5 : CHIP_ERROR GetSpake2pVerifier(MutableByteSpan & verifierBuf, size_t & outVerifierLen) override
73 : {
74 5 : const uint8_t kDefaultTestVerifier[97] = {
75 : 0xb9, 0x61, 0x70, 0xaa, 0xe8, 0x03, 0x34, 0x68, 0x84, 0x72, 0x4f, 0xe9, 0xa3, 0xb2, 0x87, 0xc3, 0x03, 0x30, 0xc2, 0xa6,
76 : 0x60, 0x37, 0x5d, 0x17, 0xbb, 0x20, 0x5a, 0x8c, 0xf1, 0xae, 0xcb, 0x35, 0x04, 0x57, 0xf8, 0xab, 0x79, 0xee, 0x25, 0x3a,
77 : 0xb6, 0xa8, 0xe4, 0x6b, 0xb0, 0x9e, 0x54, 0x3a, 0xe4, 0x22, 0x73, 0x6d, 0xe5, 0x01, 0xe3, 0xdb, 0x37, 0xd4, 0x41, 0xfe,
78 : 0x34, 0x49, 0x20, 0xd0, 0x95, 0x48, 0xe4, 0xc1, 0x82, 0x40, 0x63, 0x0c, 0x4f, 0xf4, 0x91, 0x3c, 0x53, 0x51, 0x38, 0x39,
79 : 0xb7, 0xc0, 0x7f, 0xcc, 0x06, 0x27, 0xa1, 0xb8, 0x57, 0x3a, 0x14, 0x9f, 0xcd, 0x1f, 0xa4, 0x66, 0xcf,
80 : };
81 :
82 5 : outVerifierLen = sizeof(kDefaultTestVerifier);
83 5 : if (verifierBuf.size() < outVerifierLen)
84 : {
85 0 : return CHIP_ERROR_BUFFER_TOO_SMALL;
86 : }
87 5 : memcpy(verifierBuf.data(), &kDefaultTestVerifier[0], outVerifierLen);
88 5 : verifierBuf.reduce_size(outVerifierLen);
89 5 : return CHIP_NO_ERROR;
90 : }
91 :
92 0 : CHIP_ERROR GetSetupPasscode(uint32_t & setupPasscode) override
93 : {
94 0 : constexpr uint32_t kDefaultTestPasscode = 20202021;
95 0 : setupPasscode = kDefaultTestPasscode;
96 0 : return CHIP_NO_ERROR;
97 : }
98 :
99 0 : CHIP_ERROR SetSetupPasscode(uint32_t setupPasscode) override
100 : {
101 : (void) setupPasscode;
102 0 : return CHIP_ERROR_NOT_IMPLEMENTED;
103 : }
104 : };
105 :
106 : } // namespace DeviceLayer
107 : } // namespace chip
|