Merge pull request #4345 from nextcloud/push

Push: no need to use ocClient
This commit is contained in:
Tobias Kaminsky 2019-08-20 13:57:57 +02:00 committed by GitHub
commit f7c4eecf27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,8 +3,10 @@
* *
* @author Mario Danic * @author Mario Danic
* @author Chris Narkiewicz * @author Chris Narkiewicz
* @author Tobias Kaminsky
* Copyright (C) 2017-2018 Mario Danic * Copyright (C) 2017-2018 Mario Danic
* Copyright (C) 2019 Chris Narkiewicz * Copyright (C) 2019 Chris Narkiewicz
* Copyright (C) 2019 Tobias Kaminsky
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by * it under the terms of the GNU Affero General Public License as published by
@ -149,7 +151,7 @@ public final class PushUtils {
private static void deleteRegistrationForAccount(Account account) { private static void deleteRegistrationForAccount(Account account) {
Context context = MainApp.getAppContext(); Context context = MainApp.getAppContext();
OwnCloudAccount ocAccount = null; OwnCloudAccount ocAccount;
arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().getContentResolver()); arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().getContentResolver());
try { try {
@ -169,22 +171,17 @@ public final class PushUtils {
Gson gson = new Gson(); Gson gson = new Gson();
PushConfigurationState pushArbitraryData = gson.fromJson(arbitraryValue, PushConfigurationState pushArbitraryData = gson.fromJson(arbitraryValue,
PushConfigurationState.class); PushConfigurationState.class);
RemoteOperation unregisterAccountDeviceForProxyOperation = RemoteOperationResult unregisterResult = new UnregisterAccountDeviceForProxyOperation(
new UnregisterAccountDeviceForProxyOperation(context.getResources(). context.getResources().getString(R.string.push_server_url),
getString(R.string.push_server_url), pushArbitraryData.getDeviceIdentifier(),
pushArbitraryData.getDeviceIdentifier(), pushArbitraryData.getDeviceIdentifierSignature(),
pushArbitraryData.getDeviceIdentifierSignature(), pushArbitraryData.getUserPublicKey()).run();
pushArbitraryData.getUserPublicKey());
remoteOperationResult = unregisterAccountDeviceForProxyOperation.execute(mClient); if (unregisterResult.isSuccess()) {
if (remoteOperationResult.isSuccess()) {
arbitraryDataProvider.deleteKeyForAccount(account.name, KEY_PUSH); arbitraryDataProvider.deleteKeyForAccount(account.name, KEY_PUSH);
} }
} }
} }
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) { } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
Log_OC.d(TAG, "Failed to find an account"); Log_OC.d(TAG, "Failed to find an account");
} catch (AuthenticatorException e) { } catch (AuthenticatorException e) {
@ -213,7 +210,7 @@ public final class PushUtils {
Context context = MainApp.getAppContext(); Context context = MainApp.getAppContext();
String providerValue; String providerValue;
PushConfigurationState accountPushData = null; PushConfigurationState accountPushData;
Gson gson = new Gson(); Gson gson = new Gson();
for (Account account : accountManager.getAccounts()) { for (Account account : accountManager.getAccounts()) {
providerValue = arbitraryDataProvider.getValue(account, KEY_PUSH); providerValue = arbitraryDataProvider.getValue(account, KEY_PUSH);
@ -229,29 +226,26 @@ public final class PushUtils {
TextUtils.isEmpty(providerValue)) { TextUtils.isEmpty(providerValue)) {
try { try {
OwnCloudAccount ocAccount = new OwnCloudAccount(account, context); OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton(). OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, context); getClientFor(ocAccount, context);
RemoteOperation registerAccountDeviceForNotificationsOperation =
new RegisterAccountDeviceForNotificationsOperation(pushTokenHash,
publicKey,
context.getResources().getString(R.string.push_server_url));
RemoteOperationResult remoteOperationResult = RemoteOperationResult remoteOperationResult =
registerAccountDeviceForNotificationsOperation.execute(mClient); new RegisterAccountDeviceForNotificationsOperation(pushTokenHash,
publicKey,
context.getResources().getString(R.string.push_server_url))
.execute(client);
if (remoteOperationResult.isSuccess()) { if (remoteOperationResult.isSuccess()) {
PushResponse pushResponse = remoteOperationResult.getPushResponseData(); PushResponse pushResponse = remoteOperationResult.getPushResponseData();
RemoteOperation registerAccountDeviceForProxyOperation = new RemoteOperationResult resultProxy = new RegisterAccountDeviceForProxyOperation(
RegisterAccountDeviceForProxyOperation( context.getResources().getString(R.string.push_server_url),
context.getResources().getString(R.string.push_server_url), token, pushResponse.getDeviceIdentifier(),
token, pushResponse.getDeviceIdentifier(), pushResponse.getSignature(), pushResponse.getSignature(),
pushResponse.getPublicKey()); pushResponse.getPublicKey())
.run();
remoteOperationResult = registerAccountDeviceForProxyOperation.execute(mClient); if (resultProxy.isSuccess()) {
if (remoteOperationResult.isSuccess()) {
PushConfigurationState pushArbitraryData = new PushConfigurationState(token, PushConfigurationState pushArbitraryData = new PushConfigurationState(token,
pushResponse.getDeviceIdentifier(), pushResponse.getSignature(), pushResponse.getDeviceIdentifier(), pushResponse.getSignature(),
pushResponse.getPublicKey(), false); pushResponse.getPublicKey(), false);
@ -419,7 +413,7 @@ public final class PushUtils {
final byte[] signatureBytes, final byte[] signatureBytes,
final byte[] subjectBytes final byte[] subjectBytes
) { ) {
Signature signature = null; Signature signature;
PublicKey publicKey; PublicKey publicKey;
SignatureVerification signatureVerification = new SignatureVerification(); SignatureVerification signatureVerification = new SignatureVerification();
signatureVerification.setSignatureValid(false); signatureVerification.setSignatureValid(false);
@ -471,7 +465,7 @@ public final class PushUtils {
"").replace("-----END PRIVATE KEY-----", ""); "").replace("-----END PRIVATE KEY-----", "");
} }
KeyFactory keyFactory = null; KeyFactory keyFactory;
try { try {
keyFactory = KeyFactory.getInstance("RSA"); keyFactory = KeyFactory.getInstance("RSA");
if (readPublicKey) { if (readPublicKey) {