寫在前面
在《安全啟動模式下的數據保存問題》中,小編介紹了在HAB boot和XIP encrypted boot下,讀寫外部Nor Flash數據的特點以及image的數據特征狀態,比如使能XIP encrypted boot后,Nor Flash內的bootable image是密文狀態,那是否意味著只要在使能XIP encrypted boot后,被加密的bootable image就可以隨意下發給OEM進行量產燒錄,同時在量產后,客戶可隨意訪問加密的bootable image而無需擔心application image泄漏呢?
是否泄漏呢?
為了測試是否有泄漏的風險,在MIMXRT1060-EVK上進行如下步驟測試:
在MCUXpresso Secure Provisioning工具選擇XIP encrypted模式,生成并燒錄Blink LED的bootable image;
圖1
通過NXP-MCUBootUtility查看燒錄后的image,對比右邊框中的明文image會發現密文image顯得很是雜亂,即使被查看也應該不會泄漏明文image;
圖2
接著換另一種方式查看密文image,即通過pyocd命令讀取,具體如下所示,打開9_21_readback.bin與右邊框中的明文image比較,發現居然一致,換句話說,明文image被泄漏了;
圖3
圖4
通過上述測試結果表明,使用后一種方式讀取查看密文image居然能得到明文image,直接讓XIP encrypted boot破防了,這是怎么回事呢?
原因解釋
小編在《安全啟動模式下的數據保存問題》中提到,存儲在Serial Nor flash中的加密代碼和數據在送到CPU執行之前,需要經過BEE或者OTFAD解密,這是 Encypted XIP boot模式實現的基礎,Jlink在連接目標MCU時,會把對應的flash驅動算法加載在內部RAM中運行,如果此時MCU已經正常啟動運行application image的話,則表示BEE或者OTFAD模塊也已完成好配置了,那么flash驅動在讀Nor Flash內的密文時,數據會被自動解密。
圖 5
應對策略
既然我們已經了解泄漏的原因,就要阻斷外部工具加載flashloader或者flash驅動算法到內部RAM運行,所以除了禁止Debug port外,我們還需要禁止Serial Download方式,預防不懷好意者利用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安全調試,因為產品的售后,維護往往不是一帆風順的,產品在客戶現場有時也是狀況頻出,所以Secure Debug[1]就像給Debug port加了一把堅固的鎖,只有能打開這把鎖的人才能使用調試功能。
-
Boot
+關注
關注
0文章
154瀏覽量
37744 -
泄漏
+關注
關注
0文章
8瀏覽量
8661 -
mcuxpresso
+關注
關注
1文章
46瀏覽量
4768
原文標題:Encrypted Boot image泄漏討論
文章出處:【微信號:MCU頻道,微信公眾號:MCU頻道】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
CMOS Image sensor的基礎知識
計算機信息泄漏
執行tools/mkimg.sh腳本后,image目錄下沒有ML0和u-boot.img文件是為什么?
OKMX6Q-C u-boot可以支持fastboot command直接單獨更新image嗎
Android image燒錄失敗怎么解決?
pre_encrypted_ota示例在esp_encrypted_img_decrypt_end() 中失敗的原因?
Application boot code image中Code_length的含義是什么?
Digital Image Processing (Hong
埋地管道泄漏監測檢測技術
U-Boot源代碼分析之Linux的引導
詳解U-Boot引導內核分析
詳細介紹u-boot FIT image
Halcon教程:Image、Regiong、XLD基礎
FIT Image起源及制作方法
深入解析U-Boot image.c:RK平臺鏡像處理核心邏輯
Encrypted Boot image泄漏討論
評論