From 06bc73ac8d2bcb518a405f3b56d08396266d5704 Mon Sep 17 00:00:00 2001 From: HK Date: Wed, 9 Dec 2020 04:53:36 +0100 Subject: [PATCH 1/2] proxy authentification fix using a proxy with username and password authentification needing the username:password being base64 encoded Syntax: Proxy-Authorization: example: Proxy-Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l this fix --- lib/src/main/java/xyz/gianlu/librespot/core/Session.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/xyz/gianlu/librespot/core/Session.java b/lib/src/main/java/xyz/gianlu/librespot/core/Session.java index a996669e..fc8bd619 100644 --- a/lib/src/main/java/xyz/gianlu/librespot/core/Session.java +++ b/lib/src/main/java/xyz/gianlu/librespot/core/Session.java @@ -1230,8 +1230,11 @@ static ConnectionHolder create(@NotNull String addr, @NotNull Configuration conf out.write(String.format("CONNECT %s:%d HTTP/1.0\n", apAddr, apPort).getBytes()); if (conf.proxyAuth) { - out.write("Proxy-Authorization: Basic ".getBytes()); - out.write(Base64.getEncoder().encodeToString(String.format("%s:%s\n", conf.proxyUsername, conf.proxyPassword).getBytes()).getBytes()); + String auth1 = "Proxy-Authorization: Basic"; + String auth2 = String.format("%s:%s",conf.proxyUsername, conf.proxyPassword); + String auth2coded = Base64.getEncoder().encodeToString(auth2.getBytes()); + String authFinal = String.format("%s %s\n",auth1, auth2coded); + out.write(authFinal.getBytes()); } out.write('\n'); From 2126500e354951c09c0557f1de115915ba8a0002 Mon Sep 17 00:00:00 2001 From: Gianlu Date: Wed, 9 Dec 2020 09:14:29 +0100 Subject: [PATCH 2/2] Using OkHttp Credentials util --- lib/src/main/java/xyz/gianlu/librespot/core/Session.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/src/main/java/xyz/gianlu/librespot/core/Session.java b/lib/src/main/java/xyz/gianlu/librespot/core/Session.java index fc8bd619..83f34a14 100644 --- a/lib/src/main/java/xyz/gianlu/librespot/core/Session.java +++ b/lib/src/main/java/xyz/gianlu/librespot/core/Session.java @@ -1229,13 +1229,8 @@ static ConnectionHolder create(@NotNull String addr, @NotNull Configuration conf DataInputStream in = new DataInputStream(sock.getInputStream()); out.write(String.format("CONNECT %s:%d HTTP/1.0\n", apAddr, apPort).getBytes()); - if (conf.proxyAuth) { - String auth1 = "Proxy-Authorization: Basic"; - String auth2 = String.format("%s:%s",conf.proxyUsername, conf.proxyPassword); - String auth2coded = Base64.getEncoder().encodeToString(auth2.getBytes()); - String authFinal = String.format("%s %s\n",auth1, auth2coded); - out.write(authFinal.getBytes()); - } + if (conf.proxyAuth) + out.write(String.format("Proxy-Authorization: %s\n", Credentials.basic(conf.proxyUsername, conf.proxyPassword)).getBytes()); out.write('\n'); out.flush();