diff --git a/gradle.properties b/gradle.properties index 1ec3fc7f0..bdfb4a4ce 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 272c292dc..64f738ad2 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 d86577278..d3e1443f0 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 775ff126f..980322ec7 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 1ab2166de..953ced0c9 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 7519f7891..4d36f58cb 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 c8a5e9326..476d6cc8f 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 9e304fac1..39076cd26 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 4557e485c..0fb9c5362 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 000000000..91abb7881 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/users/GetServerPublicKeyRemoteOperation.kt @@ -0,0 +1,58 @@ +/* + * 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" + } + + @Suppress("TooGenericExceptionCaught") + 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 d5d0853a7..04e7ae258 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 */