Skip to content

Commit

Permalink
Add OnCreateRefreshKey (#33202)
Browse files Browse the repository at this point in the history
* Add OnCreateRefreshKey

* Update src/app/icd/client/DefaultCheckInDelegate.h

Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>

* Update src/app/icd/client/DefaultCheckInDelegate.h

Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>

* Update src/app/icd/client/DefaultCheckInDelegate.h

Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>

* Update DefaultCheckInDelegate.cpp

* Restyled by whitespace

---------

Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
3 people committed Apr 27, 2024
1 parent dd5f6b7 commit f9ac954
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/app/icd/client/DefaultCheckInDelegate.cpp
Expand Up @@ -16,7 +16,6 @@
*/

#include <app/icd/client/DefaultCheckInDelegate.h>
#include <app/icd/client/RefreshKeySender.h>
#include <crypto/CHIPCryptoPAL.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>
Expand All @@ -40,12 +39,16 @@ void DefaultCheckInDelegate::OnCheckInComplete(const ICDClientInfo & clientInfo)
clientInfo.start_icd_counter, clientInfo.offset, ChipLogValueScopedNodeId(clientInfo.peer_node));
}

CHIP_ERROR DefaultCheckInDelegate::GenerateRefreshKey(RefreshKeySender::RefreshKeyBuffer & newKey)
{
return Crypto::DRBG_get_bytes(newKey.Bytes(), newKey.Capacity());
}

RefreshKeySender * DefaultCheckInDelegate::OnKeyRefreshNeeded(ICDClientInfo & clientInfo, ICDClientStorage * clientStorage)
{
CHIP_ERROR err = CHIP_NO_ERROR;
RefreshKeySender::RefreshKeyBuffer newKey;

err = Crypto::DRBG_get_bytes(newKey.Bytes(), newKey.Capacity());
err = GenerateRefreshKey(newKey);
if (err != CHIP_NO_ERROR)
{
ChipLogError(ICD, "Generation of new key failed: %" CHIP_ERROR_FORMAT, err.Format());
Expand Down
12 changes: 12 additions & 0 deletions src/app/icd/client/DefaultCheckInDelegate.h
Expand Up @@ -20,6 +20,7 @@

#include <app/icd/client/CheckInDelegate.h>
#include <app/icd/client/ICDClientStorage.h>
#include <app/icd/client/RefreshKeySender.h>

namespace chip {
namespace app {
Expand All @@ -33,6 +34,17 @@ class DefaultCheckInDelegate : public CheckInDelegate
virtual ~DefaultCheckInDelegate() {}
CHIP_ERROR Init(ICDClientStorage * storage, InteractionModelEngine * engine);
void OnCheckInComplete(const ICDClientInfo & clientInfo) override;

/**
* @brief Callback used to let the application generate the new ICD symmetric key
*
* If this calback is not overridden, Crypto::DRBG_get_bytes will be used to generated the key.
*
* @param[inout] newKey sensitive data buffer with type Crypto::SensitiveDataBuffer<Crypto::kAES_CCM128_Key_Length>
* @param[out] CHIP_ERROR CHIP_ERROR_INVALID_ARGUMENT
* CHIP_ERROR_INTERNAL
*/
virtual CHIP_ERROR GenerateRefreshKey(RefreshKeySender::RefreshKeyBuffer & newKey);
RefreshKeySender * OnKeyRefreshNeeded(ICDClientInfo & clientInfo, ICDClientStorage * clientStorage) override;
void OnKeyRefreshDone(RefreshKeySender * refreshKeySender, CHIP_ERROR error) override;

Expand Down

0 comments on commit f9ac954

Please sign in to comment.