Skip to content

Instantly share code, notes, and snippets.

@haraldh
Created October 13, 2020 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haraldh/fb3f82cd188b89ae767d1989727f1abb to your computer and use it in GitHub Desktop.
Save haraldh/fb3f82cd188b89ae767d1989727f1abb to your computer and use it in GitHub Desktop.
use crate::aesm_proto::Request_InitQuoteRequest;
use byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
use protobuf::Message;
use std::io::{Read, Write};
use std::mem::size_of;
use std::os::unix::net::UnixStream;
mod aesm_proto;
fn main() -> std::io::Result<()> {
let mut req = aesm_proto::Request::new();
let mut msg = Request_InitQuoteRequest::new();
msg.set_timeout(1_000_000);
req.set_initQuoteReq(msg);
let mut stream = UnixStream::connect("/var/run/aesmd/aesm.socket")?; // this connects to aesmd on the host
let mut req_bytes = vec![0u8; size_of::<u32>()];
req.write_to_writer(&mut req_bytes);
let req_len = (req_bytes.len() - size_of::<u32>()) as u32;
(&mut req_bytes[0..size_of::<u32>()]).write_u32::<NativeEndian>(req_len)?;
stream.write_all(&req_bytes)?;
stream.flush()?;
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment