Skip to contentSkip to conversation

selftests/x86: sgxsign: Do not query RSA password

PATCH Superseded Jarkko Sakkinen 1 participant 2 messages Aug 29, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 selftests/x86: sgxsign: Do not query RSA password

Pass NULL as the value for @cb in PEM_read_RSAPrivateKey() and remove pem_password_cb(). According to the man page [1], when both @cb and @u are NULL, a default callback provided by OpenSSL will be used to query the password. Since our key is not sealed, this is dead functionality.

Cc Sean Christopherson <[email protected]>
---
 tools/testing/selftests/x86/sgx/sgxsign.c | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)
tools/testing/selftests/x86/sgx/sgxsign.c +1 -16
index 0b89823fc703..3d9007af40c9 100644
@@ -20,8 +20,6 @@ struct sgx_sigstruct_payload {
 	struct sgx_sigstruct_body body;
 };
 
-static const char *sign_key_pass;
-
 static bool check_crypto_errors(void)
 {
 	int err;
@@ -50,18 +48,6 @@ static void exit_usage(const char *program)
 	exit(1);
 }
 
-static int pem_passwd_cb(char *buf, int size, int rwflag, void *u)
-{
-	if (!sign_key_pass)
-		return -1;
-
-	strncpy(buf, sign_key_pass, size);
-	/* no retry */
-	sign_key_pass = NULL;
-
-	return strlen(buf) >= size ? size - 1 : strlen(buf);
-}
-
 static inline const BIGNUM *get_modulus(RSA *key)
 {
 #if OPENSSL_VERSION_NUMBER < 0x10100000L
@@ -85,7 +71,7 @@ static RSA *load_sign_key(const char *path)
 		return NULL;
 	}
 	key = RSA_new();
-	if (!PEM_read_RSAPrivateKey(f, &key, pem_passwd_cb, NULL))
+	if (!PEM_read_RSAPrivateKey(f, &key, NULL, NULL))
 		return NULL;
 	fclose(f);
 
@@ -455,7 +441,6 @@ int main(int argc, char **argv)
 #endif
 	ss.body.xfrm = 3,
 
-	sign_key_pass = getenv("KBUILD_SGX_SIGN_PIN");
 	program = argv[0];
 
 	do {
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/2 selftests/x86/sgx: Read encl.bin and encl.ss from the file system

Do not link encl.bin and encl.ss to the test application binary. Linking data files directly to the ELF are legacy from in-kernel LE implementation.

Cc Sean Christopherson <[email protected]>
---
 tools/testing/selftests/x86/sgx/Makefile     |  14 +--
 tools/testing/selftests/x86/sgx/encl_piggy.S |  19 ----
 tools/testing/selftests/x86/sgx/main.c       | 101 +++++++++++++++----
 3 files changed, 88 insertions(+), 46 deletions(-)
 delete mode 100644 tools/testing/selftests/x86/sgx/encl_piggy.S
tools/testing/selftests/x86/sgx/Makefile +4 -10
index 4310a5b6ecc7..44805ed43413 100644
@@ -10,11 +10,11 @@ HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC -z noexecstack
 ENCL_CFLAGS := -Wall -Werror -static -nostdlib -nostartfiles -fPIC \
 	       -fno-stack-protector -mrdrnd $(INCLUDES)
 
-TEST_CUSTOM_PROGS := $(OUTPUT)/test_sgx
+TEST_CUSTOM_PROGS := $(OUTPUT)/test_sgx $(OUTPUT)/encl.bin
+
 all: $(TEST_CUSTOM_PROGS)
 
-$(TEST_CUSTOM_PROGS): $(OUTPUT)/main.o $(OUTPUT)/sgx_call.o \
-		      $(OUTPUT)/encl_piggy.o
+$(OUTPUT)/test_sgx: $(OUTPUT)/main.o $(OUTPUT)/sgx_call.o
 	$(CC) $(HOST_CFLAGS) -o $@ $^
 
 $(OUTPUT)/main.o: main.c
@@ -23,24 +23,18 @@ $(OUTPUT)/main.o: main.c
 $(OUTPUT)/sgx_call.o: sgx_call.S
 	$(CC) $(HOST_CFLAGS) -c $< -o $@
 
-$(OUTPUT)/encl_piggy.o: $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss
-	$(CC) $(HOST_CFLAGS) -I$(OUTPUT) -c encl_piggy.S -o $@
-
 $(OUTPUT)/encl.bin: $(OUTPUT)/encl.elf $(OUTPUT)/sgxsign
 	$(OBJCOPY) -O binary $< $@
+	$(OUTPUT)/sgxsign signing_key.pem $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss
 
 $(OUTPUT)/encl.elf: encl.lds encl.c encl_bootstrap.S
 	$(CC) $(ENCL_CFLAGS) -T $^ -o $@
 
-$(OUTPUT)/encl.ss: $(OUTPUT)/encl.bin  $(OUTPUT)/sgxsign
-	$(OUTPUT)/sgxsign signing_key.pem $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss
-
 $(OUTPUT)/sgxsign: sgxsign.c
 	$(CC) -o $@ $< -lcrypto
 
 EXTRA_CLEAN := \
 	$(OUTPUT)/encl.bin \
-	$(OUTPUT)/encl_piggy.o \
 	$(OUTPUT)/encl.elf \
 	$(OUTPUT)/encl.ss \
 	$(OUTPUT)/sgx_call.o \
tools/testing/selftests/x86/sgx/encl_piggy.S deleted +0 -19
deleted file mode 100644
index a7f6447abbba..000000000000
@@ -1,19 +0,0 @@
-/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
-/*
- * Copyright(c) 2016-18 Intel Corporation.
- */
-
-	.section ".rodata", "a"
-	.balign 4096
-
-encl_bin:
-	.globl encl_bin
-	.incbin	"encl.bin"
-encl_bin_end:
-	.globl encl_bin_end
-
-encl_ss:
-	.globl encl_ss
-	.incbin	"encl.ss"
-encl_ss_end:
-	.globl encl_ss_end
tools/testing/selftests/x86/sgx/main.c +84 -17

151 lines not on this page · raw message

Signature · 1 line
2.20.1