Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2023 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 :
18 : #pragma once
19 :
20 : #include "ICDClientInfo.h"
21 : #include <crypto/CHIPCryptoPAL.h>
22 : #include <lib/core/CHIPConfig.h>
23 : #include <lib/core/CHIPPersistentStorageDelegate.h>
24 : #include <lib/core/DataModelTypes.h>
25 : #include <lib/core/ScopedNodeId.h>
26 : #include <lib/support/CodeUtils.h>
27 : #include <lib/support/CommonIterator.h>
28 : #include <protocols/secure_channel/CheckinMessage.h>
29 : #include <stddef.h>
30 :
31 : namespace chip {
32 : namespace app {
33 :
34 : /**
35 : * The ICDClientStorage class is an abstract interface that defines the operations
36 : * for storing, retrieving and deleting ICD client information in persistent storage.
37 : */
38 : class ICDClientStorage
39 : {
40 : public:
41 8 : virtual ~ICDClientStorage() = default;
42 :
43 : /**
44 : * Called during ICD device registration in commissioning, commissioner/controller
45 : * provides raw key data, the shared aes key handle and hmac key handle in clientInfo are updated based upon raw key data
46 : *
47 : * @param[inout] clientInfo the ICD Client information to be updated with keyData and be saved
48 : * @param[in] aKeyData raw key data provided by application
49 : */
50 : virtual CHIP_ERROR SetKey(ICDClientInfo & clientInfo, const ByteSpan keyData) = 0;
51 :
52 : /**
53 : * Store updated ICD ClientInfo to storage when ICD registration completes or check-in message
54 : * comes.
55 : *
56 : * @param[in] clientInfo the updated ICD Client Info.
57 : */
58 : virtual CHIP_ERROR StoreEntry(const ICDClientInfo & clientInfo) = 0;
59 :
60 : /**
61 : * This function removes the ICD key from the provided clientInfo object in the event
62 : * of a failed LIT ICD device registration attempt. If the key handle is not found within
63 : * the Keystore, the function will not perform any operation.
64 : * @param[inout] clientInfo The ICD Client Info to update with uninitialized key handle if key is removed successfully.
65 : */
66 : virtual void RemoveKey(ICDClientInfo & clientInfo) = 0;
67 :
68 : /**
69 : * Delete ICD Client persistent information associated with the specified scoped node Id.
70 : * when ICD device is unpaired/removed, the corresponding entry in ICD storage is removed.
71 : * @param peerNode scoped node with peer node id and fabric index
72 : */
73 : virtual CHIP_ERROR DeleteEntry(const ScopedNodeId & peerNode) = 0;
74 :
75 : /**
76 : * Process received ICD check-in message payload. The implementation needs to parse the payload,
77 : * look for a key that allows successfully decrypting the payload, verify that the counter in the payload is valid,
78 : * and populate the clientInfo with the stored information corresponding to the key.
79 : * @param[in] payload received check-in Message payload
80 : * @param[out] clientInfo retrieved matched clientInfo from storage
81 : * @param[out] counter counter value received in the check-in message
82 : */
83 : virtual CHIP_ERROR ProcessCheckInPayload(const ByteSpan & payload, ICDClientInfo & clientInfo,
84 : Protocols::SecureChannel::CounterType & counter) = 0;
85 :
86 : // 4 bytes for counter + 2 bytes for ActiveModeThreshold
87 : static inline constexpr uint8_t kAppDataLength = 6;
88 : };
89 : } // namespace app
90 : } // namespace chip
|