mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 23:44:38 +00:00
try to do more work on auth signing (untested)
This commit is contained in:
parent
9d5299ccc1
commit
321e06f1e4
4 changed files with 101 additions and 56 deletions
29
Cargo.lock
generated
29
Cargo.lock
generated
|
@ -165,9 +165,11 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"azalea-buf",
|
"azalea-buf",
|
||||||
"base64",
|
"base64",
|
||||||
|
"byteorder",
|
||||||
"log",
|
"log",
|
||||||
"num-bigint 0.4.3",
|
"num-bigint 0.4.3",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
"ring",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sp-core",
|
"sp-core",
|
||||||
|
@ -2284,6 +2286,21 @@ dependencies = [
|
||||||
"quick-error",
|
"quick-error",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ring"
|
||||||
|
version = "0.16.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"once_cell",
|
||||||
|
"spin",
|
||||||
|
"untrusted",
|
||||||
|
"web-sys",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rsa_public_encrypt_pkcs1"
|
name = "rsa_public_encrypt_pkcs1"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
|
@ -2765,6 +2782,12 @@ dependencies = [
|
||||||
"wasmi",
|
"wasmi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "spin"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ss58-registry"
|
name = "ss58-registry"
|
||||||
version = "1.31.0"
|
version = "1.31.0"
|
||||||
|
@ -3195,6 +3218,12 @@ version = "0.2.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "untrusted"
|
||||||
|
version = "0.7.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "url"
|
name = "url"
|
||||||
version = "2.2.2"
|
version = "2.2.2"
|
||||||
|
|
|
@ -11,9 +11,11 @@ version = "0.1.0"
|
||||||
anyhow = "1.0.65"
|
anyhow = "1.0.65"
|
||||||
azalea-buf = { path = "../azalea-buf", version = "^0.1.0" }
|
azalea-buf = { path = "../azalea-buf", version = "^0.1.0" }
|
||||||
base64 = "0.13.0"
|
base64 = "0.13.0"
|
||||||
|
byteorder = "1.4.3"
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
num-bigint = "0.4.3"
|
num-bigint = "0.4.3"
|
||||||
reqwest = {version = "0.11.12", features = ["json"]}
|
reqwest = {version = "0.11.12", features = ["json"]}
|
||||||
|
ring = "0.16.20"
|
||||||
serde = {version = "1.0.145", features = ["derive"]}
|
serde = {version = "1.0.145", features = ["derive"]}
|
||||||
serde_json = "1.0.86"
|
serde_json = "1.0.86"
|
||||||
sp-core = "6.0.0"
|
sp-core = "6.0.0"
|
||||||
|
|
|
@ -9,6 +9,7 @@ use std::{
|
||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use azalea_buf::McBufWritable;
|
use azalea_buf::McBufWritable;
|
||||||
|
use byteorder::WriteBytesExt;
|
||||||
use num_bigint::BigUint;
|
use num_bigint::BigUint;
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -195,19 +196,19 @@ async fn auth_with_xbox_live(
|
||||||
"TokenType": "JWT"
|
"TokenType": "JWT"
|
||||||
});
|
});
|
||||||
let payload = auth_json.to_string();
|
let payload = auth_json.to_string();
|
||||||
let signature = sign(
|
// let signature = sign(
|
||||||
"https://user.auth.xboxlive.com/user/authenticate",
|
// "https://user.auth.xboxlive.com/user/authenticate",
|
||||||
"",
|
// "",
|
||||||
&payload,
|
// &payload,
|
||||||
)?;
|
// )?;
|
||||||
println!("auth_json: {:#?}", auth_json);
|
println!("auth_json: {:#?}", auth_json);
|
||||||
let res = client
|
let res = client
|
||||||
.post("https://user.auth.xboxlive.com/user/authenticate")
|
.post("https://user.auth.xboxlive.com/user/authenticate")
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
.header("Accept", "application/json")
|
.header("Accept", "application/json")
|
||||||
.header("x-xbl-contract-version", "2")
|
.header("x-xbl-contract-version", "1")
|
||||||
.header("Cache-Control", "no-store, must-revalidate, no-cache")
|
// .header("Cache-Control", "no-store, must-revalidate, no-cache")
|
||||||
.header("Signature", base64::encode(signature))
|
// .header("Signature", base64::encode(signature))
|
||||||
.body(payload)
|
.body(payload)
|
||||||
.send()
|
.send()
|
||||||
.await?
|
.await?
|
||||||
|
@ -306,61 +307,67 @@ async fn get_profile(
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
// from https://github.com/PrismarineJS/prismarine-auth/blob/master/src/TokenManagers/XboxTokenManager.js#L112
|
// // from https://github.com/PrismarineJS/prismarine-auth/blob/master/src/TokenManagers/XboxTokenManager.js#L112
|
||||||
fn sign(url: &str, authorization_token: &str, payload: &str) -> anyhow::Result<Vec<u8>> {
|
// fn sign(url: &str, authorization_token: &str, payload: &str) -> anyhow::Result<Vec<u8>> {
|
||||||
// const windowsTimestamp = (BigInt((Date.now() / 1000) | 0) + 11644473600n) * 10000000n
|
// // const windowsTimestamp = (BigInt((Date.now() / 1000) | 0) + 11644473600n) * 10000000n
|
||||||
// // Only the /uri?and-query-string
|
// // // Only the /uri?and-query-string
|
||||||
// const pathAndQuery = new URL(url).pathname
|
// // const pathAndQuery = new URL(url).pathname
|
||||||
|
|
||||||
// // Allocate the buffer for signature, TS, path, tokens and payload and NUL termination
|
// // // Allocate the buffer for signature, TS, path, tokens and payload and NUL termination
|
||||||
// const allocSize = /* sig */ 5 + /* ts */ 9 + /* POST */ 5 + pathAndQuery.length + 1 + authorizationToken.length + 1 + payload.length + 1
|
// // const allocSize = /* sig */ 5 + /* ts */ 9 + /* POST */ 5 + pathAndQuery.length + 1 + authorizationToken.length + 1 + payload.length + 1
|
||||||
// const buf = SmartBuffer.fromSize(allocSize)
|
// // const buf = SmartBuffer.fromSize(allocSize)
|
||||||
// buf.writeInt32BE(1) // Policy Version
|
// // buf.writeInt32BE(1) // Policy Version
|
||||||
// buf.writeUInt8(0)
|
// // buf.writeUInt8(0)
|
||||||
// buf.writeBigUInt64BE(windowsTimestamp)
|
// // buf.writeBigUInt64BE(windowsTimestamp)
|
||||||
// buf.writeUInt8(0) // null term
|
// // buf.writeUInt8(0) // null term
|
||||||
// buf.writeStringNT('POST')
|
// // buf.writeStringNT('POST')
|
||||||
// buf.writeStringNT(pathAndQuery)
|
// // buf.writeStringNT(pathAndQuery)
|
||||||
// buf.writeStringNT(authorizationToken)
|
// // buf.writeStringNT(authorizationToken)
|
||||||
// buf.writeStringNT(payload)
|
// // buf.writeStringNT(payload)
|
||||||
|
|
||||||
let windows_timestamp =
|
// let windows_timestamp: BigUint =
|
||||||
BigUint::from((SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() + 11644473600))
|
// BigUint::from(SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() + 11644473600)
|
||||||
* 10000000;
|
// * 10000000;
|
||||||
let path_and_query = Url::parse(url)?.path();
|
// let path_and_query = Url::parse(url)?.path();
|
||||||
let mut buf = Vec::new();
|
// let mut buf = Vec::new();
|
||||||
1u32.write_into(&mut buf)?; // policy version
|
// buf.write_u32(1); // policy version
|
||||||
0u8.write_into(&mut buf)?;
|
// buf.write_u8(0);
|
||||||
windows_timestamp.write_into(&mut buf)?;
|
// buf.write_u64(windows_timestamp.try_into().unwrap());
|
||||||
0u8.write_into(&mut buf)?; // null term
|
// buf.write_u8(0); // null term
|
||||||
"POST".write_into(&mut buf)?;
|
// buf.extend_from_slice("POST\0".as_bytes());
|
||||||
path_and_query.write_into(&mut buf)?;
|
|
||||||
authorization_token.write_into(&mut buf)?;
|
|
||||||
payload.write_into(&mut buf)?;
|
|
||||||
|
|
||||||
// const keyPair = crypto.generateKeyPairSync('ec', { namedCurve: 'P-256' })
|
// buf.extend_from_slice(path_and_query.as_bytes());
|
||||||
|
// buf.write_u8(0);
|
||||||
|
|
||||||
// // Get the signature from the payload
|
// buf.extend_from_slice(authorization_token.as_bytes());
|
||||||
// const signature = crypto.sign('SHA256', buf.toBuffer(), { key: this.key.privateKey, dsaEncoding: 'ieee-p1363' })
|
// buf.write_u8(0);
|
||||||
|
|
||||||
// const header = SmartBuffer.fromSize(signature.length + 12)
|
// buf.extend_from_slice(payload.as_bytes());
|
||||||
// header.writeInt32BE(1) // Policy Version
|
// buf.write_u8(0);
|
||||||
// header.writeBigUInt64BE(windowsTimestamp)
|
|
||||||
// header.writeBuffer(signature) // Add signature at end of header
|
|
||||||
|
|
||||||
// return header.toBuffer()
|
// // const keyPair = crypto.generateKeyPairSync('ec', { namedCurve: 'P-256' })
|
||||||
|
|
||||||
let key_pair = EcKeyPair::generate(&EcParams::by_curve_nid(Nid::X9_62_PRIME256V1)?)?;
|
// // // Get the signature from the payload
|
||||||
|
// // const signature = crypto.sign('SHA256', buf.toBuffer(), { key: this.key.privateKey, dsaEncoding: 'ieee-p1363' })
|
||||||
|
|
||||||
let signature =
|
// // const header = SmartBuffer.fromSize(signature.length + 12)
|
||||||
key_pair
|
// // header.writeInt32BE(1) // Policy Version
|
||||||
.private_key()
|
// // header.writeBigUInt64BE(windowsTimestamp)
|
||||||
.sign(MessageDigest::sha256(), &buf, &mut BigNumContext::new()?)?;
|
// // header.writeBuffer(signature) // Add signature at end of header
|
||||||
|
|
||||||
let mut header = Vec::new();
|
// // return header.toBuffer()
|
||||||
1u32.write_into(&mut header)?; // policy version
|
|
||||||
windows_timestamp.write_into(&mut header)?;
|
|
||||||
signature.write_into(&mut header)?;
|
|
||||||
|
|
||||||
Ok(header)
|
// let key_pair = ring::signature::EcdsaKeyPair::
|
||||||
}
|
|
||||||
|
// let signature =
|
||||||
|
// key_pair
|
||||||
|
// .private_key()
|
||||||
|
// .sign(MessageDigest::sha256(), &buf, &mut BigNumContext::new()?)?;
|
||||||
|
|
||||||
|
// let mut header = Vec::new();
|
||||||
|
// 1u32.write_into(&mut header)?; // policy version
|
||||||
|
// windows_timestamp.write_into(&mut header)?;
|
||||||
|
// signature.write_into(&mut header)?;
|
||||||
|
|
||||||
|
// Ok(header)
|
||||||
|
// }
|
||||||
|
|
|
@ -110,6 +110,13 @@ impl McBufWritable for String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl McBufWritable for &str {
|
||||||
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
|
write_utf_with_len(buf, self, MAX_STRING_LENGTH.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl McBufWritable for u32 {
|
impl McBufWritable for u32 {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
i32::write_into(&(*self as i32), buf)
|
i32::write_into(&(*self as i32), buf)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue