mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
random fixes mostly related to auth and crypto
This commit is contained in:
parent
6188230009
commit
8813330359
10 changed files with 25 additions and 40 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -203,6 +203,7 @@ dependencies = [
|
|||
"env_logger",
|
||||
"log",
|
||||
"num-bigint",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"reqwest",
|
||||
"rsa",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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")]
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -342,7 +342,7 @@ impl Client {
|
|||
conn.write(
|
||||
ServerboundHelloPacket {
|
||||
name: account.username.clone(),
|
||||
profile_id: None,
|
||||
profile_id: account.uuid,
|
||||
}
|
||||
.get(),
|
||||
)
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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() {
|
||||
// //
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue