Skip to content

Commit

Permalink
Revert "Use the real oak ClientSession/ServerSession for noise handsh…
Browse files Browse the repository at this point in the history
…ake instead"

This reverts commit 5c9e80f.

Change-Id: I13a421d792a4078d67f58a4451858ed9c805477a
  • Loading branch information
rakshita-tandon committed Aug 20, 2024
1 parent 5c9e80f commit 981ab02
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 44 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 = "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" }
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" }
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: 56 additions & 17 deletions runtime/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
use alloc::boxed::Box;
use alloc::vec::Vec;
use anyhow::Result;
use oak_proto_rust::oak::session::v1::{SessionRequest, SessionResponse};
use oak_proto_rust::oak::session::v1::{
session_request::Request, session_response::Response, SessionRequest, SessionResponse,
};
use oak_session::attestation::AttestationType;
use oak_session::config::SessionConfig;
use oak_session::handshake::HandshakeType;
use oak_session::session::{ClientSession, ServerSession, Session};
use oak_session::ProtocolEngine;
use oak_session::session::{ClientSession, ServerSession};

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

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

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>> {
self.inner.get_outgoing_message()
if self.outgoing_ciphertext.is_some() {
return Ok(Some(SessionRequest {
request: Some(Request::Ciphertext(
self.outgoing_ciphertext.take().unwrap(),
)),
}));
}
Ok(Some(SessionRequest { request: None }))
}

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

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

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

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

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

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>> {
self.inner.get_outgoing_message()
if self.outgoing_ciphertext.is_some() {
return Ok(Some(SessionResponse {
response: Some(Response::Ciphertext(
self.outgoing_ciphertext.take().unwrap(),
)),
}));
}
Ok(Some(SessionResponse { response: None }))
}

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

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

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

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

0 comments on commit 981ab02

Please sign in to comment.