Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
no need to use owncloudClient
Signed-off-by: tobiasKaminsky <[email protected]>
  • Loading branch information
tobiasKaminsky committed Aug 20, 2019
commit a3fda5aa7235e06768ec96f44044e1a9cfc02d25
54 changes: 24 additions & 30 deletions src/gplay/java/com/owncloud/android/utils/PushUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
*
* @author Mario Danic
* @author Chris Narkiewicz
* @author Tobias Kaminsky
* Copyright (C) 2017-2018 Mario Danic
* Copyright (C) 2019 Chris Narkiewicz
* Copyright (C) 2019 Tobias Kaminsky
*
* 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
Expand Down Expand Up @@ -149,7 +151,7 @@ private static int generateRsa2048KeyPair() {

private static void deleteRegistrationForAccount(Account account) {
Context context = MainApp.getAppContext();
OwnCloudAccount ocAccount = null;
OwnCloudAccount ocAccount;
arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().getContentResolver());

try {
Expand All @@ -169,22 +171,17 @@ private static void deleteRegistrationForAccount(Account account) {
Gson gson = new Gson();
PushConfigurationState pushArbitraryData = gson.fromJson(arbitraryValue,
PushConfigurationState.class);
RemoteOperation unregisterAccountDeviceForProxyOperation =
new UnregisterAccountDeviceForProxyOperation(context.getResources().
getString(R.string.push_server_url),
pushArbitraryData.getDeviceIdentifier(),
pushArbitraryData.getDeviceIdentifierSignature(),
pushArbitraryData.getUserPublicKey());
RemoteOperationResult unregisterResult = new UnregisterAccountDeviceForProxyOperation(
context.getResources().getString(R.string.push_server_url),
pushArbitraryData.getDeviceIdentifier(),
pushArbitraryData.getDeviceIdentifierSignature(),
pushArbitraryData.getUserPublicKey()).run();

remoteOperationResult = unregisterAccountDeviceForProxyOperation.execute(mClient);

if (remoteOperationResult.isSuccess()) {
if (unregisterResult.isSuccess()) {
arbitraryDataProvider.deleteKeyForAccount(account.name, KEY_PUSH);
}
}
}


} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
Log_OC.d(TAG, "Failed to find an account");
} catch (AuthenticatorException e) {
Expand Down Expand Up @@ -213,7 +210,7 @@ public static void pushRegistrationToServer(final UserAccountManager accountMana

Context context = MainApp.getAppContext();
String providerValue;
PushConfigurationState accountPushData = null;
PushConfigurationState accountPushData;
Gson gson = new Gson();
for (Account account : accountManager.getAccounts()) {
providerValue = arbitraryDataProvider.getValue(account, KEY_PUSH);
Expand All @@ -229,29 +226,26 @@ public static void pushRegistrationToServer(final UserAccountManager accountMana
TextUtils.isEmpty(providerValue)) {
try {
OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, context);

RemoteOperation registerAccountDeviceForNotificationsOperation =
new RegisterAccountDeviceForNotificationsOperation(pushTokenHash,
publicKey,
context.getResources().getString(R.string.push_server_url));

RemoteOperationResult remoteOperationResult =
registerAccountDeviceForNotificationsOperation.execute(mClient);
new RegisterAccountDeviceForNotificationsOperation(pushTokenHash,
publicKey,
context.getResources().getString(R.string.push_server_url))
.execute(client);

if (remoteOperationResult.isSuccess()) {
PushResponse pushResponse = remoteOperationResult.getPushResponseData();

RemoteOperation registerAccountDeviceForProxyOperation = new
RegisterAccountDeviceForProxyOperation(
context.getResources().getString(R.string.push_server_url),
token, pushResponse.getDeviceIdentifier(), pushResponse.getSignature(),
pushResponse.getPublicKey());

remoteOperationResult = registerAccountDeviceForProxyOperation.execute(mClient);
RemoteOperationResult resultProxy = new RegisterAccountDeviceForProxyOperation(
context.getResources().getString(R.string.push_server_url),
token, pushResponse.getDeviceIdentifier(),
pushResponse.getSignature(),
pushResponse.getPublicKey())
.run();

if (remoteOperationResult.isSuccess()) {
if (resultProxy.isSuccess()) {
PushConfigurationState pushArbitraryData = new PushConfigurationState(token,
pushResponse.getDeviceIdentifier(), pushResponse.getSignature(),
pushResponse.getPublicKey(), false);
Expand Down Expand Up @@ -419,7 +413,7 @@ public static SignatureVerification verifySignature(
final byte[] signatureBytes,
final byte[] subjectBytes
) {
Signature signature = null;
Signature signature;
PublicKey publicKey;
SignatureVerification signatureVerification = new SignatureVerification();
signatureVerification.setSignatureValid(false);
Expand Down Expand Up @@ -471,7 +465,7 @@ private static Key readKeyFromString(boolean readPublicKey, String keyString) {
"").replace("-----END PRIVATE KEY-----", "");
}

KeyFactory keyFactory = null;
KeyFactory keyFactory;
try {
keyFactory = KeyFactory.getInstance("RSA");
if (readPublicKey) {
Expand Down