From e5788016cf9792f2f4561fd78ea251bb8bda25e9 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 26 Oct 2023 13:25:33 +0200 Subject: [PATCH 1/2] Use UTF_8 for basic authorization Signed-off-by: Marcel Hibbe --- .../com/nextcloud/talk/dagger/modules/RestModule.java | 10 +++++++--- .../main/java/com/nextcloud/talk/utils/ApiUtils.java | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java b/app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java index 996d46d39c..795dd12820 100644 --- a/app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java +++ b/app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java @@ -40,6 +40,7 @@ import java.net.CookieManager; import java.net.InetSocketAddress; import java.net.Proxy; +import java.nio.charset.StandardCharsets; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; @@ -209,9 +210,12 @@ OkHttpClient provideHttpClient(Proxy proxy, AppPreferences appPreferences, if (appPreferences.getProxyCredentials() && !TextUtils.isEmpty(appPreferences.getProxyUsername()) && !TextUtils.isEmpty(appPreferences.getProxyPassword())) { - httpClient.proxyAuthenticator(new HttpAuthenticator(Credentials.basic( - appPreferences.getProxyUsername(), - appPreferences.getProxyPassword()), "Proxy-Authorization")); + httpClient.proxyAuthenticator(new HttpAuthenticator( + Credentials.basic( + appPreferences.getProxyUsername(), + appPreferences.getProxyPassword(), + StandardCharsets.UTF_8), + "Proxy-Authorization")); } } diff --git a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java index 4b0ec13d9d..eb9e5f4b89 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java @@ -34,6 +34,7 @@ import com.nextcloud.talk.models.RetrofitBucket; import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; @@ -399,7 +400,7 @@ public static String getCredentials(String username, String token) { if (TextUtils.isEmpty(username) && TextUtils.isEmpty(token)) { return null; } - return Credentials.basic(username, token); + return Credentials.basic(username, token, StandardCharsets.UTF_8); } public static String getUrlNextcloudPush(String baseUrl) { From 0e3c24b24a70ab2f69339111e7c465cd05e8adcc Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 26 Oct 2023 13:26:53 +0200 Subject: [PATCH 2/2] reformat code Signed-off-by: Marcel Hibbe --- .../talk/dagger/modules/RestModule.java | 44 +++++++++---------- .../com/nextcloud/talk/utils/ApiUtils.java | 4 +- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java b/app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java index 795dd12820..d1a241fd90 100644 --- a/app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java +++ b/app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java @@ -92,7 +92,7 @@ NcApi provideNcApi(Retrofit retrofit) { @Provides Proxy provideProxy(AppPreferences appPreferences) { if (!TextUtils.isEmpty(appPreferences.getProxyType()) && !"No proxy".equals(appPreferences.getProxyType()) - && !TextUtils.isEmpty(appPreferences.getProxyHost())) { + && !TextUtils.isEmpty(appPreferences.getProxyHost())) { GetProxyRunnable getProxyRunnable = new GetProxyRunnable(appPreferences); Thread getProxyThread = new Thread(getProxyRunnable); getProxyThread.start(); @@ -112,10 +112,10 @@ Proxy provideProxy(AppPreferences appPreferences) { @Provides Retrofit provideRetrofit(OkHttpClient httpClient) { Retrofit.Builder retrofitBuilder = new Retrofit.Builder() - .client(httpClient) - .baseUrl("https://nextcloud.com") - .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io())) - .addConverterFactory(LoganSquareConverterFactory.create()); + .client(httpClient) + .baseUrl("https://nextcloud.com") + .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io())) + .addConverterFactory(LoganSquareConverterFactory.create()); return retrofitBuilder.build(); } @@ -208,13 +208,13 @@ OkHttpClient provideHttpClient(Proxy proxy, AppPreferences appPreferences, httpClient.proxy(proxy); if (appPreferences.getProxyCredentials() && - !TextUtils.isEmpty(appPreferences.getProxyUsername()) && - !TextUtils.isEmpty(appPreferences.getProxyPassword())) { + !TextUtils.isEmpty(appPreferences.getProxyUsername()) && + !TextUtils.isEmpty(appPreferences.getProxyPassword())) { httpClient.proxyAuthenticator(new HttpAuthenticator( Credentials.basic( - appPreferences.getProxyUsername(), - appPreferences.getProxyPassword(), - StandardCharsets.UTF_8), + appPreferences.getProxyUsername(), + appPreferences.getProxyPassword(), + StandardCharsets.UTF_8), "Proxy-Authorization")); } } @@ -229,7 +229,7 @@ OkHttpClient provideHttpClient(Proxy proxy, AppPreferences appPreferences, httpClient.addInterceptor(loggingInterceptor); } else if (context.getResources().getBoolean(R.bool.nc_is_debug)) { HttpLoggingInterceptor.Logger fileLogger = - s -> LoggingUtils.INSTANCE.writeLogEntryToFile(context, s); + s -> LoggingUtils.INSTANCE.writeLogEntryToFile(context, s); HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(fileLogger); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); loggingInterceptor.redactHeader("Authorization"); @@ -247,11 +247,11 @@ public static class HeadersInterceptor implements Interceptor { public Response intercept(@NonNull Chain chain) throws IOException { Request original = chain.request(); Request request = original.newBuilder() - .header("User-Agent", ApiUtils.getUserAgent()) - .header("Accept", "application/json") - .header("OCS-APIRequest", "true") - .method(original.method(), original.body()) - .build(); + .header("User-Agent", ApiUtils.getUserAgent()) + .header("Accept", "application/json") + .header("OCS-APIRequest", "true") + .method(original.method(), original.body()) + .build(); return chain.proceed(request); } @@ -286,8 +286,8 @@ public Request authenticate(@Nullable Route route, @NonNull Response response) { } return response.request().newBuilder() - .header(authenticatorType, credentials) - .build(); + .header(authenticatorType, credentials) + .build(); } } @@ -303,12 +303,12 @@ private class GetProxyRunnable implements Runnable { public void run() { if (Proxy.Type.valueOf(appPreferences.getProxyType()) == Proxy.Type.SOCKS) { proxy = new Proxy(Proxy.Type.valueOf(appPreferences.getProxyType()), - InetSocketAddress.createUnresolved(appPreferences.getProxyHost(), Integer.parseInt( - appPreferences.getProxyPort()))); + InetSocketAddress.createUnresolved(appPreferences.getProxyHost(), Integer.parseInt( + appPreferences.getProxyPort()))); } else { proxy = new Proxy(Proxy.Type.valueOf(appPreferences.getProxyType()), - new InetSocketAddress(appPreferences.getProxyHost(), - Integer.parseInt(appPreferences.getProxyPort()))); + new InetSocketAddress(appPreferences.getProxyHost(), + Integer.parseInt(appPreferences.getProxyPort()))); } } diff --git a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java index eb9e5f4b89..f08b31e361 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java @@ -61,8 +61,8 @@ public static String getUserAgent() { } /** - * @deprecated This is only supported on API v1-3, in API v4+ please use {@link ApiUtils#getUrlForAttendees(int, - * String, String)} instead. + * @deprecated This is only supported on API v1-3, in API v4+ please use + * {@link ApiUtils#getUrlForAttendees(int, String, String)} instead. */ @Deprecated public static String getUrlForRemovingParticipantFromConversation(String baseUrl, String roomToken, boolean isGuest) {