Skip to content

Commit

Permalink
Use the real oak ClientSession/ServerSession for noise handshake instead
Browse files Browse the repository at this point in the history
of fake stubs.

Change-Id: I145b9462bba23536c0e32d4cb1dc2c08449974a1
  • Loading branch information
rakshita-tandon committed Aug 15, 2024
1 parent 6017476 commit 5c9e80f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 83 deletions.
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ members = [
]

[workspace.dependencies]
micro_rpc = { git = "https://github.com/project-oak/oak", rev = "f67f1eb1ac5cdaae75edf467f1937347e6f3728e" }
micro_rpc_build = { git = "https://github.com/project-oak/oak", rev = "f67f1eb1ac5cdaae75edf467f1937347e6f3728e" }
oak_attestation = { git = "https://github.com/project-oak/oak", rev = "f67f1eb1ac5cdaae75edf467f1937347e6f3728e" }
oak_attestation_verification = { git = "https://github.com/project-oak/oak", rev = "f67f1eb1ac5cdaae75edf467f1937347e6f3728e" }
oak_crypto = { git = "https://github.com/project-oak/oak", rev = "f67f1eb1ac5cdaae75edf467f1937347e6f3728e" }
oak_enclave_runtime_support = { git = "https://github.com/project-oak/oak", rev = "f67f1eb1ac5cdaae75edf467f1937347e6f3728e" }
oak_proto_rust = { git = "https://github.com/project-oak/oak", rev = "f67f1eb1ac5cdaae75edf467f1937347e6f3728e" }
oak_restricted_kernel_sdk = { git = "https://github.com/project-oak/oak", rev = "f67f1eb1ac5cdaae75edf467f1937347e6f3728e" }
oak_restricted_kernel_interface = { git = "https://github.com/project-oak/oak", rev = "f67f1eb1ac5cdaae75edf467f1937347e6f3728e" }
oak_session = { git = "https://github.com/project-oak/oak", rev = "f67f1eb1ac5cdaae75edf467f1937347e6f3728e" }
micro_rpc = { git = "https://github.com/project-oak/oak", rev = "cbea9551e47cf0efadc566e573f6aa44574c5cc9" }
micro_rpc_build = { git = "https://github.com/project-oak/oak", rev = "cbea9551e47cf0efadc566e573f6aa44574c5cc9" }
oak_attestation = { git = "https://github.com/project-oak/oak", rev = "cbea9551e47cf0efadc566e573f6aa44574c5cc9" }
oak_attestation_verification = { git = "https://github.com/project-oak/oak", rev = "cbea9551e47cf0efadc566e573f6aa44574c5cc9" }
oak_crypto = { git = "https://github.com/project-oak/oak", rev = "cbea9551e47cf0efadc566e573f6aa44574c5cc9" }
oak_enclave_runtime_support = { git = "https://github.com/project-oak/oak", rev = "cbea9551e47cf0efadc566e573f6aa44574c5cc9" }
oak_proto_rust = { git = "https://github.com/project-oak/oak", rev = "cbea9551e47cf0efadc566e573f6aa44574c5cc9" }
oak_restricted_kernel_sdk = { git = "https://github.com/project-oak/oak", rev = "cbea9551e47cf0efadc566e573f6aa44574c5cc9" }
oak_restricted_kernel_interface = { git = "https://github.com/project-oak/oak", rev = "cbea9551e47cf0efadc566e573f6aa44574c5cc9" }
oak_session = { git = "https://github.com/project-oak/oak", rev = "cbea9551e47cf0efadc566e573f6aa44574c5cc9" }
raft = { git = "https://github.com/google-parfait/raft-rs", rev = "10968a112dcc4143ad19a1b35b6dca6e30d2e439", package = "raft", default-features = false, features = ["prost-codec"] }
raft-proto = { git = "https://github.com/google-parfait/raft-rs", rev = "10968a112dcc4143ad19a1b35b6dca6e30d2e439", package = "raft-proto", default-features = false, features = ["prost-codec"] }
prost = { version = "0.12.4", default-features = false, features = ["prost-derive"] }
Expand Down
73 changes: 17 additions & 56 deletions runtime/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
use alloc::boxed::Box;
use alloc::vec::Vec;
use anyhow::Result;
use oak_proto_rust::oak::session::v1::{
session_request::Request, session_response::Response, SessionRequest, SessionResponse,
};
use oak_proto_rust::oak::session::v1::{SessionRequest, SessionResponse};
use oak_session::attestation::AttestationType;
use oak_session::config::SessionConfig;
use oak_session::handshake::HandshakeType;
use oak_session::session::{ClientSession, ServerSession};
use oak_session::session::{ClientSession, ServerSession, Session};
use oak_session::ProtocolEngine;

// Factory class for creating instances of `OakClientSession` and `OakServerSession`
// traits.
Expand Down Expand Up @@ -73,115 +72,77 @@ impl OakSessionFactory for DefaultOakSessionFactory {

// Default implementation of `OakClientSession`.
pub struct DefaultOakClientSession {
_inner: ClientSession,
incoming_ciphertext: Option<Vec<u8>>,
outgoing_ciphertext: Option<Vec<u8>>,
inner: ClientSession,
}

impl DefaultOakClientSession {
pub fn create() -> Result<Self> {
// TODO: Revisit config parameters.
Ok(Self {
_inner: ClientSession::create(
inner: ClientSession::create(
SessionConfig::builder(AttestationType::Bidirectional, HandshakeType::NoiseNN)
.build(),
)?,
incoming_ciphertext: None,
outgoing_ciphertext: None,
})
}
}

impl OakSession<SessionResponse, SessionRequest> for DefaultOakClientSession {
// TODO: Delegate to `inner` once the implementation is complete on Oak side.
fn get_outgoing_message(&mut self) -> Result<Option<SessionRequest>> {
if self.outgoing_ciphertext.is_some() {
return Ok(Some(SessionRequest {
request: Some(Request::Ciphertext(
self.outgoing_ciphertext.take().unwrap(),
)),
}));
}
Ok(Some(SessionRequest { request: None }))
self.inner.get_outgoing_message()
}

fn put_incoming_message(&mut self, incoming_message: &SessionResponse) -> Result<Option<()>> {
match &incoming_message.response {
Some(Response::Ciphertext(ciphertext)) => {
self.incoming_ciphertext = Some(ciphertext.to_vec());
}
_ => {}
}
Ok(Some(()))
self.inner.put_incoming_message(incoming_message)
}

fn is_open(&self) -> bool {
true
self.inner.is_open()
}

fn write(&mut self, plaintext: &[u8]) -> Result<()> {
self.outgoing_ciphertext = Some(plaintext.to_vec());
Ok(())
self.inner.write(plaintext)
}

fn read(&mut self) -> Result<Option<Vec<u8>>> {
Ok(self.incoming_ciphertext.take())
self.inner.read()
}
}

// Default implementation of `OakServerSession`.
pub struct DefaultOakServerSession {
_inner: ServerSession,
incoming_ciphertext: Option<Vec<u8>>,
outgoing_ciphertext: Option<Vec<u8>>,
inner: ServerSession,
}

impl DefaultOakServerSession {
pub fn create() -> Result<Self> {
Ok(Self {
_inner: ServerSession::new(
inner: ServerSession::new(
SessionConfig::builder(AttestationType::Bidirectional, HandshakeType::NoiseNN)
.build(),
),
incoming_ciphertext: None,
outgoing_ciphertext: None,
})
}
}

impl OakSession<SessionRequest, SessionResponse> for DefaultOakServerSession {
// TODO: Delegate to `inner` once the implementation is complete on Oak side.
fn get_outgoing_message(&mut self) -> Result<Option<SessionResponse>> {
if self.outgoing_ciphertext.is_some() {
return Ok(Some(SessionResponse {
response: Some(Response::Ciphertext(
self.outgoing_ciphertext.take().unwrap(),
)),
}));
}
Ok(Some(SessionResponse { response: None }))
self.inner.get_outgoing_message()
}

fn put_incoming_message(&mut self, incoming_message: &SessionRequest) -> Result<Option<()>> {
match &incoming_message.request {
Some(Request::Ciphertext(ciphertext)) => {
self.incoming_ciphertext = Some(ciphertext.to_vec());
}
_ => {}
}
Ok(Some(()))
self.inner.put_incoming_message(incoming_message)
}

fn is_open(&self) -> bool {
true
self.inner.is_open()
}

fn write(&mut self, plaintext: &[u8]) -> Result<()> {
self.outgoing_ciphertext = Some(plaintext.to_vec());
Ok(())
self.inner.write(plaintext)
}

fn read(&mut self) -> Result<Option<Vec<u8>>> {
Ok(self.incoming_ciphertext.take())
self.inner.read()
}
}

0 comments on commit 5c9e80f

Please sign in to comment.