Package: rust-sgx-gen
rust-sgx-genAutomatic code generator for SGX/native modules of theAuthentic Execution framework.Installation# Install rust-sgx-gen - you must be on the root of this repositorypipinstall.RunGenerally,rust-sgx-genis used withinreactive-tools, so user intervention is not needed. To try it anyway:# Check helperrust-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 rulesThe input is aRust Cargo library, created using the commandcargo new <name> --libAmain.rsshould notexist[lib]or[[bin]]sections in theCargo.tomlfileshould notexistThe developer is free to implement his own code (files, functions, data structures, external dependencies), but:They still have to respect the rules aboveThey must be aware of the limitations of a SGX enclave (e.g. some std functions are not supported). CheckhereDefine inputs, outputs, entry points, requests, handlersTutorialHelper functionsSome helper functions are provided.PrintsPrint macros are available:debug!,info!,warning!anderror!. All of them accept a single parameter, which must implement theDisplaytrait. Notice that multiple parameters can be printed together by using theformat!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 featuredebug_prints.Return values of entry pointsAs described above, an entry point must return aResultMessageelement. A developer can either:create his ownResultMessageby callingResultMessage::new(code, payload)Seeherefor more detailsuse the helper functions provided by the framework:success(data)failure(code,data)codeis aResultCode(see link above)The result code forsuccessis alwaysResultCode::Ok(0)datais anOption<Vec<u8>>which is an optional return value of the entry point.Call the entry point of a moduleUsing 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-toolscall--config<config>--module<module_name>--entry<entry_name>--arg<args_hex>ManualTo manually call the entry point of a module, we must know its id. All the identifiers are printed in the output JSON file (flag-pofrust-sgx-gen).The general rule is that the entry points are enumerated in order of appearance in thelib.rsfile, starting from 2.The first two IDs correspond to entry points used for Authentic Execution:ID 0 isset_keyID 1 ishandle_inputID 2 ishandle_handlerCalling the module directlyThe 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_idis 16 bitsdatacan be omittedOne can use thereactive_netutility functions to send more easily a message (usingwrite_message)Calling the module indirectlyWe 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_idisCommandCode::CallEntrypoint(16 bits)payload_lengthdoes not includecommand_idsm_idis the module id (provided as input to rust-sgx-gen, also present in the output JSON file)entrypoint_idanddataare the same as beforeWe can use the helper functionwrite_commandofreactive_netto send this kind of message easily.