lib.rs
1 use crate::client_hello::client_hello_handler; 2 use crate::server_hello::server_hello_handler; 3 4 mod macros; 5 mod client_hello; 6 mod server_hello; 7 8 //#[derive(Debug)] 9 //pub(crate) enum HttpsTls { 10 // ClientHello, 11 // ServerHello 12 // //NewSessionTicket {}, 13 // //EndOfEarlyData {}, 14 // //EncryptedExtensions {}, 15 // //Certificate {}, 16 // //CertificateRequest {}, 17 // //CertificateVerify {}, 18 // //Finished {}, 19 // //KeyUpdate {}, 20 // //MessageHash {}, 21 //} 22 23 #[derive(Debug)] 24 pub(crate) struct ClientHello { 25 content_type: u8, 26 version: u16, 27 length: u16, 28 handshake: Box<HandshakeProtocol>, 29 } 30 31 #[derive(Debug)] 32 pub(crate) struct ServerHello { 33 legacy_version: u16, // must be TLS v1.2 (0x0303) 34 random: Vec<u8>, // 32 bytes generated by a secure random generator 35 legacy_session_id_echo: Vec<u8>, // contents of the client's legacy_session_id field 36 } 37 38 #[derive(Debug)] 39 pub(crate) struct HandshakeProtocol { 40 pub(crate) handshake_type: u8, 41 pub(crate) length: u32, 42 pub(crate) version: u16, 43 pub(crate) random: Vec<u8>, 44 pub(crate) session_id_length: u8, 45 pub(crate) legacy_session_id: Vec<u8>, 46 pub(crate) cipher_suites_length: u16, 47 pub(crate) cipher_suites: Vec<u16>, // list of symmetric cipher options, defined in descending order of client preference 48 pub(crate) compression_methods_length: u8, 49 pub(crate) legacy_compression_methods: Vec<u8>, 50 pub(crate) extensions_length: u16, 51 pub(crate) extensions: Vec<ChExtension>, 52 } 53 54 /// TLS 1.3 ONLY! 55 #[derive(Debug)] 56 pub(crate) enum ChExtension { 57 ServerName { 58 extension_type: u16, 59 length: u16, 60 server_name_indication_extension: Vec<(u16, u8, u16, Vec<u8>)>, 61 }, 62 MaxFragmentLength {}, // NOT NEEDED 63 StatusRequest { 64 extension_type: u16, 65 length: u16, 66 certificate_status_type: u8, 67 responder_id_list_length: u16, 68 request_extensions_length: u16, 69 }, 70 SupportedGroups { 71 extension_type: u16, 72 length: u16, 73 supported_groups_list_length: u16, 74 supported_groups: Vec<u16>, 75 }, 76 SignatureAlgorithms { 77 extension_type: u16, 78 length: u16, 79 signature_hash_algorithms_length: u16, 80 signature_hash_algorithms: Vec<(u8, u8)>, 81 }, 82 UseSrtp {}, // ONLY USED FOR RTP AND RTCP 83 Heartbeat {}, 84 ApplicationLayerProtocolNegotiation { 85 extension_type: u16, 86 length: u16, 87 alpn_extension_length: u16, 88 alpn_protocol: Vec<(u8, String)>, 89 }, 90 SignedCertificateTimestamp {}, 91 ClientCertificateType {}, 92 ServerCertificateType {}, 93 Padding {}, 94 PreSharedKey {}, 95 EarlyData {}, 96 SupportedVersions { 97 extension_type: u16, 98 length: u16, 99 supported_versions_length: u8, 100 supported_versions: Vec<u16>, 101 }, 102 Cookie {}, 103 PskKeyExchangeModes { 104 extension_type: u16, 105 length: u16, 106 psk_key_exchange_modes_length: u8, 107 psk_key_exchange_mode: Vec<u8>, 108 }, 109 CertificateAuthorities {}, 110 OidFilters {}, 111 PostHandshakeAuth {}, 112 SignatureAlgorithmsCert {}, 113 KeyShare { 114 extension_type: u16, 115 length: u16, 116 client_key_share_length: u16, 117 key_share_extensions: Vec<(u16, u16, Vec<u8>)>, 118 }, 119 } 120 121 122 pub fn tls_handler(buffer: Vec<u8>) { 123 // check if there is a type :3 124 match buffer.first() { 125 Some(num) => { 126 match num { 127 22 => { 128 let client_hello = client_hello_handler(buffer); 129 server_hello_handler(client_hello); 130 } 131 _ => eprintln_red!("No clue what kind of tls message this is, are you feeling well? || type: {}", buffer[0]), 132 } 133 } 134 _ => eprintln_red!("No clue what kind of tls message this is, are you feeling well? || type: {}", buffer[0]), 135 } 136 }