Skip to content

Commit

Permalink
Remove role argument from DeriveSecureSession
Browse files Browse the repository at this point in the history
  • Loading branch information
kghost committed Apr 19, 2022
1 parent eff0885 commit 3834aa9
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/protocols/secure_channel/CASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void CASESession::OnResponseTimeout(ExchangeContext * ec)
mDelegate->OnSessionEstablishmentError(CHIP_ERROR_TIMEOUT);
}

CHIP_ERROR CASESession::DeriveSecureSession(CryptoContext & session, CryptoContext::SessionRole role) const
CHIP_ERROR CASESession::DeriveSecureSession(CryptoContext & session) const
{
size_t saltlen;

Expand All @@ -305,7 +305,7 @@ CHIP_ERROR CASESession::DeriveSecureSession(CryptoContext & session, CryptoConte
}

ReturnErrorOnFailure(session.InitFromSecret(ByteSpan(mSharedSecret, mSharedSecret.Length()), ByteSpan(msg_salt.Get(), saltlen),
CryptoContext::SessionInfoType::kSessionEstablishment, role));
CryptoContext::SessionInfoType::kSessionEstablishment, mRole));

return CHIP_NO_ERROR;
}
Expand Down
9 changes: 3 additions & 6 deletions src/protocols/secure_channel/CASESession.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,12 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler,

/**
* @brief
* Derive a secure session from the established session. The API will return error
* if called before session is established.
* Derive a secure session from the established session. The API will return error if called before session is established.
*
* @param session Reference to the secure session that will be
* initialized once session establishment is complete
* @param role Role of the new session (initiator or responder)
* @param session Reference to the secure session that will be initialized once session establishment is complete
* @return CHIP_ERROR The result of session derivation
*/
CHIP_ERROR DeriveSecureSession(CryptoContext & session, CryptoContext::SessionRole role) const override;
CHIP_ERROR DeriveSecureSession(CryptoContext & session) const override;

//// UnsolicitedMessageHandler Implementation ////
CHIP_ERROR OnUnsolicitedMessageReceived(const PayloadHeader & payloadHeader, ExchangeDelegate *& newDelegate) override
Expand Down
4 changes: 2 additions & 2 deletions src/protocols/secure_channel/PASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ void PASESession::OnResponseTimeout(ExchangeContext * ec)
mDelegate->OnSessionEstablishmentError(CHIP_ERROR_TIMEOUT);
}

CHIP_ERROR PASESession::DeriveSecureSession(CryptoContext & session, CryptoContext::SessionRole role) const
CHIP_ERROR PASESession::DeriveSecureSession(CryptoContext & session) const
{
VerifyOrReturnError(mPairingComplete, CHIP_ERROR_INCORRECT_STATE);
return session.InitFromSecret(ByteSpan(mKe, mKeLen), ByteSpan(nullptr, 0),
CryptoContext::SessionInfoType::kSessionEstablishment, role);
CryptoContext::SessionInfoType::kSessionEstablishment, mRole);
}

CHIP_ERROR PASESession::SendPBKDFParamRequest()
Expand Down
9 changes: 3 additions & 6 deletions src/protocols/secure_channel/PASESession.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,12 @@ class DLL_EXPORT PASESession : public Messaging::UnsolicitedMessageHandler,

/**
* @brief
* Derive a secure session from the paired session. The API will return error
* if called before pairing is established.
* Derive a secure session from the paired session. The API will return error if called before pairing is established.
*
* @param session Reference to the secure session that will be
* initialized once pairing is complete
* @param role Role of the new session (initiator or responder)
* @param session Reference to the secure session that will be initialized once pairing is complete
* @return CHIP_ERROR The result of session derivation
*/
CHIP_ERROR DeriveSecureSession(CryptoContext & session, CryptoContext::SessionRole role) const override;
CHIP_ERROR DeriveSecureSession(CryptoContext & session) const override;

// TODO: remove Clear, we should create a new instance instead reset the old instance.
/** @brief This function zeroes out and resets the memory used by the object.
Expand Down
2 changes: 1 addition & 1 deletion src/transport/PairingSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CHIP_ERROR PairingSession::ActivateSecureSession(const Transport::PeerAddress &
ChipLogValueScopedNodeId(GetPeer()), secureSession->GetLocalSessionId(), peerSessionId);
secureSession->Activate(GetSecureSessionType(), GetPeer(), GetPeerCATs(), peerSessionId, mRemoteMRPConfig);
secureSession->SetPeerAddress(peerAddress);
ReturnErrorOnFailure(DeriveSecureSession(secureSession->GetCryptoContext(), mRole));
ReturnErrorOnFailure(DeriveSecureSession(secureSession->GetCryptoContext()));
secureSession->GetSessionMessageCounter().GetPeerMessageCounter().SetCounter(LocalSessionMessageCounter::kInitialSyncValue);

return CHIP_NO_ERROR;
Expand Down
9 changes: 3 additions & 6 deletions src/transport/PairingSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,12 @@ class DLL_EXPORT PairingSession

/**
* @brief
* Derive a secure session from the paired session. The API will return error
* if called before pairing is established.
* Derive a secure session from the paired session. The API will return error if called before pairing is established.
*
* @param session Reference to the secure session that will be
* initialized once pairing is complete
* @param role Role of the new session (initiator or responder)
* @param session Reference to the secure session that will be initialized once pairing is complete
* @return CHIP_ERROR The result of session derivation
*/
virtual CHIP_ERROR DeriveSecureSession(CryptoContext & session, CryptoContext::SessionRole role) const = 0;
virtual CHIP_ERROR DeriveSecureSession(CryptoContext & session) const = 0;

const ReliableMessageProtocolConfig & GetRemoteMRPConfig() const { return mRemoteMRPConfig; }
void SetRemoteMRPConfig(const ReliableMessageProtocolConfig & config) { mRemoteMRPConfig = config; }
Expand Down
5 changes: 1 addition & 4 deletions src/transport/tests/TestPairingSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ class TestPairingSession : public PairingSession

const ReliableMessageProtocolConfig & GetRemoteMRPConfig() const { return mRemoteMRPConfig; }

CHIP_ERROR DeriveSecureSession(CryptoContext & session, CryptoContext::SessionRole role) const override
{
return CHIP_NO_ERROR;
}
CHIP_ERROR DeriveSecureSession(CryptoContext & session) const override { return CHIP_NO_ERROR; }

CHIP_ERROR DecodeMRPParametersIfPresent(TLV::Tag expectedTag, System::PacketBufferTLVReader & tlvReader)
{
Expand Down

0 comments on commit 3834aa9

Please sign in to comment.