@@ -981,6 +981,7 @@ TEST_F(TestCASESession, EncodeSigma2Test)
981
981
System::PacketBufferHandle msg;
982
982
CASESession session;
983
983
CASESession::EncodeSigma2Param encodeParams;
984
+ constexpr uint8_t kEncrypted2datalen = 100U ;
984
985
985
986
EXPECT_EQ (chip::Crypto::DRBG_get_bytes (&encodeParams.responderRandom [0 ], sizeof (encodeParams.responderRandom )), CHIP_NO_ERROR);
986
987
encodeParams.responderSessionId = 7315 ;
@@ -992,7 +993,8 @@ TEST_F(TestCASESession, EncodeSigma2Test)
992
993
encodeParams.pEphPubKey = &EphemeralKey->Pubkey ();
993
994
994
995
// TBEData2Encrypted
995
- encodeParams.msg_R2_Encrypted .Alloc (100 );
996
+ encodeParams.encrypted2Length = kEncrypted2datalen + CHIP_CRYPTO_AEAD_MIC_LENGTH_BYTES;
997
+ encodeParams.msg_R2_Encrypted .Alloc (encodeParams.encrypted2Length );
996
998
997
999
// responder Session Parameters
998
1000
ReliableMessageProtocolConfig MRPConfig = GetDefaultMRPConfig ();
@@ -1022,10 +1024,18 @@ TEST_F(TestCASESession, EncodeSigma2Test)
1022
1024
EXPECT_EQ (CHIP_ERROR_INCORRECT_STATE, session.EncodeSigma2 (msg, encodeParams));
1023
1025
msg = nullptr ;
1024
1026
1025
- encodeParams.msg_R2_Encrypted .Alloc (100 );
1027
+ encodeParams.msg_R2_Encrypted .Alloc (encodeParams. encrypted2Length );
1026
1028
1027
1029
EXPECT_EQ (CHIP_NO_ERROR, session.EncodeSigma2 (msg, encodeParams));
1028
1030
1031
+ // EncodeSigma1 should fail when the encrypted2Length is not set
1032
+ encodeParams.encrypted2Length = 0 ;
1033
+ EXPECT_EQ (CHIP_ERROR_INCORRECT_STATE, session.EncodeSigma2 (msg, encodeParams));
1034
+ msg = nullptr ;
1035
+
1036
+ // Set encrypted2Length again
1037
+ encodeParams.encrypted2Length = kEncrypted2datalen + CHIP_CRYPTO_AEAD_MIC_LENGTH_BYTES;
1038
+
1029
1039
// EncodeSigma1 should fail when MRP config is missing
1030
1040
encodeParams.responderMrpConfig = nullptr ;
1031
1041
EXPECT_EQ (CHIP_ERROR_INCORRECT_STATE, session.EncodeSigma2 (msg, encodeParams));
@@ -1043,8 +1053,8 @@ struct SessionResumptionTestStorage : SessionResumptionStorage
1043
1053
{
1044
1054
SessionResumptionTestStorage (CHIP_ERROR findMethodReturnCode, ScopedNodeId peerNodeId, ResumptionIdStorage * resumptionId,
1045
1055
Crypto::P256ECDHDerivedSecret * sharedSecret) :
1046
- mFindMethodReturnCode (findMethodReturnCode),
1047
- mPeerNodeId (peerNodeId), mResumptionId (resumptionId), mSharedSecret (sharedSecret)
1056
+ mFindMethodReturnCode (findMethodReturnCode), mPeerNodeId (peerNodeId), mResumptionId (resumptionId),
1057
+ mSharedSecret (sharedSecret)
1048
1058
{}
1049
1059
SessionResumptionTestStorage (CHIP_ERROR findMethodReturnCode) : mFindMethodReturnCode (findMethodReturnCode) {}
1050
1060
CHIP_ERROR FindByScopedNodeId (const ScopedNodeId & node, ResumptionIdStorage & resumptionId,
0 commit comments