Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions findbugs-filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@
</Match>
<Bug pattern="PATH_TRAVERSAL_IN" />
<Bug pattern="ANDROID_EXTERNAL_FILE_ACCESS" />

<!-- This is unmanageable for now dur to large amount of interconnected static state -->
<Bug pattern="FCCD_FIND_CLASS_CIRCULAR_DEPENDENCY"/>
</FindBugsFilter>
2 changes: 1 addition & 1 deletion scripts/analysis/findbugs-results.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
470
441
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Nextcloud Android client application
*
* @author Chris Narkiewicz
* Copyright (C) 2919 Chris Narkiewicz <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.client.di;

import dagger.Module;

@Module
abstract class VariantComponentsModule {
}
14 changes: 11 additions & 3 deletions src/generic/java/com/owncloud/android/utils/PushUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* Nextcloud Android client application
*
* @author Mario Danic
* @author Chris Narkiewicz
* Copyright (C) 2017 Mario Danic
* Copyright (C) 2019 Chris Narkiewicz
*
* 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 All @@ -22,6 +24,7 @@

import android.content.Context;

import com.nextcloud.client.account.UserAccountManager;
import com.owncloud.android.MainApp;
import com.owncloud.android.datamodel.SignatureVerification;
import com.nextcloud.client.preferences.AppPreferencesImpl;
Expand All @@ -34,11 +37,11 @@ public final class PushUtils {
private PushUtils() {
}

public static void pushRegistrationToServer(final String pushToken) {
public static void pushRegistrationToServer(final UserAccountManager accountManager, final String pushToken) {
// do nothing
}

public static void reinitKeys() {
public static void reinitKeys(UserAccountManager accountManager) {
Context context = MainApp.getAppContext();
AppPreferencesImpl.fromContext(context).setKeysReInitEnabled();
}
Expand All @@ -47,7 +50,12 @@ public static Key readKeyFromFile(boolean readPublicKey) {
return null;
}

public static SignatureVerification verifySignature(Context context, byte[] signatureBytes, byte[] subjectBytes) {
public static SignatureVerification verifySignature(
final Context context,
final UserAccountManager accountManager,
final byte[] signatureBytes,
final byte[] subjectBytes
) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Nextcloud Android client application
*
* @author Chris Narkiewicz
* Copyright (C) 2919 Chris Narkiewicz <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.client.di;

import com.owncloud.android.services.firebase.NCFirebaseInstanceIDService;

import dagger.Module;
import dagger.android.ContributesAndroidInjector;

@Module
abstract class VariantComponentsModule {
@ContributesAndroidInjector abstract NCFirebaseInstanceIDService ncFirebaseInstanceIDService();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,33 @@

import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.preferences.AppPreferences;
import com.nextcloud.client.preferences.AppPreferencesImpl;
import com.owncloud.android.R;
import com.owncloud.android.utils.PushUtils;

import javax.inject.Inject;

import dagger.android.AndroidInjection;

public class NCFirebaseInstanceIDService extends FirebaseInstanceIdService {

private AppPreferences preferences;

@Inject AppPreferences preferences;
@Inject UserAccountManager accountManager;

@Override
public void onCreate() {
super.onCreate();
preferences = AppPreferencesImpl.fromContext(this);
AndroidInjection.inject(this);
}

@Override
public void onTokenRefresh() {
//You can implement this method to store the token on your server
if (!TextUtils.isEmpty(getResources().getString(R.string.push_server_url))) {
preferences.setPushToken(FirebaseInstanceId.getInstance().getToken());
PushUtils.pushRegistrationToServer(preferences.getPushToken());
PushUtils.pushRegistrationToServer(accountManager, preferences.getPushToken());
}
}
}
22 changes: 15 additions & 7 deletions src/gplay/java/com/owncloud/android/utils/PushUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* Nextcloud Android client application
*
* @author Mario Danic
* @author Chris Narkiewicz
* Copyright (C) 2017-2018 Mario Danic
* Copyright (C) 2019 Chris Narkiewicz
*
* 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 All @@ -29,6 +31,7 @@
import android.util.Log;

import com.google.gson.Gson;
import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.preferences.AppPreferences;
import com.nextcloud.client.preferences.AppPreferencesImpl;
import com.owncloud.android.MainApp;
Expand Down Expand Up @@ -194,7 +197,7 @@ private static void deleteRegistrationForAccount(Account account) {
}
}

public static void pushRegistrationToServer(final String token) {
public static void pushRegistrationToServer(final UserAccountManager accountManager, final String token) {
arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().getContentResolver());

if (!TextUtils.isEmpty(MainApp.getAppContext().getResources().getString(R.string.push_server_url)) &&
Expand All @@ -213,7 +216,7 @@ public static void pushRegistrationToServer(final String token) {
String providerValue;
PushConfigurationState accountPushData = null;
Gson gson = new Gson();
for (Account account : AccountUtils.getAccounts(context)) {
for (Account account : accountManager.getAccounts()) {
providerValue = arbitraryDataProvider.getValue(account, KEY_PUSH);
if (!TextUtils.isEmpty(providerValue)) {
accountPushData = gson.fromJson(providerValue,
Expand Down Expand Up @@ -359,9 +362,9 @@ private static int saveKeyToFile(Key key, String path) {
return -1;
}

public static void reinitKeys() {
public static void reinitKeys(final UserAccountManager accountManager) {
Context context = MainApp.getAppContext();
Account[] accounts = AccountUtils.getAccounts(context);
Account[] accounts = accountManager.getAccounts();
for (Account account : accounts) {
deleteRegistrationForAccount(account);
}
Expand All @@ -375,7 +378,7 @@ public static void reinitKeys() {

AppPreferences preferences = AppPreferencesImpl.fromContext(context);
String pushToken = preferences.getPushToken();
pushRegistrationToServer(pushToken);
pushRegistrationToServer(accountManager, pushToken);
preferences.setKeysReInitEnabled();
}

Expand Down Expand Up @@ -411,13 +414,18 @@ private static void migratePushKeys() {
}
}

public static SignatureVerification verifySignature(Context context, byte[] signatureBytes, byte[] subjectBytes) {
public static SignatureVerification verifySignature(
final Context context,
final UserAccountManager accountManager,
final byte[] signatureBytes,
final byte[] subjectBytes
) {
Signature signature = null;
PublicKey publicKey;
SignatureVerification signatureVerification = new SignatureVerification();
signatureVerification.setSignatureValid(false);

Account[] accounts = AccountUtils.getAccounts(context);
Account[] accounts = accountManager.getAccounts();

ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver());
String arbitraryValue;
Expand Down
65 changes: 65 additions & 0 deletions src/main/java/com/nextcloud/client/account/UserAccountManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Nextcloud Android client application
*
* @author Chris Narkiewicz
* Copyright (C) 2019 Chris Narkiewicz <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.client.account;

import android.accounts.Account;

import androidx.annotation.NonNull;

public interface UserAccountManager {

int ACCOUNT_VERSION = 1;
int ACCOUNT_VERSION_WITH_PROPER_ID = 2;
String ACCOUNT_USES_STANDARD_PASSWORD = "ACCOUNT_USES_STANDARD_PASSWORD";

/**
* Get configured NextCloud's user accounts.
*
* @return Array of accounts or empty array, if accounts are not configured.
*/
@NonNull
Account[] getAccounts();

/**
* Update the accounts in AccountManager to meet the current
* version of accounts expected by the app, if needed.
* <p>
* Introduced to handle a change in the structure of stored account names
* needed to allow different Nextcloud servers in the same domain, but not in
* the same path.
*/
void updateAccountVersion();

/**
* Extract username from account.
*
* Full account name is in form of "[email protected]".
*
* @param account Account instance
* @return User name (without domain) or null, if name cannot be extracted.
*/
static String getUsername(Account account) {
if (account != null && account.name != null) {
return account.name.substring(0, account.name.lastIndexOf('@'));
} else {
return null;
}
}
}
Loading