Topic: Compilation fails when code is placed in a SGX enclave (unknown types)

Hello,

My code to validate a certificate chain and a signature does not compile when inside an enclave. I'm using v5.8.2-stable. Compilation throws errors:

/home/daniel/res/gitsaves/wolfssl/wolfssl/wolfcrypt/random.h:197:5: error: unknown type name ‘pid_t’
  197 |     pid_t pid;
      |     ^~~~~
In file included from /home/daniel/res/gitsaves/wolfssl/wolfssl/ssl.h:262:
/home/daniel/res/gitsaves/wolfssl/wolfssl/wolfio.h:529:5: error: unknown type name ‘SOCKADDR’
  529 |     SOCKADDR sa;
      |     ^~~~~~~~
/home/daniel/res/gitsaves/wolfssl/wolfssl/wolfio.h:530:5: error: unknown type name ‘SOCKADDR_IN’
  530 |     SOCKADDR_IN sa_in;
      |     ^~~~~~~~~~~

(The code works outside the enclave, though, with normal wolfSSL.)

I've placed the code in a github repository:
https://github.com/andrade/iamstuck/tre … verify-sgx

Could I get some pointers on how to fix this?

Regards,
Daniel

Post's attachments

Screenshot from 2025-09-25 14-24-39 (pid_t and SOCKADDR errors when compiling 2509-wolfssl-chain-verify-sgx 5.8.2).png 510.19 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

Share

Re: Compilation fails when code is placed in a SGX enclave (unknown types)

Hi,
My name is Anthony and I am a member of the wolfSSL team.
Do you need to include an options.h file or a user_settings.h file?

Can you tell  us a bit more about your project?  What are your goals?

Warm regards, Anthony

Share

3 (edited by andrade 2025-09-29 04:56:16)

Re: Compilation fails when code is placed in a SGX enclave (unknown types)

Hello,

I'm working on an academic research project with trusted execution environments, one of which is Intel SGX. This bit of code I'm working on is part of the attestation process. A client receives an attestation report as part of our protocol, and the client needs to validate the attestation report. This includes: 1) ensuring the certificate chain is valid, 2) ensuring the root key is known to the client, and 3) verifying the sender's signature over the attestation report (compute hash of report and then check signature).

The code I'm having trouble with validates de chain (1) and verifies the signature over the attestation report (3). Since it's working outside the enclave, in TEE terminology in the untrusted domain (i.e., the normal code), I suspect this could be related to how I'm compiling my code and how I'm compiling the wolfSSL library for use in SGX enclaves.

In addition to the unknown types errors in my previous post, several of the wolfSSL functions don't seem to be available in the SGX version of the library (below only the function wc_CertPemToDer is defined, the other functions that I use in my code are missing):

$ nm src/.libs/libwolfssl.a | grep -P "wc_CertPemToDer|wolfSSL_X509_load_certificate_buffer|wolfSSL_X509_STORE_new|wolfSSL_sk_X509_new_null"
000000000001ce7f T wc_CertPemToDer
000000000008dca4 T wolfSSL_sk_X509_new_null
000000000007d4c7 T wolfSSL_X509_load_certificate_buffer
0000000000095e3c T wolfSSL_X509_STORE_new

$ nm src/.libs/libwolfssl.so | grep -P "wc_CertPemToDer|wolfSSL_X509_load_certificate_buffer|wolfSSL_X509_STORE_new|wolfSSL_sk_X509_new_null"
0000000000181f81 T wc_CertPemToDer
0000000000318bc1 T wolfSSL_sk_X509_new_null
00000000003083db T wolfSSL_X509_load_certificate_buffer
0000000000320d59 T wolfSSL_X509_STORE_new

$ nm IDE/LINUX-SGX/libwolfssl.sgx.static.lib.a | grep -P "wc_CertPemToDer|wolfSSL_X509_load_certificate_buffer|wolfSSL_X509_STORE_new|wolfSSL_sk_X509_new_null"
000000000000a620 T wc_CertPemToDer

I don't know whether I need to include options.h or user_settings.h. (I'm new to wolfSSL so I'm not sure I need it.) This is for a proof-of-concept on a desktop machine, I don't have any constraints in terms of library size, for example, so I don't mind having a larger library. I compiled it with `--enable-static --enable-all --enable-debug`.

Regards,
Daniel

Share

Re: Compilation fails when code is placed in a SGX enclave (unknown types)

Hi Daniel,

Start with the wolfSSL SGX examples, and modify them to your use case. This is where the instructions and example build of the wolfSSL library for SGX use is https://github.com/wolfSSL/wolfssl/tree … /LINUX-SGX

The example of using the built library is located here
https://github.com/wolfSSL/wolfssl-exam … /SGX_Linux

Share

5 (edited by andrade 2025-09-29 10:11:44)

Re: Compilation fails when code is placed in a SGX enclave (unknown types)

Hello Jacob,

I've already built the library and run the official example successfully. But there are functions that are defined in libwolfssl.a/so but are undefined in libwolfssl.sgx.static.lib.a.

Below I've added the steps I've done compiling the official library and running the official SGX example to show more clearly what is the problem. (This is for branch v5.8.2-stable but I've tried branch master and the results are the same.)

---

1. First cloned and compiled wolfSSL (OK):

$ git clone git@github.com:wolfSSL/wolfssl.git
$ cd wolfssl
$ git checkout v5.8.2-stable
$ ./autogen.sh
$ ./configure --enable-static --enable-all --enable-debug
$ make

$ cd IDE/LINUX-SGX/
$ ls -l ../../wolfssl/options.h   (check file is there)
-rw-rw---- 1 daniel daniel 16129 set 29 16:55 ../../wolfssl/options.h
$ make -f sgx_t_static.mk all
(...)
LINK =>  libwolfssl.sgx.static.lib.a

2.1. Then cloned and compiled the official example (Fails out of the box):

$ git clone git@github.com:wolfSSL/wolfssl-examples.git
$ cd wolfssl-examples/SGX_Linux/
$ export WOLFSSL_ROOT=../../wolfssl
$ make SGX_MODE=SIM SGX_PRERELEASE=0 SGX_WOLFSSL_LIB=../../wolfssl/IDE/LINUX-SGX/ WOLFSSL_ROOT=../../wolfssl SGX_DEBUG=0 HAVE_WOLFSSL_TEST=0 HAVE_WOLFSSL_BENCHMARK=0 all
(...)
/usr/bin/ld: cannot find -lsgx_tstdcxx: No such file or directory
collect2: error: ld returned 1 exit status
(...)

2.2 The error is because of `-lsgx_tstdcxx`, there's an open bug report on this (https://github.com/wolfSSL/wolfssl-examples/issues/284). I replaced it, in `sgx_t.mk`, with `-lsgx_tcxx` and compiled the official example again (OK):

$ make clean
$ make SGX_MODE=SIM SGX_PRERELEASE=0 SGX_WOLFSSL_LIB=../../wolfssl/IDE/LINUX-SGX/ WOLFSSL_ROOT=../../wolfssl SGX_DEBUG=0 HAVE_WOLFSSL_TEST=0 HAVE_WOLFSSL_BENCHMARK=0 all
(...)
Succeed.
SIGN =>  Wolfssl_Enclave.signed.so

2.3. I run the server-client example successfully (OK).

3. To check whether the missing definitions is a problem with my code or with the wolfSSL official library, I've added a function needed to load a certificate to the official example. The line isn't meant to do anything, only check whether the definition is in the wolfSSL library `libwolfssl.sgx.static.lib.a` (it isn't). (I've added a screenshot with `$ git diff` to show the changes.)

I've added the line wolfSSL_X509_load_certificate_buffer(NULL, 0, 1); (Line 164) to the function enc_wolfSSL_Init in enclave file trusted/Wolfssl_Enclave.c. Then compile (Fails):

$ make clean
$ make SGX_MODE=SIM SGX_PRERELEASE=0 SGX_WOLFSSL_LIB=../../wolfssl/IDE/LINUX-SGX/ WOLFSSL_ROOT=../../wolfssl SGX_DEBUG=0 HAVE_WOLFSSL_TEST=0 HAVE_WOLFSSL_BENCHMARK=0 all
(...)
/usr/bin/ld: trusted/Wolfssl_Enclave.o: in function `enc_wolfSSL_Init':
Wolfssl_Enclave.c:(.text+0x54): undefined reference to `wolfSSL_X509_load_certificate_buffer'
collect2: error: ld returned 1 exit status
make[1]: *** [sgx_t.mk:147: Wolfssl_Enclave.so] Error 1

As seen from the error, wolfSSL_X509_load_certificate_buffer is missing from the official wolfSSL SGX library itself. This undefined reference isn't an issue with my code. (My previous post has nm output.)

---

This (wolfSSL_X509_load_certificate_buffer) is one of several functions (that I'm using in my code) missing from libwolfssl.sgx.static.lib.a. But these functions do appear in libwolfssl.a and libwolfssl.so.

Question: How can I compile wolfSSL SGX in such a way wolfSSL_X509_load_certificate_buffer is defined in libwolfssl.sgx.static.lib.a so that I can use it in an enclave?

---

The list of wolfSSL functions I'm using in my code but are undefined in libwolfssl.sgx.static.lib.a is:

```
undefined reference to `wolfSSL_X509_load_certificate_buffer'
undefined reference to `wolfSSL_X509_STORE_new'
undefined reference to `wolfSSL_X509_STORE_add_cert'
undefined reference to `wolfSSL_X509_load_certificate_buffer'
undefined reference to `wolfSSL_sk_X509_new_null'
undefined reference to `wolfSSL_sk_X509_push'
undefined reference to `wolfSSL_X509_load_certificate_buffer'
undefined reference to `wolfSSL_X509_STORE_CTX_new'
undefined reference to `wolfSSL_X509_STORE_CTX_init'
undefined reference to `wolfSSL_X509_verify_cert'
undefined reference to `wolfSSL_X509_STORE_free'
undefined reference to `wolfSSL_X509_free'
undefined reference to `wolfSSL_X509_free'
undefined reference to `wolfSSL_X509_free'
undefined reference to `wolfSSL_sk_X509_free'
```

Post's attachments

Screenshot from 2025-09-29 17-45-42 wolfssl official SGX example diff with fix and test check load cert function for definition.png 374.05 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

Share

Re: Compilation fails when code is placed in a SGX enclave (unknown types)

Hi Daniel,

The macro OPENSSL_EXTRA will need to be defined for wolfSSL to be built with the *_X509_* API. This is API in the compatibility layer which eases integration into applications previously using OpenSSL. Once at the point you are at, with the examples compiling and running, you can then adjust which macros are defined for configuring how wolfSSL is built. For example in the example IDE/LINUX-SGX/sgx_t_static.mk file there is the Wolfssl_C_Extra_Flags variable that OPENSSL_EXTRA could be added to. Note that this macro define should be added to both the building of libwolfssl and to the compiling of the application.

We've not tested with the additional functions built with SGX, there might be system calls in the compatibility layer that need worked around for running smoothly with SGX.

Here are some non SGX examples that do not use the compatibility layer API that could be referenced (https://github.com/wolfSSL/wolfssl-exam … er/certvfy).

These are also examples that show using a CA to verify a signature without using the compatibility layer API (https://github.com/wolfSSL/wolfssl-exam … ertmanager).

Share