commit b7d278484ebbb8c923fb3b956dcf2a3dbaf4dfee
parent 27bd5187124cfe45c87e26aaa9cb6d5c6f77b172
Author: MTRNord <mtrnord1@gmail.com>
Date: Sat, 13 Aug 2022 22:51:26 +0200
Fix compilation
Diffstat:
3 files changed, 37 insertions(+), 29 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
@@ -14,6 +14,7 @@ path = "src/fuzzTargets/createRoom.rs"
[dependencies]
afl = "*"
arbitrary = {version = "1", features = ["derive"]}
+cfg-if = "0.1"
fuzzcheck = {git = "https://github.com/MTRNord/fuzzcheck-rs.git", branch = "patch-1"}
once_cell = "1.13.0"
reqwest = {version = "0.11.11", features = ["blocking", "json", "gzip"]}
@@ -21,5 +22,7 @@ serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0.83"
[features]
-default = ["fuzzing"]
+default = ["fuzzing", "password_auth"]
fuzzing = []
+password_auth = []
+token_auth = []
diff --git a/src/lib.rs b/src/lib.rs
@@ -134,55 +134,60 @@ mod tests {
};
fn login(data: &LoginPostReq) -> bool {
- let mut data = data.clone();
+ let mut json_data = data.clone();
// We hardcode the type for better fuzzing
- data._type = "m.login.password".to_string();
- if data.user.is_some() {
- data.user = Some(crate::secrets::USERNAME.to_string());
- }
- if let Some(identifier) = &mut data.identifier {
- if identifier.user.is_some() {
- identifier.user = Some(crate::secrets::USERNAME.to_string());
+ cfg_if::cfg_if! {
+ if #[cfg(feature = "token_auth")] {
+ json_data._type = "com.devture.shared_secret_auth".to_string();
+ } else {
+ json_data._type = "m.login.password".to_string();
}
}
+ if json_data.user.is_some() {
+ json_data.user = Some(crate::secrets::USERNAME.to_string());
+ }
+ if let Some(identifier) = &mut json_data.identifier {
+ identifier.user = crate::secrets::USERNAME.to_string();
+ identifier._type = "m.id.user".to_string();
+ }
- if let Some(user) = &data.user {
+ if let Some(user) = &json_data.user {
if user.contains("\0") {
- data.user = Some(user.replace("\0", ""));
+ json_data.user = Some(user.replace("\0", ""));
}
}
- if let Some(medium) = &data.medium {
+ if let Some(medium) = &json_data.medium {
if medium.contains("\0") {
- data.medium = Some(medium.replace("\0", ""));
+ json_data.medium = Some(medium.replace("\0", ""));
}
}
- if let Some(address) = &data.address {
+ if let Some(address) = &json_data.address {
if address.contains("\0") {
- data.address = Some(address.replace("\0", ""));
+ json_data.address = Some(address.replace("\0", ""));
}
}
- if let Some(user) = &data.user {
+ if let Some(user) = &json_data.user {
if user.contains("\0") {
- data.user = Some(user.replace("\0", ""));
+ json_data.user = Some(user.replace("\0", ""));
}
}
- if let Some(password) = &data.password {
+ /*if let Some(password) = &json_data.password {
if password.contains("\0") {
- data.password = Some(password.replace("\0", ""));
+ json_data.password = Some(password.replace("\0", ""));
}
- }
+ }*/
let client = crate::client();
let resp = client
.post("http://localhost:8008/_matrix/client/v3/login")
- .json(&data)
+ .json(&json_data)
.send();
if let Ok(resp) = resp {
let status = resp.status();
if !status.is_success() {
- if status == 400 {
+ /*if status == 400 {
return true;
- }
+ }*/
let content = resp.text();
if let Ok(ref content) = content {
if content.contains("Unknown login type")
diff --git a/src/types.rs b/src/types.rs
@@ -34,12 +34,12 @@ pub struct LoginPostReq {
pub initial_device_display_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub medium: Option<String>,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub password: Option<String>,
+ //#[serde(skip_serializing_if = "Option::is_none")]
+ //pub password: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub refresh_token: Option<bool>,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub token: Option<String>,
+ // We assume token login where this is a required field
+ pub token: String,
#[serde(rename = "type")]
pub _type: String,
#[serde(skip_serializing_if = "Option::is_none")]
@@ -50,8 +50,8 @@ pub struct LoginPostReq {
pub struct Identifier {
#[serde(rename = "type")]
pub _type: String,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub user: Option<String>,
+ // We assume password login or token login where this is a required field
+ pub user: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub medium: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]