Skip to content

Backport SweynTooth fix for Cordio to 5.15 #12845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright (c) 2009-2019 Arm Limited
* Copyright (c) 2019-2020 Packetcraft, Inc.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -252,6 +253,17 @@ void SmpDmMsgSend(smpDmMsg_t *pMsg);
/*************************************************************************************************/
void SmpDmEncryptInd(wsfMsgHdr_t *pMsg);

/*************************************************************************************************/
/*!
* \brief Check if LE Secure Connections is enabled on the connection.
*
* \param connId Connection identifier.
*
* \return TRUE is Secure Connections is enabled, else FALSE
*/
/*************************************************************************************************/
bool_t SmpDmLescEnabled(dmConnId_t connId);

/*************************************************************************************************/
/*!
* \brief Return the STK for the given connection.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright (c) 2009-2019 Arm Limited
* Copyright (c) 2019-2020 Packetcraft, Inc.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -117,6 +118,12 @@ void dmSecHciHandler(hciEvt_t *pEvent)
return;
}
}
else if (SmpDmLescEnabled(pCcb->connId) == TRUE)
{
/* EDIV and Rand must be zero in LE Secure Connections */
HciLeLtkReqNegReplCmd(pEvent->hdr.param);
return;
}

/* call callback to get key from app */

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright (c) 2009-2019 Arm Limited
* Copyright (c) 2019-2020 Packetcraft, Inc.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -233,6 +234,7 @@ static void smpDmConnCback(dmEvt_t *pDmEvt)
pCcb->attempts = SmpDbGetFailureCount((dmConnId_t) pDmEvt->hdr.param);
pCcb->lastSentKey = 0;
pCcb->state = 0;
pCcb->keyReady = FALSE;

/* Resume the attempts state if necessary */
smpResumeAttemptsState((dmConnId_t) pDmEvt->hdr.param);
Expand Down Expand Up @@ -693,6 +695,27 @@ uint8_t smpGetScSecLevel(smpCcb_t *pCcb)
return secLevel;
}

/*************************************************************************************************/
/*!
* \brief Check if LE Secure Connections is enabled on the connection.
*
* \param connId Connection identifier.
*
* \return TRUE is Secure Connections is enabled, else FALSE
*/
/*************************************************************************************************/
bool_t SmpDmLescEnabled(dmConnId_t connId)
{
smpCcb_t *pCcb = smpCcbByConnId(connId);

if (pCcb == NULL || pCcb->pScCcb == NULL)
{
return FALSE;
}

return pCcb->pScCcb->lescEnabled;
}

/*************************************************************************************************/
/*!
* \brief Return the STK for the given connection.
Expand All @@ -710,6 +733,11 @@ uint8_t *SmpDmGetStk(dmConnId_t connId, uint8_t *pSecLevel)
/* get connection control block */
pCcb = smpCcbByConnId(connId);

if ((pCcb == NULL) || (pCcb->keyReady == FALSE))
{
return NULL;
}

if (smpCb.lescSupported && pCcb->pScCcb->lescEnabled && (pCcb->pScCcb->pLtk != NULL))
{
/* set security level */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright (c) 2009-2019 Arm Limited
* Copyright (c) 2019-2020 Packetcraft, Inc.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -314,6 +315,7 @@ typedef struct
uint8_t token; /* AES transaction token */
uint8_t attempts; /* Failed pairing attempts */
uint8_t lastSentKey; /* Command code of last sent key */
bool_t keyReady; /* Encryption key is ready */
smpScCcb_t *pScCcb; /* LE Secure Connection control blocks */
} smpCcb_t;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright (c) 2009-2019 Arm Limited
* Copyright (c) 2019-2020 Packetcraft, Inc.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -269,6 +270,7 @@ void smpiActStkEncrypt(smpCcb_t *pCcb, smpMsg_t *pMsg)
/* adjust key based on max key length */
memcpy(buf, pMsg->aes.pCiphertext, encKeyLen);
memset((buf + encKeyLen), 0, (SMP_KEY_LEN - encKeyLen));
pCcb->keyReady = TRUE;

secLevel = (pCcb->auth & SMP_AUTH_MITM_FLAG) ? DM_SEC_LEVEL_ENC_AUTH : DM_SEC_LEVEL_ENC;
DmSmpEncryptReq(pCcb->connId, secLevel, buf);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright (c) 2009-2019 Arm Limited
* Copyright (c) 2019-2020 Packetcraft, Inc.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -463,6 +464,7 @@ void smpiScActDHKeyCheckVerify(smpCcb_t *pCcb, smpMsg_t *pMsg)
/* Adjust key based on max key length */
memcpy(buf, pCcb->pScCcb->pLtk->ltk_t, encKeyLen);
memset((buf + encKeyLen), 0, (SMP_KEY_LEN - encKeyLen));
pCcb->keyReady = TRUE;

/* Initiate encryption */
DmSmpEncryptReq(pCcb->connId, smpGetScSecLevel(pCcb), buf);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright (c) 2009-2019 Arm Limited
* Copyright (c) 2019-2020 Packetcraft, Inc.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -284,6 +285,7 @@ void smprActSendPairRandom(smpCcb_t *pCcb, smpMsg_t *pMsg)
/* store STK and adjust based on max key length */
memcpy(pCcb->pScr->buf.b3, pMsg->aes.pCiphertext, encKeyLen);
memset((pCcb->pScr->buf.b3 + encKeyLen), 0, (SMP_KEY_LEN - encKeyLen));
pCcb->keyReady = TRUE;

/* start smp response timer */
smpStartRspTimer(pCcb);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright (c) 2009-2019 Arm Limited
* Copyright (c) 2019-2020 Packetcraft, Inc.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -524,6 +525,7 @@ void smprScActDHKeyCheckSend(smpCcb_t *pCcb, smpMsg_t *pMsg)
pCcb->pairReq[SMP_MAXKEY_POS] : pCcb->pairRsp[SMP_MAXKEY_POS];

memset((pCcb->pScCcb->pLtk->ltk_t + encKeyLen), 0, (SMP_KEY_LEN - encKeyLen));
pCcb->keyReady = TRUE;

/* Send the DH Key check Eb to the initiator */
smpScSendDHKeyCheck(pCcb, pMsg, pCcb->pScCcb->pScratch->Nb_Eb);
Expand Down