protocol definition

This commit is contained in:
c0repwn3r 2023-05-02 21:58:37 -04:00
parent 4f9563755a
commit d2e1a85554
Signed by: core
GPG Key ID: FDBF740DADDCEECF
2 changed files with 77 additions and 0 deletions

View File

@ -1,3 +1,4 @@
pub mod ca_pool;
pub mod pki;
pub mod util;
pub mod protocol;

76
libepf/src/protocol.rs Normal file
View File

@ -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<u8>
}
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<u8>
}
pub const FINISHED: u32 = 4;
#[derive(Serialize, Deserialize)]
pub struct EpfFinished {
pub protocol_version: u32,
pub encrypted_0x42: Vec<u8>
}
pub const APPLICATION_DATA: u32 = 5;
#[derive(Serialize, Deserialize)]
pub struct EpfApplicationData {
pub protocol_version: u32,
pub application_data: Vec<u8>
}
pub enum EpfClientState {
NotStarted,
WaitingForServerHello,
WaitingForFinished,
Transport,
Closed
}
pub enum EpfServerState {
WaitingForClientHello,
WaitingForClientKeyExchange,
WaitingForFinished,
Transport,
Closed
}
pub fn encode_packet<T: Serialize>(id: u32, packet: &T) -> Result<Vec<u8>, 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)
}