@@ -770,7 +770,7 @@ CHIP_ERROR CASESession::SendSigma1()
770
770
System::PacketBufferHandle msg_R1;
771
771
uint8_t destinationIdentifier[kSHA256_Hash_Length ] = { 0 };
772
772
773
- Sigma1Param encodeSigma1Params;
773
+ EncodeSigma1Param encodeSigma1Params;
774
774
775
775
// Lookup fabric info.
776
776
const auto * fabricInfo = mFabricsTable ->FindFabricWithIndex (mFabricIndex );
@@ -784,9 +784,11 @@ CHIP_ERROR CASESession::SendSigma1()
784
784
mEphemeralKey = mFabricsTable ->AllocateEphemeralKeypairForCASE ();
785
785
VerifyOrReturnError (mEphemeralKey != nullptr , CHIP_ERROR_NO_MEMORY);
786
786
ReturnErrorOnFailure (mEphemeralKey ->Initialize (ECPKeyTarget::ECDH));
787
+ encodeSigma1Params.pEphPubKey = &mEphemeralKey ->Pubkey ();
787
788
788
789
// Fill in the random value
789
790
ReturnErrorOnFailure (DRBG_get_bytes (mInitiatorRandom , sizeof (mInitiatorRandom )));
791
+ encodeSigma1Params.initiatorRandom = ByteSpan (mInitiatorRandom );
790
792
791
793
// Generate a Destination Identifier based on the node we are attempting to reach
792
794
{
@@ -800,15 +802,15 @@ CHIP_ERROR CASESession::SendSigma1()
800
802
Credentials::P256PublicKeySpan rootPubKeySpan{ rootPubKey.ConstBytes () };
801
803
802
804
MutableByteSpan destinationIdSpan (destinationIdentifier);
803
- ReturnErrorOnFailure (GenerateCaseDestinationId (ByteSpan (mIPK ), ByteSpan ( mInitiatorRandom ) , rootPubKeySpan, fabricId,
805
+ ReturnErrorOnFailure (GenerateCaseDestinationId (ByteSpan (mIPK ), encodeSigma1Params. initiatorRandom , rootPubKeySpan, fabricId,
804
806
mPeerNodeId , destinationIdSpan));
805
807
encodeSigma1Params.destinationId = destinationIdSpan;
806
808
}
807
809
808
810
VerifyOrReturnError (mLocalMRPConfig .HasValue (), CHIP_ERROR_INCORRECT_STATE);
811
+ encodeSigma1Params.initiatorMrpConfig = &mLocalMRPConfig .Value ();
809
812
810
813
// Try to find persistent session, and resume it.
811
- bool resuming = false ;
812
814
if (mSessionResumptionStorage != nullptr )
813
815
{
814
816
CHIP_ERROR err = mSessionResumptionStorage ->FindByScopedNodeId (fabricInfo->GetScopedNodeIdForNode (mPeerNodeId ),
@@ -817,14 +819,13 @@ CHIP_ERROR CASESession::SendSigma1()
817
819
{
818
820
// Found valid resumption state, try to resume the session.
819
821
822
+ encodeSigma1Params.resumptionId = mResumeResumptionId ;
820
823
MutableByteSpan resumeMICSpan (encodeSigma1Params.initiatorResume1MIC );
821
- ReturnErrorOnFailure (GenerateSigmaResumeMIC (ByteSpan ( mInitiatorRandom ), ByteSpan ( mResumeResumptionId ) ,
824
+ ReturnErrorOnFailure (GenerateSigmaResumeMIC (encodeSigma1Params. initiatorRandom , encodeSigma1Params. resumptionId ,
822
825
ByteSpan (kKDFS1RKeyInfo ), ByteSpan (kResume1MIC_Nonce ), resumeMICSpan));
823
826
824
827
encodeSigma1Params.initiatorResumeMICSpan = resumeMICSpan;
825
828
encodeSigma1Params.sessionResumptionRequested = true ;
826
-
827
- resuming = true ;
828
829
}
829
830
}
830
831
@@ -837,7 +838,7 @@ CHIP_ERROR CASESession::SendSigma1()
837
838
ReturnErrorOnFailure (mExchangeCtxt .Value ()->SendMessage (Protocols::SecureChannel::MsgType::CASE_Sigma1, std::move (msg_R1),
838
839
SendFlags (SendMessageFlags::kExpectResponse )));
839
840
840
- if (resuming )
841
+ if (encodeSigma1Params. sessionResumptionRequested )
841
842
{
842
843
mState = State::kSentSigma1Resume ;
843
844
@@ -861,17 +862,19 @@ CHIP_ERROR CASESession::SendSigma1()
861
862
return CHIP_NO_ERROR;
862
863
}
863
864
864
- CHIP_ERROR CASESession::EncodeSigma1 (System::PacketBufferHandle & msg, Sigma1Param & inputParams )
865
+ CHIP_ERROR CASESession::EncodeSigma1 (System::PacketBufferHandle & msg, EncodeSigma1Param & input )
865
866
{
866
867
867
868
MATTER_TRACE_SCOPE (" EncodeSigma1" , " CASESession" );
868
869
869
- size_t data_len = TLV::EstimateStructOverhead (kSigmaParamRandomNumberSize , // initiatorRandom
870
- sizeof (uint16_t ), // initiatorSessionId,
871
- kSHA256_Hash_Length , // destinationId
872
- kP256_PublicKey_Length , // InitiatorEphPubKey,
873
- SessionParameters::kEstimatedTLVSize , // initiatorSessionParams
874
- SessionResumptionStorage::kResumptionIdSize , CHIP_CRYPTO_AEAD_MIC_LENGTH_BYTES);
870
+ size_t data_len = TLV::EstimateStructOverhead (kSigmaParamRandomNumberSize , // initiatorRandom
871
+ sizeof (uint16_t ), // initiatorSessionId,
872
+ kSHA256_Hash_Length , // destinationId
873
+ kP256_PublicKey_Length , // InitiatorEphPubKey,
874
+ SessionParameters::kEstimatedTLVSize , // initiatorSessionParams
875
+ SessionResumptionStorage::kResumptionIdSize , // resumptionId
876
+ CHIP_CRYPTO_AEAD_MIC_LENGTH_BYTES // initiatorResumeMIC
877
+ );
875
878
876
879
msg = System::PacketBufferHandle::New (data_len);
877
880
VerifyOrReturnError (!msg.IsNull (), CHIP_ERROR_NO_MEMORY);
@@ -881,24 +884,21 @@ CHIP_ERROR CASESession::EncodeSigma1(System::PacketBufferHandle & msg, Sigma1Par
881
884
882
885
tlvWriter.Init (std::move (msg));
883
886
ReturnErrorOnFailure (tlvWriter.StartContainer (TLV::AnonymousTag (), TLV::kTLVType_Structure , outerContainerType));
884
- // TODO Pass this in the struct?
885
- ReturnErrorOnFailure (tlvWriter.Put (TLV::ContextTag (kInitiatorRandomTag ), ByteSpan (mInitiatorRandom )));
886
- ReturnErrorOnFailure (tlvWriter.Put (TLV::ContextTag (kInitiatorSessionIdTag ), inputParams.initiatorSessionId ));
887
-
888
- ReturnErrorOnFailure (tlvWriter.Put (TLV::ContextTag (kDestinationIdTag ), inputParams.destinationId ));
887
+ ReturnErrorOnFailure (tlvWriter.Put (TLV::ContextTag (kInitiatorRandomTag ), input.initiatorRandom ));
888
+ ReturnErrorOnFailure (tlvWriter.Put (TLV::ContextTag (kInitiatorSessionIdTag ), input.initiatorSessionId ));
889
+ ReturnErrorOnFailure (tlvWriter.Put (TLV::ContextTag (kDestinationIdTag ), input.destinationId ));
889
890
890
- // TODO Pass this in the struct?
891
- ReturnErrorOnFailure (tlvWriter.PutBytes (TLV::ContextTag (kInitiatorPubKeyTag ), mEphemeralKey -> Pubkey () ,
892
- static_cast <uint32_t >(mEphemeralKey -> Pubkey (). Length ())));
891
+ VerifyOrReturnError (input. pEphPubKey != nullptr , CHIP_ERROR_INCORRECT_STATE);
892
+ ReturnErrorOnFailure (tlvWriter.PutBytes (TLV::ContextTag (kInitiatorPubKeyTag ), *input. pEphPubKey ,
893
+ static_cast <uint32_t >(input. pEphPubKey -> Length ())));
893
894
894
- // TODO is it redudunt?
895
- VerifyOrReturnError (mLocalMRPConfig .HasValue (), CHIP_ERROR_INCORRECT_STATE);
896
- ReturnErrorOnFailure (EncodeSessionParameters (TLV::ContextTag (kInitiatorMRPParamsTag ), mLocalMRPConfig .Value (), tlvWriter));
895
+ VerifyOrReturnError (input.initiatorMrpConfig != nullptr , CHIP_ERROR_INCORRECT_STATE);
896
+ ReturnErrorOnFailure (EncodeSessionParameters (TLV::ContextTag (kInitiatorMRPParamsTag ), *input.initiatorMrpConfig , tlvWriter));
897
897
898
- if (inputParams .sessionResumptionRequested )
898
+ if (input .sessionResumptionRequested )
899
899
{
900
- ReturnErrorOnFailure (tlvWriter.Put (TLV::ContextTag (kResumptionIDTag ), mResumeResumptionId ));
901
- ReturnErrorOnFailure (tlvWriter.Put (TLV::ContextTag (kResume1MICTag ), inputParams .initiatorResumeMICSpan ));
900
+ ReturnErrorOnFailure (tlvWriter.Put (TLV::ContextTag (kResumptionIDTag ), input. resumptionId ));
901
+ ReturnErrorOnFailure (tlvWriter.Put (TLV::ContextTag (kResume1MICTag ), input .initiatorResumeMICSpan ));
902
902
}
903
903
904
904
ReturnErrorOnFailure (tlvWriter.EndContainer (outerContainerType));
@@ -1003,7 +1003,7 @@ CHIP_ERROR CASESession::HandleSigma1(System::PacketBufferHandle && msg)
1003
1003
CHIP_ERROR err = CHIP_NO_ERROR;
1004
1004
System::PacketBufferTLVReader tlvReader;
1005
1005
1006
- Sigma1Param parsedSigma1;
1006
+ ParseSigma1Param parsedSigma1;
1007
1007
1008
1008
SuccessOrExit (err = mCommissioningHash .AddData (ByteSpan{ msg->Start (), msg->DataLength () }));
1009
1009
@@ -1016,11 +1016,8 @@ CHIP_ERROR CASESession::HandleSigma1(System::PacketBufferHandle && msg)
1016
1016
1017
1017
VerifyOrExit (mFabricsTable != nullptr , err = CHIP_ERROR_INCORRECT_STATE);
1018
1018
1019
- // TODO: Added by Amine, taken from inside ParseSigma1
1020
- // This was removed to remove the non-parsing parts from ParseSigma1, decoupling it from higher levels
1021
- // TODO: Should i change it?
1022
- // Set the recieved MRP parameters included with Sigma1
1023
- if (parsedSigma1.InitiatorMRPParamsPresent == true )
1019
+ // Set the MRP parameters provided in the Sigma1 message
1020
+ if (parsedSigma1.InitiatorMRPParamsPresent )
1024
1021
{
1025
1022
mExchangeCtxt .Value ()->GetSessionHandle ()->AsUnauthenticatedSession ()->SetRemoteSessionParameters (
1026
1023
GetRemoteSessionParameters ());
@@ -2191,7 +2188,7 @@ CHIP_ERROR CASESession::OnFailureStatusReport(Protocols::SecureChannel::GeneralS
2191
2188
return err;
2192
2189
}
2193
2190
2194
- CHIP_ERROR CASESession::ParseSigma1 (TLV::ContiguousBufferTLVReader & tlvReader, Sigma1Param & output)
2191
+ CHIP_ERROR CASESession::ParseSigma1 (TLV::ContiguousBufferTLVReader & tlvReader, ParseSigma1Param & output)
2195
2192
{
2196
2193
using namespace TLV ;
2197
2194
0 commit comments