|
| 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 | +} |
0 commit comments