protocol definition
This commit is contained in:
parent
4f9563755a
commit
d2e1a85554
|
@ -1,3 +1,4 @@
|
|||
pub mod ca_pool;
|
||||
pub mod pki;
|
||||
pub mod util;
|
||||
pub mod protocol;
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue