Skip to content

Commit 366b098

Browse files
authored
Merge pull request #262 from jbdelcuv/ossl_fips_integration
OpenSSL FIPS provider support
2 parents 5304f69 + 4b83850 commit 366b098

Some content is hidden

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

55 files changed

+4883
-115
lines changed

.github/workflows/c-cpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: install SDK
2626
run: chmod +x *.bin; echo yes | ./sgx_linux_x64_sdk_2.*.bin
2727
- name: download OpenSSL code
28-
run: wget https://www.openssl.org/source/openssl-3.0.14.tar.gz --directory-prefix=openssl_source/
28+
run: wget https://www.openssl.org/source/openssl-3.1.6.tar.gz --directory-prefix=openssl_source/
2929
- name: build SGXSSL
3030
run: source sgxsdk/environment; cd Linux; make all; DEBUG=1 make all
3131
- name: run unit test in SIM

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
echo "Run, Build Application using script"
7070
wget https://download.01.org/intel-sgx/sgx-linux/2.24/distro/ubuntu22.04-server/sgx_linux_x64_sdk_2.24.100.3.bin;
7171
chmod +x *.bin; echo yes | ./sgx_linux_x64_sdk_2.*.bin;
72-
wget https://www.openssl.org/source/openssl-3.0.14.tar.gz --directory-prefix=openssl_source/;
72+
wget https://www.openssl.org/source/openssl-3.1.6.tar.gz --directory-prefix=openssl_source/;
7373
source sgxsdk/environment; cd Linux; make sgxssl_no_mitigation
7474
7575
- name: Perform CodeQL Analysis

Linux/Makefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
2+
# Copyright (C) 2011-2024 Intel Corporation. All rights reserved.
33
#
44
# Redistribution and use in source and binary forms, with or without
55
# modification, are permitted provided that the following conditions
@@ -34,8 +34,13 @@ LINUX_SGX_BUILD ?= 0
3434
EMPTY_SRC = check_lvi_toolset
3535
.PHONY: sgxssl sgxssl_no_mitigation clean install uninstall
3636

37+
ifeq ($(FIPS), 1)
38+
BUILD_TARGET = sgxssl_no_mitigation
39+
else
40+
BUILD_TARGET = sgxssl
41+
endif
3742

38-
all: sgxssl
43+
all: $(BUILD_TARGET)
3944

4045
sgxssl:
4146
@rm -rf $(EMPTY_SRC).* && touch $(EMPTY_SRC).cpp
@@ -50,17 +55,22 @@ sgxssl:
5055
$(MAKE) -C sgx/
5156

5257
sgxssl_no_mitigation:
53-
$(MAKE) -C sgx/ all
58+
$(MAKE) -C sgx/ all FIPS=$(FIPS)
59+
$(MAKE) -C ../openssl_source/ all
5460

5561
clean:
5662
$(MAKE) -C sgx/ clean
5763
rm -rf $(PACKAGE_LIB)/$(OPENSSL_LIB) $(PACKAGE_INC)/openssl/
5864
rm -rf $(PACKAGE_LIB)/cve_2020_0551_load
5965
rm -rf $(PACKAGE_LIB)/cve_2020_0551_cf
66+
$(MAKE) -C ../openssl_source/ clean
6067

6168
test:
6269
$(MAKE) -C sgx/ test
6370

71+
fips_test:
72+
$(MAKE) -C sgx/ fips_test
73+
6474
install: $(PACKAGE_LIB)/$(TRUSTED_LIB) $(PACKAGE_LIB)/$(UNTRUSTED_LIB) $(PACKAGE_LIB)/$(OPENSSL_LIB)
6575
ifeq ($(DEBUG), 1)
6676
@echo "WARNING: Installing Debug libraries."
@@ -69,6 +79,8 @@ endif
6979
mkdir -p $(DESTDIR)/include/
7080
cp -prf $(PACKAGE_LIB)/* $(DESTDIR)/lib64/
7181
cp -prf $(PACKAGE_INC)/* $(DESTDIR)/include/
82+
$(MAKE) -C ../openssl_source/ install
7283

7384
uninstall:
7485
rm -rf $(DESTDIR)/
86+
$(MAKE) -C ../openssl_source/ uninstall

Linux/build_openssl.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/bin/bash
2-
32
#
4-
# Copyright (C) 2011-2020 Intel Corporation. All rights reserved.
3+
# Copyright (C) 2011-2024 Intel Corporation. All rights reserved.
54
#
65
# Redistribution and use in source and binary forms, with or without
76
# modification, are permitted provided that the following conditions
@@ -37,7 +36,7 @@
3736
SGXSSL_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3837
echo $SGXSSL_ROOT
3938

40-
OPENSSL_VERSION=`ls $SGXSSL_ROOT/../openssl_source/*3.0.*.tar.gz | head -1 | grep -o '[^/]*$' | sed -s -- 's/\.tar\.gz//'`
39+
OPENSSL_VERSION=`ls $SGXSSL_ROOT/../openssl_source/*3.1.*.tar.gz | head -1 | grep -o '[^/]*$' | sed -s -- 's/\.tar\.gz//'`
4140
if [ "$OPENSSL_VERSION" == "" ]
4241
then
4342
echo "In order to run this script, OpenSSL tar.gz package must be located in openssl_source/ directory."
@@ -53,7 +52,7 @@ mkdir -p $SGXSSL_ROOT/package/lib64/
5352
# build openssl modules, clean previous openssl dir if it exist
5453
cd $SGXSSL_ROOT/../openssl_source || exit 1
5554
rm -rf $OPENSSL_VERSION
56-
tar xvf $OPENSSL_VERSION.tar.gz || exit 1
55+
tar xvf $OPENSSL_VERSION.tar.gz > /dev/null || exit 1
5756

5857
# Remove AESBS to support only AESNI and VPAES
5958
sed -i '/BSAES_ASM/d' $OPENSSL_VERSION/Configure
@@ -80,6 +79,13 @@ if [[ "$*" == *"only3x"* ]] ; then
8079
ADDITIONAL_CONF+="--api=3.0 no-deprecated "
8180
fi
8281

82+
if [[ "$*" == *"fips"* ]] ; then
83+
ADDITIONAL_CONF+="-DSGXSSL_FIPS "
84+
cp bss_file.c $OPENSSL_VERSION/crypto/bio/ || exit 1
85+
cp conf_mod.c $OPENSSL_VERSION/crypto/conf/ || exit 1
86+
cp o_fopen.c $OPENSSL_VERSION/crypto/ || exit 1
87+
fi
88+
8389
# Mitigation flags
8490
MITIGATION_OPT=""
8591
MITIGATION_FLAGS=""
@@ -139,7 +145,7 @@ cp sgx_config.conf $OPENSSL_VERSION/ || exit 1
139145
cp x86_64-xlate.pl $OPENSSL_VERSION/crypto/perlasm/ || exit 1
140146

141147
cd $SGXSSL_ROOT/../openssl_source/$OPENSSL_VERSION || exit 1
142-
perl Configure --config=sgx_config.conf sgx-linux-x86_64 --with-rand-seed=none $ADDITIONAL_CONF $SPACE_OPT $MITIGATION_FLAGS no-idea no-mdc2 no-rc5 no-rc4 no-bf no-ec2m no-camellia no-cast no-srp no-async no-padlockeng no-dso no-shared no-ssl3 no-md2 no-md4 no-ui-console no-stdio no-afalgeng -D_FORTIFY_SOURCE=2 -DGETPID_IS_MEANINGLESS -include$SGXSSL_ROOT/../openssl_source/bypass_to_sgxssl.h || exit 1
148+
perl Configure --config=sgx_config.conf sgx-linux-x86_64 --with-rand-seed=none $ADDITIONAL_CONF $SPACE_OPT $MITIGATION_FLAGS no-idea no-mdc2 no-rc5 no-rc4 no-bf no-ec2m no-camellia no-cast no-srp no-async no-padlockeng no-dso no-shared no-ssl3 no-md2 no-md4 no-ui-console no-stdio no-afalgeng -D_FORTIFY_SOURCE=2 -DGETPID_IS_MEANINGLESS -DOPENSSL_NO_POSIX_IO -include$SGXSSL_ROOT/../openssl_source/bypass_to_sgxssl.h || exit 1
143149

144150
sed -i 's/ENGINE_set_default_RAND/dummy_ENGINE_set_default_RAND/' crypto/engine/tb_rand.c || exit 1
145151
sed -i 's/return RUN_ONCE(&locale_base, ossl_init_locale_base);/return 1;/' crypto/ctype.c || exit 1
@@ -166,4 +172,6 @@ cp include/openssl/* $SGXSSL_ROOT/package/include/openssl/ || exit 1
166172
grep OPENSSL_VERSION_STR include/openssl/opensslv.h > $SGXSSL_ROOT/sgx/osslverstr.h || exit 1
167173
cp -r include/crypto $SGXSSL_ROOT/sgx/test_app/enclave/ || exit 1
168174
cp -r include/internal $SGXSSL_ROOT/sgx/test_app/enclave/ || exit 1
175+
cp -r include/crypto $SGXSSL_ROOT/sgx/fips_test/trusted/ || exit 1
176+
cp -r include/internal $SGXSSL_ROOT/sgx/fips_test/trusted/ || exit 1
169177
exit 0
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (C) 2011-2024 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+
/* sgxssl_file.edl - with declarations. */
33+
34+
enclave {
35+
36+
untrusted {
37+
uint64_t* u_sgxssl_fopen([in, string]const char* filename, [in, string]const char* mode);
38+
char* u_sgxssl_fgets([out, size=size]char* buffer, uint32_t size, [user_check]uint64_t* stream);
39+
void u_sgxssl_fclose([user_check]uint64_t* stream);
40+
uint32_t u_sgxssl_fread([out, size=size, count=nmemb] void *ptr, uint32_t size, uint32_t nmemb, [user_check] uint64_t* stream);
41+
int u_sgxssl_ferror([user_check]uint64_t* stream);
42+
int u_sgxssl_getpid(void);
43+
};
44+
45+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (C) 2011-2024 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+
/* sgxssl_file.edl - with empty declarations. */
33+
34+
enclave {
35+
36+
};

Linux/package/include/sgx_tsgxssl.edl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
2+
* Copyright (C) 2011-2024 Intel Corporation. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -34,7 +34,8 @@
3434
enclave {
3535

3636
from "sgx_tstdc.edl" import *;
37-
37+
from "sgxssl_file.edl" import *;
38+
3839
untrusted {
3940
void u_sgxssl_ftime([out, size=timeb_len] void * timeptr, uint32_t timeb_len);
4041
//void u_sgxssl_usleep(int micro_seconds);

Linux/package/include/tsgxsslio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
2+
* Copyright (C) 2011-2024 Intel Corporation. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -32,6 +32,6 @@
3232
#ifndef _TSGXSSL_IO_H_
3333
#define _TSGXSSL_IO_H_
3434

35-
typedef void FILE;
35+
typedef unsigned long FILE;
3636

3737
#endif // _TSGXSSL_IO_H_

Linux/sgx/Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
2+
# Copyright (C) 2011-2024 Intel Corporation. All rights reserved.
33
#
44
# Redistribution and use in source and binary forms, with or without
55
# modification, are permitted provided that the following conditions
@@ -53,17 +53,26 @@ ifeq ($(OSSL3ONLY), 1)
5353
OPENSSL_CONFIG += only3x
5454
endif
5555

56+
ifeq ($(FIPS), 1)
57+
OPENSSL_CONFIG += fips
58+
endif
59+
5660
all: $(PACKAGE_LIB)/$(OPENSSL_LIB)
5761
ifneq ($(CRYPTO_ONLY), 1)
5862
$(MAKE) -C $(TRUSTED_LIB_DIR) all
5963
$(MAKE) -C $(UNTRUSTED_LIB_DIR) all
6064

6165
ifeq ($(LINUX_SGX_BUILD), 0)
6266
ifneq ($(NO_THREADS), 1)
67+
# Don't build the test app by default in FIPS mode since it depends on
68+
# the FIPS provider.
69+
# Execute the install target first.
70+
ifneq ($(FIPS), 1)
6371
$(MAKE) -C $(TEST_DIR) all
6472
endif
6573
endif
6674
endif
75+
endif
6776

6877
ifneq ($(MITIGATION-CVE-2020-0551),)
6978
$(RM) -r $(PACKAGE_LIB)$(MITIGATION_LIB_PATH)/$(TRUSTED_LIB)
@@ -82,8 +91,12 @@ clean:
8291
$(MAKE) -C $(TRUSTED_LIB_DIR) clean
8392
$(MAKE) -C $(UNTRUSTED_LIB_DIR) clean
8493
$(MAKE) -C $(TEST_DIR) clean
94+
$(MAKE) -C $(FIPS_TEST_DIR) clean
8595
rm -f $(PACKAGE_LIB)/$(TRUSTED_LIB) $(PACKAGE_LIB)/$(UNTRUSTED_LIB)
8696

8797
test: $(PACKAGE_LIB)/$(OPENSSL_LIB) all
8898
$(MAKE) -C $(TEST_DIR) test
8999

100+
fips_test: $(PACKAGE_LIB)/$(OPENSSL_LIB) all
101+
$(MAKE) -C $(FIPS_TEST_DIR) run
102+

Linux/sgx/buildenv.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export PACKAGE_INC := $(ROOT_DIR)/../package/include/
5151
export TRUSTED_LIB_DIR := $(ROOT_DIR)/libsgx_tsgxssl/
5252
export UNTRUSTED_LIB_DIR := $(ROOT_DIR)/libsgx_usgxssl/
5353
export TEST_DIR := $(ROOT_DIR)/test_app/
54+
export FIPS_TEST_DIR := $(ROOT_DIR)/fips_test/
5455
export OS_ID=0
5556
export LINUX_SGX_BUILD ?= 0
5657
export TRUSTED_LIB := libsgx_tsgxssl.a

0 commit comments

Comments
 (0)