From f4dd3a9293367fa8f3d839a184e8055b22595204 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 24 Apr 2022 22:46:41 -0500 Subject: ENCRYPTION WORKS!!!!!!!!!!! --- azalea-protocol/src/write.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'azalea-protocol/src/write.rs') diff --git a/azalea-protocol/src/write.rs b/azalea-protocol/src/write.rs index 821ed6e8..e72a74b1 100755 --- a/azalea-protocol/src/write.rs +++ b/azalea-protocol/src/write.rs @@ -1,5 +1,6 @@ use crate::{mc_buf::Writable, packets::ProtocolPacket, read::MAXIMUM_UNCOMPRESSED_LENGTH}; use async_compression::tokio::bufread::ZlibEncoder; +use azalea_auth::encryption::Aes128Cfb; use tokio::{ io::{AsyncReadExt, AsyncWriteExt}, net::TcpStream, @@ -50,14 +51,22 @@ async fn compression_encoder(data: &[u8], compression_threshold: u32) -> Result< } } -pub async fn write_packet

(packet: P, stream: &mut TcpStream, compression_threshold: Option) -where +pub async fn write_packet

( + packet: P, + stream: &mut TcpStream, + compression_threshold: Option, + cipher: &mut Option, +) where P: ProtocolPacket + std::fmt::Debug, { let mut buf = packet_encoder(&packet).unwrap(); if let Some(threshold) = compression_threshold { buf = compression_encoder(&buf, threshold).await.unwrap(); } + // if we were given a cipher, encrypt the packet + if let Some(cipher) = cipher { + azalea_auth::encryption::encrypt_packet(cipher, &mut buf); + } buf = frame_prepender(&mut buf).unwrap(); stream.write_all(&buf).await.unwrap(); } -- cgit v1.2.3