azalea_auth::encryption -> azalea_crypto

This commit is contained in:
mat 2022-04-30 21:30:45 -05:00
parent cc70d80932
commit 80d49a7607
13 changed files with 49 additions and 27 deletions

36
Cargo.lock generated
View file

@ -75,12 +75,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
name = "azalea-auth" name = "azalea-auth"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"aes",
"cfb8",
"num-bigint", "num-bigint",
"rand",
"rsa_public_encrypt_pkcs1",
"sha-1",
"uuid", "uuid",
] ]
@ -102,6 +97,7 @@ name = "azalea-client"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"azalea-auth", "azalea-auth",
"azalea-crypto",
"azalea-protocol", "azalea-protocol",
"tokio", "tokio",
] ]
@ -115,6 +111,18 @@ dependencies = [
"uuid", "uuid",
] ]
[[package]]
name = "azalea-crypto"
version = "0.1.0"
dependencies = [
"aes",
"cfb8",
"num-bigint",
"rand",
"rsa_public_encrypt_pkcs1",
"sha-1",
]
[[package]] [[package]]
name = "azalea-nbt" name = "azalea-nbt"
version = "0.1.0" version = "0.1.0"
@ -140,6 +148,7 @@ dependencies = [
"azalea-brigadier", "azalea-brigadier",
"azalea-chat", "azalea-chat",
"azalea-core", "azalea-core",
"azalea-crypto",
"azalea-nbt", "azalea-nbt",
"byteorder", "byteorder",
"bytes", "bytes",
@ -163,9 +172,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]] [[package]]
name = "block-buffer" name = "block-buffer"
version = "0.10.0" version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1d36a02058e76b040de25a4464ba1c80935655595b661505c8b39b664828b95" checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324"
dependencies = [ dependencies = [
"generic-array", "generic-array",
] ]
@ -404,13 +413,12 @@ checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57"
[[package]] [[package]]
name = "digest" name = "digest"
version = "0.10.1" version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b697d66081d42af4fba142d56918a3cb21dc8eb63372c6b85d14f44fb9c5979b" checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506"
dependencies = [ dependencies = [
"block-buffer", "block-buffer",
"crypto-common", "crypto-common",
"generic-array",
] ]
[[package]] [[package]]
@ -784,9 +792,9 @@ dependencies = [
[[package]] [[package]]
name = "num-complex" name = "num-complex"
version = "0.4.0" version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26873667bbbb7c5182d4a37c1add32cdf09f841af72da53318fdb81543c15085" checksum = "97fbc387afefefd5e9e39493299f3069e14a140dd34dc19b4c1c1a8fddb6a790"
dependencies = [ dependencies = [
"num-traits", "num-traits",
] ]
@ -814,9 +822,9 @@ dependencies = [
[[package]] [[package]]
name = "num-iter" name = "num-iter"
version = "0.1.42" version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"num-integer", "num-integer",

View file

@ -9,6 +9,7 @@ members = [
"azalea-auth", "azalea-auth",
"azalea-nbt", "azalea-nbt",
"azalea-brigadier", "azalea-brigadier",
"azalea-crypto",
] ]
[profile.release] [profile.release]

View file

@ -6,10 +6,5 @@ version = "0.1.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
aes = "0.8.1"
cfb8 = "0.8.1"
num-bigint = "^0.4.3" num-bigint = "^0.4.3"
rand = {version = "^0.8.4", features = ["getrandom"]}
rsa_public_encrypt_pkcs1 = "0.4.0"
sha-1 = "^0.10.0"
uuid = "^0.8.2" uuid = "^0.8.2"

View file

@ -1,4 +1,3 @@
//! Handle Minecraft authentication. //! Handle Minecraft authentication.
pub mod encryption;
pub mod game_profile; pub mod game_profile;

View file

@ -7,5 +7,6 @@ version = "0.1.0"
[dependencies] [dependencies]
azalea-auth = {path = "../azalea-auth"} azalea-auth = {path = "../azalea-auth"}
azalea-crypto = {path = "../azalea-crypto"}
azalea-protocol = {path = "../azalea-protocol"} azalea-protocol = {path = "../azalea-protocol"}
tokio = {version = "1.18.0", features = ["sync"]} tokio = {version = "1.18.0", features = ["sync"]}

View file

@ -74,7 +74,7 @@ impl Client {
Ok(packet) => match packet { Ok(packet) => match packet {
LoginPacket::ClientboundHelloPacket(p) => { LoginPacket::ClientboundHelloPacket(p) => {
println!("Got encryption request"); println!("Got encryption request");
let e = azalea_auth::encryption::encrypt(&p.public_key, &p.nonce).unwrap(); let e = azalea_crypto::encrypt(&p.public_key, &p.nonce).unwrap();
// TODO: authenticate with the server here (authenticateServer) // TODO: authenticate with the server here (authenticateServer)

14
azalea-crypto/Cargo.toml Normal file
View file

@ -0,0 +1,14 @@
[package]
edition = "2021"
name = "azalea-crypto"
version = "0.1.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
aes = "0.8.1"
cfb8 = "0.8.1"
num-bigint = "^0.4.3"
rand = {version = "^0.8.4", features = ["getrandom"]}
rsa_public_encrypt_pkcs1 = "0.4.0"
sha-1 = "^0.10.0"

3
azalea-crypto/README.md Normal file
View file

@ -0,0 +1,3 @@
# Azalea Crypto
Cryprography features used in Minecraft.

View file

@ -13,6 +13,7 @@ azalea-auth = {path = "../azalea-auth"}
azalea-brigadier = {path = "../azalea-brigadier"} azalea-brigadier = {path = "../azalea-brigadier"}
azalea-chat = {path = "../azalea-chat"} azalea-chat = {path = "../azalea-chat"}
azalea-core = {path = "../azalea-core"} azalea-core = {path = "../azalea-core"}
azalea-crypto = {path = "../azalea-crypto"}
azalea-nbt = {path = "../azalea-nbt"} azalea-nbt = {path = "../azalea-nbt"}
byteorder = "^1.4.3" byteorder = "^1.4.3"
bytes = "^1.1.0" bytes = "^1.1.0"

View file

@ -7,7 +7,7 @@ use crate::packets::status::StatusPacket;
use crate::read::read_packet; use crate::read::read_packet;
use crate::write::write_packet; use crate::write::write_packet;
use crate::ServerIpAddress; use crate::ServerIpAddress;
use azalea_auth::encryption::{Aes128CfbDec, Aes128CfbEnc}; use azalea_crypto::{Aes128CfbDec, Aes128CfbEnc};
use tokio::net::TcpStream; use tokio::net::TcpStream;
pub enum PacketFlow { pub enum PacketFlow {
@ -159,7 +159,7 @@ impl LoginConnection {
pub fn set_encryption_key(&mut self, key: [u8; 16]) { pub fn set_encryption_key(&mut self, key: [u8; 16]) {
// minecraft has a cipher decoder and encoder, i don't think it matters though? // minecraft has a cipher decoder and encoder, i don't think it matters though?
let (enc_cipher, dec_cipher) = azalea_auth::encryption::create_cipher(&key); let (enc_cipher, dec_cipher) = azalea_crypto::create_cipher(&key);
self.enc_cipher = Some(enc_cipher); self.enc_cipher = Some(enc_cipher);
self.dec_cipher = Some(dec_cipher); self.dec_cipher = Some(dec_cipher);
} }

View file

@ -6,7 +6,7 @@ use std::{
use crate::{connect::PacketFlow, mc_buf::Readable, packets::ProtocolPacket}; use crate::{connect::PacketFlow, mc_buf::Readable, packets::ProtocolPacket};
use async_compression::tokio::bufread::ZlibDecoder; use async_compression::tokio::bufread::ZlibDecoder;
use azalea_auth::encryption::Aes128CfbDec; use azalea_crypto::Aes128CfbDec;
use tokio::io::{AsyncRead, AsyncReadExt}; use tokio::io::{AsyncRead, AsyncReadExt};
async fn frame_splitter<R: ?Sized>(mut stream: &mut R) -> Result<Vec<u8>, String> async fn frame_splitter<R: ?Sized>(mut stream: &mut R) -> Result<Vec<u8>, String>
@ -122,7 +122,7 @@ where
// (but only on linux and release mode for some reason LMAO) // (but only on linux and release mode for some reason LMAO)
if buf.remaining() == 0 { if buf.remaining() == 0 {
if let Some(cipher) = self.as_mut().cipher.get_mut() { if let Some(cipher) = self.as_mut().cipher.get_mut() {
azalea_auth::encryption::decrypt_packet(cipher, buf.filled_mut()); azalea_crypto::decrypt_packet(cipher, buf.filled_mut());
} }
} }
match r { match r {

View file

@ -1,6 +1,6 @@
use crate::{mc_buf::Writable, packets::ProtocolPacket, read::MAXIMUM_UNCOMPRESSED_LENGTH}; use crate::{mc_buf::Writable, packets::ProtocolPacket, read::MAXIMUM_UNCOMPRESSED_LENGTH};
use async_compression::tokio::bufread::ZlibEncoder; use async_compression::tokio::bufread::ZlibEncoder;
use azalea_auth::encryption::Aes128CfbEnc; use azalea_crypto::Aes128CfbEnc;
use std::fmt::Debug; use std::fmt::Debug;
use tokio::{ use tokio::{
io::{AsyncReadExt, AsyncWrite, AsyncWriteExt}, io::{AsyncReadExt, AsyncWrite, AsyncWriteExt},
@ -67,7 +67,7 @@ pub async fn write_packet<P, W>(
} }
// if we were given a cipher, encrypt the packet // if we were given a cipher, encrypt the packet
if let Some(cipher) = cipher { if let Some(cipher) = cipher {
azalea_auth::encryption::encrypt_packet(cipher, &mut buf); azalea_crypto::encrypt_packet(cipher, &mut buf);
} }
buf = frame_prepender(&mut buf).unwrap(); buf = frame_prepender(&mut buf).unwrap();
stream.write_all(&buf).await.unwrap(); stream.write_all(&buf).await.unwrap();