Skip to content

Commit feeae39

Browse files
committed
Add backup schema for sgx_kms
1 parent 9973733 commit feeae39

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+8398
-12
lines changed

cczoo/ehsm/README.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

cczoo/ehsm/ehsm

Submodule ehsm deleted from 5c91d6d

cczoo/sgx_kms/.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
rkeyserver/App/enclave_u.*
2+
rkeyserver/Enclave/enclave_t.*
3+
rkeyserver/App/*.o
4+
rkeyserver/Enclave/*.o
5+
6+
utils/tkey_exchange/*.o
7+
utils/tkey_exchange/sgx_tkey_exchange_t.*
8+
utils/tkey_exchange/sgx_tkey_exchange_u.*
9+
utils/ukey_exchange/*.o
10+
11+
out/
12+
13+
.history/
14+
.vscode/
15+
16+
rkeyserver/App/auto_version.h

cczoo/sgx_kms/License.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
BSD 3-clause "New" or "Revised" License
2+
3+
Copyright (C) 2020-2022 Intel Corporation. All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions
7+
are met:
8+
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in
13+
the documentation and/or other materials provided with the
14+
distribution.
15+
* Neither the name of Intel Corporation nor the names of its
16+
contributors may be used to endorse or promote products derived
17+
from this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
31+
=================================================================

cczoo/sgx_kms/Makefile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#
2+
# Copyright (C) 2011-2020 Intel Corporation. All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions
6+
# are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright
9+
# notice, this list of conditions and the following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright
11+
# notice, this list of conditions and the following disclaimer in
12+
# the documentation and/or other materials provided with the
13+
# distribution.
14+
# * Neither the name of Intel Corporation nor the names of its
15+
# contributors may be used to endorse or promote products derived
16+
# from this software without specific prior written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
#
30+
#
31+
32+
include buildenv.mk
33+
34+
SUB_DIR := utils/tkey_exchange utils/ukey_exchange rkeyserver
35+
36+
.PHONY: all clean
37+
38+
all:
39+
for dir in $(SUB_DIR); do \
40+
$(MAKE) -C $$dir; \
41+
done
42+
43+
ifeq ($(Build_Mode), HW_DEBUG)
44+
@echo "The project has been built in hardware debug mode."
45+
else ifeq ($(Build_Mode), HW_RELEAESE)
46+
@echo "The project has been built in hardware release mode."
47+
else ifeq ($(Build_Mode), HW_PRERELEAESE)
48+
@echo "The project has been built in hardware pre-release mode."
49+
else ifeq ($(Build_Mode), SIM_DEBUG)
50+
@echo "The project has been built in simulation debug mode."
51+
else ifeq ($(Build_Mode), SIM_RELEAESE)
52+
@echo "The project has been built in simulation release mode."
53+
else ifeq ($(Build_Mode), SIM_PRERELEAESE)
54+
@echo "The project has been built in simulation pre-release mode."
55+
endif
56+
57+
clean:
58+
@rm -rf $(OUTDIR)
59+
for dir in $(SUB_DIR); do \
60+
$(MAKE) -C $$dir clean; \
61+
done

cczoo/sgx_kms/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
## Overview of this backup schema of sgx_kms
2+
3+
In the design architecture of sgx_kms, the TCP/IP socket server is used to provide the root key, the remote secure channel provided by SGX is used to transmit the root key in the enclave, and the SGX Keys are used to encrypt the root key and store it in a local file or database, so that it can be safely stored outside the enclave environment. In this way, the root key is also bound with the unique SGX Keys of the processor, reducing the correlation between the root key and the maintenance personnel. Considering that the server may fail, we have designed a backup architecture. When we start the standby server, we will ask the primary server for the root key and keep it securely. When the primary server goes down, the backup server can play a role as the primary server.
4+
5+
The root key stored in the keystore needs to be decrypted by all root key providing service instances, while other platforms cannot decrypt the root key encrypted through the SGX sealing mechanism. Therefore, in the SGX security enhanced root key providing service design, the Root Key is deployed in each backup instance by using SGX remote authentication to establish a secure session. The scheme design is shown in the figure. This scheme is stored on the platform through SGX sealed encryption, and the root key is only used for decryption in Enclave, so that every instance has the same root key, and the attacker is prevented from directly obtaining the master key from memory.
6+
7+
<img src="./docs/arch-of-back-sgxkms.png" alt="arch-of-back-sgxkms" style="zoom:50%;" />
8+
9+
## Build Instructions
10+
11+
- If you need to synchronize the domain key between the host machine (the machine that has the domain key) and the backup machine (the machine that requests the domain key from the host machine), then you can compile first.
12+
13+
``` bash
14+
make
15+
```
16+
17+
- In this way, the directory `out/` will be generated, and in this directory, there will be the following files
18+
19+
```
20+
rkeyserver
21+
22+
lib
23+
```
24+
25+
- Enter the folder rkeyserver, there will be the following file rkeyserver
26+
27+
```
28+
libenclave-rkeyserver.signed.so
29+
30+
libenclave-rkeyserver.so
31+
```
32+
33+
- On the host side, execute
34+
35+
``` bash
36+
./rkeyserver
37+
```
38+
39+
- on the backup machine, execute
40+
41+
``` bash
42+
./ehsm-rkeyserver -i 10.23.100.2 -p 8888
43+
```
44+
45+
`-i` is followed by the ip address of the host (`10.23.100.2` is used here as an example), `-p` is the port number of the host, the default is `8888`.
46+
47+
- If the following message is displayed
48+
49+
```
50+
INFO [App/ra_getkey.cpp(454) -> start_getkey]: Successfully received the DomainKey from deploy server.
51+
```
52+
53+
It means that the domain key is successfully obtained on the backup machine. By default, the domain key is stored in the directory `/etc/rkey.bin` in encrypted form.
54+
55+
It is worth mentioning that when the `/etc/rkey.bin` file already exists, when the backup machine continues to request the domain key from the host, the original `rkey.bin` file will be replaced by the new `rkey.bin` file and the following information is output on the screen
56+
57+
```
58+
file already exist, substitute by new file
59+
```
60+
61+

cczoo/sgx_kms/buildenv.mk

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#
2+
# Copyright (C) 2011-2020 Intel Corporation. All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions
6+
# are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright
9+
# notice, this list of conditions and the following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright
11+
# notice, this list of conditions and the following disclaimer in
12+
# the documentation and/or other materials provided with the
13+
# distribution.
14+
# * Neither the name of Intel Corporation nor the names of its
15+
# contributors may be used to endorse or promote products derived
16+
# from this software without specific prior written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
#
30+
#
31+
32+
######## auto_version Settings ########
33+
DATE_STRING := `date "+20%y.%m.%d %k:%M"`
34+
KMS_GIT_SHA=$(shell git rev-parse --short=7 --verify HEAD)
35+
36+
# -------------------------------------------------------------------
37+
# Function : parent-dir
38+
# Arguments: 1: path
39+
# Returns : Parent dir or path of $1, with final separator removed.
40+
# -------------------------------------------------------------------
41+
parent-dir = $(patsubst %/,%,$(dir $(1:%/=%)))
42+
43+
# ------------------------------------------------------------------
44+
# Macro : my-dir
45+
# Returns : the directory of the current Makefile
46+
# Usage : $(my-dir)
47+
# ------------------------------------------------------------------
48+
my-dir = $(realpath $(call parent-dir,$(lastword $(MAKEFILE_LIST))))
49+
50+
ROOT_DIR := $(call my-dir)
51+
ifneq ($(words $(subst :, ,$(ROOT_DIR))), 1)
52+
$(error main directory cannot contain spaces nor colons)
53+
endif
54+
55+
######## Output Settings ########
56+
TOPDIR = $(ROOT_DIR)
57+
OUTDIR := out
58+
OUTLIB_DIR := $(OUTDIR)/lib
59+
60+
######## Compiler Settings ########
61+
CP = cp
62+
CC ?= gcc
63+
CXX ?= g++
64+
RM = rm -f
65+
66+
######## SGX SDK Settings ########
67+
68+
SGX_SDK ?= /opt/intel/sgxsdk
69+
SGX_MODE ?= HW
70+
SGX_ARCH ?= x64
71+
SGX_DEBUG ?= 1
72+
#SUPPLIED_KEY_DERIVATION ?= 1
73+
74+
include $(SGX_SDK)/buildenv.mk
75+
76+
ifeq ($(shell getconf LONG_BIT), 32)
77+
SGX_ARCH := x86
78+
else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32)
79+
SGX_ARCH := x86
80+
endif
81+
82+
ifeq ($(SGX_ARCH), x86)
83+
SGX_COMMON_FLAGS := -m32
84+
SGX_LIBRARY_PATH := $(SGX_SDK)/lib
85+
SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign
86+
SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r
87+
else
88+
SGX_COMMON_FLAGS := -m64
89+
SGX_LIBRARY_PATH := $(SGX_SDK)/lib64
90+
SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign
91+
SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r
92+
endif
93+
94+
ifeq ($(SGX_DEBUG), 1)
95+
ifeq ($(SGX_PRERELEASE), 1)
96+
$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!)
97+
endif
98+
endif
99+
100+
ifeq ($(SUPPLIED_KEY_DERIVATION), 1)
101+
SGX_COMMON_FLAGS += -DSUPPLIED_KEY_DERIVATION
102+
endif
103+
104+
ifeq ($(SGX_DEBUG), 1)
105+
SGX_COMMON_FLAGS += -O0 -ggdb3
106+
else
107+
SGX_COMMON_FLAGS += -O2
108+
endif
109+
110+
SGX_COMMON_FLAGS += -Wall -Wextra -Winit-self -Wpointer-arith -Wreturn-type \
111+
-Waddress -Wsequence-point -Wformat-security \
112+
-Wmissing-include-dirs -Wfloat-equal -Wundef -Wshadow \
113+
-Wcast-align -Wredundant-decls
114+
115+
#SGX_COMMON_CFLAGS += $(SGX_COMMON_FLAGS) -Wstrict-prototypes -Wunsuffixed-float-constants -Wcast-qual
116+
117+
SGX_COMMON_CXXFLAGS := $(SGX_COMMON_FLAGS) -Wnon-virtual-dtor -std=c++11
118+
119+
######## BUILD Settings ########
120+
ifeq ($(SGX_MODE), HW)
121+
ifeq ($(SGX_DEBUG), 1)
122+
Build_Mode = HW_DEBUG
123+
else ifeq ($(SGX_PRERELEASE), 1)
124+
Build_Mode = HW_PRERELEASE
125+
else
126+
Build_Mode = HW_RELEASE
127+
endif
128+
else
129+
ifeq ($(SGX_DEBUG), 1)
130+
Build_Mode = SIM_DEBUG
131+
else ifeq ($(SGX_PRERELEASE), 1)
132+
Build_Mode = SIM_PRERELEASE
133+
else
134+
Build_Mode = SIM_RELEASE
135+
endif
136+
endif
137+
138+
ifneq ($(SGX_MODE), HW)
139+
Urts_Library_Name := sgx_urts_sim
140+
else
141+
Urts_Library_Name := sgx_urts
142+
endif
143+
144+
ifneq ($(SGX_MODE), HW)
145+
Trts_Library_Name := sgx_trts_sim
146+
Service_Library_Name := sgx_tservice_sim
147+
else
148+
Trts_Library_Name := sgx_trts
149+
Service_Library_Name := sgx_tservice
150+
endif
151+
97.3 KB
Loading

0 commit comments

Comments
 (0)