#![allow(clippy::ptr_arg)]
#![allow(dead_code)]
use puffin::algebra::error::FnError;
use crate::nyi_fn;
use crate::tls::rustls::key;
use crate::tls::rustls::msgs::alert::AlertMessagePayload;
use crate::tls::rustls::msgs::base::{Payload, PayloadU16, PayloadU24, PayloadU8};
use crate::tls::rustls::msgs::ccs::ChangeCipherSpecPayload;
use crate::tls::rustls::msgs::enums::*;
use crate::tls::rustls::msgs::handshake::{
CertificateEntry, CertificateStatus, HelloRetryExtension, *,
};
use crate::tls::rustls::msgs::heartbeat::HeartbeatPayload;
use crate::tls::rustls::msgs::message::{Message, MessagePayload, OpaqueMessage};
pub fn fn_opaque_message(message: &OpaqueMessage) -> Result<OpaqueMessage, FnError> {
Ok(message.clone())
}
pub fn fn_empty_handshake_message() -> Result<OpaqueMessage, FnError> {
Ok(OpaqueMessage {
typ: ContentType::Handshake,
version: ProtocolVersion::TLSv1_2,
payload: Payload::empty(),
})
}
pub fn fn_alert_close_notify() -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Alert(AlertMessagePayload {
level: AlertLevel::Warning,
description: AlertDescription::CloseNotify,
}),
})
}
pub fn fn_change_cipher_spec() -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::ChangeCipherSpec(ChangeCipherSpecPayload {}),
})
}
pub fn fn_application_data(data: &Vec<u8>) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::ApplicationData(Payload::new(data.clone())),
})
}
pub fn fn_heartbeat_fake_length(payload: &Vec<u8>, fake_length: &u64) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Heartbeat(HeartbeatPayload {
typ: HeartbeatMessageType::Request,
payload: PayloadU16::new(payload.clone()),
fake_length: Some(*fake_length as u16),
}),
})
}
pub fn fn_heartbeat(payload: &Vec<u8>) -> Result<Message, FnError> {
fn_heartbeat_fake_length(payload, &(payload.len() as u64))
}
pub fn fn_hello_request() -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::HelloRequest,
payload: HandshakePayload::HelloRequest,
}),
})
}
pub fn fn_client_hello(
client_version: &ProtocolVersion,
random: &Random,
session_id: &SessionID,
cipher_suites: &Vec<CipherSuite>,
compression_methods: &Vec<Compression>,
extensions: &Vec<ClientExtension>,
) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::ClientHello,
payload: HandshakePayload::ClientHello(ClientHelloPayload {
client_version: *client_version,
random: *random,
session_id: *session_id,
cipher_suites: cipher_suites.clone(),
compression_methods: compression_methods.clone(),
extensions: extensions.clone(),
}),
}),
})
}
pub fn fn_server_hello(
legacy_version: &ProtocolVersion,
random: &Random,
session_id: &SessionID,
cipher_suite: &CipherSuite,
compression_method: &Compression,
extensions: &Vec<ServerExtension>,
) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::ServerHello,
payload: HandshakePayload::ServerHello(ServerHelloPayload {
legacy_version: *legacy_version,
random: *random,
session_id: *session_id,
cipher_suite: *cipher_suite,
compression_method: *compression_method,
extensions: extensions.clone(),
}),
}),
})
}
nyi_fn! {
}
pub fn fn_new_session_ticket(lifetime_hint: &u32, ticket: &Vec<u8>) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::NewSessionTicket,
payload: HandshakePayload::NewSessionTicket(NewSessionTicketPayload {
lifetime_hint: *lifetime_hint,
ticket: PayloadU16::new(ticket.clone()),
}),
}),
})
}
pub fn fn_new_session_ticket13(
nonce: &Vec<u8>,
ticket: &Vec<u8>,
extensions: &Vec<NewSessionTicketExtension>,
) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::NewSessionTicket,
payload: HandshakePayload::NewSessionTicketTLS13(NewSessionTicketPayloadTLS13 {
lifetime: 10,
age_add: 12,
nonce: PayloadU8::new(nonce.clone()),
ticket: PayloadU16::new(ticket.clone()),
exts: NewSessionTicketExtensions(extensions.clone()),
}),
}),
})
}
nyi_fn! {
}
pub fn fn_hello_retry_request(
legacy_version: &ProtocolVersion,
session_id: &SessionID,
cipher_suite: &CipherSuite,
extensions: &Vec<HelloRetryExtension>,
) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::HelloRetryRequest,
payload: HandshakePayload::HelloRetryRequest(HelloRetryRequest {
legacy_version: *legacy_version,
session_id: *session_id,
cipher_suite: *cipher_suite,
extensions: extensions.clone(),
}),
}),
})
}
pub fn fn_encrypted_extensions(
server_extensions: &Vec<ServerExtension>,
) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::EncryptedExtensions,
payload: HandshakePayload::EncryptedExtensions(EncryptedExtensions(
server_extensions.clone(),
)),
}),
})
}
nyi_fn! {
}
nyi_fn! {
}
pub fn fn_certificate(certs: &Vec<key::Certificate>) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::Certificate,
payload: HandshakePayload::Certificate(CertificatePayload(certs.clone())),
}),
})
}
pub fn fn_certificate13(
context: &Vec<u8>,
entries: &Vec<CertificateEntry>,
) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::Certificate,
payload: HandshakePayload::CertificateTLS13(CertificatePayloadTLS13 {
context: PayloadU8::new(context.clone()),
entries: entries.clone(),
}),
}),
})
}
pub fn fn_server_key_exchange(data: &Vec<u8>) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::ServerKeyExchange,
payload: HandshakePayload::ServerKeyExchange(ServerKeyExchangePayload::Unknown(
Payload::new(data.clone()),
)),
}),
})
}
pub fn fn_certificate_request() -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::CertificateRequest,
payload: HandshakePayload::CertificateRequest(CertificateRequestPayload {
certtypes: ClientCertificateTypes(vec![ClientCertificateType::RSASign]),
sigschemes: SupportedSignatureSchemes(vec![SignatureScheme::ED25519]),
canames: VecU16OfPayloadU16(vec![PayloadU16::new(
"some ca name?".as_bytes().to_vec(),
)]),
}),
}),
})
}
pub fn fn_certificate_request13(
context: &Vec<u8>,
extensions: &Vec<CertReqExtension>,
) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::CertificateRequest,
payload: HandshakePayload::CertificateRequestTLS13(CertificateRequestPayloadTLS13 {
context: PayloadU8::new(context.clone()),
extensions: CertReqExtensions(extensions.clone()),
}),
}),
})
}
pub fn fn_server_hello_done() -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::ServerHelloDone,
payload: HandshakePayload::ServerHelloDone,
}),
})
}
pub fn fn_certificate_verify(
scheme: &SignatureScheme,
signature: &Vec<u8>,
) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::CertificateVerify,
payload: HandshakePayload::CertificateVerify(DigitallySignedStruct {
scheme: *scheme,
sig: PayloadU16::new(signature.clone()),
}),
}),
})
}
pub fn fn_client_key_exchange(encoded_pubkey_data: &Vec<u8>) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::ClientKeyExchange,
payload: HandshakePayload::ClientKeyExchange(Payload::new(encoded_pubkey_data.clone())),
}),
})
}
pub fn fn_finished(verify_data: &Vec<u8>) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::Finished,
payload: HandshakePayload::Finished(Payload::new(verify_data.clone())),
}),
})
}
nyi_fn! {
}
pub fn fn_certificate_status(ocsp_response: &Vec<u8>) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::CertificateStatus,
payload: HandshakePayload::CertificateStatus(CertificateStatus {
ocsp_response: PayloadU24::new(ocsp_response.clone()),
}),
}),
})
}
pub fn fn_key_update() -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::KeyUpdate,
payload: HandshakePayload::KeyUpdate(KeyUpdateRequest::UpdateRequested),
}),
})
}
pub fn fn_key_update_not_requested() -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::KeyUpdate,
payload: HandshakePayload::KeyUpdate(KeyUpdateRequest::UpdateNotRequested),
}),
})
}
nyi_fn! {
}
nyi_fn! {
}
pub fn fn_message_hash(hash: &Vec<u8>) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::MessageHash,
payload: HandshakePayload::MessageHash(Payload::new(hash.clone())),
}),
})
}