Loading src/com/owncloud/android/lib/ocs/responses/PrivateKey.java 0 → 100644 +41 −0 Original line number Diff line number Diff line /* ownCloud Android Library is available under MIT license * Copyright (C) 2018 Bartosz Przybylski * Copyright (C) 2018 Nextcloud GmbH * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ package com.owncloud.android.lib.ocs.responses; import com.google.gson.annotations.SerializedName; /** * @author Bartosz Przybylski */ public class PrivateKey { @SerializedName("private-key") public String key; public String getKey() { return key; } } src/com/owncloud/android/lib/resources/users/GetPrivateKeyOperation.java +6 −14 Original line number Diff line number Diff line Loading @@ -21,13 +21,14 @@ package com.owncloud.android.lib.resources.users; import com.owncloud.android.lib.common.OwnCloudClient; 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 com.owncloud.android.lib.ocs.ServerResponse; import com.owncloud.android.lib.ocs.responses.PrivateKey; import com.owncloud.android.lib.resources.OCSRemoteOperation; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.GetMethod; import org.json.JSONObject; import java.util.ArrayList; Loading @@ -36,18 +37,13 @@ import java.util.ArrayList; * Remote operation performing the fetch of the public key for an user */ public class GetPrivateKeyOperation extends RemoteOperation { public class GetPrivateKeyOperation extends OCSRemoteOperation { private static final String TAG = GetPrivateKeyOperation.class.getSimpleName(); private static final int SYNC_READ_TIMEOUT = 40000; private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String PUBLIC_KEY_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/private-key"; // JSON node names private static final String NODE_OCS = "ocs"; private static final String NODE_DATA = "data"; private static final String NODE_PRIVATE_KEY = "private-key"; private static final String JSON_FORMAT = "?format=json"; /** Loading @@ -66,15 +62,11 @@ public class GetPrivateKeyOperation extends RemoteOperation { int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); if (status == HttpStatus.SC_OK) { String response = getMethod.getResponseBodyAsString(); // Parse the response JSONObject respJSON = new JSONObject(response); String key = (String) respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA).get(NODE_PRIVATE_KEY); ServerResponse<PrivateKey> serverResponse = getServerResponse(getMethod); result = new RemoteOperationResult(true, getMethod); ArrayList<Object> keys = new ArrayList<>(); keys.add(key); keys.add(serverResponse.getOcs().getData().getKey()); result.setData(keys); } else { result = new RemoteOperationResult(false, getMethod); Loading Loading
src/com/owncloud/android/lib/ocs/responses/PrivateKey.java 0 → 100644 +41 −0 Original line number Diff line number Diff line /* ownCloud Android Library is available under MIT license * Copyright (C) 2018 Bartosz Przybylski * Copyright (C) 2018 Nextcloud GmbH * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ package com.owncloud.android.lib.ocs.responses; import com.google.gson.annotations.SerializedName; /** * @author Bartosz Przybylski */ public class PrivateKey { @SerializedName("private-key") public String key; public String getKey() { return key; } }
src/com/owncloud/android/lib/resources/users/GetPrivateKeyOperation.java +6 −14 Original line number Diff line number Diff line Loading @@ -21,13 +21,14 @@ package com.owncloud.android.lib.resources.users; import com.owncloud.android.lib.common.OwnCloudClient; 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 com.owncloud.android.lib.ocs.ServerResponse; import com.owncloud.android.lib.ocs.responses.PrivateKey; import com.owncloud.android.lib.resources.OCSRemoteOperation; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.GetMethod; import org.json.JSONObject; import java.util.ArrayList; Loading @@ -36,18 +37,13 @@ import java.util.ArrayList; * Remote operation performing the fetch of the public key for an user */ public class GetPrivateKeyOperation extends RemoteOperation { public class GetPrivateKeyOperation extends OCSRemoteOperation { private static final String TAG = GetPrivateKeyOperation.class.getSimpleName(); private static final int SYNC_READ_TIMEOUT = 40000; private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String PUBLIC_KEY_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/private-key"; // JSON node names private static final String NODE_OCS = "ocs"; private static final String NODE_DATA = "data"; private static final String NODE_PRIVATE_KEY = "private-key"; private static final String JSON_FORMAT = "?format=json"; /** Loading @@ -66,15 +62,11 @@ public class GetPrivateKeyOperation extends RemoteOperation { int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); if (status == HttpStatus.SC_OK) { String response = getMethod.getResponseBodyAsString(); // Parse the response JSONObject respJSON = new JSONObject(response); String key = (String) respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA).get(NODE_PRIVATE_KEY); ServerResponse<PrivateKey> serverResponse = getServerResponse(getMethod); result = new RemoteOperationResult(true, getMethod); ArrayList<Object> keys = new ArrayList<>(); keys.add(key); keys.add(serverResponse.getOcs().getData().getKey()); result.setData(keys); } else { result = new RemoteOperationResult(false, getMethod); Loading