Linux ubuntu20.04 安装使用 Intel sgx

文章目录

  • 前言
  • 一、简介
  • 二、安装Intel SGX Software Stack
    • 2.1 安装Intel SGX driver
    • 2.2 Build the Intel SGX SDK and Inte SGX PSW Package
    • 2.3 Build the Intel SGX SDK and Intel SGX SDK Installer
    • 2.4 Install the Intel(R) SGX SDK
    • 2.5 Build the Intel SGX PSW and Intel SGX PSW Installer
    • 2.6 Install the Intel SGX PSW
  • 三、Test the Intel SGX SDK Package with the Code Samples
  • 参考资料

前言

开发平台:

# lscpu
Model name:                         Intel(R) Core(TM) i3-9100 CPU @ 3.60GHz

操作系统版本:

# 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硬件功能。
启动后输出如下:

# cpuid | grep -i sgxSGX: Software Guard Extensions supported = true......SGX1 supported                         = trueSGX2 supported                         = false

查看内核启动日志:

# dmesg | grep -i sgx
[    0.398363] sgx: EPC section 0x80200000-0x85f7ffff

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

输出如下:

root@qax-TianYi510S-07ICB:/home/qax/test/SGX-hardware# ./test-sgx
Start test-sgx
......
Supports SGX
SGX1 leaf instructions (SGX1): 1

参考文章:https://github.com/intel/linux-sgx

一、简介

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

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

Intel SGX 驱动程序托管在 linux-sgx-driver 项目中。
Intel SGX SDK 和 Intel SGX PSW 托管在 linux-sgx 项目中。

自从 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驱动程序。

二、安装Intel SGX Software Stack

英特尔SGX SDK Linux操作系统软件堆栈由 the driver, the SDK, and the PW(platform software) 组成。

2.1 安装Intel SGX driver

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

由于我这里的内核版本是5.15,已经Support for Intel SGX,所以不需要安装驱动。
如果内核版本低于5.11,请参考 the out-of-tree driver 进行驱动安装: linux-sgx-driver 。

2.2 Build the Intel SGX SDK and Inte SGX PSW Package

参考 linux-sgx

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

$ 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:

$ 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)下载源代码并准备子模块和预构建的二进制文件:

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,并确保它们具有执行权限:

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

对于我的系统即:

linux-sgx# sudo cp external/toolset/ubuntu20.04/* /usr/local/bin
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 。

2.3 Build the Intel SGX SDK and Intel SGX SDK Installer

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

make sdk
or
make sdk DEBUG=1  //(with debug information)

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

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}表示版本号。

2.4 Install the Intel® SGX SDK

这步要先做,不让在构建Intel SGX PSW时会报错。
请参看:https://github.com/intel/linux-sgx/issues/466

Generated sdk installer: ./linux/installer/bin/sgx_linux_x64_sdk_2.22.100.3.bin
/linux-sgx/linux/installer/bin# ./sgx_linux_x64_sdk_2.22.100.3.binDo you want to install in current directory? [yes/no] : noPlease input the directory which you want to install in : /opt/intel/......Installation is successful! The SDK package can be found in /opt/intel/sgxsdkPlease set the environment variables with below command:source /opt/intel/sgxsdk/environment

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

source /opt/intel/sgxsdk/environment

步骤总结:

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

2.5 Build the Intel SGX PSW and Intel SGX PSW Installer

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

linux-sgx# make psw
or
make psw DEBUG=1 (with debug information)

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

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

 $ cd psw/ae/le$ make

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

make deb_psw_pkg

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

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

2.6 Install the Intel SGX PSW

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

/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

出现以上问题。

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

# 将以下库添加到源中
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

apt-get install libsgx-launch libsgx-urts

(2)EPID-based attestation service

apt-get install libsgx-epid libsgx-urts

(3)algorithm agnostic attestation service

apt-get install libsgx-quote-ex libsgx-urts

(4)DCAP ECDSA-based service

apt-get install libsgx-dcap-ql

三、Test the Intel SGX SDK Package with the Code Samples

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

$ cd ${sgx-sdk-install-path}/SampleCode/LocalAttestation
$ make SGX_MODE=SIM
The project has been built in simulation debug mode.$ cd bin
$ ./app
/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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/183318.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

5 面试题--redis

伪客户端: 伪客户端的 fd 属性值为 -1;伪客户端处理的命令请求来源于 AOF ⽂件或者 Lua 脚本,⽽不是⽹络,所以这种客户端不需要套接字连接,⾃然也不需要记录套接字描述符。⽬前 Redis 服务器会在两个地⽅ ⽤到伪客户端…

ThermalLabel SDK for .NET 13.0.23.1113 Crack

ThermalLabel SDK for .NET 是一个 .NET 典型类库,它允许用户和开发人员创建非常创新的条码标签并将其发布在 zebra ZPL、EPL、EPSON ESC、POS 以及 Honeywell intermec 指纹中通过在 VB.NET 或 C# 上编写 .NET 纯代码来实现热敏打印机,以实现项目框架的…

BiLSTM-CRF的中文命名实体识别

项目地址:NLP-Application-and-Practice/11_BiLSTM-ner-bilstm-crf/11.3-BiLSTM-CRF的中文命名实体识别/ner_bilstm_crf at master zz-zik/NLP-Application-and-Practice (github.com) 读取renmindata.pkl文件 read_file_pkl.py # encoding:utf-8import pickle# …

分享一些基于php商城案例

案例1: ​​​​​​http://www.9520.xin/ 案例2: http://ptll.hasbuy.com/ 案例3: http://likeshop.9520.xin/mobile 案例4: http://www.hasbuy.com/

Ubuntu Linux玩童年小霸王插卡游戏

1.下载安装模拟器 在Windows平台模拟器非常多,而且效果也很优秀,Linux平台的用户常常很羡慕,却因为系统的缘故,无法使用这样的模拟器,但是随着时代的发展,Linux平台也出现了许多优秀的模拟器,现…

CTF ssrf+pin

什么是pin码 pin码是flask在开启debug模式下,进行代码调试模式所需的进入密码,需要正确的PIN码才能进入调试模式,可以理解为自带的webshell pin码如何生成 pin码生成要六要素 1.username 在可以任意文件读的条件下读 /etc/passwd进行猜测 2.modname 默…

navigator.clipboard is undefined in JavaScript issue [Fixed]

navigator.clipboard 在不安全的网站是无法访问的。 在本地开发使用localhost或127.0.0.1没有这个问题。因为它不是不安全网站。 在现实开发中,可能遇到测试环境为不安全网站。 遇到这个问题,就需要将不安全网站标记为非不安全网站即可。 外网提供了3…

【HTML】VScode不打开浏览器实时预览html

1. 问题描述 预览HTML时,不想打开浏览器,想在VScode中直接实时预览 2. 解决方案 下载Microsoft官方的Live Preview 点击预览按钮即可预览

Unity中Shader优化通用规则

文章目录 前言一、精度优化1、三种精度 fixed / half / float2、位置坐标、物理坐标类使用float3、HDR颜色、方向向量类使用half4、普通纹理、颜色类使用 fixed5、实际上,使用的精度取决于 平台 和 GPU6、现在桌面级GPU都是直接采用 float , Shader中的 fixed / hal…

J2EE征程——第一个纯servletCURD

第一个纯servletCURD 前言在此之前 一,概述二、CURD1介绍2查询并列表显示准备实体类country编写 CountryListServlet配置web.xml为web应用导入mysql-jdbc的jar包 3增加准备增加的页面addc.html编写 CAddServlet配置web.xml测试 4删除修改CountryListServlet&#xf…

RabbitMQ消息模型之Routing-Topic

Routing Topic Topic类型的Exchange与Direct相比,都是可以根据RoutingKey把消息路由到不同的队列。只不过Topic类型Exchange可以让队列在绑定Routing key的时候使用通配符!这种模型Routingkey一般都是由一个或多个单词组成,多个单词之间以”…

ESP32-Web-Server编程- WebSocket 编程

ESP32-Web-Server编程- WebSocket 编程 概述 在前述 ESP32-Web-Server 实战编程-通过网页控制设备的 GPIO 中,我们创建了一个基于 HTTP 协议的 ESP32 Web 服务器,每当浏览器向 Web 服务器发送请求,我们将 HTML/CSS 文件提供给浏览器。 使用…

智能手表上的音频(四):语音通话

上篇讲了智能手表上音频文件播放。本篇开始讲语音通话。同音频播放一样有两种case:内置codec和BT。先看这两种case下audio data path,分别如下图: 内置codec下的语音通话audio data path 蓝牙下的语音通话audio data path 从上面两张图可以看…

享元模式 (Flyweight Pattern)

定义: 享元模式(Flyweight Pattern)是一种结构型设计模式,用于优化性能和内存使用。它通过共享尽可能多的相似对象来减少内存占用,特别是在有大量对象时。这种模式通常用于减少应用程序中对象的数量,并在多…

Redis 实战缓存

本篇概要: 1. 设置、查询、获取过期时间;2. 缓存穿透:设置空键;3. 封杀单ip;4. 封杀ip段;5. 缓存预热;6. 使用 hash 数据类型保存新闻的缓存,增加点击量;7. Sorted set&a…

纯js实现录屏并保存视频到本地的尝试

前言:先了解下:navigator.mediaDevices,mediaDevices 是 Navigator 只读属性,返回一个 MediaDevices 对象,该对象可提供对相机和麦克风等媒体输入设备的连接访问,也包括屏幕共享。 const media navigator…

【刷题】DFS

DFS 递归: 1.判断是否失败终止 2.判断是否成功终止,如果成功的,记录一个成果 3.遍历各种选择,在这部分可以进行剪枝 4.在每种情况下进行DFS,并进行回退。 199. 二叉树的右视图 给定一个二叉树的 根节点 root&#x…

深度学习之十二(图像翻译AI算法--UNIT(Unified Neural Translation))

概念 UNIT(Unified Neural Translation)是一种用于图像翻译的 AI 模型。它是一种基于生成对抗网络(GAN)的框架,用于将图像从一个域转换到另一个域。在图像翻译中,这意味着将一个风格或内容的图像转换为另一个风格或内容的图像,而不改变图像的内容或语义。 UNIT 的核心…

IDEA2022 Git 回滚及回滚内容恢复

IDEA2022 Git 回滚 ①选择要回滚的地方,右键选择 ②选择要回滚的模式 ③开始回滚 ④soft模式回滚的内容会保留在暂存区 ⑤输入git push -f ,然后重新提交,即可同步远程 注意观察IDEA右下角分支的标记,蓝色代表远程内容未同步到本…

数据结构 / day06 作业

1.下面的代码打印在屏幕上的值是多少? /下面的代码打印在屏幕上的值是多少?#include "stdio.h"int compute_data(int arr[], unsigned int len) {long long int result 0;if(result len)return arr[0];resultcompute_data(arr,--len);printf("len%d, res…