From d2e1a8555453ab2957196b7c2dc3e7f5dd78c92e Mon Sep 17 00:00:00 2001 From: c0repwn3r Date: Tue, 2 May 2023 21:58:37 -0400 Subject: [PATCH] protocol definition --- libepf/src/lib.rs | 1 + libepf/src/protocol.rs | 76 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 libepf/src/protocol.rs diff --git a/libepf/src/lib.rs b/libepf/src/lib.rs index 2095d00..b6dccfa 100644 --- a/libepf/src/lib.rs +++ b/libepf/src/lib.rs @@ -1,3 +1,4 @@ pub mod ca_pool; pub mod pki; pub mod util; +pub mod protocol; \ No newline at end of file diff --git a/libepf/src/protocol.rs b/libepf/src/protocol.rs new file mode 100644 index 0000000..08f750a --- /dev/null +++ b/libepf/src/protocol.rs @@ -0,0 +1,76 @@ +use serde::{Deserialize, Serialize}; +use crate::pki::EPFCertificate; + +pub const PROTOCOL_VERSION: u32 = 1; + +#[derive(Serialize, Deserialize)] +pub struct EpfMessage { + pub packet_id: u32, + pub packet_data: Vec +} + +pub const CLIENT_HELLO: u32 = 1; + +#[derive(Serialize, Deserialize)] +pub struct EpfClientHello { + pub protocol_version: u32, + pub client_random: [u8; 16] +} + +pub const SERVER_HELLO: u32 = 2; + +#[derive(Serialize, Deserialize)] +pub struct EpfServerHello { + pub protocol_version: u32, + pub server_certificate: EPFCertificate, + pub server_random: [u8; 16] +} + +pub const CLIENT_KEY_EXCHANGE: u32 = 3; + +#[derive(Serialize, Deserialize)] +pub struct EpfClientKeyExchange { + pub protocol_version: u32, + pub encrypted_shared_secret: Vec +} + +pub const FINISHED: u32 = 4; + +#[derive(Serialize, Deserialize)] +pub struct EpfFinished { + pub protocol_version: u32, + pub encrypted_0x42: Vec +} + +pub const APPLICATION_DATA: u32 = 5; + +#[derive(Serialize, Deserialize)] +pub struct EpfApplicationData { + pub protocol_version: u32, + pub application_data: Vec +} + +pub enum EpfClientState { + NotStarted, + WaitingForServerHello, + WaitingForFinished, + Transport, + Closed +} + +pub enum EpfServerState { + WaitingForClientHello, + WaitingForClientKeyExchange, + WaitingForFinished, + Transport, + Closed +} + +pub fn encode_packet(id: u32, packet: &T) -> Result, rmp_serde::encode::Error> { + let message_data = rmp_serde::to_vec(packet)?; + let message_wrapper = EpfMessage { + packet_id: id, + packet_data: message_data, + }; + rmp_serde::to_vec(&message_wrapper) +} \ No newline at end of file