Skip to content

Commit

Permalink
Merge pull request #12785 from LDong-Arm/port_packetcraft_ltk_improve…
Browse files Browse the repository at this point in the history
…ments

Cordio: Apply Packetcraft's fix for possible SweynTooth vulnerabilities
  • Loading branch information
0xc0170 authored Apr 15, 2020
2 parents c1048c6 + c927773 commit 4128efd
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 0 deletions.
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

0 comments on commit 4128efd

Please sign in to comment.