Linux ubuntu20.04 安装使用 Intel sgx

文章目录

  • 前言
  • 一、简介
    • [1.1 SGXDataCenterAttestationPrimitives](#1.1 SGXDataCenterAttestationPrimitives)
    • [1.2 linux-sgx-driver](#1.2 linux-sgx-driver)
    • [1.3 Intel SGX Support in the Linux Kernel](#1.3 Intel SGX Support in the Linux Kernel)
    • [1.4 Platform Uses Legacy Launch](#1.4 Platform Uses Legacy Launch)
  • [二、 安装Intel SGX driver](#二、 安装Intel SGX driver)
    • [2.1 Intel SGX driver简介](#2.1 Intel SGX driver简介)
    • [2.2 In-Kernel Driver Module Installation](#2.2 In-Kernel Driver Module Installation)
    • [2.3 DCAP Driver Installation](#2.3 DCAP Driver Installation)
    • [2.4 Out-of-Tree Driver Installation](#2.4 Out-of-Tree Driver Installation)
  • [三、 Build the Intel SGX SDK and Inte SGX PSW Package](#三、 Build the Intel SGX SDK and Inte SGX PSW Package)
  • [四、 Build the Intel SGX SDK and Intel SGX SDK Installer](#四、 Build the Intel SGX SDK and Intel SGX SDK Installer)
    • [4.1 build Intel SGX SDK](#4.1 build Intel SGX SDK)
    • [4.2 Install the Intel SGX SDK](#4.2 Install the Intel SGX SDK)
    • [4.3 Test the Intel SGX SDK Package with the Code Samples](#4.3 Test the Intel SGX SDK Package with the Code Samples)
  • [五、Build the Intel SGX PSW and Intel SGX PSW Installer](#五、Build the Intel SGX PSW and Intel SGX PSW Installer)
    • [5.1 build Intel SGX PSW](#5.1 build Intel SGX PSW)
    • [5.2 Install the Intel SGX PSW](#5.2 Install the Intel SGX PSW)
    • [5.3 Compile and Run the Code Samples in the Hardware Mode](#5.3 Compile and Run the Code Samples in the Hardware Mode)
  • 参考资料

前言

开发平台:

c 复制代码
# lscpu
Model name:                         Intel(R) Core(TM) i3-9100 CPU @ 3.60GHz

操作系统版本:

c 复制代码
# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.4 LTS (Focal Fossa)"
# uname -r
5.15.0-89-generic

我这台处理器默认没有打开Intel sgx硬件功能,因此需要在BIOS中启动Intel sgx硬件功能。

启动后输出如下:

c 复制代码
# cpuid | grep -i sgx
      SGX: Software Guard Extensions supported = true
      SGX_LC: SGX launch config supported      = false

	  ......
      SGX1 supported                         = true
      SGX2 supported                         = false

查看内核启动日志:

c 复制代码
# dmesg | grep -i sgx
[    0.398363] sgx: EPC section 0x80200000-0x85f7ffff

或者使用github项目上查看是否支持SGX:https://github.com/ayeks/SGX-hardware/

输出如下:

c 复制代码
SGX-hardware# ./test-sgx
Start test-sgx
......
Supports SGX
SGX Launch Configuration (SGX_LC): 0
SGX Attestation Services (SGX_KEYS): 0
SGX1 leaf instructions (SGX1): 1
SGX2 leaf instructions (SGX2): 0

以下内容参考

github:https://github.com/intel/linux-sgx
https://www.intel.com/content/www/us/en/developer/tools/software-guard-extensions/linux-overview.html
https://download.01.org/intel-sgx/latest/linux-latest/docs/Intel_SGX_SW_Installation_Guide_for_Linux.pdf

一、简介

Intel Software Guard Extensions (Intel SGX) 是一项由英特尔提供的技术,旨在保护应用程序开发人员选择的代码和数据免受泄露或修改。

Linux Intel SGX 软件栈由 IntelSGX 驱动程序、Intel SGX SDK 和 Intel SGX 平台软件 (PSW) 组成。

• Intel® SGX Software Development Kit (SDK): 这个SDK帮助软件开发人员创建使用Intel SGX技术的应用程序。它提供了一组工具、库和文档,使开发人员能够在应用程序中利用SGX的安全功能,包括创建和管理SGX enclaves(安全容器)、进行加密操作和进行远程验证等。

• Intel® SGX Platform Software (PSW) for Linux* OS: 这个软件提供了在Linux操作系统上运行Intel SGX应用程序所需的软件模块。它包括驱动程序、库和运行时组件,为SGX应用程序提供了必要的运行环境和安全保护机制。PSW负责管理SGX enclaves的创建、加载和执行,并提供与硬件的接口交互,以实现SGX的安全功能。

• Intel® SGX Data Center Attestation Primitives (DCAP) for Linux* OS: 这个软件提供了在数据中心环境中进行SGX应用程序验证的软件模块。DCAP为Intel应用程序提供了进行数据中心内的验证和信任建立所需的功能。它包括用于生成、验证和传输证明数据的API和工具,确保SGX enclaves的真实性和完整性,并帮助应用程序与远程系统进行安全交互。

这些软件组件共同构成了Intel SGX技术的开发和运行环境。SDK提供了开发SGX应用程序所需的工具和资源,PSW为应用程序提供了在Linux操作系统上运行的基础设施,而DCAP为数据中心内的SGX应用程序提供了验证和信任建立的支持。这些组件协同工作,使开发人员能够利用Intel SGX的安全功能来保护和保障应用程序的安全性。

1.1 SGXDataCenterAttestationPrimitives

SGXDataCenterAttestationPrimitives项目是为Linux Intel SGX软件栈维护的一个外部驱动程序。该驱动程序被用作临时解决方案,直到驱动程序被纳入官方Linux内核中。

•Intel® SGX Data Center Attestation Primitives (DCAP) for Linux OS: 这个软件提供了在数据中心环境中进行SGX应用程序验证的软件模块。DCAP为Intel应用程序提供了进行数据中心内的验证和信任建立所需的功能。它包括用于生成、验证和传输证明数据的API和工具,确保SGX enclaves的真实性和完整性,并帮助应用程序与远程系统进行安全交互。

SGXDataCenterAttestationPrimitives驱动程序专门针对支持Flexible Launch Control (FLC)和Intel AES New Instructions (AES-NI)的平台。FLC是一种安全特性,有助于保护SGX enclave启动过程的完整性,而AES-NI为加密操作提供了硬件加速。

该驱动程序为数据中心环境中的Intel SGX enclave提供了证明能力。它支持两种类型的证明:

(1)基于椭圆曲线数字签名算法(ECDSA)的证明:ECDSA是一种广泛使用的公钥密码算法。它允许生成和验证数字签名,用于证明SGX enclave的真实性和完整性。

(2)基于增强隐私识别(EPID)的证明:EPID是一种保护隐私的证明方案,允许远程方验证SGX enclave的完整性,同时不泄露被验证平台的身份。EPID-based的证明旨在提供强大的安全保证同时保持隐私。

SGXDataCenterAttestationPrimitives项目提供了在Linux SGX软件栈中支持这些证明机制所需的组件和功能。它使在支持SGX的平台上运行的应用程序能够建立信任,并与远程系统或服务进行安全交互。

1.2 linux-sgx-driver

linux-sgx-driver项目是Linux Intel SGX软件栈的另一个外部驱动程序,用于支持没有Flexible Launch Control (FLC)的平台上的增强隐私识别(EPID)基于证明,直到驱动程序上游过程完成为止。

这个驱动程序可以用于支持早期的 SGX-capable 的CPU,这些CPU没有Flexible Launch Control (FLC)功能。然而,请注意该驱动程序的ABI与上游的SGX内核补丁不同。因此,将使用该驱动程序的软件迁移到未来支持SGX的内核可能需要额外的工作量。

为了减少ABI的差异,并更好地与未来支持SGX的内核对齐,该驱动程序将不再添加新功能。这样做的目的是确保兼容性,并方便将来在内核版本中集成SGX支持时的平稳过渡。

对于那些不支持FLC的平台,linux-sgx-driver项目提供了所需的驱动程序功能,以支持EPID基于证明的功能。EPID是一种隐私保护的证明方案,允许远程方验证SGX enclave的完整性,同时不泄露被验证平台的身份。

这个驱动程序允许在不支持FLC的平台上进行SGX enclave的EPID证明。它提供了必要的组件和功能,使这些平台上的应用程序能够与远程系统或服务建立安全信任,并进行受保护的通信。

与SGXDataCenterAttestationPrimitives项目类似,linux-sgx-driver项目也是一个临时解决方案,直到驱动程序被合并到官方Linux内核中。这些驱动程序为使用Intel SGX技术的应用程序提供了在非FLC平台上进行EPID证明的能力。

1.3 Intel SGX Support in the Linux Kernel

自从 Linux 内核版本 5.11 发布以来,主线 Linux 内核已经内置了 Intel SGX 支持。内核内置的 Intel SGX 驱动程序需要平台支持并配置为灵活启动控制(flexible launch control - FLC)。尽可能使用带有 Intel SGX 支持的主线内核。

对于特殊用例,还有两个其他的内核空间选项可供选择:

(1)如果您的发行版内核版本早于 5.11 或不支持内核内置的 Intel SGX,您可以使用 Intel SGX DCAP 驱动程序作为临时解决方案,然后过渡到 5.11 或更高版本的内核。它提供了接近主线内核的接口,也需要平台支持并配置为 FLC。

(2)如果您需要在不支持 FLC 的平台上使用 Intel SGX,Intel SGX for Linux OS 驱动程序项目提供了一个非内核驱动程序(out-of-tree driver)。该驱动程序用于支持在仅支持传统启动控制的平台上运行 Intel SGX enclave。它也可以安装在配置了 FLC 的平台上,但这些平台只能加载符合传统启动控制策略的生产 enclave。

注意:尽管Intel SGX SDK和平台软件与所有这些驱动程序兼容,但传统的非FLC驱动程序和Intel SGX DCAP驱动程序仅针对关键的安全修复进行更新。由于 out-of-tree 实现的限制,主线内核中实现的新特性或功能无法移植到传统的非FLC驱动程序或Intel SGX DCAP驱动程序。

1.4 Platform Uses Legacy Launch

传统启动(Legacy Launch)是指在平台配置中,需要由Intel签名的启动信封提供一个启动令牌。平台(可以是虚拟机或裸机平台)是否需要传统启动取决于两个因素:

(1)平台硬件和配置:所有配置了Intel® SGX支持的平台都有能力支持传统启动;然而,只有支持Intel® SGX启动配置 -- Launch Configuration(在CPUID[7].ECX[SGX_LC]中详细说明,其中SGX_LC位为第30位)并配置了Intel® SGX启动控制(在IA32_FEATURE_CONTROL MSR中的第17位指定,由BIOS配置)的平台才能在不使用传统启动的情况下运行。详细信息请参阅Intel®软件开发手册。

(2)Linux内核中的Intel® SGX支持:可以通过对内核打补丁或安装驱动程序来在Linux内核中支持Intel® SGX。此外,目前有两个支持的Intel® SGX驱动程序。因此,有三种选项来配置Intel® SGX启动平台:

内核驱动程序:内核已经打了补丁以支持Intel® SGX。这只能在能够支持Intel® SGX启动配置并启用了该功能的平台上运行。

DCAP驱动程序:DCAP驱动程序是Linux内核模式驱动程序,模拟了内核驱动程序的解决方案。与内核驱动程序类似,DCAP驱动程序只能在能够支持Intel® SGX启动配置并启用了该功能的平台上运行。

Out-of-Tree驱动程序:Out-of-Tree驱动程序的命名有些不准确,因为DCAP驱动程序也是提供的Out-of-Tree驱动程序;然而,该驱动程序可以在所有平台上运行,无论是否支持或启用了Intel® SGX启动配置。因此,它支持传统启动。它有一个接口,在初始化一个信封时需要提供一个启动令牌。有关Intel® SGX启动令牌的更多信息,请参阅Intel®软件开发手册。

二、 安装Intel SGX driver

2.1 Intel SGX driver简介

为了配置运行Intel SGX Enclaves的平台,了解Launch Control是非常重要的,它是控制和限制Intel SGX enclaves启动的方法。Launch Control为应用程序提供令牌,允许它们启动enclaves。Launch Control有两种特征配置方式:

(1)Flexible Launch Control:支持Intel SGX Launch Control的平台,包括虚拟机,可以通过内核模式驱动程序配置为特定的enclave签名者。在许多情况下,驱动程序会为每个加载的enclave动态重新配置launch control,使enclave无需有效的Launch Token即可运行(有关Launch Token的更多信息,请参阅Intel® 64和IA-32 Architectures Software Developer Manuals)。

(2)Legacy Launch Control:不支持Intel SGX Launch Control或未通过BIOS配置为Flexible Launch Control的平台仍然可以使用传统Launch Control加载enclave。在这种模式下,需要使用Intel签名的Launch Enclave为驱动程序提供Launch Token以加载enclave。此外,必须将enclave所有者的MRSIGNER(所有者公共签名密钥的哈希值)添加到Intel的Launch Policy List中,以在release模式下运行enclave(有关Legacy Launch Control和添加MRSIGNER到Launch Policy List的更多详细信息,请参阅Intel® SGX Request License页面)。

需要注意的是,Legacy Launch Control限制了哪些enclave可以在release模式下运行,但是它允许enclave在SGX debug模式下运行,而不管enclave所有者的MRSIGNER是否已添加到Launch Policy中。SGX debug模式允许开发和调试测试签名的debug enclaves。有关SGX debug模式enclave的更多信息,请参阅Intel® 64和IA-32 Architectures Software Developer Manuals

当使用Intel® SGX时,有三种不同的驱动程序可供选择:

(1)内核驱动程序(/dev/{sgx_enclave, sgx_provision}):主线内核版本5.11或更高版本包括SGX内核驱动程序。内核驱动程序要求平台支持并配置为Flexible Launch Control。

c 复制代码
此驱动程序包含在主线内核版本5.11或更高版本中。
它要求平台支持并配置为Flexible Launch Control。
内核驱动程序是推荐的选择。
它与内核进行本地集成,并利用后续内核版本支持的新功能,如EDMM(Enclave Dynamic Memory Management)、SGX KVM、SGX cgroups和NUMA感知的EPC(Enclave Page Cache)分配。

(2)DCAP驱动程序(/dev/{sgx_enclave, sgx_provision}):DCAP驱动程序的目标是提供接口接近于内核驱动程序,以便为没有将Intel SGX驱动程序集成到内核中的Linux操作系统提供Intel SGX支持。该驱动程序也需要平台支持并配置为 Flexible Launch Control 。由于该驱动程序支持的是一个外部实现,它不包括后续内核版本支持的新功能,如EDMM、SGX KVM、SGX cgroups和NUMA感知EPC分配。该驱动程序仅针对必要的安全修复进行更新。在可能的情况下,应使用内核驱动程序。

c 复制代码
DCAP(Data Center Attestation Primitives)驱动程序的目标是为没有在内核中集成Intel® SGX驱动程序的Linux操作系统提供类似的接口。
类似于内核驱动程序,它要求平台支持并配置为Flexible Launch Control。
然而,DCAP驱动程序是一个外部实现,可能不包含较新内核版本支持的最新功能。它主要用于必要的安全修复。
如果可用,建议使用内核驱动程序而不是DCAP驱动程序。

(3)非内核驱动程序(/dev/isgx):该驱动程序用于支持在仅支持Legacy Launch Control的平台上运行Intel® SGX enclaves。它也可以安装在配置为 Flexible Launch Control的平台上,但是这些平台只能加载符合Legacy Launch Control策略的enclave。

c 复制代码
此驱动程序用于支持在仅支持Legacy Launch Control的平台上运行Intel® SGX enclaves。
它也可以安装在配置为Flexible Launch Control的平台上,但在这种情况下,这些平台只能加载符合Legacy Launch Control策略的enclave。
非内核驱动程序用于平台不具备原生Flexible Launch Control支持的情况。

需要根据平台的能力和配置选择适合的驱动程序。内核驱动程序是推荐且功能最丰富的选项,DCAP驱动程序可用于没有在内核中集成Intel® SGX驱动程序的系统。非内核驱动程序适用于仅支持Legacy Launch Control的平台。

Linux SGX driver为SGX环境运行必要驱动。

以下各节介绍了每个驱动器的选择和安装过程。

2.2 In-Kernel Driver Module Installation

内核内驱动程序是由5.11版本开始的Linux内核提供的。开发人员和平台所有者可以安装Linux发行版提供的5.11(或更高版本)内核二进制文件,或者按照中所述的步骤从源代码构建内核https://wiki.ubuntu.com/kernelteam/gitkernelbuild.SGX选项CONFIG_X86_SGX必须在makemenuconfig步骤中启用,否则无法构建SGX模块。其他SGX配置选项,如CONFIG_X86_SGX_KVM,可能会根据用户需要启用。内核的早期版本可以通过补丁进行调整。最新的英特尔SGX内核补丁可在https://patchwork.kernel.org/project/intel-sgx/list/.本文档不涉及修补和构建内核的过程。

查看我的Ubuntu20.04配置:

c 复制代码
CONFIG_X86_SGX=y
CONFIG_X86_SGX_KVM=y

但是我的Intel处理器没有配置Launch Control:

c 复制代码
# cpuid | grep -i sgx
      SGX: Software Guard Extensions supported = true
      SGX_LC: SGX launch config supported      = false

2.3 DCAP Driver Installation

DCAP驱动是推荐在Linux内核版本4.15到5.6之间(包括这两个版本)以及支持并配置了Flexible Launch Control的平台上使用的驱动程序。在使用SGX In-Kernel驱动程序的5.11或更高版本内核上安装DCAP驱动程序时,会出现构建错误消息:"无法安装带有内核内SGX支持的DCAP SGX驱动程序"。

这个错误消息表示在启用了SGX In-Kernel驱动程序的情况下,无法安装DCAP驱动程序。因此,在使用5.11或更高版本的内核时,您应该选择使用SGX In-Kernel驱动程序而不是DCAP驱动程序。

如果您的内核版本是5.11或更高版本,并且已启用了SGX In-Kernel驱动程序,那么您不需要安装DCAP驱动程序。您可以继续使用内核自带的SGX支持。

请注意,在使用SGX In-Kernel驱动程序的情况下,建议使用的内核版本是5.11或更高版本,并且在支持Flexible Launch Control的平台上进行配置。如果您的平台不支持Flexible Launch Control或未进行配置,则可能无法正常使用SGX功能。

由于我的Intel处理器没有配置Launch Control,这里不讨论其安装过程,其安装过程可以参考:
https://download.01.org/intel-sgx/latest/linux-latest/docs/Intel_SGX_SW_Installation_Guide_for_Linux.pdf

2.4 Out-of-Tree Driver Installation

对于不支持或未配置Flexible Launch Control的平台,建议使用Out-of-Tree驱动程序。不建议在启用了FLC的平台上安装传统的Out-of-Tree驱动程序。如果在运行Kernel 5.11或更高版本的FLC平台上安装传统的Out-of-Tree驱动程序,安装会成功,但是Intel SGX PSW仅使用内核内驱动程序。

虽然我这里的内核版本是5.15,内核主线已经Support for Intel SGX,但是我的Intel处理器没有配置Launch Control,接下来参考 the out-of-tree driver 进行驱动安装: linux-sgx-driver

c 复制代码
git clone https://github.com/intel/linux-sgx-driver.git
c 复制代码
make

Install the Intel® SGX Driver:

c 复制代码
$ sudo mkdir -p "/lib/modules/"`uname -r`"/kernel/drivers/intel/sgx"    
$ sudo cp isgx.ko "/lib/modules/"`uname -r`"/kernel/drivers/intel/sgx"    
$ sudo sh -c "cat /etc/modules | grep -Fxq isgx || echo isgx >> /etc/modules"    
$ sudo /sbin/depmod
$ sudo /sbin/modprobe isgx

Uninstall the Intel® SGX Driver:

在卸载Intel(R)SGX驱动程序之前,请确保aesmd服务已停止。

c 复制代码
$ sudo /sbin/modprobe -r isgx
$ sudo rm -rf "/lib/modules/"`uname -r`"/kernel/drivers/intel/sgx"
$ sudo /sbin/depmod
$ sudo /bin/sed -i '/^isgx$/d' /etc/modules
c 复制代码
# ls -l /dev/isgx
crw-rw-rw- 1 root root 10, 121 11月 30 10:26 /dev/isgx

三、 Build the Intel SGX SDK and Inte SGX PSW Package

参考 linux-sgx

(1)使用以下命令安装构建 Intel SGX SDK 所需的工具:

c 复制代码
$ sudo apt-get install build-essential ocaml ocamlbuild automake autoconf libtool wget python-is-python3 libssl-dev git cmake perl

(2)使用以下命令安装所需的其他工具和最新的Intel SGX SDK安装程序,以构建IntelSGX PSW:

c 复制代码
$ sudo apt-get install libssl-dev libcurl4-openssl-dev protobuf-compiler libprotobuf-dev debhelper cmake reprepro unzip pkgconf libboost-dev libboost-system-dev libboost-thread-dev lsb-release libsystemd0

(3)下载源代码并准备子模块和预构建的二进制文件:

c 复制代码
git clone https://github.com/intel/linux-sgx.git
cd linux-sgx && make preparation

上面的make准备将触发脚本download_prebuild.sh来下载预构建的二进制文件。

将与当前操作系统分发对应的 the mitigation tools 从external/toolset/{current_distr}复制到/usr/local/bin,并确保它们具有执行权限:

c 复制代码
sudo cp external/toolset/{current_distr}/* /usr/local/bin
c 复制代码
# ls external/toolset/
anolis8.6  centos8  centos8.3  debian10  rhel8.4  rhel8.6  sles15.4  ubuntu18.04  ubuntu20.04

对于我的系统即:

c 复制代码
linux-sgx# sudo cp external/toolset/ubuntu20.04/* /usr/local/bin
c 复制代码
linux-sgx# which ar as ld objcopy objdump ranlib
/usr/local/bin/ar
/usr/local/bin/as
/usr/local/bin/ld
/usr/local/bin/objcopy
/usr/local/bin/objdump
/usr/local/bin/ranlib

注意:即使您之前将以前的 mitigation tools 复制到/usr/local/bin,也必须执行上述操作。它确保在以后的构建中使用更新的 mitigation tools 。

四、 Build the Intel SGX SDK and Intel SGX SDK Installer

4.1 build Intel SGX SDK

要使用默认配置构建 Intel SGX SDK ,请输入以下命令:

c 复制代码
make sdk
or
make sdk DEBUG=1  //(with debug information)

要构建 Intel® SGX SDK安装程序,请输入以下命令:

c 复制代码
make sdk_install_pkg
or
make sdk_install_pkg DEBUG=1  //(with debug information kept in the tools and libraries)

可以在linux/installer/bin/下找到生成的 Intel SGX SDK 安装程序sgx_linux_x64_sdk_{version}.bin,其中{version}表示版本号。

4.2 Install the Intel SGX SDK

这步要先做,不让在构建Intel SGX PSW时会报错。

请参看:https://github.com/intel/linux-sgx/issues/466

c 复制代码
Generated sdk installer: ./linux/installer/bin/sgx_linux_x64_sdk_2.22.100.3.bin
c 复制代码
/linux-sgx/linux/installer/bin# ./sgx_linux_x64_sdk_2.22.100.3.bin

Do you want to install in current directory? [yes/no] : no

Please input the directory which you want to install in : /opt/intel/

......

Installation is successful! The SDK package can be found in /opt/intel/sgxsdk

Please set the environment variables with below command:

source /opt/intel/sgxsdk/environment

注意:在编译代码之前,需要设置所需的环境变量。要执行此操作,请运行:

c 复制代码
source /opt/intel/sgxsdk/environment

步骤总结:

c 复制代码
make sdk
make sdk_install_pkg
/sgx_linux_x64_sdk_2.22.100.3.bin //(选择安装在/opt/intel/目录下)
source /opt/intel/sgxsdk/environment

4.3 Test the Intel SGX SDK Package with the Code Samples

在安装Intel SGX PSW包之前,我们先用模拟模式测试SGX SDK包是否安装正常。

在模拟模式下编译并运行每个代码示例,以确保SGX SDK包运行良好:

c 复制代码
$ cd ${sgx-sdk-install-path}/SampleCode/LocalAttestation
$ make SGX_MODE=SIM
The project has been built in simulation debug mode.

$ cd bin
$ ./app
c 复制代码
/linux-sgx/SampleCode/LocalAttestation/bin# ./app
succeed to load enclaves.
succeed to establish secure channel.
Succeed to exchange secure message...
Succeed to close Session...

注意模拟模式下不需要SGX PSW包。

五、Build the Intel SGX PSW and Intel SGX PSW Installer

5.1 build Intel SGX PSW

要使用默认配置构建Intel SGX PSW,请输入以下命令:

c 复制代码
linux-sgx# make psw
or
make psw DEBUG=1 (with debug information)

可以在build/linux目录中找到生成的工具和库。注意:也可以转到psw文件夹,并使用make命令仅构建IntelSGX psw组件。

要构建 Intel SGX PSW 安装程序,请输入以下命令:

c 复制代码
$ make deb_psw_pkg
......
scripts/
scripts/install.sh
scripts/installConfig
Generated psw installer: ./linux/installer/bin/sgx_linux_x64_psw_2.22.100.3.bin

sgx_linux_x64_psw_2.22.100.3.bin就是pws安装器二进制文件。

可以在下面找到生成的相应 Intel SGX PSW 安装程序:

c 复制代码
linux/installer/deb/libsgx-urts, linux/installer/deb/libsgx-enclave-common, linux/installer/deb/libsgx-uae-service, linux/installer/deb/libsgx-epid, linux/installer/deb/libsgx-launch, linux/installer/deb/libsgx-quote-ex and linux/installer/deb/sgx-aesm-service

运行psw安装器:

c 复制代码
linux-sgx# cd linux/installer/bin
linux-sgx/linux/installer/bin# ls

build-installpkg.sh  install-sgx-psw.bin.tmpl  install-sgx-sdk.bin.tmpl  sgx_linux_x64_psw_2.22.100.3.bin  sgx_linux_x64_sdk_2.22.100.3.bin
linux-sgx/linux/installer/bin# ./sgx_linux_x64_psw_2.22.100.3.bin

要自行构建这些飞地(无需签名),首先需要从Intel(R)SGX SDK安装最新的 Intel SGX SDK ,然后使用默认配置构建PSW。之后,您可以使用相应文件夹中的make命令来构建每个Architecture Enclave:

c 复制代码
 $ cd psw/ae/le
 $ make

5.2 Install the Intel SGX PSW

SGX PSW提供3项服务:启动、基于EPID的认证和算法无关认证。从2.8版本开始,SGX PSW被拆分为更小的软件包,用户可以选择安装哪些功能和服务。有两种方法可以安装所需的软件包:使用单个软件包或使用构建系统生成的本地repo。建议使用本地repo,因为系统将自动解决依赖关系。目前,我们支持基于.deb和.rpm的repos。

c 复制代码
/linux-sgx# apt-get install libsgx-launch libsgx-urts
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libsgx-launch
E: Unable to locate package libsgx-urts

出现以上问题。

在安装前,首先执行以下三条命令:

c 复制代码
# 将以下库添加到源中
echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu focal main' | sudo tee /etc/apt/sources.list.d/intel-sgx.list
# 获取 Debian 存储库公钥并将其添加到 apt 用于验证软件包的受信任密钥列表中
wget -qO - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | sudo apt-key add
# 更新apt
sudo apt-get update

Using the local repo(recommended):

(1)launch service

c 复制代码
apt-get install libsgx-launch libsgx-urts

(2)EPID-based attestation service

c 复制代码
apt-get install libsgx-epid libsgx-urts

(3)algorithm agnostic attestation service

c 复制代码
apt-get install libsgx-quote-ex libsgx-urts

(4)DCAP ECDSA-based service

c 复制代码
apt-get install libsgx-dcap-ql

5.3 Compile and Run the Code Samples in the Hardware Mode

如果使用启用英特尔SGX硬件的机器,则可以在硬件模式下运行代码示例。请确保在计算机上安装 Intel SGX driver 和 Intel SGX PSW installer 。

在硬件模式下编译并运行每个代码示例,调试构建,如下所示:

c 复制代码
linux-sgx/SampleCode/LocalAttestation# make
......
The project has been built in hardware debug mode.
c 复制代码
linux-sgx/SampleCode/LocalAttestation# cd bin/
linux-sgx/SampleCode/LocalAttestation/bin# ./app
succeed to load enclaves.
succeed to establish secure channel.
Succeed to exchange secure message...
Succeed to close Session...

参考资料

https://blog.csdn.net/cacique111/article/details/133246169
https://blog.csdn.net/shuizhongmose/article/details/131290471
https://blog.csdn.net/weixin_43292691/article/details/119917066
https://blog.csdn.net/qq_42557044/article/details/127259835
https://blog.csdn.net/hhh078/article/details/132273182

相关推荐
冷白白19 分钟前
【C++】C++对象初探及友元
c语言·开发语言·c++·算法
活跃的煤矿打工人20 分钟前
【星海saul随笔】Ubuntu基础知识
linux·运维·ubuntu
睡觉然后上课37 分钟前
c基础面试题
c语言·开发语言·c++·面试
武昌库里写JAVA1 小时前
【Java】Java面试题笔试
c语言·开发语言·数据结构·算法·二维数组
fasewer1 小时前
第五章 linux实战-挖矿 二
linux·运维·服务器
楚灵魈1 小时前
[Linux]从零开始的网站搭建教程
linux·运维·服务器
小小不董1 小时前
《Linux从小白到高手》理论篇:深入理解Linux的网络管理
linux·运维·服务器·数据库·php·dba
这可就有点麻烦了2 小时前
强化学习笔记之【TD3算法】
linux·笔记·算法·机器学习
DY009J2 小时前
深度探索Kali Linux的精髓与实践应用
linux·运维·服务器
l1x1n02 小时前
No.2 笔记 | 网络安全攻防:PC、CS工具与移动应用分析
安全·web安全