/// Starts a server loop for serving PA-RoT requests, as described by `opts`.
Starts a server loop for serving PA-RoT requests, as described by `opts`.
Starts a server loop for serving PA - RoT requests as described by ` opts ` .
pub fn serve(opts: Options) -> ! {
    log::info!("configuring server...");
    let networking = capabilities::Networking {
        max_message_size: opts.max_message_size,
        max_packet_size: opts.max_packet_size,
        mode: capabilities::RotMode::Platform,
        roles: capabilities::BusRole::HOST,
    };
    let timeouts = capabilities::Timeouts {
        regular: opts.regular_timeout,
        crypto: opts.crypto_timeout,
    };
    struct Id {
        firmware_version: [u8; 32],
        unique_device_identity: Vec<u8>,
    }
    impl manticore::hardware::Identity for Id {
        fn firmware_version(&self) -> &[u8; 32] {
            &self.firmware_version
        }
        fn unique_device_identity(&self) -> &[u8] {
            &self.unique_device_identity[..]
        }
    }
    let mut identity = Id {
        firmware_version: [0; 32],
        unique_device_identity: opts.unique_device_identity,
    };
    let prefix_len = opts.firmware_version.len().min(32);
    identity.firmware_version[..prefix_len]
        .copy_from_slice(&opts.firmware_version[..prefix_len]);
    struct Reset {
        startup_time: Instant,
        resets_since_power_on: u32,
    }
    impl manticore::hardware::Reset for Reset {
        fn resets_since_power_on(&self) -> u32 {
            self.resets_since_power_on
        }
        fn uptime(&self) -> Duration {
            self.startup_time.elapsed()
        }
    }
    let reset = Reset {
        startup_time: Instant::now(),
        resets_since_power_on: opts.resets_since_power_on,
    };
    let mut ciphers = ring::sig::Ciphers::new();
    let mut server = PaRot::new(manticore::server::pa_rot::Options {
        identity: &identity,
        reset: &reset,
        ciphers: &mut ciphers,
        device_id: opts.device_id,
        networking,
        timeouts,
    });
    let mut host = match TcpHostPort::bind() {
        Ok(host) => host,
        Err(e) => {
            log::error!("could not connect to host: {:?}", e);
            std::process::exit(1);
        }
    };
    let port = host.port();
    log::info!("bound to port {}", port);
    // Notify parent that we're listening.
    println!("listening@{}", port);
    let mut arena = vec![0; 64];
    let mut arena = BumpArena::new(&mut arena);
    log::info!("entering server loop");
    loop {
        if let Err(e) = server.process_request(&mut host, &arena) {
            log::error!("failed to process request: {:?}", e);
        }
        arena.reset();
    }
}
pub fn serve ( opts : Options ) -> ! { log :: info ! ( " " ) ; let networking = capabilities :: Networking { max_message_size : opts . max_message_size , max_packet_size : opts . max_packet_size , mode : capabilities :: RotMode :: Platform , roles : capabilities :: BusRole :: HOST , } ; let timeouts = capabilities :: Timeouts { regular : opts . regular_timeout , crypto : opts . crypto_timeout , } ; struct Id { firmware_version : [ u8 ; 32 ] , unique_device_identity : Vec < u8 > , } impl manticore :: hardware :: Identity for Id { fn firmware_version ( & self ) -> & [ u8 ; 32 ] { & self . firmware_version } fn unique_device_identity ( & self ) -> & [ u8 ] { & self . unique_device_identity [ .. ] } } let mut identity = Id { firmware_version : [ 0 ; 32 ] , unique_device_identity : opts . unique_device_identity , } ; let prefix_len = opts . firmware_version . len ( ) . min ( 32 ) ; identity . firmware_version [ .. prefix_len ] . copy_from_slice ( & opts . firmware_version [ .. prefix_len ] ) ; struct Reset { startup_time : Instant , resets_since_power_on : u32 , } impl manticore :: hardware :: Reset for Reset { fn resets_since_power_on ( & self ) -> u32 { self . resets_since_power_on } fn uptime ( & self ) -> Duration { self . startup_time . elapsed ( ) } } let reset = Reset { startup_time : Instant :: now ( ) , resets_since_power_on : opts . resets_since_power_on , } ; let mut ciphers = ring :: sig :: Ciphers :: new ( ) ; let mut server = PaRot :: new ( manticore :: server :: pa_rot :: Options { identity : & identity , reset : & reset , ciphers : & mut ciphers , device_id : opts . device_id , networking , timeouts , } ) ; let mut host = match TcpHostPort :: bind ( ) { Ok ( host ) => host , Err ( e ) => { log :: error ! ( " " e ) ; std :: process :: exit ( 1 ) ; } } ; let port = host . port ( ) ; log :: info ! ( " " port ) ; // Notify parent that we're listening. println ! ( " " port ) ; let mut arena = vec ! [ 0 64 ] ; let mut arena = BumpArena :: new ( & mut arena ) ; log :: info ! ( " " ) ; loop { if let Err ( e ) = server . process_request ( & mut host , & arena ) { log :: error ! ( " " e ) ; } arena . reset ( ) ; } }
Starts a server loop for serving PA-RoT requests, as described by `opts`.
Starts a server loop for serving PA - RoT requests as described by ` opts ` .
opts
Options