Skip to main content

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.

Metadata

Release files for rust-sgx-gen 0.3.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rust-sgx-gen 0.3.8
File Size Uploaded Provenance Actions
rust-sgx-gen-0.3.8.tar.gz 18.0 kB Without provenance Details for rust-sgx-gen-0.3.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rust-sgx-gen 0.3.8
File Interpreter ABI Platform Actions
rust_sgx_gen-0.3.8-py3-none-any.whl Python 3 none any Details for rust_sgx_gen-0.3.8-py3-none-any.whl

Total release size: 40.7 kB

Release files / rust-sgx-gen-0.3.8.tar.gz

Download URL rust-sgx-gen-0.3.8.tar.gz
Size 18.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0facb6d49611de9b014d44e3e71f1fac4b701450d4e4aebba49e189ab3e86f7f
BLAKE2b-256 checksum
How to use checksums
0d193cf0d7f48d1d754a8298179374a018b4137375bc1d1ed58f1fbf1eb5c37c
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / rust_sgx_gen-0.3.8-py3-none-any.whl

Download URL rust_sgx_gen-0.3.8-py3-none-any.whl
Size 22.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe0d4e4e038e7e71f091d8e3c9afe06da5ec33d5e65a2ec0e678eca32e34c960
BLAKE2b-256 checksum
How to use checksums
bca18aff7c058850ea198a0bb9a765d659618673d5b5f1ce819b197dfe5ebaa5
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for rust-sgx-gen 0.3.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page