Skip to content

Commit 8998377

Browse files
authored
Make the Makefile more robust
Make the Makefile more robust by adding conditional checks to prevent errors when OpenSSL tarball files or required directories are missing. Ensure that FIPS-related operations only execute when the necessary OpenSSL 3.1 tarball is present and improves the version detection logic --------- Signed-off-by: Juan del Cuvillo <juan.b.del.cuvillo@intel.com>
1 parent 070657f commit 8998377

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

.github/workflows/codeql.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ jobs:
7070
wget https://download.01.org/intel-sgx/sgx-linux/2.26/distro/ubuntu22.04-server/sgx_linux_x64_sdk_2.26.100.0.bin;
7171
chmod +x *.bin; echo yes | ./sgx_linux_x64_sdk_2.*.bin;
7272
wget https://www.openssl.org/source/openssl-3.0.17.tar.gz --directory-prefix=openssl_source/;
73-
wget https://www.openssl.org/source/openssl-3.1.6.tar.gz --directory-prefix=openssl_source/;
7473
source sgxsdk/environment; cd Linux; make sgxssl_no_mitigation
7574
7675
- name: Perform CodeQL Analysis

openssl_source/Makefile

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,19 @@ FIPSMODULE:=fips.so
3737
FIPSMODULECONF:=fipsmodule.cnf
3838
LIBDIR := lib64
3939

40-
OPENSSL_VERSION := $(shell ls *3.1.*.tar.gz | head -1 | grep -o '[^/]*$$' | sed -s -- 's/\.tar\.gz//')
41-
OSSL_FIPS_SOURCE_DIR := $(CURDIR)/$(OPENSSL_VERSION)-source-fips
42-
OSSL_FIPS_INSTALL_DIR := $(CURDIR)/$(OPENSSL_VERSION)-install-fips
43-
OSSL_FIPS_BUILD_DIR := $(CURDIR)/$(OPENSSL_VERSION)-build-fips
40+
OPENSSL_VERSION := $(shell ls *3.1.*.tar.gz 2>/dev/null | sort -V | tail -1 | sed -s -- 's/\.tar\.gz$$//')
41+
ifeq ($(OPENSSL_VERSION),)
42+
$(info No matching OpenSSL 3.1 tarball found for FIPS provider support.)
43+
else
44+
$(info Found OpenSSL version $(OPENSSL_VERSION) for FIPS provider support.)
45+
OSSL_FIPS_SOURCE_DIR := $(CURDIR)/$(OPENSSL_VERSION)-source-fips
46+
OSSL_FIPS_BUILD_DIR := $(CURDIR)/$(OPENSSL_VERSION)-build-fips
47+
OSSL_FIPS_INSTALL_DIR := $(CURDIR)/$(OPENSSL_VERSION)-install-fips
48+
OSSL_FIPS_SOURCE_DIR_SET = $(shell test -d $(OSSL_FIPS_SOURCE_DIR) && echo 1 || echo 0)
49+
OSSL_FIPS_BUILD_DIR_SET = $(shell test -d $(OSSL_FIPS_BUILD_DIR) && echo 1 || echo 0)
50+
OSSL_FIPS_INSTALL_DIR_SET = $(shell test -d $(OSSL_FIPS_INSTALL_DIR) && echo 1 || echo 0)
51+
endif
4452

45-
OSSL_FIPS_BUILD_DIR_SET := $(shell test -d $(OSSL_FIPS_BUILD_DIR) && echo 1 || echo 0)
46-
OSSL_FIPS_INSTALL_DIR_SET := $(shell test -d $(OSSL_FIPS_INSTALL_DIR) && echo 1 || echo 0)
4753

4854
BUILD_TARGET = fips
4955

@@ -55,6 +61,7 @@ fips:
5561
@echo OSSL_FIPS_SOURCE_DIR is $(OSSL_FIPS_SOURCE_DIR)
5662
@echo OSSL_FIPS_INSTALL_DIR is $(OSSL_FIPS_INSTALL_DIR)
5763
@echo OSSL_FIPS_BUILD_DIR is $(OSSL_FIPS_BUILD_DIR)
64+
ifneq ($(OPENSSL_VERSION),)
5865
rm -rf $(OSSL_FIPS_SOURCE_DIR)/
5966
rm -rf $(OSSL_FIPS_INSTALL_DIR)/
6067
rm -rf $(OSSL_FIPS_BUILD_DIR)/
@@ -64,6 +71,7 @@ fips:
6471
tar xvf $(OPENSSL_VERSION).tar.gz -C $(OSSL_FIPS_SOURCE_DIR) --strip-components=1 > /dev/null
6572
cd $(OSSL_FIPS_BUILD_DIR) && $(OSSL_FIPS_SOURCE_DIR)/Configure enable-fips --with-rand-seed=rdcpu --prefix=$(OSSL_FIPS_INSTALL_DIR) && \
6673
$(MAKE) -j$(shell getconf _NPROCESSORS_ONLN) && $(MAKE) install_fips
74+
endif
6775

6876
# Install the FIPS provider and its configuration file in the SGX SDK location
6977
install:
@@ -83,13 +91,15 @@ endif
8391

8492
# Remove the FIPS provider and configuration file from the SGX SDK location
8593
uninstall:
94+
ifeq ($(OSSL_FIPS_INSTALL_DIR_SET), 1)
8695
@echo "*** Uninstalling FIPS module"
8796
@echo "uninstall $(SGX_SDK)/$(LIBDIR)/$(FIPSMODULE)"
8897
rm -f $(SGX_SDK)/$(LIBDIR)/$(FIPSMODULE)
8998

9099
@echo "*** Uninstalling FIPS module configuration"
91100
@echo "uninstall $(SGX_SDK)/$(LIBDIR)/$(FIPSMODULECONF)"
92101
rm -f $(SGX_SDK)/$(LIBDIR)/$(FIPSMODULECONF)
102+
endif
93103

94104
clean:
95105
ifeq ($(OSSL_FIPS_BUILD_DIR_SET), 1)
@@ -98,8 +108,10 @@ ifeq ($(OSSL_FIPS_BUILD_DIR_SET), 1)
98108
endif
99109

100110
clean_dirs:
111+
ifeq ($(OSSL_FIPS_SOURCE_DIR_SET), 1)
101112
@rm -rf $(OSSL_FIPS_SOURCE_DIR)/
102113
@rm -rf $(OSSL_FIPS_INSTALL_DIR)/
103114
@rm -rf $(OSSL_FIPS_BUILD_DIR)/
115+
endif
104116

105117
clean_all: clean clean_dirs

0 commit comments

Comments
 (0)