diff options
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | azalea-auth/Cargo.toml | 1 | ||||
| -rw-r--r-- | azalea-auth/src/certs.rs | 24 | ||||
| -rwxr-xr-x | azalea-auth/src/sessionserver.rs | 5 | ||||
| -rw-r--r-- | azalea-client/src/client.rs | 2 | ||||
| -rw-r--r-- | azalea-client/src/interact.rs | 5 | ||||
| -rw-r--r-- | azalea-client/src/mining.rs | 8 | ||||
| -rwxr-xr-x | azalea-crypto/src/signing.rs | 10 | ||||
| -rwxr-xr-x | azalea/examples/echo.rs | 7 | ||||
| -rw-r--r-- | azalea/examples/steal.rs | 2 |
10 files changed, 25 insertions, 40 deletions
@@ -203,6 +203,7 @@ dependencies = [ "env_logger", "log", "num-bigint", + "once_cell", "parking_lot", "reqwest", "rsa", diff --git a/azalea-auth/Cargo.toml b/azalea-auth/Cargo.toml index bf557dc9..71c64716 100644 --- a/azalea-auth/Cargo.toml +++ b/azalea-auth/Cargo.toml @@ -15,6 +15,7 @@ base64 = "0.21.2" chrono = { version = "0.4.22", default-features = false, features = ["serde"] } log = "0.4.17" num-bigint = "0.4.3" +once_cell = "1.17.1" parking_lot = "0.12.1" reqwest = { version = "0.11.12", default-features = false, features = [ "json", diff --git a/azalea-auth/src/certs.rs b/azalea-auth/src/certs.rs index 809a10c6..6030b886 100644 --- a/azalea-auth/src/certs.rs +++ b/azalea-auth/src/certs.rs @@ -55,14 +55,11 @@ pub async fn fetch_certificates( .unwrap(); // the private key also contains the public key so it's basically a keypair - let key_pair = RsaPrivateKey::from_pkcs8_der(&private_key_der).unwrap(); + let private_key = RsaPrivateKey::from_pkcs8_der(&private_key_der).unwrap(); let certificates = Certificates { - key_pair, - key_pair_bytes: KeyPairBytes { - private_key: private_key_der, - public_key: public_key_der, - }, + private_key, + public_key_der, signature_v1: base64::engine::general_purpose::STANDARD .decode(&res.public_key_signature) @@ -81,10 +78,10 @@ pub async fn fetch_certificates( /// A chat signing certificate. #[derive(Clone, Debug)] pub struct Certificates { - /// The RSA private and public key. - pub key_pair: RsaPrivateKey, - /// The keypair as DER-encoded bytes. - pub key_pair_bytes: KeyPairBytes, + /// The RSA private key. + pub private_key: RsaPrivateKey, + /// The RSA public key encoded as DER. + pub public_key_der: Vec<u8>, pub signature_v1: Vec<u8>, pub signature_v2: Vec<u8>, @@ -93,13 +90,6 @@ pub struct Certificates { pub refresh_after: DateTime<Utc>, } -/// A keypair as DER-encoded bytes. -#[derive(Clone, Debug)] -pub struct KeyPairBytes { - pub private_key: Vec<u8>, - pub public_key: Vec<u8>, -} - #[derive(Debug, Deserialize)] pub struct CertificatesResponse { #[serde(rename = "keyPair")] diff --git a/azalea-auth/src/sessionserver.rs b/azalea-auth/src/sessionserver.rs index 5eefb292..e82e55d6 100755 --- a/azalea-auth/src/sessionserver.rs +++ b/azalea-auth/src/sessionserver.rs @@ -1,5 +1,6 @@ //! Tell Mojang you're joining a multiplayer server. use log::debug; +use once_cell::sync::Lazy; use reqwest::StatusCode; use serde::Deserialize; use serde_json::json; @@ -48,6 +49,8 @@ pub struct ForbiddenError { pub path: String, } +static REQWEST_CLIENT: Lazy<reqwest::Client> = Lazy::new(|| reqwest::Client::new()); + /// Tell Mojang's servers that you are going to join a multiplayer server, /// which is required to join online-mode servers. The server ID is an empty /// string. @@ -58,7 +61,7 @@ pub async fn join( uuid: &Uuid, server_id: &str, ) -> Result<(), ClientSessionServerError> { - let client = reqwest::Client::new(); + let client = REQWEST_CLIENT.clone(); let server_hash = azalea_crypto::hex_digest(&azalea_crypto::digest_data( server_id.as_bytes(), diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index 739ec434..fb977f36 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -342,7 +342,7 @@ impl Client { conn.write( ServerboundHelloPacket { name: account.username.clone(), - profile_id: None, + profile_id: account.uuid, } .get(), ) diff --git a/azalea-client/src/interact.rs b/azalea-client/src/interact.rs index afb55bbf..a6b8e061 100644 --- a/azalea-client/src/interact.rs +++ b/azalea-client/src/interact.rs @@ -23,7 +23,6 @@ use derive_more::{Deref, DerefMut}; use log::warn; use crate::{ - client::PlayerAbilities, inventory::InventoryComponent, local_player::{handle_send_packet_event, LocalGameMode}, Client, LocalPlayer, @@ -235,7 +234,7 @@ pub fn check_is_interaction_restricted( /// Check if the item has the `CanDestroy` tag for the block. pub fn check_block_can_be_broken_by_item_in_adventure_mode( item: &ItemSlotData, - block: &BlockState, + _block: &BlockState, ) -> bool { // minecraft caches the last checked block but that's kind of an unnecessary // optimization and makes the code too complicated @@ -249,7 +248,7 @@ pub fn check_block_can_be_broken_by_item_in_adventure_mode( return false; }; - let NbtList::String(can_destroy) = can_destroy else { + let NbtList::String(_can_destroy) = can_destroy else { // CanDestroy tag must be a list of strings return false; }; diff --git a/azalea-client/src/mining.rs b/azalea-client/src/mining.rs index 5af9a20b..ab141661 100644 --- a/azalea-client/src/mining.rs +++ b/azalea-client/src/mining.rs @@ -28,8 +28,8 @@ pub struct StartMiningBlockEvent { pub position: BlockPos, } -fn handle_start_mining_block_event(mut events: EventReader<StartMiningBlockEvent>) { - for event in events.iter() { - // - } +fn handle_start_mining_block_event(mut _events: EventReader<StartMiningBlockEvent>) { + // for event in events.iter() { + // // + // } } diff --git a/azalea-crypto/src/signing.rs b/azalea-crypto/src/signing.rs index ebab4356..5ecafa46 100755 --- a/azalea-crypto/src/signing.rs +++ b/azalea-crypto/src/signing.rs @@ -82,22 +82,12 @@ pub fn sign_chat_message(opts: &SignChatMessageOptions) -> MessageSignature { // signatures of last seen messages // ... not implemented yet - // hash with sha256 and then sign with rsa - - // let mut hasher = Sha256::new(); - // hasher.update(data_to_sign.as_slice()); - // let hash = hasher.finalize(); - - // println!("hash: {:?}", hash); - let signing_key = rsa::pkcs1v15::SigningKey::<Sha256>::new(opts.private_key.clone()); let mut rng = rand::thread_rng(); let signature = signing_key .sign_with_rng(&mut rng, &data_to_sign) .to_bytes(); - println!("signature: {:?}", signature); - MessageSignature { bytes: signature .as_ref() diff --git a/azalea/examples/echo.rs b/azalea/examples/echo.rs index 292e12cd..8cbd15f7 100755 --- a/azalea/examples/echo.rs +++ b/azalea/examples/echo.rs @@ -4,12 +4,12 @@ use azalea::prelude::*; #[tokio::main] async fn main() { - let account = Account::offline("bot"); - // or let account = Account::microsoft("email").await; + // let account = Account::offline("bot"); + let account = Account::microsoft("minecraft3@matdoes.dev").await.unwrap(); ClientBuilder::new() .set_handler(handle) - .start(account, "localhost") + .start(account, "85.190.131.233") .await .unwrap(); } @@ -18,6 +18,7 @@ async fn main() { pub struct State {} async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> { + std::process::exit(0); match event { Event::Chat(m) => { if let (Some(sender), content) = m.split_sender_and_content() { diff --git a/azalea/examples/steal.rs b/azalea/examples/steal.rs index 3302079a..7a7ee4bb 100644 --- a/azalea/examples/steal.rs +++ b/azalea/examples/steal.rs @@ -9,7 +9,7 @@ use std::sync::Arc; #[tokio::main] async fn main() { let account = Account::offline("bot"); - // or let bot = Account::microsoft("email").await; + // or let bot = Account::microsoft("email").await.unwrap(); ClientBuilder::new() .set_handler(handle) |
