01/28/2017 Secure Boot in OVMF and vTPM Configuration

I generally got accustomed to using English for writing. It is like more convenient for you do not need any additional software as assistance. And in most cases you will not worry about how to translate some terminology in English into Chinese . Yeah. I am just looking for some excuse for my laziness....

As an important part of my undergraduate thesis, UEFI System based Firmware IMA and Remote Attestation is supposed to be first stage of my study. for the next phase, I am looking forward to applying the machine learning based technology into the attack detection of firmware security.

(1) Enabling Secure Boot in OVMF

OK, we are to resolve the problems remained unresolved in the previous chapter.

// Guidance for Secure Boot in OVMF
* https://wiki.ubuntu.com/UEFI/EDK2
* $EDKII_HOME/CryptoPkg/Library/OpensslLib/Patch-HOWTO.txt

change path to the edk2 root path

git submodule update --init --recursive
git pull --recurse-submodules && git submodule update --recursive --remote
cd CryptoPkg/Library/OpensslLib/openssl/
git tag // Change to the version required
git checkout b2758a2292aceda93e9f44c219b94fe21bb9a650

And build OVMF with SECURE_BOOT_ENABLE tag of TRUE

build -p OvmfPkg/OvmfPkgIa32X64.dsc -t GCC5 -b RELEASE -a IA32 -a X64 -D SECURE_BOOT_ENABLE

We can successfully get a firmware device then.

(2) Install Software TPM and enable vTPM Support

If we simply run the OVMF without passing tpm device to QEMU, the output of TPM testing application:

Running UEFI Application in Shell

Still cannot find EFI_TCG_PROTOCOL with TPM support. Refer to the DSC file of Ovmf

!if $(SECURE_BOOT_ENABLE) == TRUE
  PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf
  TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf
  AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf
!else
  TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
  AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf
!endif
  VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf

------------------------------------------------------

!if $(SECURE_BOOT_ENABLE) == TRUE
  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf {
    <LibraryClasses>
      NULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf
        }
!else
  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
!endif

---------------------------------------------------

!if $(SECURE_BOOT_ENABLE) == TRUE
  SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
!endif

I have got a TPM 2.0 chip on my host machine. But the VirtualBox might not be able to virtualize it
Also see an interesting software suite named Vagrant at

Difference between Docker and VagrantL: https://www.zhihu.com/question/32324376

It is a suite based on virtualization techniques that configure the development environment (While Docker is for configuring execution environment).

OK. Here we are to install vTPM in the Ubuntu 16.04 LTS in VirtualBox.

  • install libtpms
cd libtpms
./bootstrap.sh
./configure --prefix=/usr --with-openssl
make
make install
  • Install swtpm
cd swtpm
./bootstrap.sh
./configure --prefix=/usr --with-openssl
make
make check
sudo make install
cp /usr/etc/swtpm_setup.conf /etc/swtpm_setup.conf
  • Startup vTPM
sudo modprobe cuse
mkdir /tmp/myvtpm0
sudo chown -R tss:root  /tmp/myvtpm0
sudo swtpm_setup --tpm-state /tmp/myvtpm0  --createek

then we got outpit like

Starting vTPM manufacturing as tss:tss @ 2018年01月28日 星期日 12時(shí)43分46秒
TPM is listening on TCP port 48173.
Successfully created EK.
Successfully authored TPM state.
Ending vTPM manufacturing @ 2018年01月28日 星期日 12時(shí)43分47秒

The SWTPM should be similar to the TPM emulator provided by TCG Group, which enables the application to communicate with the TPM with Socket model via certain TCP port.

  • Map the TPM to /dev/vtpm0
sudo env TPM_PATH=/tmp/myvtpm0/ swtpm_cuse -n vtpm0

After finishing steps shown above, we can locate vtpm in /dev/ path.

(3) Run QEMU with TPM Support

To note that the QEMU install by running "sudo apt-get install qemu" cannot support vTPM.

// sse the QEMU-TPM version 
git clone https://github.com/Hecmay/vtpm-support.git
cd qemu-tpm
./configure --enable-kvm --enable-tpm --enable-sdl
make
make install

And then

qemu-system-x86_64 -display sdl -m 1024 \
-boot c -bios Build/Ovmf3264/RELEASE_GCC5/FV/OVMF.fd \
-boot menu=on -tpmdev cuse-tpm,id=tpm0,path=/dev/vtpm0 \
-device tpm-tis,tpmdev=tpm0 Build/test.img

(4) Further Modification with OVMF.dsc

Unfortunately the TPM Application still cannot locate EFI_TCG_PROTOCOL. Follow the steps:

https://github.com/tianocore/tianocore.github.io/wiki/How-to-Enable-Security#Enabling_Trusted_Compute_Module_TPM

Some tips from the debugging process

  • INF file of certain module specifies the TYPE (e.g. PEIM) and the lib required by the UEFI module must be included in the [LibraryClass.PEIM] of the Pkg's DSC file.
  • Please make sure the Lib with same name for different phase is different (Otherwise "error 1001 not supported")
  • Modification mainly focused on [Components] && [LibraryClasses.common] of OVMF.dsc (including Lib Tpm12CommandLib/Tpm12DeviceLib/Tpm12CommLib.....etc)

After getting the OVMF with TPM driver built-in, the Shell still cannot locate EFI_TCG_PROTOCOL

(5) Whether a GRUB2 Boot Loader is compulsory

I noticed that BootManager is a built-in component of Tianocore, the functionality of which is similar to common Boot loader. So if we want to load a OS, do we still need to add additional bootloader.efi to load our OS?

Let us have a try:

sudo ../vtpm-support/qemu-tpm/x86_64-softmmu/qemu-system-x86_64 -display sdl \
-cdrom /home/hecmay/Downloads/ubuntu-16.04.3-server-amd64.iso  -m 1024 \
-boot c -bios Build/Ovmf3264/RELEASE_GCC5/FV/OVMF.fd -boot menu=on -tpmdev \
cuse-tpm,id=tpm0,path=/dev/vtpm0 -device tpm-tis,tpmdev=tpm0 Build/server.img

It seems that Bootmanager can be used as a boot loader to load Ubuntu Server.iso in the CDROM. And after the ISO file is loaded, the built-in GRUB in Ubuntu will appear.

Built-in GRUB of Ubuntu Server

But the Ubuntu will also install GRUB boot loader afterwards. This GRUB should be the one installed on the hard disk drive rather then the previous one built-in with original Ubuntu ISO.


installation of GRUB

After installing and entering the Ubuntu server with basic LAMP built-in, we can see the TPM device is actually installed. So the problem is still lied in the OVMF setting.

/dev/tpm0

links might be helpful:

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市瘩例,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖奴饮,帶你破解...
    沈念sama閱讀 217,406評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異趋厉,居然都是意外死亡缝龄,警方通過(guò)查閱死者的電腦和手機(jī)汰现,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,732評(píng)論 3 393
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)叔壤,“玉大人瞎饲,你說(shuō)我怎么就攤上這事×痘妫” “怎么了嗅战?”我有些...
    開(kāi)封第一講書人閱讀 163,711評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)饭望。 經(jīng)常有香客問(wèn)我仗哨,道長(zhǎng),這世上最難降的妖魔是什么铅辞? 我笑而不...
    開(kāi)封第一講書人閱讀 58,380評(píng)論 1 293
  • 正文 為了忘掉前任厌漂,我火速辦了婚禮,結(jié)果婚禮上斟珊,老公的妹妹穿的比我還像新娘苇倡。我一直安慰自己,他們只是感情好囤踩,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,432評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布旨椒。 她就那樣靜靜地躺著,像睡著了一般堵漱。 火紅的嫁衣襯著肌膚如雪综慎。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書人閱讀 51,301評(píng)論 1 301
  • 那天勤庐,我揣著相機(jī)與錄音示惊,去河邊找鬼。 笑死愉镰,一個(gè)胖子當(dāng)著我的面吹牛米罚,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播丈探,決...
    沈念sama閱讀 40,145評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼录择,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起隘竭,我...
    開(kāi)封第一講書人閱讀 39,008評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤塘秦,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后货裹,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體嗤形,經(jīng)...
    沈念sama閱讀 45,443評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡精偿,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,649評(píng)論 3 334
  • 正文 我和宋清朗相戀三年弧圆,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片笔咽。...
    茶點(diǎn)故事閱讀 39,795評(píng)論 1 347
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡搔预,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出叶组,到底是詐尸還是另有隱情拯田,我是刑警寧澤,帶...
    沈念sama閱讀 35,501評(píng)論 5 345
  • 正文 年R本政府宣布甩十,位于F島的核電站船庇,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏侣监。R本人自食惡果不足惜鸭轮,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,119評(píng)論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望橄霉。 院中可真熱鬧窃爷,春花似錦、人聲如沸姓蜂。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 31,731評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)钱慢。三九已至逮京,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間束莫,已是汗流浹背懒棉。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 32,865評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留麦箍,地道東北人漓藕。 一個(gè)月前我還...
    沈念sama閱讀 47,899評(píng)論 2 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像挟裂,于是被迫代替她去往敵國(guó)和親享钞。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,724評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • 1. 槍蝦與蝦虎魚(yú)的共生。 “槍蝦會(huì)挖洞栗竖,住在洞里暑脆。可有個(gè)家伙卻要去住在它的洞里狐肢,那就是蝦虎魚(yú)添吗。不過(guò)蝦虎魚(yú)也不白住...
    柑橘與檸檬呢閱讀 24,071評(píng)論 0 5
  • 體驗(yàn)、邏輯是思考方法份名,是人類必備的工具碟联, 精進(jìn)、也是建構(gòu)知識(shí)的必要基礎(chǔ)僵腺。它可以檢測(cè)一句話與其他的話之間是否矛盾鲤孵,是...
    馮祥林閱讀 210評(píng)論 0 0
  • 最新的需求中,需要實(shí)現(xiàn)一個(gè)展示寶貝上新的視圖辰如,展現(xiàn)方式是點(diǎn)擊一個(gè)UITableView的cell普监,在cell拉出一...
    zzqiltw閱讀 672評(píng)論 0 1
  • 周瑜看見(jiàn)諸葛亮挺有才干,心里十分妒忌琉兜,想用造十萬(wàn)支箭為難諸葛亮凯正,周瑜:10天造好十萬(wàn)箭。諸葛亮卻說(shuō):三天豌蟋,只...
    李浩7655閱讀 509評(píng)論 0 0
  • 17日廊散,老公領(lǐng)兒子到專門的眼科醫(yī)院做了視力檢查,18日做了散瞳檢查夺饲,兒子視力有點(diǎn)下降奸汇。長(zhǎng)期用眼不健康,是我們預(yù)料之...
    玫瑰鏗鏘閱讀 628評(píng)論 1 1