|
| 1 | +# RA-TLS Minimal Example |
| 2 | + |
| 3 | +This directory contains the Makefile, the template server manifest, and the |
| 4 | +minimal server and client written against the mbedTLS library. |
| 5 | + |
| 6 | +The server and client are based on `ssl_server.c` and `ssl_client1.c` example |
| 7 | +programs shipped with mbedTLS. We modified them to allow using RA-TLS flows. In |
| 8 | +particular, the server uses a self-signed RA-TLS cert with the SGX quote |
| 9 | +embedded in it via `ra_tls_create_key_and_crt_der()`. The client uses an RA-TLS |
| 10 | +verification callback to verify the server RA-TLS certificate via |
| 11 | +`ra_tls_verify_callback_der()`. |
| 12 | + |
| 13 | +This example uses the RA-TLS libraries `ra_tls_attest.so` for server and |
| 14 | +`ra_tls_verify_dcap.so` for client. These libraries are installed together with |
| 15 | +Gramine (you need `meson setup ... -Ddcap=enabled`, which is the default). The |
| 16 | +DCAP software infrastructure must be installed and work correctly on the host. |
| 17 | + |
| 18 | +For more documentation about ECDSA (DCAP) remote attestation scheme, refer to |
| 19 | +https://gramine.readthedocs.io/en/stable/attestation.html. |
| 20 | + |
| 21 | +## RA-TLS server |
| 22 | + |
| 23 | +The server is supposed to run in the SGX enclave with Gramine and RA-TLS |
| 24 | +dlopen-loaded. If the server is started not in the SGX enclave, then it falls |
| 25 | +back to using normal X.509 PKI flows. |
| 26 | + |
| 27 | +If server is run with a command-line argument ``--test-malicious-quote``, then |
| 28 | +the server will maliciously modify the SGX quote before sending to the client. |
| 29 | +This is useful for testing purposes. |
| 30 | + |
| 31 | +## RA-TLS client |
| 32 | + |
| 33 | +The client is supposed to run on a trusted machine (*not* in an SGX enclave). |
| 34 | +If RA-TLS library `ra_tls_verify_dcap.so` is not requested by user via `dcap` |
| 35 | +command-line argument respectively, the client falls back to using normal X.509 |
| 36 | +PKI flows (specified as `native` command-line argument). |
| 37 | + |
| 38 | +It is also possible to run the client in an SGX enclave. This will create a |
| 39 | +secure channel between two Gramine SGX processes, possibly running on different |
| 40 | +machines. It can be used as an example of in-enclave remote attestation and |
| 41 | +verification. |
| 42 | + |
| 43 | +If client is run without additional command-line arguments, it uses default |
| 44 | +RA-TLS verification callback that compares `MRENCLAVE`, `MRSIGNER`, |
| 45 | +`ISV_PROD_ID` and `ISV_SVN` against the corresonding `RA_TLS_*` environment |
| 46 | +variables. `MRENCLAVE`, `MRSIGNER` and `ISV_PROD_ID` are expected to match |
| 47 | +`RA_TLS_*` ones. `ISV_SVN` is expected to be equal or greater than `RA_TLS_ISV_SVN`. |
| 48 | +To run the client with its own verification callback, execute it with four |
| 49 | +additional command-line arguments (see the source code for details). |
| 50 | + |
| 51 | +Also, because this example builds and uses debug SGX enclaves (`sgx.debug` is |
| 52 | +set to `true`), we use environment variable `RA_TLS_ALLOW_DEBUG_ENCLAVE_INSECURE=1`. |
| 53 | +Note that in production environments, you must *not* use this option! |
| 54 | + |
| 55 | +Moreover, we set `RA_TLS_ALLOW_OUTDATED_TCB_INSECURE=1`, |
| 56 | +`RA_TLS_ALLOW_HW_CONFIG_NEEDED=1` and `RA_TLS_ALLOW_SW_HARDENING_NEEDED=1` to |
| 57 | +allow performing the tests when some of Intel's security advisories haven't been |
| 58 | +addressed (for example, when the microcode or architectural enclaves aren't |
| 59 | +fully up-to-date). Note that in production environments, you must carefully |
| 60 | +analyze whether to use these options! |
| 61 | + |
| 62 | +## KSS features |
| 63 | +In addition to the existing ra-tls example, this example shows the use of the following four values |
| 64 | +provided by the Key Separation and Sharing (KSS) feature of SGX: |
| 65 | +* ISV Extended Production ID (ISV_EXT_PROD_ID) |
| 66 | +* ISV Family ID (ISV_FAMILY_ID) |
| 67 | +* Config ID (CONFIG_ID) |
| 68 | +* Config SVN (CONFIG_SVN) |
| 69 | + |
| 70 | +The KSS enable, ISV_EXT_PROD_ID and ISV_FAMILY_ID of the server enclave are specified |
| 71 | +in the manifest (`sgx.kss`, `sgx.isvextprodid` and `sgx.isvfamilyid`), |
| 72 | +while the CONFIG_ID and CONFIG_SVN are specified via command line arguments or |
| 73 | +environment variables when executing the `gramine-sgx` command. |
| 74 | + |
| 75 | +These values cannot be used when running under non-SGX conditions. |
| 76 | + |
| 77 | +# Quick Start |
| 78 | + |
| 79 | +In most of the examples below, you need to tell the client what values it should |
| 80 | +expect for `MRENCLAVE`, `MRSIGNER`, `ISV_PROD_ID` and `ISV_SVN`. One way to |
| 81 | +obtain them is to run `gramine-sgx-sigstruct-view server.sig`. |
| 82 | + |
| 83 | +For all examples, we set the following environment variables: |
| 84 | +```sh |
| 85 | +export RA_TLS_ALLOW_DEBUG_ENCLAVE_INSECURE=1 |
| 86 | +export RA_TLS_ALLOW_OUTDATED_TCB_INSECURE=1 |
| 87 | +export RA_TLS_ALLOW_HW_CONFIG_NEEDED=1 |
| 88 | +export RA_TLS_ALLOW_SW_HARDENING_NEEDED=1 |
| 89 | +``` |
| 90 | + |
| 91 | +- Normal non-RA-TLS flows; without SGX and without Gramine: |
| 92 | + |
| 93 | +```sh |
| 94 | +make app |
| 95 | +./server & |
| 96 | +./client native |
| 97 | +# client will successfully connect to the server via normal x.509 PKI flows |
| 98 | +kill %% |
| 99 | +``` |
| 100 | + |
| 101 | +- RA-TLS flows with SGX and with Gramine, ECDSA-based (DCAP) attestation: |
| 102 | + |
| 103 | +```sh |
| 104 | +make clean |
| 105 | +make app dcap |
| 106 | + |
| 107 | +gramine-sgx --config-id=<CONFIG_ID to set to the server enclave> \ |
| 108 | + --config-svn=<CONFIG_SVN to set to the server enclave> \ |
| 109 | + ./server & |
| 110 | + |
| 111 | +RA_TLS_MRENCLAVE=<MRENCLAVE of the server enclave> \ |
| 112 | +RA_TLS_MRSIGNER=<MRSIGNER of the server enclave> \ |
| 113 | +RA_TLS_ISV_PROD_ID=<ISV_PROD_ID of the server enclave> \ |
| 114 | +RA_TLS_ISV_SVN=<ISV_SVN of the server enclave> \ |
| 115 | +RA_TLS_ISV_EXT_PROD_ID=<ISV_EXT_PROD_ID of the server enclave> \ |
| 116 | +RA_TLS_ISV_FAMILY_ID=<ISV_FAMILY_ID of the server enclave> \ |
| 117 | +RA_TLS_CONFIG_ID=<CONFIG_ID of the server enclave> \ |
| 118 | +RA_TLS_CONFIG_SVN=<CONFIG_SVN of the server enclave> \ |
| 119 | +./client dcap |
| 120 | + |
| 121 | +# client will successfully connect to the server via RA-TLS/DCAP flows |
| 122 | +kill %% |
| 123 | +``` |
| 124 | + |
| 125 | +The environment variables SGX_CONFIG_ID and SGX_CONFIG_SVN can also be used to specify |
| 126 | +the Config ID and Config SVN. |
| 127 | +If both command line arguments and environment variables are specified, |
| 128 | +an error is returned if those values do not match. |
| 129 | + |
| 130 | +``` sh |
| 131 | +SGX_CONFIG_ID=<CONFIG_ID to set to the server enclave> \ |
| 132 | +SGX_CONFIG_SVN=<CONFIG_SVN to set to the server enclave> \ |
| 133 | +gramine-sgx ./server |
| 134 | +``` |
| 135 | + |
| 136 | +- RA-TLS flows with SGX and with Gramine, client with its own verification callback: |
| 137 | + |
| 138 | +```sh |
| 139 | +make clean |
| 140 | +make app dcap |
| 141 | + |
| 142 | +gramine-sgx --config-id=<CONFIG_ID to set to the server enclave> \ |
| 143 | + --config-svn=<CONFIG_SVN to set to the server enclave> \ |
| 144 | + ./server & |
| 145 | + |
| 146 | +./client dcap \ |
| 147 | + <MRENCLAVE of the server enclave> \ |
| 148 | + <MRSIGNER of the server enclave> \ |
| 149 | + <ISV_PROD_ID of the server enclave> \ |
| 150 | + <ISV_SVN of the server enclave> \ |
| 151 | + <ISV_EXT_PROD_ID of the server enclave> \ |
| 152 | + <ISV_FAMILY_ID of the server enclave> \ |
| 153 | + <CONFIG_ID of the server enclave> \ |
| 154 | + <CONFIG_SVN of the server enclave> |
| 155 | + |
| 156 | +# client will successfully connect to the server via RA-TLS/DCAP flows |
| 157 | +kill %% |
| 158 | +``` |
| 159 | + |
| 160 | +Note that the Config ID must be specified as a hexadecimal string and the Config SVN as a decimal number. |
| 161 | + |
| 162 | +- RA-TLS flows with SGX and with Gramine, server sends malicious SGX quote: |
| 163 | + |
| 164 | +```sh |
| 165 | +make clean |
| 166 | +make app dcap |
| 167 | + |
| 168 | +gramine-sgx ./server --test-malicious-quote & |
| 169 | +./client dcap |
| 170 | + |
| 171 | +# client will fail to verify the malicious SGX quote and will *not* connect to the server |
| 172 | +kill %% |
| 173 | +``` |
| 174 | + |
| 175 | +- RA-TLS flows with SGX and with Gramine, running DCAP client in SGX: |
| 176 | + |
| 177 | +```sh |
| 178 | +make clean |
| 179 | +make app dcap |
| 180 | + |
| 181 | +gramine-sgx --config-id=<CONFIG_ID to set to the server enclave> \ |
| 182 | + --config-svn=<CONFIG_SVN to set to the server enclave> \ |
| 183 | + ./server & |
| 184 | + |
| 185 | +gramine-sgx ./client_dcap dcap \ |
| 186 | + <MRENCLAVE of the server enclave> \ |
| 187 | + <MRSIGNER of the server enclave> \ |
| 188 | + <ISV_PROD_ID of the server enclave> \ |
| 189 | + <ISV_SVN of the server enclave> \ |
| 190 | + <ISV_EXT_PROD_ID of the server enclave> \ |
| 191 | + <ISV_FAMILY_ID of the server enclave> \ |
| 192 | + <CONFIG_ID of the server enclave> \ |
| 193 | + <CONFIG_SVN of the server enclave> |
| 194 | + |
| 195 | +# client will successfully connect to the server via RA-TLS/DCAP flows |
| 196 | +kill %% |
| 197 | +``` |
0 commit comments