Skip to main content

Rust code generator for the Authentic Execution framework

Project description

rust-sgx-gen

Automatic code generator for SGX/native modules of the Authentic Execution framework.

Installation

# Install rust-sgx-gen - you must be on the root of this repository
pip install .

Run

Generally, rust-sgx-gen is used within reactive-tools, so user intervention is not needed. To try it anyway:

# Check helper
rust-sgx-gen -h

# generate code and create output of a SGX module
### <input_fldr>: input folder of the Rust module
### <output_fldr>: output folder of the Rust module + the generated code
### <module_id>: ID of the module
### <reactive_port>: port used by the local Event Manager to listen for events
### <result_json>: a result JSON file containing the description of the module
### <runner>: either "sgx" or "native", depending on the nature of the module
### <ra_sp_pubkey>: path to ra_sp public key (for Remote Attestation - only SGX)
rust-sgx-gen -i <input_fldr> -o <output_fldr> -m <module_id> -e <reactive_port> -p <result_json> -r <runner> -s <ra_sp_pubkey>

General rules

The input is a Rust Cargo library, created using the command cargo new <name> --lib

  • A main.rs should not exist

  • [lib] or [[bin]] sections in the Cargo.toml file should not exist

  • The developer is free to implement his own code (files, functions, data structures, external dependencies), but:

    • They still have to respect the rules above
    • They must be aware of the limitations of a SGX enclave (e.g. some std functions are not supported). Check here

Define inputs, outputs, entry points, requests, handlers

Tutorial

Helper functions

Some helper functions are provided.

Prints

Print macros are available: debug!, info!, warning! and error!. All of them accept a single parameter, which must implement the Display trait. Notice that multiple parameters can be printed together by using the format! macro.

// This instruction prints to stdout the following string: `[sm1] DEBUG: hello, world!`
debug!("hello, world!"); 

// This instruction prints to stdout the following string: `[sm1] INFO: hello, sm 1:22!`
info!(&format!("Hello, sm {}:{}!", 1, 22));

Note: debug! normally is disabled. Which means that the macro does not print anything to stdout. To enable debug prints, the module has to be compiled with the feature debug_prints.

Return values of entry points

As described above, an entry point must return a ResultMessage element. A developer can either:

  • create his own ResultMessage by calling ResultMessage::new(code, payload)

  • See here for more details

  • use the helper functions provided by the framework:

    success(data)
    failure(code, data)
    
    • code is a ResultCode (see link above)
      • The result code for success is always ResultCode::Ok (0)
    • data is an Option<Vec<u8>> which is an optional return value of the entry point.

Call the entry point of a module

Using reactive-tools

# Call the entry point of a module (the arg flag is optional)
### <config>: the output JSON file of a previous deploy command
### <module_name>: the name of the module
### <entry_name>: the name of the entry point
### <args_ex>: byte array as hexadecimal string, e.g., "deadbeef"
reactive-tools call --config <config> --module <module_name> --entry <entry_name> --arg <args_hex>

Manual

To manually call the entry point of a module, we must know its id. All the identifiers are printed in the output JSON file (flag -p of rust-sgx-gen).

The general rule is that the entry points are enumerated in order of appearance in the lib.rs file, starting from 2.

The first two IDs correspond to entry points used for Authentic Execution:

  • ID 0 is set_key
  • ID 1 is handle_input
  • ID 2 is handle_handler

Calling the module directly

The module must be loaded inside the same machine of the caller (because it listens for connections from the loopback interface).

To call an entry point, we must send the following payload:

<payload_length><entrypoint_id><data>

Where:

  • entrypoint_id is 16 bits
  • data can be omitted

One can use the reactive_net utility functions to send more easily a message (using write_message)

Calling the module indirectly

We can call an entry point by sending the corresponding command to its Event Manager. We can connect to the EM from any machine connected to Internet.

The payload is the following:

<command_id><payload_length><sm_id><entrypoint_id><data>

Where:

  • command_id is CommandCode::CallEntrypoint (16 bits)
  • payload_length does not include command_id
  • sm_id is the module id (provided as input to rust-sgx-gen, also present in the output JSON file)
  • entrypoint_id and data are the same as before

We can use the helper function write_command of reactive_net to send this kind of message easily.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rust-sgx-gen-0.3.8.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rust_sgx_gen-0.3.8-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file rust-sgx-gen-0.3.8.tar.gz.

File metadata

  • Download URL: rust-sgx-gen-0.3.8.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for rust-sgx-gen-0.3.8.tar.gz
Algorithm Hash digest
SHA256 0facb6d49611de9b014d44e3e71f1fac4b701450d4e4aebba49e189ab3e86f7f
MD5 c59a22752d61e389a565d2cb33593132
BLAKE2b-256 0d193cf0d7f48d1d754a8298179374a018b4137375bc1d1ed58f1fbf1eb5c37c

See more details on using hashes here.

File details

Details for the file rust_sgx_gen-0.3.8-py3-none-any.whl.

File metadata

  • Download URL: rust_sgx_gen-0.3.8-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for rust_sgx_gen-0.3.8-py3-none-any.whl
Algorithm Hash digest
SHA256 fe0d4e4e038e7e71f091d8e3c9afe06da5ec33d5e65a2ec0e678eca32e34c960
MD5 fa3b52435b125c692b9eb12c76ba4d8e
BLAKE2b-256 bca18aff7c058850ea198a0bb9a765d659618673d5b5f1ce819b197dfe5ebaa5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page