Skip to content

Commit 0e55cf8

Browse files
authored
Align Spake2 protocol message type definition with spec (project-chip#4167)
1 parent 4e78f50 commit 0e55cf8

File tree

3 files changed

+32
-38
lines changed

3 files changed

+32
-38
lines changed

src/protocols/secure_channel/SecureChannelProtocol.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ enum class MsgType
5252
StandaloneAck = 0x10,
5353

5454
// Password-based session establishment Message Types
55-
PASE_Spake2pA = 0x20,
56-
PASE_Spake2pB = 0x21,
57-
PASE_Spake2cA = 0x22,
55+
PBKDFParamRequest = 0x20,
56+
PBKDFParamResponse = 0x21,
57+
PASE_Spake2p1 = 0x22,
58+
PASE_Spake2p2 = 0x23,
59+
PASE_Spake2p3 = 0x24,
60+
PASE_Spake2pError = 0x2F,
5861

5962
// Certificate-based session establishment Message Types
6063
CASE_SigmaR1 = 0x30,

src/transport/SecurePairingSession.cpp

+23-23
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void SecurePairingSession::Clear()
6363
memset(&mPoint[0], 0, sizeof(mPoint));
6464
memset(&mWS[0][0], 0, sizeof(mWS));
6565
memset(&mKe[0], 0, sizeof(mKe));
66-
mNextExpectedMsg = Spake2pMsgType::kSpake2pMsgError;
66+
mNextExpectedMsg = Protocols::SecureChannel::MsgType::PASE_Spake2pError;
6767
mSpake2p.Init(nullptr);
6868
mCommissioningHash.Clear();
6969
mIterationCount = 0;
@@ -240,7 +240,7 @@ CHIP_ERROR SecurePairingSession::WaitForPairing(uint32_t mySetUpPINCode, uint32_
240240

241241
mIterationCount = pbkdf2IterCount;
242242

243-
mNextExpectedMsg = Spake2pMsgType::kPBKDFParamRequest;
243+
mNextExpectedMsg = Protocols::SecureChannel::MsgType::PBKDFParamRequest;
244244
mPairingComplete = false;
245245

246246
ChipLogDetail(Ble, "Waiting for PBKDF param request");
@@ -253,14 +253,14 @@ CHIP_ERROR SecurePairingSession::WaitForPairing(uint32_t mySetUpPINCode, uint32_
253253
return err;
254254
}
255255

256-
CHIP_ERROR SecurePairingSession::AttachHeaderAndSend(uint8_t msgType, System::PacketBufferHandle msgBuf)
256+
CHIP_ERROR SecurePairingSession::AttachHeaderAndSend(Protocols::SecureChannel::MsgType msgType, System::PacketBufferHandle msgBuf)
257257
{
258258
CHIP_ERROR err = CHIP_NO_ERROR;
259259

260260
PayloadHeader payloadHeader;
261261

262262
payloadHeader
263-
.SetMessageType(msgType) //
263+
.SetMessageType(static_cast<uint8_t>(msgType)) //
264264
.SetProtocolID(Protocols::kProtocol_SecureChannel);
265265

266266
uint16_t headerSize = payloadHeader.EncodeSizeBytes();
@@ -331,9 +331,9 @@ CHIP_ERROR SecurePairingSession::SendPBKDFParamRequest()
331331
err = mCommissioningHash.AddData(req->Start(), req->DataLength());
332332
SuccessOrExit(err);
333333

334-
mNextExpectedMsg = Spake2pMsgType::kPBKDFParamResponse;
334+
mNextExpectedMsg = Protocols::SecureChannel::MsgType::PBKDFParamResponse;
335335

336-
err = AttachHeaderAndSend(Spake2pMsgType::kPBKDFParamRequest, std::move(req));
336+
err = AttachHeaderAndSend(Protocols::SecureChannel::MsgType::PBKDFParamRequest, std::move(req));
337337
SuccessOrExit(err);
338338

339339
ChipLogDetail(Ble, "Sent PBKDF param request");
@@ -422,9 +422,9 @@ CHIP_ERROR SecurePairingSession::SendPBKDFParamResponse()
422422
err = mSpake2p.ComputeL(mPoint, &sizeof_point, &mWS[1][0], kSpake2p_WS_Length);
423423
SuccessOrExit(err);
424424

425-
mNextExpectedMsg = Spake2pMsgType::kSpake2pMsg1;
425+
mNextExpectedMsg = Protocols::SecureChannel::MsgType::PASE_Spake2p1;
426426

427-
err = AttachHeaderAndSend(Spake2pMsgType::kPBKDFParamResponse, std::move(resp));
427+
err = AttachHeaderAndSend(Protocols::SecureChannel::MsgType::PBKDFParamResponse, std::move(resp));
428428
SuccessOrExit(err);
429429

430430
ChipLogDetail(Ble, "Sent PBKDF param response");
@@ -505,10 +505,10 @@ CHIP_ERROR SecurePairingSession::SendMsg1()
505505
memcpy(msg_pA->Start(), &X[0], X_len);
506506

507507
msg_pA->SetDataLength(data_len);
508-
mNextExpectedMsg = Spake2pMsgType::kSpake2pMsg2;
508+
mNextExpectedMsg = Protocols::SecureChannel::MsgType::PASE_Spake2p2;
509509

510510
// Call delegate to send the Msg1 to peer
511-
err = AttachHeaderAndSend(Spake2pMsgType::kSpake2pMsg1, std::move(msg_pA));
511+
err = AttachHeaderAndSend(Protocols::SecureChannel::MsgType::PASE_Spake2p1, std::move(msg_pA));
512512
SuccessOrExit(err);
513513

514514
ChipLogDetail(Ble, "Sent spake2p msg1");
@@ -568,10 +568,10 @@ CHIP_ERROR SecurePairingSession::HandleMsg1_and_SendMsg2(const PacketHeader & he
568568
}
569569

570570
resp->SetDataLength(data_len);
571-
mNextExpectedMsg = Spake2pMsgType::kSpake2pMsg3;
571+
mNextExpectedMsg = Protocols::SecureChannel::MsgType::PASE_Spake2p3;
572572

573573
// Call delegate to send the Msg2 to peer
574-
err = AttachHeaderAndSend(Spake2pMsgType::kSpake2pMsg2, std::move(resp));
574+
err = AttachHeaderAndSend(Protocols::SecureChannel::MsgType::PASE_Spake2p2, std::move(resp));
575575
SuccessOrExit(err);
576576

577577
ChipLogDetail(Ble, "Sent spake2p msg2");
@@ -625,7 +625,7 @@ CHIP_ERROR SecurePairingSession::HandleMsg2_and_SendMsg3(const PacketHeader & he
625625
resp->SetDataLength(verifier_len);
626626

627627
// Call delegate to send the Msg3 to peer
628-
err = AttachHeaderAndSend(Spake2pMsgType::kSpake2pMsg3, std::move(resp));
628+
err = AttachHeaderAndSend(Protocols::SecureChannel::MsgType::PASE_Spake2p3, std::move(resp));
629629
SuccessOrExit(err);
630630

631631
ChipLogDetail(Ble, "Sent spake2p msg3");
@@ -665,9 +665,9 @@ CHIP_ERROR SecurePairingSession::HandleMsg3(const PacketHeader & header, const S
665665

666666
ChipLogDetail(Ble, "Received spake2p msg3");
667667

668-
// We will set NextExpectedMsg to kSpake2pMsgError in all cases
669-
// However, when we are using IP rendezvous, we might set it to kSpake2pMsg1.
670-
mNextExpectedMsg = Spake2pMsgType::kSpake2pMsgError;
668+
// We will set NextExpectedMsg to PASE_Spake2pError in all cases
669+
// However, when we are using IP rendezvous, we might set it to PASE_Spake2p1.
670+
mNextExpectedMsg = Protocols::SecureChannel::MsgType::PASE_Spake2pError;
671671

672672
VerifyOrExit(hash != nullptr, err = CHIP_ERROR_MESSAGE_INCOMPLETE);
673673
VerifyOrExit(msg->DataLength() == kMAX_Hash_Length, err = CHIP_ERROR_INVALID_MESSAGE_LENGTH);
@@ -715,7 +715,7 @@ void SecurePairingSession::SendErrorMsg(Spake2pErrorType errorCode)
715715

716716
msg->SetDataLength(msglen);
717717

718-
err = AttachHeaderAndSend(Spake2pMsgType::kSpake2pMsgError, std::move(msg));
718+
err = AttachHeaderAndSend(Protocols::SecureChannel::MsgType::PASE_Spake2pError, std::move(msg));
719719
SuccessOrExit(err);
720720

721721
exit:
@@ -758,25 +758,25 @@ CHIP_ERROR SecurePairingSession::HandlePeerMessage(const PacketHeader & packetHe
758758

759759
mPeerAddress = peerAddress;
760760

761-
switch (static_cast<Spake2pMsgType>(payloadHeader.GetMessageType()))
761+
switch (static_cast<Protocols::SecureChannel::MsgType>(payloadHeader.GetMessageType()))
762762
{
763-
case Spake2pMsgType::kPBKDFParamRequest:
763+
case Protocols::SecureChannel::MsgType::PBKDFParamRequest:
764764
err = HandlePBKDFParamRequest(packetHeader, msg);
765765
break;
766766

767-
case Spake2pMsgType::kPBKDFParamResponse:
767+
case Protocols::SecureChannel::MsgType::PBKDFParamResponse:
768768
err = HandlePBKDFParamResponse(packetHeader, msg);
769769
break;
770770

771-
case Spake2pMsgType::kSpake2pMsg1:
771+
case Protocols::SecureChannel::MsgType::PASE_Spake2p1:
772772
err = HandleMsg1_and_SendMsg2(packetHeader, msg);
773773
break;
774774

775-
case Spake2pMsgType::kSpake2pMsg2:
775+
case Protocols::SecureChannel::MsgType::PASE_Spake2p2:
776776
err = HandleMsg2_and_SendMsg3(packetHeader, msg);
777777
break;
778778

779-
case Spake2pMsgType::kSpake2pMsg3:
779+
case Protocols::SecureChannel::MsgType::PASE_Spake2p3:
780780
err = HandleMsg3(packetHeader, msg);
781781
break;
782782

src/transport/SecurePairingSession.h

+3-12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#pragma once
2828

2929
#include <crypto/CHIPCryptoPAL.h>
30+
#include <protocols/secure_channel/SecureChannelProtocol.h>
3031
#include <support/Base64.h>
3132
#include <system/SystemPacketBuffer.h>
3233
#include <transport/SecureSession.h>
@@ -232,25 +233,15 @@ class DLL_EXPORT SecurePairingSession
232233
void SendErrorMsg(Spake2pErrorType errorCode);
233234
void HandleErrorMsg(const PacketHeader & header, const System::PacketBufferHandle & msg);
234235

235-
CHIP_ERROR AttachHeaderAndSend(uint8_t msgType, System::PacketBufferHandle msgBuf);
236+
CHIP_ERROR AttachHeaderAndSend(Protocols::SecureChannel::MsgType msgType, System::PacketBufferHandle msgBuf);
236237

237238
void Clear();
238239

239240
static constexpr size_t kSpake2p_WS_Length = kP256_FE_Length + 8;
240241

241-
enum Spake2pMsgType : uint8_t
242-
{
243-
kPBKDFParamRequest = 0x20,
244-
kPBKDFParamResponse = 0x21,
245-
kSpake2pMsg1 = 0x22,
246-
kSpake2pMsg2 = 0x23,
247-
kSpake2pMsg3 = 0x24,
248-
kSpake2pMsgError = 0x2f,
249-
};
250-
251242
SecurePairingSessionDelegate * mDelegate = nullptr;
252243

253-
Spake2pMsgType mNextExpectedMsg = Spake2pMsgType::kSpake2pMsgError;
244+
Protocols::SecureChannel::MsgType mNextExpectedMsg = Protocols::SecureChannel::MsgType::PASE_Spake2pError;
254245

255246
Spake2p_P256_SHA256_HKDF_HMAC mSpake2p;
256247

0 commit comments

Comments
 (0)