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时43分46秒
TPM is listening on TCP port 48173.
Successfully created EK.
Successfully authored TPM state.
Ending vTPM manufacturing @ 2018年01月28日 星期日 12时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:

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,692评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,482评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,995评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,223评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,245评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,208评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,091评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,929评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,346评论 1 311
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,570评论 2 333
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,739评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,437评论 5 344
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,037评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,677评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,833评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,760评论 2 369
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,647评论 2 354

推荐阅读更多精彩内容

  • 1. 枪虾与虾虎鱼的共生。 “枪虾会挖洞,住在洞里。可有个家伙却要去住在它的洞里,那就是虾虎鱼。不过虾虎鱼也不白住...
    柑橘与柠檬呢阅读 24,068评论 0 5
  • 体验、逻辑是思考方法,是人类必备的工具, 精进、也是建构知识的必要基础。它可以检测一句话与其他的话之间是否矛盾,是...
    冯祥林阅读 210评论 0 0
  • 最新的需求中,需要实现一个展示宝贝上新的视图,展现方式是点击一个UITableView的cell,在cell拉出一...
    zzqiltw阅读 672评论 0 1
  • 周瑜看见诸葛亮挺有才干,心里十分妒忌,想用造十万支箭为难诸葛亮,周瑜:10天造好十万箭。诸葛亮却说:三天,只...
    李浩7655阅读 509评论 0 0
  • 17日,老公领儿子到专门的眼科医院做了视力检查,18日做了散瞳检查,儿子视力有点下降。长期用眼不健康,是我们预料之...
    玫瑰铿锵阅读 628评论 1 1