From 7531ea7b315416507c564f31ec8a5a3b52005145 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 7 Aug 2022 12:42:06 -0700 Subject: [PATCH] Add LoginStart_Sig, EncryptionResponse_Sig --- protocol/src/protocol/packet.rs | 21 ++++++++++++++++++- protocol/src/protocol/versions/v1_19.rs | 4 ++-- src/server/mod.rs | 28 +++++++++++++++++++++---- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/protocol/src/protocol/packet.rs b/protocol/src/protocol/packet.rs index eacd692..07214ab 100644 --- a/protocol/src/protocol/packet.rs +++ b/protocol/src/protocol/packet.rs @@ -2359,15 +2359,34 @@ state_packets!( } login Login { serverbound Serverbound { - /// LoginStart is sent immeditately after switching into the login + /// LoginStart is sent immediately after switching into the login /// state. The passed username is used by the server to authenticate /// the player in online mode. + packet LoginStart_Sig { + field username: String =, + field has_sign_data: bool =, + field timestamp: Option = when(|p: &LoginStart_Sig| p.has_sign_data), + field public_key: Option> = when(|p: &LoginStart_Sig| p.has_sign_data), + field signature: Option> = when(|p: &LoginStart_Sig| p.has_sign_data), + } packet LoginStart { field username: String =, } /// EncryptionResponse is sent as a reply to EncryptionRequest. All /// packets following this one must be encrypted with AES/CFB8 /// encryption. + packet EncryptionResponse_Sig { + /// The key for the AES/CFB8 cipher encrypted with the + /// public key + field shared_secret: LenPrefixedBytes =, + /// Whether or not the Verify Token should be sent. If not, then the salt and signature will be sent. + field has_verify_token: bool =, + /// The verify token from the request encrypted with the + /// public key + field verify_token: Option> = when(|p: &EncryptionResponse_Sig| p.has_verify_token), + field salt: Option = when(|p: &EncryptionResponse_Sig| !p.has_verify_token), + field signature: Option> = when(|p: &EncryptionResponse_Sig| !p.has_verify_token), + } packet EncryptionResponse { /// The key for the AES/CFB8 cipher encrypted with the /// public key diff --git a/protocol/src/protocol/versions/v1_19.rs b/protocol/src/protocol/versions/v1_19.rs index fc330b7..04af739 100644 --- a/protocol/src/protocol/versions/v1_19.rs +++ b/protocol/src/protocol/versions/v1_19.rs @@ -166,8 +166,8 @@ protocol_packet_ids!( } login Login { serverbound Serverbound { - 0x00 => LoginStart - 0x01 => EncryptionResponse + 0x00 => LoginStart_Sig + 0x01 => EncryptionResponse_Sig 0x02 => LoginPluginResponse } clientbound Clientbound { diff --git a/src/server/mod.rs b/src/server/mod.rs index 54731bc..093f9ae 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -132,9 +132,19 @@ impl Server { next: protocol::VarInt(2), })?; conn.state = protocol::State::Login; - conn.write_packet(protocol::packet::login::serverbound::LoginStart { - username: profile.username.clone(), - })?; + if protocol_version >= 759 { + conn.write_packet(protocol::packet::login::serverbound::LoginStart_Sig { + username: profile.username.clone(), + has_sign_data: false, + public_key: None, + signature: None, + timestamp: None, + })?; + } else { + conn.write_packet(protocol::packet::login::serverbound::LoginStart { + username: profile.username.clone(), + })?; + } use std::rc::Rc; let (server_id, public_key, verify_token); @@ -207,7 +217,17 @@ impl Server { profile.join_server(&server_id, &shared, &public_key)?; } - if protocol_version >= 47 { + if protocol_version >= 759 { + conn.write_packet( + protocol::packet::login::serverbound::EncryptionResponse_Sig { + shared_secret: protocol::LenPrefixedBytes::new(shared_e), + verify_token: Some(protocol::LenPrefixedBytes::new(token_e)), + has_verify_token: true, + salt: None, + signature: None, + }, + )?; + } else if protocol_version >= 47 { conn.write_packet(protocol::packet::login::serverbound::EncryptionResponse { shared_secret: protocol::LenPrefixedBytes::new(shared_e), verify_token: protocol::LenPrefixedBytes::new(token_e),