aboutsummaryrefslogtreecommitdiff
path: root/azalea-auth/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-04-24 19:28:29 -0500
committermat <github@matdoes.dev>2022-04-24 19:28:29 -0500
commit4c00bd886578c70f6aeb35400d9d03b355df3155 (patch)
treef4903dd0b8f9690a6c52a180babd56d12c3926c0 /azalea-auth/src
parent3e507f0db4020eaf406ba69aae3d4dc1301d29ac (diff)
downloadazalea-drasl-4c00bd886578c70f6aeb35400d9d03b355df3155.tar.xz
Add ServerboundKeyPacket
Diffstat (limited to 'azalea-auth/src')
-rw-r--r--azalea-auth/src/encryption.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/azalea-auth/src/encryption.rs b/azalea-auth/src/encryption.rs
index 334d8cb3..72739620 100644
--- a/azalea-auth/src/encryption.rs
+++ b/azalea-auth/src/encryption.rs
@@ -24,9 +24,28 @@ fn hex_digest(digest: &[u8]) -> String {
num_bigint::BigInt::from_signed_bytes_be(digest).to_str_radix(16)
}
-fn encrypt(public_key: &[u8], server_id: String, nonce: &[u8]) {
+pub struct EncryptResult {
+ pub encrypted_public_key: Vec<u8>,
+ pub encrypted_nonce: Vec<u8>,
+}
+
+pub fn encrypt(public_key: &[u8], nonce: &[u8]) -> Result<EncryptResult, String> {
+ // On receipt of a Encryption Request from the server, the client will
+ // generate a random 16-byte shared secret, to be used with the AES/CFB8
+ // stream cipher.
let secret_key = generate_secret_key();
- let hash = hex_digest(&digest_data(server_id.as_bytes(), public_key, &secret_key));
+ // let hash = hex_digest(&digest_data(server_id.as_bytes(), public_key, &secret_key));
+
+ // this.keybytes = Crypt.encryptUsingKey(publicKey, secretKey.getEncoded());
+ // this.nonce = Crypt.encryptUsingKey(publicKey, arrby);
+ let encrypted_public_key: Vec<u8> =
+ rsa_public_encrypt_pkcs1::encrypt(&public_key, &secret_key)?;
+ let encrypted_nonce: Vec<u8> = rsa_public_encrypt_pkcs1::encrypt(&public_key, &nonce)?;
+
+ Ok(EncryptResult {
+ encrypted_public_key,
+ encrypted_nonce,
+ })
}
#[cfg(test)]