#![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::{CertificateStatus, *};
use crate::tls::rustls::msgs::heartbeat::HeartbeatPayload;
use crate::tls::rustls::msgs::message::{Message, MessagePayload, OpaqueMessage};
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: &PayloadU16,
fake_length: &u64,
) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Heartbeat(HeartbeatPayload {
typ: HeartbeatMessageType::Request,
payload: payload.clone(),
fake_length: Some(*fake_length as u16),
}),
})
}
pub fn fn_heartbeat(payload: &PayloadU16) -> Result<Message, FnError> {
fn_heartbeat_fake_length(payload, &(payload.0.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: &CipherSuites,
compression_methods: &Compressions,
extensions: &ClientExtensions,
) -> 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: &ServerExtensions,
) -> 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: &PayloadU16) -> 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: ticket.clone(),
}),
}),
})
}
pub fn fn_new_session_ticket_extensions(
extensions: &Vec<NewSessionTicketExtension>,
) -> Result<NewSessionTicketExtensions, FnError> {
Ok(NewSessionTicketExtensions(extensions.clone()))
}
pub fn fn_new_session_ticket13(
nonce: &PayloadU8,
ticket: &PayloadU16,
extensions: &NewSessionTicketExtensions,
) -> 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: nonce.clone(),
ticket: ticket.clone(),
exts: extensions.clone(),
}),
}),
})
}
nyi_fn! {
}
pub fn fn_hello_retry_request_random() -> Result<Random, FnError> {
Ok(Random([
0xcf, 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e, 0x65, 0xb8,
0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07, 0x9e, 0x09, 0xe2, 0xc8, 0xa8,
0x33, 0x9c,
]))
}
pub fn fn_hello_retry_request(
legacy_version: &ProtocolVersion,
random: &Random,
session_id: &SessionID,
cipher_suite: &CipherSuite,
compression_methods: &Compressions,
extensions: &HelloRetryExtensions,
) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::HelloRetryRequest,
payload: HandshakePayload::HelloRetryRequest(HelloRetryRequest {
legacy_version: *legacy_version,
random: *random,
session_id: *session_id,
cipher_suite: *cipher_suite,
compression_methods: compression_methods.clone(),
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: &PayloadU8,
entries: &CertificateEntries,
) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::Certificate,
payload: HandshakePayload::CertificateTLS13(CertificatePayloadTLS13 {
context: 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: &PayloadU8,
extensions: &Vec<CertReqExtension>,
) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::CertificateRequest,
payload: HandshakePayload::CertificateRequestTLS13(CertificateRequestPayloadTLS13 {
context: 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_payload_u8(vec: &Vec<u8>) -> Result<PayloadU8, FnError> {
Ok(PayloadU8::new(vec.clone()))
}
pub fn fn_payload_u16(vec: &Vec<u8>) -> Result<PayloadU16, FnError> {
Ok(PayloadU16::new(vec.clone()))
}
pub fn fn_payload_u24(vec: &Vec<u8>) -> Result<PayloadU24, FnError> {
Ok(PayloadU24::new(vec.clone()))
}
pub fn fn_empty_payload_u16_vec() -> Result<Vec<PayloadU16>, FnError> {
Ok(vec![])
}
pub fn fn_append_payload_u16_vec(
p: &PayloadU16,
vec: &Vec<PayloadU16>,
) -> Result<Vec<PayloadU16>, FnError> {
let mut vec = vec.clone();
vec.push(p.clone());
Ok(vec)
}
pub fn fn_make_payload_u16_vec_u16(vec: &Vec<PayloadU16>) -> Result<VecU16OfPayloadU16, FnError> {
Ok(VecU16OfPayloadU16(vec.clone()))
}
pub fn fn_empty_payload_u8_vec() -> Result<Vec<PayloadU8>, FnError> {
Ok(vec![])
}
pub fn fn_append_payload_u8_vec(
p: &PayloadU8,
vec: &Vec<PayloadU8>,
) -> Result<Vec<PayloadU8>, FnError> {
let mut vec = vec.clone();
vec.push(p.clone());
Ok(vec)
}
pub fn fn_make_payload_u8_vec_u16(vec: &Vec<PayloadU8>) -> Result<VecU16OfPayloadU8, FnError> {
Ok(VecU16OfPayloadU8(vec.clone()))
}
pub fn fn_certificate_verify(
scheme: &SignatureScheme,
signature: &PayloadU16,
) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::CertificateVerify,
payload: HandshakePayload::CertificateVerify(DigitallySignedStruct {
scheme: *scheme,
sig: 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: &PayloadU24) -> Result<Message, FnError> {
Ok(Message {
version: ProtocolVersion::TLSv1_2,
payload: MessagePayload::Handshake(HandshakeMessagePayload {
typ: HandshakeType::CertificateStatus,
payload: HandshakePayload::CertificateStatus(CertificateStatus {
ocsp_response: 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())),
}),
})
}