diff options
| author | mat <git@matdoes.dev> | 2023-05-27 01:57:31 -0500 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-05-27 01:57:31 -0500 |
| commit | 881333035987867f897042df7173bb2fa05b7621 (patch) | |
| tree | 283d44ea32bcb9119ec9546dcde59477012fc3bc /azalea-auth/src | |
| parent | 6188230009b49f96b755ade32a28b932e7810196 (diff) | |
| download | azalea-drasl-881333035987867f897042df7173bb2fa05b7621.tar.xz | |
random fixes mostly related to auth and crypto
Diffstat (limited to 'azalea-auth/src')
| -rw-r--r-- | azalea-auth/src/certs.rs | 24 | ||||
| -rwxr-xr-x | azalea-auth/src/sessionserver.rs | 5 |
2 files changed, 11 insertions, 18 deletions
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(), |
