Spiegel von
https://github.com/dani-garcia/vaultwarden.git
synchronisiert 2025-01-22 07:09:00 +01:00
Refactor the uri match fix and fix ssh-key sync (#5339)
* Refactor the uri match change Refactored the uri match fix to also convert numbers within a string to an int. If it fails it will be null. Signed-off-by: BlackDex <black.dex@gmail.com> * Fix ssh-key sync issues If any of the mandatory ssh-key json data values are not a string or are an empty string, this will break the mobile clients. This commit fixes this by checking if any of the values are missing or invalid and converts the json data to `null`. It will ensure the clients can sync and show the vault. Fixes #5343 Fixes #5322 Signed-off-by: BlackDex <black.dex@gmail.com> --------- Signed-off-by: BlackDex <black.dex@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
b1481c7c1a
Commit
dfd9e65396
1 geänderte Dateien mit 28 neuen und 12 gelöschten Zeilen
|
@ -241,20 +241,23 @@ impl Cipher {
|
||||||
// NOTE: This was marked as *Backwards Compatibility Code*, but as of January 2021 this is still being used by upstream
|
// NOTE: This was marked as *Backwards Compatibility Code*, but as of January 2021 this is still being used by upstream
|
||||||
// Set the first element of the Uris array as Uri, this is needed several (mobile) clients.
|
// Set the first element of the Uris array as Uri, this is needed several (mobile) clients.
|
||||||
if self.atype == 1 {
|
if self.atype == 1 {
|
||||||
if type_data_json["uris"].is_array() {
|
// Upstream always has an `uri` key/value
|
||||||
// Fix uri match values first, they are only allowed to be a number or null
|
|
||||||
// If it is a string, convert it to null since all clients do not allow strings anyway
|
|
||||||
let uri_count = type_data_json["uris"].as_array().unwrap().len();
|
|
||||||
for n in 0..uri_count {
|
|
||||||
if type_data_json["uris"][n]["match"].is_string() {
|
|
||||||
type_data_json["uris"][n]["match"] = Value::Null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let uri = type_data_json["uris"][0]["uri"].clone();
|
|
||||||
type_data_json["uri"] = uri;
|
|
||||||
} else {
|
|
||||||
// Upstream always has an Uri key/value
|
|
||||||
type_data_json["uri"] = Value::Null;
|
type_data_json["uri"] = Value::Null;
|
||||||
|
if let Some(uris) = type_data_json["uris"].as_array_mut() {
|
||||||
|
if !uris.is_empty() {
|
||||||
|
// Fix uri match values first, they are only allowed to be a number or null
|
||||||
|
// If it is a string, convert it to an int or null if that fails
|
||||||
|
for uri in &mut *uris {
|
||||||
|
if uri["match"].is_string() {
|
||||||
|
let match_value = match uri["match"].as_str().unwrap_or_default().parse::<u8>() {
|
||||||
|
Ok(n) => json!(n),
|
||||||
|
_ => Value::Null,
|
||||||
|
};
|
||||||
|
uri["match"] = match_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
type_data_json["uri"] = uris[0]["uri"].clone();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,6 +272,19 @@ impl Cipher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fix invalid SSH Entries
|
||||||
|
// This breaks at least the native mobile client if invalid
|
||||||
|
// The only way to fix this is by setting type_data_json to `null`
|
||||||
|
// Opening this ssh-key in the mobile client will probably crash the client, but you can edit, save and afterwards delete it
|
||||||
|
if self.atype == 5
|
||||||
|
&& (type_data_json["keyFingerprint"].as_str().is_none_or(|v| v.is_empty())
|
||||||
|
|| type_data_json["privateKey"].as_str().is_none_or(|v| v.is_empty())
|
||||||
|
|| type_data_json["publicKey"].as_str().is_none_or(|v| v.is_empty()))
|
||||||
|
{
|
||||||
|
warn!("Error parsing ssh-key, mandatory fields are invalid for {}", self.uuid);
|
||||||
|
type_data_json = Value::Null;
|
||||||
|
}
|
||||||
|
|
||||||
// Clone the type_data and add some default value.
|
// Clone the type_data and add some default value.
|
||||||
let mut data_json = type_data_json.clone();
|
let mut data_json = type_data_json.clone();
|
||||||
|
|
||||||
|
|
Laden …
In neuem Issue referenzieren