当前位置: 首页 > news >正文

Windows10 下测试 Intel SGX 功能

文章目录

  • 参考文献
  • 系统要求
  • 一、安装Open Enclave SDK 环境
    • (一)什么是Open Enclave SDK
    • (二)启动SGX功能
      • 方法一: BIOS启动
      • 方法二:软件方式启动
    • (三)安装必要环境
      • (1)安装编译工具:Visual Studio Build 2019(x64)
      • (2)安装Git环境
      • (3)安装Clang环境
      • (4)安装OpenSSL
      • (5)安装ME
      • (6.1)自动安装Guard Extension SDK for windows(PSW)
      • (6.2)手动安装PSW(Intel Platform Software for Windows)
      • (7)安装openenclave SDK
      • (8)安装Intel SGX DCAP for Windows
  • 二、使用Open Enclave SDK
    • (一)Open Enclave SDK目录文件说明
    • (二)配置 Open Enclave SDK
    • (三)运行测试例子(helloworld)

参考文献

  • 哪些平台支持英特尔® Software Guard Extensions (英特尔® SGX) 数据中心标记基元 (DCAP
  • 官方文档一:Install the Open Enclave SDK NuGet Package
  • 官方文档二:Using the Open Enclave SDK on Windows
  • 官方文档三: Building and Running the Samples on Windows
  • Win10安装Intel SGX环境并执行一个基础demo
  • windows10下使用Intel SGX编程初体验

系统要求

  • x86-64。
  • Windows Server 2019 or Windows 10 (1709 or newer)。
  • 支持SGX1(+FLC),如果不支持FLC,则只能使用simulation mode。

一、安装Open Enclave SDK 环境

(一)什么是Open Enclave SDK

Open Enclave SDK提供了对Open Portable TEE OS(OP-TEE OS)的预览支持。OP-TEE是一个用于实现传统内核模式和用户模式执行环境的TEE的操作系统。它在支持ARM TrustZone的A-profile ARM系统上运行。因此,Open Enclave SDK 也可以被用来针对这些系统。

原文链接请参考Open Enclave SDK for OP-TEE OS。

(二)启动SGX功能

启动SGX功能的前提条件时:Windows® 10 is booted in Legacy or UEFI Mode。如果是Legacy mode,则需要修改为UEFI mode,并重装windows 10。

方法一: BIOS启动

  1. 查看是否支持SGX,可参考官方文档:在电脑设置中找到CPU类型,在Intel官网查询该型号是否支持SGX。
  1. 如果电脑支持SGX,则重启电脑进入【BIOS->Security】下启动SGX。如果BIOS无法设置,则不支持使用Intel SGX功能。

方法二:软件方式启动

在 Microsoft Store 中下载安装Intel(R) Software Guard Extensions Activation APP。并以 Admin 方式打开 Intel(R) Software Guard Extensions Activation APP,单击 【Activate】启动SGX。

(三)安装必要环境

安装Open Enclave SDK的环境要求如下:

  • Git v2.31.1
  • OpenSSL 1.1.1
  • Visual Studio Build Tools
  • Clang 10.0.0
  • ShellCheck v0.7.0
  • Nuget 3.4.3
  • Python 3
  • Python pip
  • Intel SGX PSW v2.13.100.2

下面根据自己电脑上缺失工具进行安装。

(1)安装编译工具:Visual Studio Build 2019(x64)

  1. Visual Studio Build 2019下载地址在这儿。
  2. 安装时选择【C++ build tools】,中文是【使用C++的桌面开发】进行安装;
  3. Visual Studio Build Tools 2019支持CMake 3.15版(构建Open Enclave SDK需要CMake 3.12版或以上)。

(2)安装Git环境

  1. 如果有git、git bash等环境,则跳过。
  2. 下载地址在这儿,按步骤安装即可。
  3. C:\Program Files\Git\binC:\Program Files\Git\mingw64\bin添加到 PATH

(3)安装Clang环境

  1. 下载地址在这儿
  2. 安装Clang 8.0.1并将LLVM文件夹添加到路径中.

(4)安装OpenSSL

  1. 安装Git之后,在Git Bash中可以使用openssl了。
  2. 记住,电脑中一定只能有一个openssl。不然ninja 编译的时候会出错,参考这儿

(5)安装ME

windows10的ME下载地址在这儿。下载后直接安装,安装文件为\ME_SW_2216.16.0.2805\ME_SW_DCH\SetupME.exe

(6.1)自动安装Guard Extension SDK for windows(PSW)

实验中这种方式总是提示版本不对,即使在 SGX 已经激活的状态下。

下载地址在这儿。下载后直接安装。

(6.2)手动安装PSW(Intel Platform Software for Windows)

官方文档说SGX1+FLC才安装PSW,但是所有支持SGX的都需要安装PSW。

  1. 查看windows版本。在cmdpowershell中输入:winver,查看版本。1709是指2017年9月第一版windows10。所以一般都是使用above版本安装。

  2. 解压Intel SGX PSW v2.13.100.2,下载地址在这儿。下载之后,解压。

  3. 进入\Intel SGX PSW for Windows v2.13.100.2\PSW_INF_RS3_and_above目录,command(Admin)下执行:

pnputil /add-driver sgx_psw.inf /install

注:官方文档使用devcon.exe update安装总是出错,使用pnputil没有问题。

  1. 检查PSW是否安装成功:检查C:\Windows\System32下是否有sgx_urts.dll,【右键->属性->详细信息】查看版本。

  2. 查看PSW是否启动。command(Admin)下执行sc query aesmservice,输出如下信息表示已经启动。启动命令Start-Service "AESMService",重启命令Restart-Service "AESMService"

SERVICE_NAME: aesmserviceTYPE               : 10  WIN32_OWN_PROCESSSTATE              : 4  RUNNING(STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)WIN32_EXIT_CODE    : 0  (0x0)SERVICE_EXIT_CODE  : 0  (0x0)CHECKPOINT         : 0x0WAIT_HINT          : 0x0

(7)安装openenclave SDK

  1. 下载 openenclave nupkg
    代码在这儿,下载最新版本。我下载的是v0.18.5。
  2. 安装nuget工具。
    1. 下载nuget工具,无需安装。下载地址在这儿。
    2. 下载之后将nuget存放地址加入到PATH
    3. 在Powershell(Admin)中测试nuget是否可用。

3.安装openenclave nupkg。打开Powershell(Admin),执行以下命令:

nuget.exe install open-enclave -Source D:\software\windows\SGX  -OutputDirectory C:\oe -ExcludeVersion -pre
  1. 安装完成后,Open Enclave SDK将被放置在C:\oe路径下。使用下面的命令来复制SDK到C:\openenclave
xcopy /E  C:\oe C:\openenclave\
  1. 查看当前SGX
// Powershell或者cmd下输入:
> oesgx.exe
CPU supports Software Guard Extensions:SGX1
MaxEnclaveSize_64: 2^(36)
CPU supports Key Sharing & Separation (KSS): false
EPC size on the platform: 98041856
oesgx outputSGX support level
CPU supports SGX_FLC:Flexible Launch Control CPU supports Software Guard Extensions:SGX1SGX1+FLC
CPU supports Software Guard Extensions:SGX1SGX1
CPU does not support SGXNone

所以本系统支持SGX1

(8)安装Intel SGX DCAP for Windows

  1. 安装WDK(Windows Driver Kit),获取devcon.exe等工具。

    1. 关闭visual studio。
    2. 安装Windows SDK,下载地址在这儿。下载之后安装,安装目录默认是C:\Program Files (x86)\Windows Kits\10\WindowsSDK,其他选项根据需要进行修改。(Windows SDK 貌似不支持家庭版,因为在安装WDK的时候总是提示Windows SDK未安装。
    3. Windows SDK安装完成之后,将C:\Program Files (x86)\Windows Kits\10添加到PATH
    4. 安装WDK,下载地址在这儿。默认安装路径,安装之后将C:\Program Files (x86)\Windows Kits\10\Tools\x64添加到PATH
  2. 安装Intel SGX DCAP for Windows。

    1. DCAP的下载地址在这儿。下载DCAP到存放路径。
    2. 运行Intel SGX DCAP for Windows v1.11.100.2.exe,解压到C:
    3. 允许SGX启动配置驱动程序运行: command(Admin)下执行:
    reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\sgx_lc_msr\Parameters /v "SGX_Launch_Config_Optin" /t REG_DWORD /d 1
    reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\sgx_lc_msr\Parameters /v "SGX_Launch_Config_Optin"
    
    1. 安装和升级驱动。进入C:\Intel SGX DCAP for Windows v1.11.100.2目录,在command(Admin)下执行如下安装命令:
    devcon.exe update dcap\WindowsServer2016\sgx_dcap_dev.inf "SWC\VEN_INT&DEV_0E0C_DCAP"
    devcon.exe update base\WindowsServer2019_Windows10\sgx_base.inf *INT0E0C// 或
    pnputil /add-driver base\WindowsServer2019_Windows10\sgx_base.inf /install
    pnputil /add-driver dcap\WindowsServer2016\sgx_dcap_dev.inf /install
    
    1. 安装DCAP_Components。command(Amind)执行如下命令。
    // 安装 DCAP_Components
    nuget.exe install DCAP_Components -Source "C:\Intel SGX DCAP for Windows v1.11.100.2\nuget\DCAP_Components" -OutputDirectory C:\oe_prereqs -ExcludeVersion// 安装 EnclaveCommonAPI
    > nuget.exe install EnclaveCommonAPI -Source "C:\Intel SGX DCAP for Windows v1.11.100.2\nuget\EnclaveCommonAPI" -OutputDirectory C:\oe_prereqs -ExcludeVersion
    

    如果安装EnclaveCommonAPI提示错误Unable to resolve dependency 'SgxHeaders'. Source(s) used: 'nuget.org'.或错误Unable to find package 'DCAP_Components'. Existing packages must be restored before performing an install or update.。则不指定源,使用所有源安装EnclaveCommonAPI

    nuget.exe install EnclaveCommonAPI -OutputDirectory C:\oe_prereqs -ExcludeVersion
    

二、使用Open Enclave SDK

注意:目前该SDK仅支持64bit的程序。

(一)Open Enclave SDK目录文件说明

Path说明
binDeveloper tools such as oedebugrt.dll for debugging and oesign for signing your enclaves.
include\openenclaveOpen Enclave runtime headers for use in your enclave (enclave.h) and its host (host.h).
include\openenclave\3rdpartyHeaders for libc, libcxx and mbedlts libraries for use inside the enclave. See the API Reference section for supported functions.
lib\openenclave\cmakeOpen Enclave SDK CMake Package for integration with your CMake projects. See README.md for more details.
lib\openenclave\enclaveLibraries for linking into the enclave, including the libc, libcxx and mbedtls libraries for Open Enclave.
lib\openenclave\hostLibrary for linking into the host process of the enclave.
lib\openenclave\debuggerLibraries used by the gdb plug-in for debugging enclaves.
share\openenclave\samplesSample code showing how to use the Open Enclave SDK.

(二)配置 Open Enclave SDK

在环境变量中增加CMAKE_PREFIX_PATH,值为C:\openenclave\lib\openenclave\cmake。或者:

set CMAKE_PREFIX_PATH=%CMAKE_PREFIX_PATH%;C:\openenclave\lib\openenclave\cmake

(三)运行测试例子(helloworld)

Open Enclave SDK的测试例相关文档:

  • Open Enclave SDK Samples
  • Build and Sign an Enclave
  • Open Enclave Debugging
  1. 拷贝所有测试示例到本地地址
// 示例
xcopy /E C:\openenclave\share\openenclave\samples E:\codes\MPC\oe-tee
  1. 在菜单栏展开Visual Studio 2019,以 Admin 的方式打开x64 Native Tools Command Prompt for VS 2019编译(如果选择其他,则会提示find_package The following configuration files were considered but not accepted的错误)。进入到程序目录。

注:visual studio的各个shell工具说明在这儿。

  1. 编译helloworld测试代码
mkdir build
cd build
> cmake .. -G Ninja -DNUGET_PACKAGE_PATH=C:\oe_prereqs
// 等待无错误输出> ninja
[1/1] Generating enclave/enclave.signed
Created E:/codes/MPC/oe-samples/helloworld/build/enclave/enclave.signed> ninja run
[1/1] cmd.exe /C "cd /D E:\codes\MPC\oe-samples\helloworld...es/MPC/oe-samples/helloworld/build/enclave/enclave.signed"
Hello world from the enclave
Enclave called into host to print: Hello World!
http://www.lryc.cn/news/19175.html

相关文章:

  • Tina_Linux_功耗管理_开发指南
  • golang编译dll失败问题解决
  • Convolutional Neural Networks for Sentence Classification
  • 基于SpringBoot的共享汽车管理系统
  • TCP三次握手
  • 未来土地利用模拟FLUS模型
  • 压力传感器MPX5700D/MPX5700GP/MPX5700AP产品概述、特征
  • taobao.trades.sold.query( 根据收件人信息查询交易单号 )
  • 【JavaWeb】JSON、AJAX(305-317)
  • AI入场,搜索这个“营销枢纽”有新故事吗?
  • 字节在职5年,一个测试工程师的坎坷之路
  • 什么是web框架?
  • 说一说关系数据库中的范式建模
  • Mysql是怎样运行的之Inno页介绍
  • 【华为OD机试模拟题】用 C++ 实现 - 找字符(2023.Q1)
  • JAVA 8 新特性 Lamdba表达式
  • 使用antlr实现一个简单的表达式解析
  • 2月24日作业
  • SpringBoot可以同时处理多少请求?
  • 代码随想录【Day23】| 669. 修剪二叉搜索树、108. 将有序数组转换为二叉搜索树、538. 把二叉搜索树转换为累加树
  • Wsl2 ubuntu 配置git 阿里云codeup
  • 展会邀约 | 昂视与您相约BTF第12届上海锂电展
  • RK3568平台开发系列讲解(驱动基础篇)中断子系统框架
  • 消费复苏迎“春”暖,服装行业如何开启“狂飙”模式?
  • Springboot 整合Flowable工作流框架搭建
  • ASE0510SH-ASEMI的MOS管ASE0510SH
  • Golang学习Day2
  • Android 中malloc_debug 原理详解
  • D. Triangle Coloring【组合数学,乘法逆元】
  • 【读论文】AttentionFGAN