Skip to content

Commit c5bcf92

Browse files
committed
Split FIPS test into smaller functions and have the application call
several of the consecutively. Signed-off-by: Juan del Cuvillo <[email protected]>
1 parent 366b098 commit c5bcf92

File tree

3 files changed

+83
-19
lines changed

3 files changed

+83
-19
lines changed

Linux/sgx/fips_test/trusted/enclave.cpp

+45-16
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,22 @@ void print_OSSL_errors(void)
8686
}
8787
}
8888

89-
/* Enclave ECALL */
89+
OSSL_PROVIDER *g_prov = NULL;
90+
91+
/* Enclave ECALLs */
9092
int enclave_fips_test()
93+
{
94+
enclave_fips_provider_load();
95+
enclave_fips_provider_test();
96+
enclave_fips_provider_unload();
97+
98+
return 0;
99+
}
100+
101+
int enclave_fips_provider_load(void)
91102
{
92103
int ret = -1;
93104
void *entry = NULL;
94-
OSSL_PROVIDER *prov = NULL;
95105

96106
printf(ANSI_COLOR_YELLOW "%s started\n" ANSI_COLOR_RESET, __FUNCTION__);
97107

@@ -120,20 +130,20 @@ int enclave_fips_test()
120130
PRINT_PASS("FIPS provider added to the OSSL_PROVIDER store\n");
121131
}
122132

123-
/* Check if the "fips" provider is available */
124-
if (1 == OSSL_PROVIDER_available(NULL, "fips"))
133+
/* Verify the "fips" provider is available before attempting to load it */
134+
if (0 == OSSL_PROVIDER_available(NULL, "fips"))
125135
{
126-
PRINT_PASS("FIPS provider is available\n");
136+
PRINT_ERROR("FIPS provider is not available\n");
137+
print_OSSL_errors();
127138
}
128139
else
129140
{
130-
PRINT_ERROR("FIPS provider is not available\n");
131-
print_OSSL_errors();
141+
PRINT_PASS("FIPS provider is available\n");
132142
}
133143

134144
/* Load the FIPS provider */
135-
prov = OSSL_PROVIDER_load(NULL, "fips");
136-
if (NULL == prov)
145+
g_prov = OSSL_PROVIDER_load(NULL, "fips");
146+
if (NULL == g_prov)
137147
{
138148
PRINT_ERROR("FIPS provider failed to load\n");
139149
print_OSSL_errors();
@@ -145,8 +155,8 @@ int enclave_fips_test()
145155
}
146156
#else
147157
/* Load the default provider */
148-
prov = OSSL_PROVIDER_load(NULL, "default");
149-
if (NULL == prov)
158+
g_prov = OSSL_PROVIDER_load(NULL, "default");
159+
if (NULL == g_prov)
150160
{
151161
printf("Default provider failed to load\n");
152162
print_OSSL_errors();
@@ -157,17 +167,17 @@ int enclave_fips_test()
157167
printf("Default provider loaded\n");
158168
}
159169
#endif
160-
if (1 == OSSL_PROVIDER_self_test(prov))
170+
if (1 == OSSL_PROVIDER_self_test(g_prov))
161171
{
162172
PRINT_PASS("OSSL_PROVIDER_self_test passed\n");
163-
printf("Provider name: %s\n", OSSL_PROVIDER_get0_name(prov));
173+
printf("Provider name: %s\n", OSSL_PROVIDER_get0_name(g_prov));
164174
const char *build = NULL;
165175
OSSL_PARAM request[] = {
166176
{ "buildinfo", OSSL_PARAM_UTF8_PTR, &build, 0, 0 },
167177
{ NULL, 0, NULL, 0, 0 }
168178
};
169179

170-
OSSL_PROVIDER_get_params(prov, request);
180+
OSSL_PROVIDER_get_params(g_prov, request);
171181
printf("Provider buildinfo: %s\n", build);
172182
}
173183
else
@@ -180,7 +190,19 @@ int enclave_fips_test()
180190
// Initialize SGXSSL crypto
181191
OPENSSL_init_crypto(0, NULL);
182192

183-
/* Perform some crypto tests */
193+
end:
194+
printf(ANSI_COLOR_YELLOW "%s completed\n" ANSI_COLOR_RESET, __FUNCTION__);
195+
196+
return 0;
197+
}
198+
199+
/*
200+
* Perform some crypto tests
201+
*/
202+
int enclave_fips_provider_test(void)
203+
{
204+
int ret = -1;
205+
184206
ret = aesgcm_test();
185207
if (0 != ret)
186208
{
@@ -206,7 +228,14 @@ int enclave_fips_test()
206228
PRINT_PASS("HMAC test completed\n");
207229

208230
end:
209-
OSSL_PROVIDER_unload(prov);
231+
printf(ANSI_COLOR_YELLOW "%s completed\n" ANSI_COLOR_RESET, __FUNCTION__);
232+
233+
return 0;
234+
}
235+
236+
int enclave_fips_provider_unload(void)
237+
{
238+
OSSL_PROVIDER_unload(g_prov);
210239

211240
printf(ANSI_COLOR_YELLOW "%s completed\n" ANSI_COLOR_RESET, __FUNCTION__);
212241

Linux/sgx/fips_test/trusted/enclave.edl

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ enclave {
4949

5050
trusted {
5151
public int enclave_fips_test();
52+
public int enclave_fips_provider_load();
53+
public int enclave_fips_provider_test();
54+
public int enclave_fips_provider_unload();
5255

5356
};
5457
};

Linux/sgx/fips_test/untrusted/app.cpp

+35-3
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,44 @@ int main(int argc, char *argv[])
268268
return 1;
269269

270270
int ret = -1;
271-
sgx_status_t status = enclave_fips_test(global_eid, &ret);
272-
if (status != SGX_SUCCESS || ret != 0) {
273-
printf("Call to enclave_fips_test failed: 0x%08X, %d.\n", status, ret);
271+
sgx_status_t sgx_ret = SGX_ERROR_UNEXPECTED;
272+
273+
sgx_ret = enclave_fips_test(global_eid, &ret);
274+
if (sgx_ret != SGX_SUCCESS || ret != 0) {
275+
printf("First ECall to enclave_fips_test failed: 0x%08X, %d.\n", sgx_ret, ret);
276+
return 1; //Test failed
277+
}
278+
279+
sgx_ret = enclave_fips_test(global_eid, &ret);
280+
if (sgx_ret != SGX_SUCCESS || ret != 0) {
281+
printf("Second ECall to enclave_fips_test failed: 0x%08X, %d.\n", sgx_ret, ret);
274282
return 1; //Test failed
275283
}
276284

285+
sgx_ret = enclave_fips_provider_load(global_eid, &ret);
286+
if (sgx_ret != SGX_SUCCESS || ret != 0) {
287+
printf("ECall to enclave_fips_provider_load failed: 0x%08X, %d.\n", sgx_ret, ret);
288+
return 1;
289+
}
290+
291+
sgx_ret = enclave_fips_provider_test(global_eid, &ret);
292+
if (sgx_ret != SGX_SUCCESS || ret != 0) {
293+
printf("ECall to enclave_fips_provider_test failed: 0x%08X, %d.\n", sgx_ret, ret);
294+
return 1;
295+
}
296+
297+
sgx_ret = enclave_fips_provider_test(global_eid, &ret);
298+
if (sgx_ret != SGX_SUCCESS || ret != 0) {
299+
printf("ECall to enclave_fips_provider_test failed: 0x%08X, %d.\n", sgx_ret, ret);
300+
return 1;
301+
}
302+
303+
sgx_ret = enclave_fips_provider_unload(global_eid, &ret);
304+
if (sgx_ret != SGX_SUCCESS || ret != 0) {
305+
printf("ECall to enclave_fips_provider_unload failed: 0x%08X, %d.\n", sgx_ret, ret);
306+
return 1;
307+
}
308+
277309
sgx_destroy_enclave(global_eid);
278310

279311
return 0;

0 commit comments

Comments
 (0)