Skip to content

Commit 4128efd

Browse files
authored
Merge pull request #12785 from LDong-Arm/port_packetcraft_ltk_improvements
Cordio: Apply Packetcraft's fix for possible SweynTooth vulnerabilities
2 parents c1048c6 + c927773 commit 4128efd

File tree

8 files changed

+57
-0
lines changed

8 files changed

+57
-0
lines changed

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/include/smp_api.h

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright (c) 2009-2019 Arm Limited
2+
* Copyright (c) 2019-2020 Packetcraft, Inc.
23
* SPDX-License-Identifier: Apache-2.0
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -252,6 +253,17 @@ void SmpDmMsgSend(smpDmMsg_t *pMsg);
252253
/*************************************************************************************************/
253254
void SmpDmEncryptInd(wsfMsgHdr_t *pMsg);
254255

256+
/*************************************************************************************************/
257+
/*!
258+
* \brief Check if LE Secure Connections is enabled on the connection.
259+
*
260+
* \param connId Connection identifier.
261+
*
262+
* \return TRUE is Secure Connections is enabled, else FALSE
263+
*/
264+
/*************************************************************************************************/
265+
bool_t SmpDmLescEnabled(dmConnId_t connId);
266+
255267
/*************************************************************************************************/
256268
/*!
257269
* \brief Return the STK for the given connection.

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/sources/stack/dm/dm_sec.c

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright (c) 2009-2019 Arm Limited
2+
* Copyright (c) 2019-2020 Packetcraft, Inc.
23
* SPDX-License-Identifier: Apache-2.0
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -117,6 +118,12 @@ void dmSecHciHandler(hciEvt_t *pEvent)
117118
return;
118119
}
119120
}
121+
else if (SmpDmLescEnabled(pCcb->connId) == TRUE)
122+
{
123+
/* EDIV and Rand must be zero in LE Secure Connections */
124+
HciLeLtkReqNegReplCmd(pEvent->hdr.param);
125+
return;
126+
}
120127

121128
/* call callback to get key from app */
122129

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/sources/stack/smp/smp_main.c

+28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright (c) 2009-2019 Arm Limited
2+
* Copyright (c) 2019-2020 Packetcraft, Inc.
23
* SPDX-License-Identifier: Apache-2.0
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -233,6 +234,7 @@ static void smpDmConnCback(dmEvt_t *pDmEvt)
233234
pCcb->attempts = SmpDbGetFailureCount((dmConnId_t) pDmEvt->hdr.param);
234235
pCcb->lastSentKey = 0;
235236
pCcb->state = 0;
237+
pCcb->keyReady = FALSE;
236238

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

698+
/*************************************************************************************************/
699+
/*!
700+
* \brief Check if LE Secure Connections is enabled on the connection.
701+
*
702+
* \param connId Connection identifier.
703+
*
704+
* \return TRUE is Secure Connections is enabled, else FALSE
705+
*/
706+
/*************************************************************************************************/
707+
bool_t SmpDmLescEnabled(dmConnId_t connId)
708+
{
709+
smpCcb_t *pCcb = smpCcbByConnId(connId);
710+
711+
if (pCcb == NULL || pCcb->pScCcb == NULL)
712+
{
713+
return FALSE;
714+
}
715+
716+
return pCcb->pScCcb->lescEnabled;
717+
}
718+
696719
/*************************************************************************************************/
697720
/*!
698721
* \brief Return the STK for the given connection.
@@ -710,6 +733,11 @@ uint8_t *SmpDmGetStk(dmConnId_t connId, uint8_t *pSecLevel)
710733
/* get connection control block */
711734
pCcb = smpCcbByConnId(connId);
712735

736+
if ((pCcb == NULL) || (pCcb->keyReady == FALSE))
737+
{
738+
return NULL;
739+
}
740+
713741
if (smpCb.lescSupported && pCcb->pScCcb->lescEnabled && (pCcb->pScCcb->pLtk != NULL))
714742
{
715743
/* set security level */

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/sources/stack/smp/smp_main.h

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright (c) 2009-2019 Arm Limited
2+
* Copyright (c) 2019-2020 Packetcraft, Inc.
23
* SPDX-License-Identifier: Apache-2.0
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -314,6 +315,7 @@ typedef struct
314315
uint8_t token; /* AES transaction token */
315316
uint8_t attempts; /* Failed pairing attempts */
316317
uint8_t lastSentKey; /* Command code of last sent key */
318+
bool_t keyReady; /* Encryption key is ready */
317319
smpScCcb_t *pScCcb; /* LE Secure Connection control blocks */
318320
} smpCcb_t;
319321

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/sources/stack/smp/smpi_act.c

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

273275
secLevel = (pCcb->auth & SMP_AUTH_MITM_FLAG) ? DM_SEC_LEVEL_ENC_AUTH : DM_SEC_LEVEL_ENC;
274276
DmSmpEncryptReq(pCcb->connId, secLevel, buf);

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/sources/stack/smp/smpi_sc_act.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright (c) 2009-2019 Arm Limited
2+
* Copyright (c) 2019-2020 Packetcraft, Inc.
23
* SPDX-License-Identifier: Apache-2.0
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -463,6 +464,7 @@ void smpiScActDHKeyCheckVerify(smpCcb_t *pCcb, smpMsg_t *pMsg)
463464
/* Adjust key based on max key length */
464465
memcpy(buf, pCcb->pScCcb->pLtk->ltk_t, encKeyLen);
465466
memset((buf + encKeyLen), 0, (SMP_KEY_LEN - encKeyLen));
467+
pCcb->keyReady = TRUE;
466468

467469
/* Initiate encryption */
468470
DmSmpEncryptReq(pCcb->connId, smpGetScSecLevel(pCcb), buf);

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/sources/stack/smp/smpr_act.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright (c) 2009-2019 Arm Limited
2+
* Copyright (c) 2019-2020 Packetcraft, Inc.
23
* SPDX-License-Identifier: Apache-2.0
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -284,6 +285,7 @@ void smprActSendPairRandom(smpCcb_t *pCcb, smpMsg_t *pMsg)
284285
/* store STK and adjust based on max key length */
285286
memcpy(pCcb->pScr->buf.b3, pMsg->aes.pCiphertext, encKeyLen);
286287
memset((pCcb->pScr->buf.b3 + encKeyLen), 0, (SMP_KEY_LEN - encKeyLen));
288+
pCcb->keyReady = TRUE;
287289

288290
/* start smp response timer */
289291
smpStartRspTimer(pCcb);

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/sources/stack/smp/smpr_sc_act.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright (c) 2009-2019 Arm Limited
2+
* Copyright (c) 2019-2020 Packetcraft, Inc.
23
* SPDX-License-Identifier: Apache-2.0
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -524,6 +525,7 @@ void smprScActDHKeyCheckSend(smpCcb_t *pCcb, smpMsg_t *pMsg)
524525
pCcb->pairReq[SMP_MAXKEY_POS] : pCcb->pairRsp[SMP_MAXKEY_POS];
525526

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

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

0 commit comments

Comments
 (0)