From a93aa191f2bce7ddcaf606029b46af2675b4e4b2 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 23 Aug 2024 15:21:04 +0200 Subject: [PATCH 1/2] update headers and add new operation Signed-off-by: alperozturk --- gradle.properties | 2 +- library/build.gradle | 2 +- .../extensions/DavPropertyProcessorTest.kt | 2 +- .../nextcloud/extensions/ElementCreator.kt | 2 +- .../extensions/XmlDataProcessorTest.kt | 2 +- .../extensions/ArrayListExtensions.kt | 2 +- .../nextcloud/extensions/GsonExtensions.kt | 2 +- .../android/lib/common/network/WebdavEntry.kt | 2 +- .../lib/common/network/WebdavUtils.java | 2 +- .../GetServerPublicKeyRemoteOperation.kt | 57 +++++++++++++++++++ sample_client/build.gradle | 2 +- 11 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 library/src/main/java/com/owncloud/android/lib/resources/users/GetServerPublicKeyRemoteOperation.kt diff --git a/gradle.properties b/gradle.properties index 1ec3fc7f0c..bdfb4a4ced 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors # SPDX-FileCopyrightText: 2018-2023 Tobias Kaminsky # SPDX-FileCopyrightText: 2023 Andy Scherzinger -# SPDX-FileCopyrightText: 2023 Alper Ozturk +# SPDX-FileCopyrightText: 2023 Alper Ozturk # SPDX-License-Identifier: MIT # can be overriden by ~/.gradle/gradle.properties diff --git a/library/build.gradle b/library/build.gradle index ac16c1cf64..8fb3d8d1ae 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -4,7 +4,7 @@ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2023 Andy Scherzinger * SPDX-FileCopyrightText: 2023 Tobias Kaminsky - * SPDX-FileCopyrightText: 2023 Alper Ozturk + * SPDX-FileCopyrightText: 2023 Alper Ozturk * SPDX-FileCopyrightText: 2022 Álvaro Brey Vilas * SPDX-License-Identifier: MIT */ diff --git a/library/src/androidTest/java/com/nextcloud/extensions/DavPropertyProcessorTest.kt b/library/src/androidTest/java/com/nextcloud/extensions/DavPropertyProcessorTest.kt index d865772781..d3e1443f00 100644 --- a/library/src/androidTest/java/com/nextcloud/extensions/DavPropertyProcessorTest.kt +++ b/library/src/androidTest/java/com/nextcloud/extensions/DavPropertyProcessorTest.kt @@ -2,7 +2,7 @@ * Nextcloud Android Library * * SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-FileCopyrightText: 2023 Alper Ozturk + * SPDX-FileCopyrightText: 2023 Alper Ozturk * SPDX-License-Identifier: MIT */ diff --git a/library/src/androidTest/java/com/nextcloud/extensions/ElementCreator.kt b/library/src/androidTest/java/com/nextcloud/extensions/ElementCreator.kt index 775ff126f3..980322ec76 100644 --- a/library/src/androidTest/java/com/nextcloud/extensions/ElementCreator.kt +++ b/library/src/androidTest/java/com/nextcloud/extensions/ElementCreator.kt @@ -2,7 +2,7 @@ * Nextcloud Android Library * * SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-FileCopyrightText: 2023 Alper Ozturk + * SPDX-FileCopyrightText: 2023 Alper Ozturk * SPDX-License-Identifier: MIT */ diff --git a/library/src/androidTest/java/com/nextcloud/extensions/XmlDataProcessorTest.kt b/library/src/androidTest/java/com/nextcloud/extensions/XmlDataProcessorTest.kt index 1ab2166dec..953ced0c92 100644 --- a/library/src/androidTest/java/com/nextcloud/extensions/XmlDataProcessorTest.kt +++ b/library/src/androidTest/java/com/nextcloud/extensions/XmlDataProcessorTest.kt @@ -2,7 +2,7 @@ * Nextcloud Android Library * * SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-FileCopyrightText: 2023 Alper Ozturk + * SPDX-FileCopyrightText: 2023 Alper Ozturk * SPDX-License-Identifier: MIT */ diff --git a/library/src/main/java/com/nextcloud/extensions/ArrayListExtensions.kt b/library/src/main/java/com/nextcloud/extensions/ArrayListExtensions.kt index 7519f7891b..4d36f58cb3 100644 --- a/library/src/main/java/com/nextcloud/extensions/ArrayListExtensions.kt +++ b/library/src/main/java/com/nextcloud/extensions/ArrayListExtensions.kt @@ -2,7 +2,7 @@ * Nextcloud Android Library * * SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-FileCopyrightText: 2023 Alper Ozturk + * SPDX-FileCopyrightText: 2023 Alper Ozturk * SPDX-License-Identifier: MIT */ diff --git a/library/src/main/java/com/nextcloud/extensions/GsonExtensions.kt b/library/src/main/java/com/nextcloud/extensions/GsonExtensions.kt index c8a5e93268..476d6cc8ff 100644 --- a/library/src/main/java/com/nextcloud/extensions/GsonExtensions.kt +++ b/library/src/main/java/com/nextcloud/extensions/GsonExtensions.kt @@ -2,7 +2,7 @@ * Nextcloud Android Library * * SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-FileCopyrightText: 2023 Alper Ozturk + * SPDX-FileCopyrightText: 2023 Alper Ozturk * SPDX-License-Identifier: MIT */ package com.nextcloud.extensions diff --git a/library/src/main/java/com/owncloud/android/lib/common/network/WebdavEntry.kt b/library/src/main/java/com/owncloud/android/lib/common/network/WebdavEntry.kt index 9e304fac19..39076cd269 100644 --- a/library/src/main/java/com/owncloud/android/lib/common/network/WebdavEntry.kt +++ b/library/src/main/java/com/owncloud/android/lib/common/network/WebdavEntry.kt @@ -2,7 +2,7 @@ * Nextcloud Android Library * * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-FileCopyrightText: 2023 Alper Ozturk + * SPDX-FileCopyrightText: 2023 Alper Ozturk * SPDX-FileCopyrightText: 2023 Álvaro Brey * SPDX-FileCopyrightText: 2015 ownCloud Inc. * SPDX-License-Identifier: MIT diff --git a/library/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java b/library/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java index 4557e485cf..0fb9c53626 100644 --- a/library/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java +++ b/library/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java @@ -2,7 +2,7 @@ * Nextcloud Android Library * * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-FileCopyrightText: 2023 Alper Ozturk + * SPDX-FileCopyrightText: 2023 Alper Ozturk * SPDX-FileCopyrightText: 2022 Álvaro Brey * SPDX-FileCopyrightText: 2018-2022 Tobias Kaminsky * SPDX-FileCopyrightText: 2014-2015 ownCloud Inc. diff --git a/library/src/main/java/com/owncloud/android/lib/resources/users/GetServerPublicKeyRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/users/GetServerPublicKeyRemoteOperation.kt new file mode 100644 index 0000000000..f8d6516beb --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/users/GetServerPublicKeyRemoteOperation.kt @@ -0,0 +1,57 @@ +/* + * Nextcloud Android Library + * + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * SPDX-License-Identifier: MIT + */ + +package com.owncloud.android.lib.resources.users + +import com.nextcloud.common.NextcloudClient +import com.nextcloud.operations.GetMethod +import com.owncloud.android.lib.common.operations.RemoteOperation +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.common.utils.Log_OC +import org.apache.commons.httpclient.HttpStatus +import org.json.JSONObject + +class GetServerPublicKeyRemoteOperation : RemoteOperation() { + companion object { + private val TAG: String = GetPublicKeyRemoteOperation::class.java.simpleName + private const val ENDPOINT = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/server-key" + } + + override fun run(client: NextcloudClient): RemoteOperationResult { + var getMethod: GetMethod? = null + var result: RemoteOperationResult + val user: String = client.userId + + try { + getMethod = GetMethod(client.baseUri.toString() + ENDPOINT + JSON_FORMAT, true) + + val status = client.execute(getMethod) + + if (status == HttpStatus.SC_OK) { + val response = getMethod.getResponseBodyAsString() + val respJSON = JSONObject(response) + val serverKey = respJSON.getJSONObject("ocs").getJSONObject("data").getString("public-key") + + result = RemoteOperationResult(true, getMethod) + result.setResultData(serverKey) + } else { + result = RemoteOperationResult(false, getMethod) + } + } catch (e: Exception) { + result = RemoteOperationResult(e) + Log_OC.e( + TAG, + "Fetching of server public key failed for user " + user + ": " + result.logMessage, + result.exception + ) + } finally { + getMethod?.releaseConnection() + } + + return result + } +} diff --git a/sample_client/build.gradle b/sample_client/build.gradle index 980f8f52be..060c70431b 100644 --- a/sample_client/build.gradle +++ b/sample_client/build.gradle @@ -4,7 +4,7 @@ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2022-2023 Tobias Kaminsky * SPDX-FileCopyrightText: 2023 Andy Scherzinger - * SPDX-FileCopyrightText: 2023 Alper Ozturk + * SPDX-FileCopyrightText: 2023 Alper Ozturk * SPDX-FileCopyrightText: 2014 Marcello Steiner * SPDX-License-Identifier: MIT */ From 55f3a8ce9da6d6d50683ed083a6900b4ea4559d4 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 23 Aug 2024 15:36:55 +0200 Subject: [PATCH 2/2] fix code analytics Signed-off-by: alperozturk --- .../lib/resources/users/GetServerPublicKeyRemoteOperation.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/users/GetServerPublicKeyRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/users/GetServerPublicKeyRemoteOperation.kt index f8d6516beb..91abb78819 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/users/GetServerPublicKeyRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/users/GetServerPublicKeyRemoteOperation.kt @@ -21,6 +21,7 @@ class GetServerPublicKeyRemoteOperation : RemoteOperation() { private const val ENDPOINT = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/server-key" } + @Suppress("TooGenericExceptionCaught") override fun run(client: NextcloudClient): RemoteOperationResult { var getMethod: GetMethod? = null var result: RemoteOperationResult