Skip to content

Commit

Permalink
Use current time during CASE session handshake (#13462)
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-apple authored and pull[bot] committed Jan 4, 2024
1 parent 2483814 commit 1fbf5e7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
29 changes: 24 additions & 5 deletions src/protocols/secure_channel/CASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,22 +1298,41 @@ CHIP_ERROR CASESession::RetrieveIPK(FabricId fabricId, MutableByteSpan & ipk)
return CHIP_NO_ERROR;
}

// TODO: Remove this and replace with system method to retrieve current time
CHIP_ERROR CASESession::SetEffectiveTime(void)
CHIP_ERROR CASESession::GetHardcodedTime()
{
using namespace ASN1;
ASN1UniversalTime effectiveTime;

effectiveTime.Year = 2021;
effectiveTime.Month = 2;
effectiveTime.Day = 12;
effectiveTime.Year = 2022;
effectiveTime.Month = 1;
effectiveTime.Day = 1;
effectiveTime.Hour = 10;
effectiveTime.Minute = 10;
effectiveTime.Second = 10;

return ASN1ToChipEpochTime(effectiveTime, mValidContext.mEffectiveTime);
}

CHIP_ERROR CASESession::SetEffectiveTime()
{
System::Clock::Milliseconds64 currentTimeMS;
CHIP_ERROR err = System::SystemClock().GetClock_RealTimeMS(currentTimeMS);
if (err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE)
{
ChipLogError(
SecureChannel,
"The device does not support GetClock_RealTimeMS() API. This will eventually result in CASE session setup failures.");
// TODO: Remove use of hardcoded time during CASE setup
return GetHardcodedTime();
}
ReturnErrorOnFailure(err);

System::Clock::Seconds32 currentTime = std::chrono::duration_cast<System::Clock::Seconds32>(currentTimeMS);
VerifyOrReturnError(UnixEpochToChipEpochTime(currentTime.count(), mValidContext.mEffectiveTime), CHIP_ERROR_INVALID_TIME);

return CHIP_NO_ERROR;
}

void CASESession::OnSuccessStatusReport()
{
ChipLogProgress(SecureChannel, "Success status report received. Session was established");
Expand Down
5 changes: 3 additions & 2 deletions src/protocols/secure_channel/CASESession.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ class DLL_EXPORT CASESession : public Messaging::ExchangeDelegate, public Pairin
*/
void DiscardExchange();

// TODO: Remove this and replace with system method to retrieve current time
CHIP_ERROR SetEffectiveTime(void);
CHIP_ERROR GetHardcodedTime();

CHIP_ERROR SetEffectiveTime();

CHIP_ERROR ValidateReceivedMessage(Messaging::ExchangeContext * ec, const PayloadHeader & payloadHeader,
System::PacketBufferHandle & msg);
Expand Down

0 comments on commit 1fbf5e7

Please sign in to comment.