diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2018-01-09 15:27:33 +0100 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2018-01-09 15:27:33 +0100 |
| commit | a87c4b54d4350ed08687fb871910a1ee80fcfb0b (patch) | |
| tree | 8d06c4c24568096bd3c436c7739664c84b7c5f20 | |
| parent | 31d4a322b066a3cf09a91847779b4dd9ba108d3f (diff) | |
| parent | faec80c9eeba4c828601df764bf9b836497fbabd (diff) | |
| download | mullvadvpn-a87c4b54d4350ed08687fb871910a1ee80fcfb0b.tar.xz mullvadvpn-a87c4b54d4350ed08687fb871910a1ee80fcfb0b.zip | |
Merge branch 'metadata-in-problemreport'
| -rw-r--r-- | CHANGELOG.md | 3 | ||||
| -rw-r--r-- | mullvad-daemon/build.rs | 2 | ||||
| -rw-r--r-- | mullvad-daemon/src/bin/problem-report.rs | 50 | ||||
| -rw-r--r-- | mullvad-daemon/src/main.rs | 3 | ||||
| -rw-r--r-- | mullvad-rpc/src/lib.rs | 10 |
5 files changed, 43 insertions, 25 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 72520ddf56..d33b631b7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Fixed +- Fixed bug where problem report tool would redact some things in the logs which were not IPv6 + addresses, but looked like ones. ## [2018.1-beta8] - 2018-01-09 diff --git a/mullvad-daemon/build.rs b/mullvad-daemon/build.rs index b39c3fb9ab..14320da319 100644 --- a/mullvad-daemon/build.rs +++ b/mullvad-daemon/build.rs @@ -28,7 +28,7 @@ fn main() { // if it was able to obtain it, otherwise an empty string. fn commit_info() -> String { match (commit_description(), commit_date()) { - (Some(hash), Some(date)) => format!("({} {})", hash.trim(), date), + (Some(hash), Some(date)) => format!("{} {}", hash.trim(), date), _ => String::new(), } } diff --git a/mullvad-daemon/src/bin/problem-report.rs b/mullvad-daemon/src/bin/problem-report.rs index 2f344a1039..0365771f14 100644 --- a/mullvad-daemon/src/bin/problem-report.rs +++ b/mullvad-daemon/src/bin/problem-report.rs @@ -18,6 +18,7 @@ use error_chain::ChainedError; use regex::Regex; use std::cmp::min; +use std::collections::HashMap; use std::env; use std::fmt; use std::fs::File; @@ -154,10 +155,11 @@ fn collect_report( fn send_problem_report(user_email: &str, user_message: &str, report_path: &Path) -> Result<()> { let report_content = read_file_lossy(report_path, REPORT_MAX_SIZE) .chain_err(|| ErrorKind::ReadLogError(report_path.to_path_buf()))?; + let metadata = collect_metadata(); let mut rpc_client = mullvad_rpc::ProblemReportProxy::connect().chain_err(|| ErrorKind::RpcError)?; rpc_client - .problem_report(user_email, user_message, &report_content) + .problem_report(user_email, user_message, &report_content, &metadata) .call() .chain_err(|| ErrorKind::RpcError) } @@ -174,7 +176,7 @@ fn write_problem_report(path: &Path, problem_report: ProblemReport) -> io::Resul #[derive(Debug)] struct ProblemReport { - system_info: Vec<String>, + metadata: HashMap<String, String>, logs: Vec<(String, String)>, redact_custom_strings: Vec<String>, } @@ -184,19 +186,12 @@ impl ProblemReport { /// Logs will have all strings in `redact_custom_strings` removed from them. pub fn new(redact_custom_strings: Vec<String>) -> Self { ProblemReport { - system_info: Self::collect_system_info(), + metadata: collect_metadata(), logs: Vec::new(), redact_custom_strings, } } - fn collect_system_info() -> Vec<String> { - vec![ - format!("Mullvad daemon: {}", daemon_version()), - format!("OS: {}", os_version()), - ] - } - /// Attach file log to this report. This method uses the error chain instead of log /// contents if error occurred when reading log file. pub fn add_log(&mut self, path: &Path) { @@ -226,7 +221,7 @@ impl ProblemReport { fn redact_network_info(&self, input: &str) -> String { let combined_pattern = format!( - "\\b{}|{}|{}\\b", + "\\b({}|{}|{})\\b", self.build_ipv4_regex(), self.build_ipv6_regex(), self.build_mac_regex() @@ -300,8 +295,8 @@ impl ProblemReport { impl fmt::Display for ProblemReport { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { writeln!(fmt, "System information:")?; - for system_info in &self.system_info { - writeln!(fmt, "{}", system_info)?; + for (key, value) in &self.metadata { + writeln!(fmt, "{}: {}", key, value)?; } writeln!(fmt, "")?; for &(ref label, ref content) in &self.logs { @@ -331,12 +326,18 @@ fn read_file_lossy(path: &Path, max_bytes: usize) -> io::Result<String> { Ok(String::from_utf8_lossy(&buffer).into_owned()) } +fn collect_metadata() -> HashMap<String, String> { + let mut metadata = HashMap::new(); + metadata.insert(String::from("mullvad-daemon-version"), daemon_version()); + metadata.insert(String::from("os"), os_version()); + metadata +} + fn daemon_version() -> String { - format!( - "v{} {}", - env!("CARGO_PKG_VERSION"), - include_str!(concat!(env!("OUT_DIR"), "/git-commit-info.txt")) - ) + String::from(include_str!(concat!( + env!("OUT_DIR"), + "/git-commit-info.txt" + ))) } #[cfg(target_os = "linux")] @@ -376,7 +377,7 @@ mod tests { use super::*; #[test] - fn test_redacts_ipv4() { + fn redacts_ipv4() { assert_redacts_ipv4("1.2.3.4"); assert_redacts_ipv4("10.127.0.1"); assert_redacts_ipv4("192.168.1.1"); @@ -392,14 +393,14 @@ mod tests { } #[test] - fn test_does_not_redact_localhost_ipv4() { + fn does_not_redact_localhost_ipv4() { let report = ProblemReport::new(vec![]); let res = report.redact("127.0.0.1".to_owned()); assert_eq!("127.0.0.1", res); } #[test] - fn test_redacts_ipv6() { + fn redacts_ipv6() { assert_redacts_ipv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334"); assert_redacts_ipv6("2001:db8:85a3:0:0:8a2e:370:7334"); assert_redacts_ipv6("2001:db8:85a3::8a2e:370:7334"); @@ -413,6 +414,13 @@ mod tests { assert_redacts_ipv6("0:0:0:0::1"); } + #[test] + fn doesnt_redact_not_ipv6() { + let report = ProblemReport::new(vec![]); + let actual = report.redact(format!("[talpid_core::firewall]")); + assert_eq!("[talpid_core::firewall]", actual); + } + fn assert_redacts_ipv6(input: &str) { let report = ProblemReport::new(vec![]); let actual = report.redact(format!("pre {} post", input)); diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index 59446eb5af..696e85d783 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -789,9 +789,8 @@ fn init_logger(log_level: log::LogLevelFilter, log_file: Option<&PathBuf>) -> Re fn log_version() { info!( - "Starting {} v{} {}", + "Starting {} {}", env!("CARGO_PKG_NAME"), - env!("CARGO_PKG_VERSION"), include_str!(concat!(env!("OUT_DIR"), "/git-commit-info.txt")) ) } diff --git a/mullvad-rpc/src/lib.rs b/mullvad-rpc/src/lib.rs index bfbf4c6ab6..19d9a29287 100644 --- a/mullvad-rpc/src/lib.rs +++ b/mullvad-rpc/src/lib.rs @@ -24,6 +24,8 @@ pub use jsonrpc_client_http::{Error as HttpError, HttpHandle}; use mullvad_types::account::AccountToken; use mullvad_types::relay_list::RelayList; +use std::collections::HashMap; + static MASTER_API_URI: &str = "https://api.mullvad.net/rpc/"; @@ -37,7 +39,13 @@ jsonrpc_client!(pub struct AccountsProxy { }); jsonrpc_client!(pub struct ProblemReportProxy { - pub fn problem_report(&mut self, email: &str, message: &str, log: &str) -> RpcRequest<()>; + pub fn problem_report( + &mut self, + email: &str, + message: &str, + log: &str, + metadata: &HashMap<String, String>) + -> RpcRequest<()>; }); impl ProblemReportProxy<HttpHandle> { |
