Skip to content

Commit

Permalink
CI
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <[email protected]>
  • Loading branch information
tobiasKaminsky committed Jan 24, 2024
1 parent 66aa603 commit cd72cda
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
13 changes: 6 additions & 7 deletions library/src/main/java/com/nextcloud/common/NextcloudClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ import okhttp3.OkHttpClient
import okhttp3.Request
import org.apache.commons.httpclient.HttpStatus
import java.io.IOException
import java.net.MalformedURLException
import java.net.URL
import java.net.InetSocketAddress
import java.net.Proxy
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -126,11 +124,12 @@ class NextcloudClient private constructor(

@Suppress("TooGenericExceptionCaught")
fun <T> execute(remoteOperation: RemoteOperation<T>): RemoteOperationResult<T> {
val result = try {
remoteOperation.run(this)
} catch (ex: Exception) {
RemoteOperationResult(ex)
}
val result =
try {
remoteOperation.run(this)
} catch (ex: Exception) {
RemoteOperationResult(ex)
}
if (result.httpCode == HttpStatus.SC_BAD_REQUEST) {
val url = remoteOperation.client.hostConfiguration.hostURL
Log_OC.e(TAG, "Received http status 400 for $url -> removing client certificate")
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/com/nextcloud/common/PlainClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ package com.nextcloud.common
import android.content.Context
import android.text.TextUtils
import com.owncloud.android.lib.common.OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT_LONG
import com.owncloud.android.lib.common.network.AdvancedX509KeyManager
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
import com.owncloud.android.lib.common.network.AdvancedX509KeyManager
import com.owncloud.android.lib.common.network.AdvancedX509TrustManager
import com.owncloud.android.lib.common.network.NetworkUtils
import com.owncloud.android.lib.common.utils.Log_OC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ of this software and associated documentation files (the "Software"), to deal
*/
package com.owncloud.android.lib.common.network;

import static android.Manifest.permission.POST_NOTIFICATIONS;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static com.owncloud.android.lib.common.network.AdvancedX509KeyManager.AKMAlias.Type.KEYCHAIN;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
Expand All @@ -37,6 +41,12 @@ of this software and associated documentation files (the "Software"), to deal
import android.util.SparseArray;
import android.webkit.ClientCertRequest;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

import com.owncloud.android.lib.R;
import com.owncloud.android.lib.common.utils.Log_OC;

Expand All @@ -57,6 +67,7 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -66,17 +77,9 @@ of this software and associated documentation files (the "Software"), to deal
import javax.net.ssl.X509ExtendedKeyManager;
import javax.net.ssl.X509KeyManager;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import okhttp3.HttpUrl;

import static android.Manifest.permission.POST_NOTIFICATIONS;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static com.owncloud.android.lib.common.network.AdvancedX509KeyManager.AKMAlias.Type.KEYCHAIN;

/**
* AdvancedX509KeyManager is an implementation of X509KeyManager that handles key management,
* as well as user interaction to select an TLS client certificate, and also persist the selection.
Expand Down Expand Up @@ -563,6 +566,7 @@ private void startActivityNotification(@NonNull Intent intent, int decisionId, @
* @param port port of connection
* @return decision object with result of user interaction
*/
@SuppressFBWarnings({"UW", "WA"})
private @NonNull AKMDecision interactClientCert(@NonNull final String hostname, final int port) {
Log_OC.d(TAG, "interactClientCert(hostname=" + hostname + ", port=" + port + ")");

Expand Down Expand Up @@ -657,6 +661,10 @@ public String getPrefix() {
return prefix;
}

/**
* @throws IllegalArgumentException if prefix is unknown
*/
@SuppressFBWarnings("DRE")
public static Type parse(String prefix) throws IllegalArgumentException {
for (Type type : Type.values()) {
if (type.getPrefix().equals(prefix)) {
Expand Down Expand Up @@ -728,10 +736,10 @@ public String toString() {
constructedAlias.append(type.getPrefix());
constructedAlias.append(alias);
if (hostname != null) {
constructedAlias.append(":");
constructedAlias.append(':');
constructedAlias.append(hostname);
if (port != null) {
constructedAlias.append(":");
constructedAlias.append(':');
constructedAlias.append(port);
}
}
Expand All @@ -749,6 +757,11 @@ public boolean equals(Object object) {
Objects.equals(port, other.port);
}

@Override
public int hashCode() {
return Objects.hash(type, alias, hostname, port);
}

/**
* @param filter AKMAlias object used as filter
* @return true if each non-null field of filter equals the same field of this instance; false otherwise
Expand Down Expand Up @@ -821,7 +834,7 @@ public static KeyType parse(String keyType) {
}

public static Set<KeyType> parse(Iterable<String> keyTypes) {
Set<KeyType> keyTypeSet = new HashSet<>();
EnumSet<KeyType> keyTypeSet = EnumSet.noneOf(KeyType.class);
if (keyTypes != null) {
for (String keyType : keyTypes) {
keyTypeSet.add(parse(keyType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ private const val HOST_SAME = "hostname"
private const val HOST_OTHER = "hostname1"

class AdvancedX509KeyManagerTests {

@Test
fun testAKMAliasMatches() {
val akmAlias1 = AKMAlias(AKMAlias.Type.KEYCHAIN, ALIAS_SAME, HOST_SAME, PORT_SAME)
Expand Down

0 comments on commit cd72cda

Please sign in to comment.