Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
feat(rtc_data_service::data_upload): add auth_enclave_id to DataUploa…
Browse files Browse the repository at this point in the history
…dMessage
  • Loading branch information
PiDelport committed Jul 7, 2021
1 parent 475f2d9 commit 118a927
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion rtc_data_service/src/data_upload/message.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use actix::{Handler, Message};
use rtc_types::{DataUploadError, DataUploadResponse, EcallError, UploadMetadata};
use sgx_types::sgx_enclave_id_t;

use crate::data_enclave_actor::DataEnclaveActor;

Expand All @@ -11,11 +12,12 @@ pub struct DataUploadRequest {
pub payload: Box<[u8]>,
}

/// [`Message`]: Process a sealed [`DataUploadRequest`].
/// [`Message`]: Process a [`DataUploadRequest`] sealed for [`auth_enclave_id`].
/// Return a sealed [`DataUploadResponse`].
///
/// See: [`rtc_uenclave::enclaves::rtc_data::upload_data`]
pub struct DataUploadMessage {
pub auth_enclave_id: sgx_enclave_id_t,
pub request: DataUploadRequest,
}

Expand Down
13 changes: 12 additions & 1 deletion rtc_data_service/src/data_upload/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ use actix_web::{post, web};
use models::*;
use rtc_types::{DataUploadError, DataUploadResponse, EcallError};

use crate::auth_enclave_actor::AuthEnclaveActor;
use crate::data_enclave_actor::DataEnclaveActor;
use crate::data_upload::{DataUploadMessage, DataUploadRequest};
use crate::enclave_messages::GetEnclaveId;
use crate::merge_error::*;

/// Save uploaded data file using a [`DataUploadMessage`] for [`DataEnclaveActor`].
Expand All @@ -20,10 +22,19 @@ use crate::merge_error::*;
#[post("/data/uploads")]
pub async fn upload_file(
req_body: web::Json<RequestBody>,
auth_enclave: web::Data<Addr<AuthEnclaveActor>>,
data_enclave: web::Data<Addr<DataEnclaveActor>>,
) -> actix_web::Result<web::Json<ResponseBody>> {
let auth_enclave_id = auth_enclave
.send(GetEnclaveId)
.await
.map_err(ErrorInternalServerError)?;

let request: DataUploadRequest = req_body.0.try_into()?;
let message = DataUploadMessage { request };
let message = DataUploadMessage {
auth_enclave_id,
request,
};

let result: Result<DataUploadResponse, MergedError<EcallError<DataUploadError>, MailboxError>> =
data_enclave.send(message).await.merge_err();
Expand Down

0 comments on commit 118a927

Please sign in to comment.