Skip to content

Commit 783966f

Browse files
committed
Add Oak Session Low-Level SDK stub
Bug: 338559159 Change-Id: Ia07a064aa6d00d97fcf0206a26818f5e3847aafd
1 parent 04e524d commit 783966f

File tree

3 files changed

+185
-1
lines changed

3 files changed

+185
-1
lines changed

oak_session/src/attestation.rs

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414
// limitations under the License.
1515
//
1616

17+
//! This module provides an implementation of the Attestation Provider, which
18+
//! handles remote attestation between two parties.
19+
20+
use alloc::vec::Vec;
21+
1722
use oak_proto_rust::oak::{
1823
attestation::v1::{AttestationResults, Endorsements, Evidence},
19-
session::v1::EndorsedEvidence,
24+
session::v1::{AttestRequest, AttestResponse, EndorsedEvidence},
2025
};
2126

2227
pub trait Attester {
@@ -30,3 +35,74 @@ pub trait AttestationVerifier {
3035
endorsements: &Endorsements,
3136
) -> anyhow::Result<AttestationResults>;
3237
}
38+
39+
#[allow(dead_code)]
40+
struct AttestationProvider<'a> {
41+
self_attesters: Vec<&'a dyn Attester>,
42+
peer_verifiers: Vec<&'a dyn AttestationVerifier>,
43+
}
44+
45+
impl<'a> AttestationProvider<'a> {
46+
pub fn new(
47+
self_attesters: Vec<&'a dyn Attester>,
48+
peer_verifiers: Vec<&'a dyn AttestationVerifier>,
49+
) -> Self {
50+
Self { self_attesters, peer_verifiers }
51+
}
52+
}
53+
54+
/// Client-side Attestation Provider that initiates remote attestation with the
55+
/// server.
56+
#[allow(dead_code)]
57+
pub struct ClientAttestationProvider<'a> {
58+
inner: AttestationProvider<'a>,
59+
}
60+
61+
impl<'a> ClientAttestationProvider<'a> {
62+
pub fn new(
63+
self_attesters: Vec<&'a dyn Attester>,
64+
peer_verifiers: Vec<&'a dyn AttestationVerifier>,
65+
) -> Self {
66+
Self { inner: AttestationProvider::new(self_attesters, peer_verifiers) }
67+
}
68+
69+
pub fn get_request(&self) -> anyhow::Result<AttestRequest> {
70+
core::unimplemented!();
71+
}
72+
73+
pub fn put_response(&self, _response: &AttestResponse) -> anyhow::Result<()> {
74+
core::unimplemented!();
75+
}
76+
77+
pub fn get_attestation_results(self) -> Option<AttestationResults> {
78+
core::unimplemented!();
79+
}
80+
}
81+
82+
/// Server-side Attestation Provider that responds to the remote attestation
83+
/// request from the client.
84+
#[allow(dead_code)]
85+
pub struct ServerAttestationProvider<'a> {
86+
inner: AttestationProvider<'a>,
87+
}
88+
89+
impl<'a> ServerAttestationProvider<'a> {
90+
pub fn new(
91+
self_attesters: Vec<&'a dyn Attester>,
92+
peer_verifiers: Vec<&'a dyn AttestationVerifier>,
93+
) -> Self {
94+
Self { inner: AttestationProvider::new(self_attesters, peer_verifiers) }
95+
}
96+
97+
pub fn put_request(&self, _request: &AttestRequest) -> anyhow::Result<()> {
98+
core::unimplemented!();
99+
}
100+
101+
pub fn get_response(&self) -> anyhow::Result<AttestResponse> {
102+
core::unimplemented!();
103+
}
104+
105+
pub fn get_attestation_results(self) -> Option<AttestationResults> {
106+
core::unimplemented!();
107+
}
108+
}

oak_session/src/handshake.rs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//
2+
// Copyright 2024 The Project Oak Authors
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
//! This module provides an implementation of the Handshaker, which
18+
//! handles cryptographic handshake and secure session creation.
19+
20+
use alloc::vec::Vec;
21+
22+
use oak_proto_rust::oak::{
23+
crypto::v1::SessionKeys,
24+
session::v1::{HandshakeRequest, HandshakeResponse},
25+
};
26+
27+
pub trait EncryptionKeyHandle {
28+
fn derive_session_keys(
29+
&self,
30+
static_peer_public_key: &[u8],
31+
ephemeral_peer_public_key: &[u8],
32+
) -> anyhow::Result<SessionKeys>;
33+
}
34+
35+
pub enum HandshakeType {
36+
NoiseKK,
37+
NoiseNK,
38+
}
39+
40+
/// Client-side Handshaker that initiates the crypto handshake with the server.
41+
#[allow(dead_code)]
42+
pub struct ClientHandshaker<'a> {
43+
handshake_type: HandshakeType,
44+
self_static_private_key: Option<&'a dyn EncryptionKeyHandle>,
45+
peer_static_public_key: Option<Vec<u8>>,
46+
}
47+
48+
impl<'a> ClientHandshaker<'a> {
49+
pub fn new(
50+
handshake_type: HandshakeType,
51+
self_static_private_key: Option<&'a dyn EncryptionKeyHandle>,
52+
peer_static_public_key: Option<&[u8]>,
53+
) -> Self {
54+
Self {
55+
handshake_type,
56+
self_static_private_key,
57+
peer_static_public_key: peer_static_public_key.map(|k| k.to_vec()),
58+
}
59+
}
60+
61+
pub fn get_request(&mut self) -> anyhow::Result<HandshakeRequest> {
62+
core::unimplemented!();
63+
}
64+
65+
pub fn put_response(&mut self, _response: HandshakeResponse) -> anyhow::Result<()> {
66+
core::unimplemented!();
67+
}
68+
69+
pub fn derive_session_keys(self) -> Option<SessionKeys> {
70+
core::unimplemented!();
71+
}
72+
}
73+
74+
/// Server-side Attestation Provider that responds to the crypto handshake
75+
/// request from the client.
76+
#[allow(dead_code)]
77+
pub struct ServerHandshaker<'a> {
78+
handshake_type: HandshakeType,
79+
self_static_private_key: Option<&'a dyn EncryptionKeyHandle>,
80+
peer_static_public_key: Option<Vec<u8>>,
81+
}
82+
83+
impl<'a> ServerHandshaker<'a> {
84+
pub fn new(
85+
handshake_type: HandshakeType,
86+
self_static_private_key: Option<&'a dyn EncryptionKeyHandle>,
87+
peer_static_public_key: Option<&[u8]>,
88+
) -> Self {
89+
Self {
90+
handshake_type,
91+
self_static_private_key,
92+
peer_static_public_key: peer_static_public_key.map(|k| k.to_vec()),
93+
}
94+
}
95+
96+
pub fn put_request(&mut self, _request: HandshakeRequest) -> anyhow::Result<()> {
97+
core::unimplemented!();
98+
}
99+
100+
pub fn get_response(&mut self) -> anyhow::Result<HandshakeResponse> {
101+
core::unimplemented!();
102+
}
103+
104+
pub fn derive_session_keys(self) -> Option<SessionKeys> {
105+
core::unimplemented!();
106+
}
107+
}

oak_session/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extern crate std;
2323

2424
pub mod attestation;
2525
pub mod config;
26+
pub mod handshake;
2627
mod session;
2728

2829
pub use session::{ClientSession, ServerSession, Session};

0 commit comments

Comments
 (0)