寫在前面
在《安全啟動模式下的數(shù)據(jù)保存問題》中,小編介紹了在HAB boot和XIP encrypted boot下,讀寫外部Nor Flash數(shù)據(jù)的特點以及image的數(shù)據(jù)特征狀態(tài),比如使能XIP encrypted boot后,Nor Flash內(nèi)的bootable image是密文狀態(tài),那是否意味著只要在使能XIP encrypted boot后,被加密的bootable image就可以隨意下發(fā)給OEM進(jìn)行量產(chǎn)燒錄,同時在量產(chǎn)后,客戶可隨意訪問加密的bootable image而無需擔(dān)心application image泄漏呢?
是否泄漏呢?
為了測試是否有泄漏的風(fēng)險,在MIMXRT1060-EVK上進(jìn)行如下步驟測試:
在MCUXpresso Secure Provisioning工具選擇XIP encrypted模式,生成并燒錄Blink LED的bootable image;
圖1
通過NXP-MCUBootUtility查看燒錄后的image,對比右邊框中的明文image會發(fā)現(xiàn)密文image顯得很是雜亂,即使被查看也應(yīng)該不會泄漏明文image;
圖2
接著換另一種方式查看密文image,即通過pyocd命令讀取,具體如下所示,打開9_21_readback.bin與右邊框中的明文image比較,發(fā)現(xiàn)居然一致,換句話說,明文image被泄漏了;
圖3 圖4
通過上述測試結(jié)果表明,使用后一種方式讀取查看密文image居然能得到明文image,直接讓XIP encrypted boot破防了,這是怎么回事呢?
原因解釋
小編在《安全啟動模式下的數(shù)據(jù)保存問題》中提到,存儲在Serial Nor flash中的加密代碼和數(shù)據(jù)在送到CPU執(zhí)行之前,需要經(jīng)過BEE或者OTFAD解密,這是 Encypted XIP boot模式實現(xiàn)的基礎(chǔ),Jlink在連接目標(biāo)MCU時,會把對應(yīng)的flash驅(qū)動算法加載在內(nèi)部RAM中運行,如果此時MCU已經(jīng)正常啟動運行application image的話,則表示BEE或者OTFAD模塊也已完成好配置了,那么flash驅(qū)動在讀Nor Flash內(nèi)的密文時,數(shù)據(jù)會被自動解密。
圖 5
應(yīng)對策略
既然我們已經(jīng)了解泄漏的原因,就要阻斷外部工具加載flashloader或者flash驅(qū)動算法到內(nèi)部RAM運行,所以除了禁止Debug port外,我們還需要禁止Serial Download方式,預(yù)防不懷好意者利用Serial Downloader方式,使得ROM code加載專門的flashloader到RAM中運行,通過配置BEE或OTFAD模塊來讀取image明文(如下代碼所示)。
status=SLN_AUTH_check_context(SLN_CRYPTO_CTX_1); configPRINTF(("Contextcheckstatus%d ",status)); //DEBUG_LOG_DELAY_MS(1000);//Optionaldelay,enablefordebuggingtoensurelogisprintedbeforeacrash if(SLN_AUTH_NO_CONTEXT==status) { configPRINTF(("Ensuringcontext... ")); //DEBUG_LOG_DELAY_MS(1000);//Optionaldelay,enablefordebuggingtoensurelogisprintedbeforeacrash //Loadcryptocontextsandmakesuretheyarevalid(ourowncontextshouldbegoodtogettothispoint!) status=bl_nor_encrypt_ensure_context(); if(kStatus_Fail==status) { configPRINTF(("Failedtoloadcryptocontext... ")); //DEBUG_LOG_DELAY_MS(1000);//Optionaldelay,enablefordebuggingtoensurelogisprintedbeforeacrash //DoublecheckifencryptedXIPisenabled if(!bl_nor_encrypt_is_enabled()) { configPRINTF(("NotrunninginencryptedXIPmode,ignoreerror. ")); //DEBUG_LOG_DELAY_MS(1000);//Optionaldelay,enablefordebuggingtoensurelogisprintedbeforea //crash //NoencryptedXIPenabled,wecanignorethebadstatus status=kStatus_Success; } } elseif(kStatus_ReadOnly== status)//UsingthisstatusfromstandardstatustoindicatethatweneedtosplitPRDB { volatileuint32_tdelay=1000000; //Setupcontextasneededforthisapplication status=bl_nor_encrypt_split_prdb(); configPRINTF(("RestartingBOOTLOADER... ")); while(delay--) ; //Restart DbgConsole_Deinit(); NVIC_DisableIRQ(LPUART6_IRQn); NVIC_SystemReset(); } } elseif(SLN_AUTH_OK==status) { configPRINTF(("Ensuringcontext... ")); //DEBUG_LOG_DELAY_MS(1000);//Optionaldelay,enablefordebuggingtoensurelogisprintedbeforeacrash //WewillchecktoseeifweneedtoupdatethebackuptothereducedscopePRDB0forbootloaderspace status=bl_nor_encrypt_ensure_context(); if(kStatus_Fail==status) { configPRINTF(("Failedtoloadcryptocontext... ")); //DEBUG_LOG_DELAY_MS(1000);//Optionaldelay,enablefordebuggingtoensurelogisprintedbeforeacrash //DoublecheckifencryptedXIPisenabled if(!bl_nor_encrypt_is_enabled()) { configPRINTF(("NotrunninginencryptedXIPmode,ignoreerror. ")); //NoencryptedXIPenabled,wecanignorethebadstatus status=kStatus_Success; } } elseif(kStatus_Success==status)//WehavegoodPRDBssowecanupdatethebackup { boolisMatch=false; boolisOriginal=false; configPRINTF(("Checkingbackupcontext... ")); //DEBUG_LOG_DELAY_MS(1000);//Optionaldelay,enablefordebuggingtoensurelogisprintedbeforeacrash //CheckifwehaveidenticalKIBsandinitialCTR status=bl_nor_crypto_ctx_compare_backup(&isMatch,&isOriginal,SLN_CRYPTO_CTX_0); if(kStatus_Success==status) { if(isMatch&&isOriginal) { configPRINTF(("Updatingbackupcontextwithvalidaddressspace... ")); //DEBUG_LOG_DELAY_MS(1000);//Optionaldelay,enablefordebuggingtoensurelogisprintedbefore //acrash //UpdatebackupPRDB0 status=SLN_AUTH_backup_context(SLN_CRYPTO_CTX_0); } } } }
但相較于直接永久禁止Debug port的簡單粗暴, 小編更加推薦Secure Debug安全調(diào)試,因為產(chǎn)品的售后,維護(hù)往往不是一帆風(fēng)順的,產(chǎn)品在客戶現(xiàn)場有時也是狀況頻出,所以Secure Debug[1]就像給Debug port加了一把堅固的鎖,只有能打開這把鎖的人才能使用調(diào)試功能。
-
Boot
+關(guān)注
關(guān)注
0文章
150瀏覽量
35944 -
泄漏
+關(guān)注
關(guān)注
0文章
8瀏覽量
8492 -
mcuxpresso
+關(guān)注
關(guān)注
1文章
41瀏覽量
4236
原文標(biāo)題:Encrypted Boot image泄漏討論
文章出處:【微信號:MCU頻道,微信公眾號:MCU頻道】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
相關(guān)推薦
評論