Build a RUST Server/Client EDP Application Using Confidential Computing Manager Issued Certificates and Trusted CA

Overview

This example shows how certificates can be used for authenticating other parties.

In em-app/examples/ there are 2 folders: 

  • server - holds an example that listens on a hardcoded address.
  • client - holds an example that connects to the hardcoded address.

Both applications use a hardcoded certificate authority public key for peer verifications. This is obtained through the './register_and_run.sh' script from the account where they are added. This can be done manually as well.

The register_and_run.sh script above is only meant as an example and the script automates the following steps:

  • Building the SGX application
  • Registering the EDP application with Fortanix Confidential Computing Manager (CCM), and
  • Running the EDP application

To do the above steps manually, refer to the article Bringing EDP RUST Apps to Fortanix Confidential Computing Manager.

Example for Good Weather Usage

Server-side operations

  • Update ./config file in https://github.com/fortanix/rust-sgx/tree/master/em-app/examples/server folder with credentials, the desired account, and application names.
  • Run ./register_and_run.sh' script which automates the steps for building the SGX application/Registering the EDP application with Fortanix CCM, and Running the EDP application.
  • Logs:
    em-app/examples/server$ ./register_and_run.sh ./config
    Logged in
    export token=Q3SxmoKzaq8sW6vl6HoDL4Qs2xNxSdotwFobt2LRSxeyjaP-AB0Lh5UfJ0UcZ0KSX9dGZOlDvgo-3mPPKVcQuQ
    export em_url=https://localhost:9090
    Account selected
    Building application.
    Compiling get-certificate v0.1.0 (/home/acruceru/work/rust-sgx-patch/em-app/examples/server)
    Finished dev [unoptimized + debuginfo] target(s) in 0.35s
    Signing application.
    Application configuration finished.
    Domain whitelisting finished.
    Build configuration finished
    Build whitelist result: SUCCESS
    Build whitelisting finished
    Application: obtained signed certificate from EM: {
    "task_id": "807ec66f-4c03-41e5-a374-15786a7812ef",
    "task_status": "SUCCESS",
    "certificate": "-----BEGIN CERTIFICATE-----\nMIIEljCCAv6gAwIBAgIUc4vW9ugcTYTEeq7+fAmpmuDICFQwDQYJKoZIhvcNAQEL\nBQAwgZIxNTAzBgsrBgEEAYOEGgEDAQwkZGFhMTJjNDctMGRhNy00OGU5LTlhMjUt\nOTUzMjc3NGI4N2Q4MTUwMwYLKwYBBAGDhBoBAwIMJGRjYjNj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eBcmIa/08SwD\nrLdlJ5ZOUqzyUlPFaAxeaHTi8D0U/8mSGtsZXMHSYNkxWgJh7kn4G77Okii6mM72\nXqMMf0xfyNjAAKi8+HmMvzGgKgAfKmiXiERxl27spZ7KIhC0QW9EHo4E3jZh1nFr\ncMR8UyFw0IWf9xzgbkvL2Tl6kdq2FJc6X4usIl3mtz4o0U/4sYIKTckKR1hRsQqB\nKLZFrmjXkMzLBCq1Jwcytgcdoqv6si/Aze5qWUUasiqqWQ3g75500tePXhOvgBlH\n0yyTNxbCiIua8loJG8khfpPyFN+zcxyXzIbJEYYabrRR8uCu6Q3ULF3RuTAb/X1N\nf66F1T4vMauDwNSsa72LmrnwYsrKbprhvcQ=\n-----END CERTIFICATE-----\n"
    }
    Waiting for clients on: "localhost:21000"
    Handled client: V4(127.0.0.1:33426)

Client-Side Operations

  • Update ./config file in https://github.com/fortanix/rust-sgx/tree/master/em-app/examples/client folder with credentials, the desired account, and application names.
  • Run './register_and_run.sh' script which automates the steps for building the SGX application/Registering the EDP application with Fortanix CCM, and Running the EDP application.
  • Logs:
    em-app/examples/client$ ./register_and_run.sh ./config
    Logged in
    export token=SiMxMNM7-_qcTvOxRyesVrnINfsvz09rtlY2Niw7KQNPI16FZoBBtd1W-Glkt2A5ASbwXp0xhwb3lFh-ITE6_g
    export em_url=https://localhost:9090
    Account selected
    Building application.
    Compiling get-certificate v0.1.0 (/home/acruceru/work/rust-sgx-patch/em-app/examples/client)
    Finished dev [unoptimized + debuginfo] target(s) in 0.31s
    Signing application.
    Application configuration finished.
    Domain whitelisting finished.
    Build configuration finished
    Build whitelisting finished
    Application: obtained signed certificate from EM: {
    "task_id": "1e72abe6-f12d-4123-a00a-4b9513caa0c6",
    "task_status": "SUCCESS",
    "certificate": "-----BEGIN CERTIFICATE-----\nMIIEljCCAv6gAwIBAgIUGsKTopB4hHT1yqL+PLeYT/JkVPkwDQYJKoZIhvcNAQEL\nBQAwgZIxNTAzBgsrBgEEAYOEGgEDAQwkZGFh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D/hX92kHHsIa10U0WjULu\nTfIcBe/c70EiVNt+j8Awu46wO++P9QWu5Pu/oGpXRPKf/CyBW7+y8rNUZnVOCHDi\nIbrgil6KHMc35jt8TVuVxn8nH2Am8Iz7IEYjoq1pnDVYItf/OcsKsF9xuumDYS04\nhB79KDeemkhc/gX2lzdO1BGlL85A+lQO+pVIa6C0tsgndHB/P3qsCVkj/6zK83We\nHeOHhQd47u+q3eb0HUjueShPuk+cfCkn54kaOzKYlVni4Pcv8bJsKmPrpVNPFpiw\n5zX8T+bylkJygbVf32zfft10vxqWZtOUV0GRHjbvNo4Kfp+BPfkNK87M136Y7C7/\nFmaU+pbRoZZH8Enl8VWkL2O9JlbShwF/vjkUlS1USxzFhK4tHF03mIl0boe2ijo1\nyddDuwUFmTVlZNPPz0NVz5bjgYWLclgsBg8=\n-----END CERTIFICATE-----\n"
    }
    Application: received data from server: "Hello world from server".
    Client finished

Example for Bad Actor Server

A properly configured client attempts to connect to a server that does not have a certificate signed by the expected CA:

Client sees an error:

Error: "Error in client: \"TLS Session error: X509CertVerifyFailed\""

Full Log:

$ ./register_and_run.sh ./config
Logged in
export token=YFOUM4UFazRrkhruZMTIjeSTMAS_0Cy5b110TFF7i_LE6LgzvX8zTtArFhZA7I5-BPQI2vT2lwb2sE7jQ2OyOw
export em_url=https://localhost:9090
Account selected
Building application.
Compiling get-certificate v0.1.0 (/home/acruceru/work/rust-sgx-patch/em-app/examples/client)
Finished dev [unoptimized + debuginfo] target(s) in 0.32s
Signing application.
Creating application
Application configuration finished.
Domain whitelist result: SUCCESS
Domain whitelisting finished.
Build configuration finished
Build whitelist result: SUCCESS
Build whitelisting finished
Application: obtained signed certificate from EM: {
"task_id": "bd661840-1d9f-45ed-898b-0ad30bc5229d",
"task_status": "SUCCESS",
"certificate": "-----BEGIN CERTIFICATE-----\nMIIEljCCAv6gAwIBAgIUIn4xxQzzZ0/qCP7D+71O+cMuWX8wDQYJKoZIhvcNAQEL\nBQAwgZIxNTAzBgsrBgE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zQmZSaVIhuDcsYwD5uighXuU+\nBG14szMAfn18rh+NUreG+fImVRbKKzRbikuC4KEpZOGzlhvtzv1HnS+lk2EkAZl7\nbSqdzk1nrfDG3aWhNwzl8ij/yN3ezrmW1euUtcyPXmJMmuxbSeFigL1G/lpDSNqg\naHzJn9YZuImZ7ewF1ioqg8kU+P/rHG2ZbCWJdKJTafJ0zwHL42rMKle0ZY8Ky1V2\n3HwmqELWKCrP8MeJdK25jPwGqOzfIL6XLGscxS10/7DCS9zS7aGepT1/Ed1VvsIF\noyrcgkCDo5xn09+1rRImae23+dRZGUxG6hgW8jEcACeediD3Y/PTmYTxMNmSNhSY\n6G17HC9zhGPjqUECMtQ1R9dpyKoDylDP2Oi23qHuk0ZFfMfxEaahCmsongrrJ0Iv\nbHmpVUXgBBF5CiTvHvqY7zcnGgdTWB9U+8c=\n-----END CERTIFICATE-----\n"
}
Error: "Error in client: \"TLS Session error: X509CertVerifyFailed\""

Example for Bad Actor Client

A client with a certificate that is not issued by a proper Fortanix CCM account will result in server error:

Connection failed: X509CertVerifyFailed

Full Log:

$ ./register_and_run.sh ./config
Logged in
export token=Q3SxmoKzaq8sW6vl6HoDL4Qs2xNxSdotwFobt2LRSxeyjaP-AB0Lh5UfJ0UcZ0KSX9dGZOlDvgo-3mPPKVcQuQ
export em_url=https://localhost:9090
Account selected
Building application.
Compiling get-certificate v0.1.0 (/home/acruceru/work/rust-sgx-patch/em-app/examples/server)
Finished dev [unoptimized + debuginfo] target(s) in 0.35s
Signing application.
Application configuration finished.
Domain whitelisting finished.
Build configuration finished
Build whitelist result: SUCCESS
Build whitelisting finished
Application: obtained signed certificate from EM: {
"task_id": "807ec66f-4c03-41e5-a374-15786a7812ef",
"task_status": "SUCCESS",
"certificate": "-----BEGIN CERTIFICATE-----\nMIIEljCCAv6gAwIBAgIUc4vW9ugcTYTEeq7+fAmpmuDICFQwDQYJKoZIhvcNAQEL\nBQAwgZIxNTAzBgsrBgEEAYOEGgEDAQwkZGFhMTJj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dU0s7UfKLPk0KASiNOHvX2D\nHNnQO05OZWNG+23Z1rUvQU8Le74D8vCU6UDnUOh/lqWRrGLywZ08eBcmIa/08SwD\nrLdlJ5ZOUqzyUlPFaAxeaHTi8D0U/8mSGtsZXMHSYNkxWgJh7kn4G77Okii6mM72\nXqMMf0xfyNjAAKi8+HmMvzGgKgAfKmiXiERxl27spZ7KIhC0QW9EHo4E3jZh1nFr\ncMR8UyFw0IWf9xzgbkvL2Tl6kdq2FJc6X4usIl3mtz4o0U/4sYIKTckKR1hRsQqB\nKLZFrmjXkMzLBCq1Jwcytgcdoqv6si/Aze5qWUUasiqqWQ3g75500tePXhOvgBlH\n0yyTNxbCiIua8loJG8khfpPyFN+zcxyXzIbJEYYabrRR8uCu6Q3ULF3RuTAb/X1N\nf66F1T4vMauDwNSsa72LmrnwYsrKbprhvcQ=\n-----END CERTIFICATE-----\n"
}
Waiting for clients on: "localhost:21000"
Connection failed: X509CertVerifyFailed

 

Was this article helpful?
0 out of 0 found this helpful