From 4c1562f2458e73ccc99b605649872e15e5db66be Mon Sep 17 00:00:00 2001 From: Nick Steel Date: Wed, 13 Mar 2019 18:34:38 +0000 Subject: [PATCH 1/3] discover: do not panic on MAC mismatch. (Fixes #289) The client's expected MAC will not match librespot's derived MAC if the client used the wrong public key. This can happen if librespot is restarted (and thus generated a new key) but the client is still mistakingly using the old public key. When this happens we do not need to panic, we can just abort the connection attempt. --- connect/src/discovery.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/connect/src/discovery.rs b/connect/src/discovery.rs index 529c0ebd..739c62fc 100644 --- a/connect/src/discovery.rs +++ b/connect/src/discovery.rs @@ -132,7 +132,17 @@ impl Discovery { h.result().code().to_owned() }; - assert_eq!(&mac[..], cksum); + if mac != cksum { + warn!("Login error for user {:?}: MAC mismatch", username); + let result = json!({ + "status": 102, + "spotifyError": 1, + "statusString": "ERROR-MAC" + }); + + let body = result.to_string(); + return ::futures::finished(Response::new().with_body(body)) + } let decrypted = { let mut data = vec![0u8; encrypted.len()]; From 83bfdffcfe5faa1cee6e1e8408d94d82447e551d Mon Sep 17 00:00:00 2001 From: Nick Steel Date: Wed, 13 Mar 2019 18:45:43 +0000 Subject: [PATCH 2/3] discover: log the actual HTTP port that is used. If the default port is used (i.e. no command line argument specified), this logging incorrectly reports the server is running at port 0. --- connect/src/discovery.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connect/src/discovery.rs b/connect/src/discovery.rs index 739c62fc..2eacabf1 100644 --- a/connect/src/discovery.rs +++ b/connect/src/discovery.rs @@ -231,7 +231,6 @@ pub fn discovery( let serve = { let http = Http::new(); - debug!("Zeroconf server listening on 0.0.0.0:{}", port); http.serve_addr_handle( &format!("0.0.0.0:{}", port).parse().unwrap(), &handle, @@ -240,6 +239,7 @@ pub fn discovery( }; let s_port = serve.incoming_ref().local_addr().port(); + debug!("Zeroconf server listening on 0.0.0.0:{}", s_port); let server_future = { let handle = handle.clone(); From 6a600596e826bed66d27d931a59699b3fc70e0ef Mon Sep 17 00:00:00 2001 From: Nick Steel Date: Wed, 13 Mar 2019 18:47:56 +0000 Subject: [PATCH 3/3] main: exit librespot after the first ctrl+c if no currently active spirc session. --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index 36cd1b5d..14965ad5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -445,6 +445,8 @@ impl Future for Main { if !self.shutdown { if let Some(ref spirc) = self.spirc { spirc.shutdown(); + } else { + return Ok(Async::Ready(())); } self.shutdown = true; } else {