Use actual OS and kernel versions

This commit is contained in:
Roderick van Domburg 2022-08-26 21:14:43 +02:00
parent 65e48864a5
commit 111c7781d2
No known key found for this signature in database
GPG key ID: 87F5FDE8A56219F4
4 changed files with 54 additions and 16 deletions

24
Cargo.lock generated
View file

@ -1430,6 +1430,7 @@ dependencies = [
"serde_json", "serde_json",
"sha1", "sha1",
"shannon", "shannon",
"sysinfo",
"thiserror", "thiserror",
"time", "time",
"tokio", "tokio",
@ -1718,6 +1719,15 @@ dependencies = [
"minimal-lexical", "minimal-lexical",
] ]
[[package]]
name = "ntapi"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "num" name = "num"
version = "0.4.0" version = "0.4.0"
@ -2746,6 +2756,20 @@ dependencies = [
"unicode-xid", "unicode-xid",
] ]
[[package]]
name = "sysinfo"
version = "0.25.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71eb43e528fdc239f08717ec2a378fdb017dddbc3412de15fff527554591a66c"
dependencies = [
"cfg-if",
"core-foundation-sys",
"libc",
"ntapi",
"once_cell",
"winapi",
]
[[package]] [[package]]
name = "system-deps" name = "system-deps"
version = "6.0.2" version = "6.0.2"

View file

@ -47,6 +47,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
sha1 = "0.10" sha1 = "0.10"
shannon = "0.2" shannon = "0.2"
sysinfo = { version = "0.25", default-features = false }
thiserror = "1.0" thiserror = "1.0"
time = "0.3" time = "0.3"
tokio = { version = "1", features = ["io-util", "macros", "net", "parking_lot", "rt", "sync", "time"] } tokio = { version = "1", features = ["io-util", "macros", "net", "parking_lot", "rt", "sync", "time"] }

View file

@ -11,6 +11,7 @@ use hyper::{
use hyper_proxy::{Intercept, Proxy, ProxyConnector}; use hyper_proxy::{Intercept, Proxy, ProxyConnector};
use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder}; use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder};
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use sysinfo::{System, SystemExt};
use thiserror::Error; use thiserror::Error;
use url::Url; use url::Url;
@ -82,18 +83,24 @@ pub struct HttpClient {
impl HttpClient { impl HttpClient {
pub fn new(proxy_url: Option<&Url>) -> Self { pub fn new(proxy_url: Option<&Url>) -> Self {
let spotify_platform = match OS { let zero_str = String::from("0");
"android" => "Android/31", let os_version = System::new()
"ios" => "iOS/15.2.1", .os_version()
"macos" => "OSX/0", .unwrap_or_else(|| zero_str.clone());
"windows" => "Win32/0",
_ => "Linux/0", let (spotify_platform, os_version) = match OS {
"android" => ("Android", os_version),
"ios" => ("iOS", os_version),
"macos" => ("OSX", zero_str),
"windows" => ("Win32", zero_str),
_ => ("Linux", zero_str),
}; };
let user_agent_str = &format!( let user_agent_str = &format!(
"Spotify/{} {} ({})", "Spotify/{} {}/{} ({})",
spotify_version(), spotify_version(),
spotify_platform, spotify_platform,
os_version,
VERSION_STRING VERSION_STRING
); );

View file

@ -16,6 +16,7 @@ use hyper::{
use protobuf::{Message, ProtobufEnum}; use protobuf::{Message, ProtobufEnum};
use rand::Rng; use rand::Rng;
use sha1::{Digest, Sha1}; use sha1::{Digest, Sha1};
use sysinfo::{System, SystemExt};
use thiserror::Error; use thiserror::Error;
use crate::{ use crate::{
@ -173,8 +174,15 @@ impl SpClient {
let platform_data = connectivity_data.mut_platform_specific_data(); let platform_data = connectivity_data.mut_platform_specific_data();
let sys = System::new();
let os_version = sys.os_version().unwrap_or_else(|| String::from("0"));
let kernel_version = sys.kernel_version().unwrap_or_else(|| String::from("0"));
match std::env::consts::OS { match std::env::consts::OS {
"windows" => { "windows" => {
let os_version = os_version.parse::<f32>().unwrap_or(10.) as i32;
let kernel_version = kernel_version.parse::<i32>().unwrap_or(21370);
let (pe, image_file) = match std::env::consts::ARCH { let (pe, image_file) = match std::env::consts::ARCH {
"arm" => (448, 452), "arm" => (448, 452),
"aarch64" => (43620, 452), "aarch64" => (43620, 452),
@ -183,8 +191,8 @@ impl SpClient {
}; };
let windows_data = platform_data.mut_desktop_windows(); let windows_data = platform_data.mut_desktop_windows();
windows_data.set_os_version(10); windows_data.set_os_version(os_version);
windows_data.set_os_build(21370); windows_data.set_os_build(kernel_version);
windows_data.set_platform_id(2); windows_data.set_platform_id(2);
windows_data.set_unknown_value_6(9); windows_data.set_unknown_value_6(9);
windows_data.set_image_file_machine(image_file); windows_data.set_image_file_machine(image_file);
@ -196,11 +204,11 @@ impl SpClient {
ios_data.set_user_interface_idiom(0); ios_data.set_user_interface_idiom(0);
ios_data.set_target_iphone_simulator(false); ios_data.set_target_iphone_simulator(false);
ios_data.set_hw_machine("iPhone14,5".to_string()); ios_data.set_hw_machine("iPhone14,5".to_string());
ios_data.set_system_version("15.2.1".to_string()); ios_data.set_system_version(os_version);
} }
"android" => { "android" => {
let android_data = platform_data.mut_android(); let android_data = platform_data.mut_android();
android_data.set_android_version("12.0.0_r26".to_string()); android_data.set_android_version(os_version);
android_data.set_api_version(31); android_data.set_api_version(31);
android_data.set_device_name("Pixel".to_owned()); android_data.set_device_name("Pixel".to_owned());
android_data.set_model_str("GF5KQ".to_owned()); android_data.set_model_str("GF5KQ".to_owned());
@ -208,17 +216,15 @@ impl SpClient {
} }
"macos" => { "macos" => {
let macos_data = platform_data.mut_desktop_macos(); let macos_data = platform_data.mut_desktop_macos();
macos_data.set_system_version("Darwin Kernel Version 17.7.0: Fri Oct 30 13:34:27 PDT 2020; root:xnu-4570.71.82.8~1/RELEASE_X86_64".to_string()); macos_data.set_system_version(os_version);
macos_data.set_hw_model("iMac21,1".to_string()); macos_data.set_hw_model("iMac21,1".to_string());
macos_data.set_compiled_cpu_type(std::env::consts::ARCH.to_string()); macos_data.set_compiled_cpu_type(std::env::consts::ARCH.to_string());
} }
_ => { _ => {
let linux_data = platform_data.mut_desktop_linux(); let linux_data = platform_data.mut_desktop_linux();
linux_data.set_system_name("Linux".to_string()); linux_data.set_system_name("Linux".to_string());
linux_data.set_system_release("5.15.0-46-generic".to_string()); linux_data.set_system_release(kernel_version);
linux_data.set_system_version( linux_data.set_system_version(os_version);
"#49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022".to_string(),
);
linux_data.set_hardware(std::env::consts::ARCH.to_string()); linux_data.set_hardware(std::env::consts::ARCH.to_string());
} }
} }