Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/android.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortobiasKaminsky <tobias@kaminsky.me>2020-02-03 08:45:37 +0300
committerAndy Scherzinger <info@andy-scherzinger.de>2020-11-10 01:35:02 +0300
commit0342c47a1c99ee7d4820d7d2aec63b325ef32945 (patch)
treeea6969e54ec4a7ba37fe7c784b17c4dc5de67fb2
parent5d035b31d999f7109c5dc3122afe7e4b70a50530 (diff)
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
-rw-r--r--build.gradle18
-rw-r--r--src/androidTest/java/com/nextcloud/client/AuthenticatorActivityIT.java56
-rw-r--r--src/themedWhite/AndroidManifest.xml84
-rw-r--r--src/themedWhite/google-services.json35
-rw-r--r--src/themedWhite/java/com/nextcloud/client/di/VariantComponentsModule.java34
-rw-r--r--src/themedWhite/java/com/owncloud/android/authentication/ModifiedAuthenticatorActivity.java42
-rw-r--r--src/themedWhite/java/com/owncloud/android/services/firebase/NCFirebaseInstanceIDService.java55
-rw-r--r--src/themedWhite/java/com/owncloud/android/services/firebase/NCFirebaseMessagingService.java46
-rw-r--r--src/themedWhite/java/com/owncloud/android/utils/GooglePlayUtils.java52
-rw-r--r--src/themedWhite/java/com/owncloud/android/utils/PushUtils.java486
-rw-r--r--src/themedWhite/java/com/owncloud/android/utils/SecurityUtils.java41
-rw-r--r--src/themedWhite/res/values/setup.xml13
12 files changed, 961 insertions, 1 deletions
diff --git a/build.gradle b/build.gradle
index 03afbc9060..fec2083afd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -93,7 +93,13 @@ def versionBuild = 0 // 0-50=Alpha / 51-98=RC / 90-99=stable
for (TaskExecutionRequest tr : getGradle().getStartParameter().getTaskRequests()) {
for (String arg : tr.args) {
// any gplay, but only exact "build", as e.g. buildGeneric shall not apply gplay.grade
- if (arg.contains("Gplay") || arg.contains("lint") || arg.contains("ExecuteScreenshot") || arg == "build") {
+ if (arg.contains("Gplay") ||
+ arg.contains("themed") ||
+ arg.contains("ExecuteScreenshot") ||
+ arg.contains("executeScreenshotTests") ||
+ arg.contains("lint") ||
+ arg == "build")
+ {
apply from: 'gplay.gradle'
System.console().println("Applying gplay.gradle")
break
@@ -102,6 +108,10 @@ for (TaskExecutionRequest tr : getGradle().getStartParameter().getTaskRequests()
}
+shot {
+ appId = 'com.nextcloud.client'
+ instrumentationTestTask = 'connectedThemedWhiteDebugAndroidTest'
+}
android {
lintOptions {
@@ -184,6 +194,11 @@ android {
versionCode 1
versionName "1"
}
+
+ themedWhite {
+ applicationId 'com.nextcloud.client'
+ dimension "default"
+ }
}
testOptions {
@@ -277,6 +292,7 @@ dependencies {
gplayImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
versionDevImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
qaImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
+ themedWhiteImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
kapt 'javax.xml.bind:jaxb-api:2.3.1'
kapt 'org.glassfish.jaxb:jaxb-core:2.3.0.1'
diff --git a/src/androidTest/java/com/nextcloud/client/AuthenticatorActivityIT.java b/src/androidTest/java/com/nextcloud/client/AuthenticatorActivityIT.java
new file mode 100644
index 0000000000..a7f5d02e06
--- /dev/null
+++ b/src/androidTest/java/com/nextcloud/client/AuthenticatorActivityIT.java
@@ -0,0 +1,56 @@
+/*
+ *
+ * Nextcloud Android client application
+ *
+ * @author Tobias Kaminsky
+ * Copyright (C) 2020 Tobias Kaminsky
+ * Copyright (C) 2020 Nextcloud GmbH
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) 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 <https://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.client;
+
+import android.Manifest;
+import android.app.Activity;
+
+import com.facebook.testing.screenshot.Screenshot;
+import com.owncloud.android.authentication.AuthenticatorActivity;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+import androidx.test.espresso.intent.rule.IntentsTestRule;
+import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.rule.GrantPermissionRule;
+
+
+public class AuthenticatorActivityIT {
+ @Rule public IntentsTestRule<AuthenticatorActivity> activityRule = new IntentsTestRule<>(AuthenticatorActivity.class,
+ true,
+ false);
+
+ @Rule
+ public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
+ Manifest.permission.WRITE_EXTERNAL_STORAGE);
+
+ @Test
+ public void open() {
+ Activity sut = activityRule.launchActivity(null);
+
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
+
+ Screenshot.snapActivity(sut).record();
+ }
+}
diff --git a/src/themedWhite/AndroidManifest.xml b/src/themedWhite/AndroidManifest.xml
new file mode 100644
index 0000000000..9100cbbaea
--- /dev/null
+++ b/src/themedWhite/AndroidManifest.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ Nextcloud Android client application
+
+ Copyright (C) 2017 Mario Danic
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2,
+ as published by the Free Software Foundation.
+
+ 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ package="com.owncloud.android">
+
+ <application
+ android:name=".MainApp"
+ android:icon="@mipmap/ic_launcher"
+ android:label="@string/app_name"
+ android:fullBackupContent="@xml/backup_config"
+ android:theme="@style/Theme.ownCloud.Toolbar"
+ android:manageSpaceActivity="com.owncloud.android.ui.activity.ManageSpaceActivity">
+
+ <meta-data
+ android:name="firebase_analytics_collection_deactivated"
+ android:value="true" />
+ <meta-data
+ android:name="google_analytics_adid_collection_enabled"
+ android:value="false" />
+
+ <activity
+ android:name=".authentication.ModifiedAuthenticatorActivity"
+ android:exported="true"
+ android:launchMode="singleTask"
+ android:theme="@style/Theme.ownCloud.noActionBar.Login">
+ <intent-filter>
+ <action android:name="com.owncloud.android.workaround.accounts.CREATE" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+
+ <data
+ android:scheme="@string/login_data_own_scheme"
+ android:host="login" />
+ </intent-filter>
+ </activity>
+
+ <activity-alias
+ android:name=".authentication.AuthenticatorActivity"
+ android:targetActivity=".authentication.ModifiedAuthenticatorActivity"
+ tools:replace="android:targetActivity" />
+
+
+ <service android:name=".services.firebase.NCFirebaseMessagingService">
+ <intent-filter>
+ <action android:name="com.google.firebase.MESSAGING_EVENT" />
+ </intent-filter>
+ </service>
+
+ <service android:name=".services.firebase.NCFirebaseInstanceIDService">
+ <intent-filter>
+ <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
+ </intent-filter>
+ </service>
+
+ <service
+ android:name="com.evernote.android.job.gcm.PlatformGcmService"
+ android:enabled="true"
+ tools:node="remove"></service>
+
+ </application>
+
+</manifest>
diff --git a/src/themedWhite/google-services.json b/src/themedWhite/google-services.json
new file mode 100644
index 0000000000..60bbf2f7f9
--- /dev/null
+++ b/src/themedWhite/google-services.json
@@ -0,0 +1,35 @@
+{
+ "project_info": {
+ "project_number": "",
+ "project_id": ""
+ },
+ "client": [
+ {
+ "client_info": {
+ "mobilesdk_app_id": "",
+ "android_client_info": {
+ "package_name": "com.nextcloud.client"
+ }
+ },
+ "oauth_client": [],
+ "api_key": [
+ {
+ "current_key": ""
+ }
+ ],
+ "services": {
+ "analytics_service": {
+ "status": 1
+ },
+ "appinvite_service": {
+ "status": 1,
+ "other_platform_oauth_client": []
+ },
+ "ads_service": {
+ "status": 1
+ }
+ }
+ }
+ ],
+ "configuration_version": "1"
+}
diff --git a/src/themedWhite/java/com/nextcloud/client/di/VariantComponentsModule.java b/src/themedWhite/java/com/nextcloud/client/di/VariantComponentsModule.java
new file mode 100644
index 0000000000..7d2f0eec86
--- /dev/null
+++ b/src/themedWhite/java/com/nextcloud/client/di/VariantComponentsModule.java
@@ -0,0 +1,34 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Chris Narkiewicz
+ * Copyright (C) 2919 Chris Narkiewicz <hello@ezaquarii.com>
+ *
+ * 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.authentication.ModifiedAuthenticatorActivity;
+import com.owncloud.android.services.firebase.NCFirebaseInstanceIDService;
+
+import dagger.Module;
+import dagger.android.ContributesAndroidInjector;
+
+@Module
+abstract class VariantComponentsModule {
+ @ContributesAndroidInjector abstract NCFirebaseInstanceIDService ncFirebaseInstanceIDService();
+
+ @ContributesAndroidInjector
+ abstract ModifiedAuthenticatorActivity modifiedAuthenticatorActivity();
+}
diff --git a/src/themedWhite/java/com/owncloud/android/authentication/ModifiedAuthenticatorActivity.java b/src/themedWhite/java/com/owncloud/android/authentication/ModifiedAuthenticatorActivity.java
new file mode 100644
index 0000000000..a9c0e80db5
--- /dev/null
+++ b/src/themedWhite/java/com/owncloud/android/authentication/ModifiedAuthenticatorActivity.java
@@ -0,0 +1,42 @@
+package com.owncloud.android.authentication;
+
+import android.os.Bundle;
+
+import com.nextcloud.client.di.Injectable;
+import com.owncloud.android.utils.GooglePlayUtils;
+
+/**
+ * Nextcloud Android client application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017 Mario Danic
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) 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/>.
+ */
+
+public class ModifiedAuthenticatorActivity extends AuthenticatorActivity implements Injectable {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ GooglePlayUtils.checkPlayServices(this);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ GooglePlayUtils.checkPlayServices(this);
+ }
+
+}
diff --git a/src/themedWhite/java/com/owncloud/android/services/firebase/NCFirebaseInstanceIDService.java b/src/themedWhite/java/com/owncloud/android/services/firebase/NCFirebaseInstanceIDService.java
new file mode 100644
index 0000000000..de6371d46c
--- /dev/null
+++ b/src/themedWhite/java/com/owncloud/android/services/firebase/NCFirebaseInstanceIDService.java
@@ -0,0 +1,55 @@
+/**
+ * Nextcloud Android client application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017 Mario Danic
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) 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.owncloud.android.services.firebase;
+
+import android.text.TextUtils;
+
+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.owncloud.android.R;
+import com.owncloud.android.utils.PushUtils;
+
+import javax.inject.Inject;
+
+import dagger.android.AndroidInjection;
+
+public class NCFirebaseInstanceIDService extends FirebaseInstanceIdService {
+
+
+ @Inject AppPreferences preferences;
+ @Inject UserAccountManager accountManager;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ 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(accountManager, preferences.getPushToken());
+ }
+ }
+}
diff --git a/src/themedWhite/java/com/owncloud/android/services/firebase/NCFirebaseMessagingService.java b/src/themedWhite/java/com/owncloud/android/services/firebase/NCFirebaseMessagingService.java
new file mode 100644
index 0000000000..c8c5a88c33
--- /dev/null
+++ b/src/themedWhite/java/com/owncloud/android/services/firebase/NCFirebaseMessagingService.java
@@ -0,0 +1,46 @@
+/**
+ * Nextcloud Android client application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017 Mario Danic
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) 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.owncloud.android.services.firebase;
+
+import com.evernote.android.job.JobRequest;
+import com.evernote.android.job.util.support.PersistableBundleCompat;
+import com.google.firebase.messaging.FirebaseMessagingService;
+import com.google.firebase.messaging.RemoteMessage;
+import com.owncloud.android.jobs.NotificationJob;
+
+public class NCFirebaseMessagingService extends FirebaseMessagingService {
+
+ @Override
+ public void onMessageReceived(RemoteMessage remoteMessage) {
+ if (remoteMessage != null && remoteMessage.getData() != null) {
+ PersistableBundleCompat persistableBundleCompat = new PersistableBundleCompat();
+ persistableBundleCompat.putString(NotificationJob.KEY_NOTIFICATION_SUBJECT, remoteMessage.getData().get
+ (NotificationJob.KEY_NOTIFICATION_SUBJECT));
+ persistableBundleCompat.putString(NotificationJob.KEY_NOTIFICATION_SIGNATURE, remoteMessage.getData().get
+ (NotificationJob.KEY_NOTIFICATION_SIGNATURE));
+ new JobRequest.Builder(NotificationJob.TAG)
+ .addExtras(persistableBundleCompat)
+ .setUpdateCurrent(false)
+ .startNow()
+ .build()
+ .schedule();
+ }
+ }
+}
diff --git a/src/themedWhite/java/com/owncloud/android/utils/GooglePlayUtils.java b/src/themedWhite/java/com/owncloud/android/utils/GooglePlayUtils.java
new file mode 100644
index 0000000000..55fdb99934
--- /dev/null
+++ b/src/themedWhite/java/com/owncloud/android/utils/GooglePlayUtils.java
@@ -0,0 +1,52 @@
+/**
+ * Nextcloud Android client application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017 Mario Danic
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) 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.owncloud.android.utils;
+
+import android.app.Activity;
+import android.util.Log;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.GoogleApiAvailability;
+
+public final class GooglePlayUtils {
+ private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
+ private static final String TAG = "GooglePlayUtils";
+
+ private GooglePlayUtils() {
+ }
+
+ public static boolean checkPlayServices(Activity activity) {
+ GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
+ int resultCode = apiAvailability.isGooglePlayServicesAvailable(activity);
+ if (resultCode != ConnectionResult.SUCCESS) {
+ if (apiAvailability.isUserResolvableError(resultCode)) {
+ apiAvailability.getErrorDialog(activity, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
+ .show();
+ } else {
+ Log.i(TAG, "This device is not supported.");
+ activity.finish();
+ }
+ return false;
+ }
+ return true;
+ }
+
+} \ No newline at end of file
diff --git a/src/themedWhite/java/com/owncloud/android/utils/PushUtils.java b/src/themedWhite/java/com/owncloud/android/utils/PushUtils.java
new file mode 100644
index 0000000000..4e0f41b94d
--- /dev/null
+++ b/src/themedWhite/java/com/owncloud/android/utils/PushUtils.java
@@ -0,0 +1,486 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @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
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) 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.owncloud.android.utils;
+
+import android.accounts.Account;
+import android.accounts.AuthenticatorException;
+import android.accounts.OperationCanceledException;
+import android.content.Context;
+import android.text.TextUtils;
+import android.util.Base64;
+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;
+import com.owncloud.android.R;
+import com.owncloud.android.datamodel.ArbitraryDataProvider;
+import com.owncloud.android.datamodel.PushConfigurationState;
+import com.owncloud.android.datamodel.SignatureVerification;
+import com.owncloud.android.lib.common.OwnCloudAccount;
+import com.owncloud.android.lib.common.OwnCloudClient;
+import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
+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.resources.notifications.RegisterAccountDeviceForNotificationsOperation;
+import com.owncloud.android.lib.resources.notifications.RegisterAccountDeviceForProxyOperation;
+import com.owncloud.android.lib.resources.notifications.UnregisterAccountDeviceForNotificationsOperation;
+import com.owncloud.android.lib.resources.notifications.UnregisterAccountDeviceForProxyOperation;
+import com.owncloud.android.lib.resources.notifications.models.PushResponse;
+
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.io.FileUtils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.KeyFactory;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.PublicKey;
+import java.security.Signature;
+import java.security.SignatureException;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.security.spec.X509EncodedKeySpec;
+import java.util.Locale;
+
+public final class PushUtils {
+
+ public static final String KEY_PUSH = "push";
+ private static final String TAG = "PushUtils";
+ private static final String KEYPAIR_FOLDER = "nc-keypair";
+ private static final String KEYPAIR_FILE_NAME = "push_key";
+ private static final String KEYPAIR_PRIV_EXTENSION = ".priv";
+ private static final String KEYPAIR_PUB_EXTENSION = ".pub";
+ private static ArbitraryDataProvider arbitraryDataProvider;
+
+ private PushUtils() {
+ }
+
+ public static String generateSHA512Hash(String pushToken) {
+ MessageDigest messageDigest = null;
+ try {
+ messageDigest = MessageDigest.getInstance("SHA-512");
+ messageDigest.update(pushToken.getBytes());
+ return bytesToHex(messageDigest.digest());
+ } catch (NoSuchAlgorithmException e) {
+ Log_OC.d(TAG, "SHA-512 algorithm not supported");
+ }
+ return "";
+ }
+
+ public static String bytesToHex(byte[] bytes) {
+ StringBuilder result = new StringBuilder();
+ for (byte individualByte : bytes) {
+ result.append(Integer.toString((individualByte & 0xff) + 0x100, 16)
+ .substring(1));
+ }
+ return result.toString();
+ }
+
+ private static int generateRsa2048KeyPair() {
+ migratePushKeys();
+ String keyPath = MainApp.getAppContext().getFilesDir().getAbsolutePath() + File.separator +
+ MainApp.getDataFolder() + File.separator + KEYPAIR_FOLDER;
+
+ String privateKeyPath = keyPath + File.separator + KEYPAIR_FILE_NAME + KEYPAIR_PRIV_EXTENSION;
+ String publicKeyPath = keyPath + File.separator + KEYPAIR_FILE_NAME + KEYPAIR_PUB_EXTENSION;
+ File keyPathFile = new File(keyPath);
+
+ if (!new File(privateKeyPath).exists() && !new File(publicKeyPath).exists()) {
+ try {
+ if (!keyPathFile.exists()) {
+ keyPathFile.mkdir();
+ }
+ KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
+ keyGen.initialize(2048);
+
+ KeyPair pair = keyGen.generateKeyPair();
+ int statusPrivate = saveKeyToFile(pair.getPrivate(), privateKeyPath);
+ int statusPublic = saveKeyToFile(pair.getPublic(), publicKeyPath);
+
+ if (statusPrivate == 0 && statusPublic == 0) {
+ // all went well
+ return 0;
+ } else {
+ return -2;
+ }
+ } catch (NoSuchAlgorithmException e) {
+ Log_OC.d(TAG, "RSA algorithm not supported");
+ }
+ } else {
+ // we already have the key
+ return -1;
+ }
+
+ // we failed to generate the key
+ return -2;
+ }
+
+ private static void deleteRegistrationForAccount(Account account) {
+ Context context = MainApp.getAppContext();
+ OwnCloudAccount ocAccount;
+ arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().getContentResolver());
+
+ try {
+ ocAccount = new OwnCloudAccount(account, context);
+ OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
+ getClientFor(ocAccount, context);
+
+ RemoteOperation unregisterAccountDeviceForNotificationsOperation = new
+ UnregisterAccountDeviceForNotificationsOperation();
+
+ RemoteOperationResult remoteOperationResult = unregisterAccountDeviceForNotificationsOperation.
+ execute(mClient);
+
+ if (remoteOperationResult.getHttpCode() == HttpStatus.SC_ACCEPTED) {
+ String arbitraryValue;
+ if (!TextUtils.isEmpty(arbitraryValue = arbitraryDataProvider.getValue(account, KEY_PUSH))) {
+ Gson gson = new Gson();
+ PushConfigurationState pushArbitraryData = gson.fromJson(arbitraryValue,
+ PushConfigurationState.class);
+ RemoteOperationResult unregisterResult = new UnregisterAccountDeviceForProxyOperation(
+ context.getResources().getString(R.string.push_server_url),
+ pushArbitraryData.getDeviceIdentifier(),
+ pushArbitraryData.getDeviceIdentifierSignature(),
+ pushArbitraryData.getUserPublicKey()).run();
+
+ 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) {
+ Log_OC.d(TAG, "Failed via AuthenticatorException");
+ } catch (IOException e) {
+ Log_OC.d(TAG, "Failed via IOException");
+ } catch (OperationCanceledException e) {
+ Log_OC.d(TAG, "Failed via OperationCanceledException");
+ }
+ }
+
+ 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)) &&
+ !TextUtils.isEmpty(token)) {
+ PushUtils.generateRsa2048KeyPair();
+ String pushTokenHash = PushUtils.generateSHA512Hash(token).toLowerCase(Locale.ROOT);
+ PublicKey devicePublicKey = (PublicKey) PushUtils.readKeyFromFile(true);
+ if (devicePublicKey != null) {
+ byte[] publicKeyBytes = Base64.encode(devicePublicKey.getEncoded(), Base64.NO_WRAP);
+ String publicKey = new String(publicKeyBytes);
+ publicKey = publicKey.replaceAll("(.{64})", "$1\n");
+
+ publicKey = "-----BEGIN PUBLIC KEY-----\n" + publicKey + "\n-----END PUBLIC KEY-----\n";
+
+ Context context = MainApp.getAppContext();
+ String providerValue;
+ PushConfigurationState accountPushData;
+ Gson gson = new Gson();
+ for (Account account : accountManager.getAccounts()) {
+ providerValue = arbitraryDataProvider.getValue(account, KEY_PUSH);
+ if (!TextUtils.isEmpty(providerValue)) {
+ accountPushData = gson.fromJson(providerValue,
+ PushConfigurationState.class);
+ } else {
+ accountPushData = null;
+ }
+
+ if (accountPushData != null && !accountPushData.getPushToken().equals(token) &&
+ !accountPushData.isShouldBeDeleted() ||
+ TextUtils.isEmpty(providerValue)) {
+ try {
+ OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
+ OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton().
+ getClientFor(ocAccount, context);
+
+ RemoteOperationResult remoteOperationResult =
+ new RegisterAccountDeviceForNotificationsOperation(pushTokenHash,
+ publicKey,
+ context.getResources().getString(R.string.push_server_url))
+ .execute(client);
+
+ if (remoteOperationResult.isSuccess()) {
+ PushResponse pushResponse = remoteOperationResult.getPushResponseData();
+
+ RemoteOperationResult resultProxy = new RegisterAccountDeviceForProxyOperation(
+ context.getResources().getString(R.string.push_server_url),
+ token, pushResponse.getDeviceIdentifier(),
+ pushResponse.getSignature(),
+ pushResponse.getPublicKey())
+ .run();
+
+ if (resultProxy.isSuccess()) {
+ PushConfigurationState pushArbitraryData = new PushConfigurationState(token,
+ pushResponse.getDeviceIdentifier(), pushResponse.getSignature(),
+ pushResponse.getPublicKey(), false);
+ arbitraryDataProvider.storeOrUpdateKeyValue(account.name, KEY_PUSH,
+ gson.toJson(pushArbitraryData));
+ }
+ } else if (remoteOperationResult.getCode() ==
+ RemoteOperationResult.ResultCode.ACCOUNT_USES_STANDARD_PASSWORD) {
+ arbitraryDataProvider.storeOrUpdateKeyValue(account.name,
+ UserAccountManager.ACCOUNT_USES_STANDARD_PASSWORD, "true");
+ }
+ } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
+ Log_OC.d(TAG, "Failed to find an account");
+ } catch (AuthenticatorException e) {
+ Log_OC.d(TAG, "Failed via AuthenticatorException");
+ } catch (IOException e) {
+ Log_OC.d(TAG, "Failed via IOException");
+ } catch (OperationCanceledException e) {
+ Log_OC.d(TAG, "Failed via OperationCanceledException");
+ }
+ } else if (accountPushData != null && accountPushData.isShouldBeDeleted()) {
+ deleteRegistrationForAccount(account);
+ }
+ }
+ }
+ }
+ }
+
+ public static Key readKeyFromFile(boolean readPublicKey) {
+ String keyPath = MainApp.getAppContext().getFilesDir().getAbsolutePath() + File.separator +
+ MainApp.getDataFolder() + File.separator + KEYPAIR_FOLDER;
+
+ String privateKeyPath = keyPath + File.separator + KEYPAIR_FILE_NAME + KEYPAIR_PRIV_EXTENSION;
+ String publicKeyPath = keyPath + File.separator + KEYPAIR_FILE_NAME + KEYPAIR_PUB_EXTENSION;
+
+ String path;
+
+ if (readPublicKey) {
+ path = publicKeyPath;
+ } else {
+ path = privateKeyPath;
+ }
+
+ FileInputStream fileInputStream = null;
+ try {
+ fileInputStream = new FileInputStream(path);
+ byte[] bytes = new byte[fileInputStream.available()];
+ fileInputStream.read(bytes);
+
+ KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+
+ if (readPublicKey) {
+ X509EncodedKeySpec keySpec = new X509EncodedKeySpec(bytes);
+ return keyFactory.generatePublic(keySpec);
+ } else {
+ PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(bytes);
+ return keyFactory.generatePrivate(keySpec);
+ }
+
+ } catch (FileNotFoundException e) {
+ Log_OC.d(TAG, "Failed to find path while reading the Key");
+ } catch (IOException e) {
+ Log_OC.d(TAG, "IOException while reading the key");
+ } catch (InvalidKeySpecException e) {
+ Log_OC.d(TAG, "InvalidKeySpecException while reading the key");
+ } catch (NoSuchAlgorithmException e) {
+ Log_OC.d(TAG, "RSA algorithm not supported");
+ } finally {
+ if (fileInputStream != null) {
+ try {
+ fileInputStream.close();
+ } catch (IOException e) {
+ Log_OC.e(TAG, "Error closing input stream during reading key from file", e);
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private static int saveKeyToFile(Key key, String path) {
+ byte[] encoded = key.getEncoded();
+ FileOutputStream keyFileOutputStream = null;
+ try {
+ if (!new File(path).exists()) {
+ File newFile = new File(path);
+ newFile.getParentFile().mkdirs();
+ newFile.createNewFile();
+ }
+ keyFileOutputStream = new FileOutputStream(path);
+ keyFileOutputStream.write(encoded);
+ return 0;
+ } catch (FileNotFoundException e) {
+ Log_OC.d(TAG, "Failed to save key to file");
+ } catch (IOException e) {
+ Log_OC.d(TAG, "Failed to save key to file via IOException");
+ } finally {
+ if (keyFileOutputStream != null) {
+ try {
+ keyFileOutputStream.close();
+ } catch (IOException e) {
+ Log_OC.e(TAG, "Error closing input stream during reading key from file", e);
+ }
+ }
+ }
+
+ return -1;
+ }
+
+ public static void reinitKeys(final UserAccountManager accountManager) {
+ Context context = MainApp.getAppContext();
+ Account[] accounts = accountManager.getAccounts();
+ for (Account account : accounts) {
+ deleteRegistrationForAccount(account);
+ }
+
+ String keyPath = context.getDir("nc-keypair", Context.MODE_PRIVATE).getAbsolutePath();
+ File privateKeyFile = new File(keyPath, "push_key.priv");
+ File publicKeyFile = new File(keyPath, "push_key.pub");
+
+ FileUtils.deleteQuietly(privateKeyFile);
+ FileUtils.deleteQuietly(publicKeyFile);
+
+ AppPreferences preferences = AppPreferencesImpl.fromContext(context);
+ String pushToken = preferences.getPushToken();
+ pushRegistrationToServer(accountManager, pushToken);
+ preferences.setKeysReInitEnabled();
+ }
+
+ private static void migratePushKeys() {
+ Context context = MainApp.getAppContext();
+ AppPreferences preferences = AppPreferencesImpl.fromContext(context);
+ if (!preferences.isKeysMigrationEnabled()) {
+ String oldKeyPath = MainApp.getStoragePath() + File.separator + MainApp.getDataFolder()
+ + File.separator + "nc-keypair";
+ File oldPrivateKeyFile = new File(oldKeyPath, "push_key.priv");
+ File oldPublicKeyFile = new File(oldKeyPath, "push_key.pub");
+
+ String keyPath = context.getDir("nc-keypair", Context.MODE_PRIVATE).getAbsolutePath();
+ File privateKeyFile = new File(keyPath, "push_key.priv");
+ File publicKeyFile = new File(keyPath, "push_key.pub");
+
+ if ((privateKeyFile.exists() && publicKeyFile.exists()) ||
+ (!oldPrivateKeyFile.exists() && !oldPublicKeyFile.exists())) {
+ preferences.setKeysMigrationEnabled(true);
+ } else {
+ if (oldPrivateKeyFile.exists()) {
+ FileStorageUtils.moveFile(oldPrivateKeyFile, privateKeyFile);
+ }
+
+ if (oldPublicKeyFile.exists()) {
+ FileStorageUtils.moveFile(oldPublicKeyFile, publicKeyFile);
+ }
+
+ if (privateKeyFile.exists() && publicKeyFile.exists()) {
+ preferences.setKeysMigrationEnabled(true);
+ }
+ }
+ }
+ }
+
+ public static SignatureVerification verifySignature(
+ final Context context,
+ final UserAccountManager accountManager,
+ final byte[] signatureBytes,
+ final byte[] subjectBytes
+ ) {
+ Signature signature;
+ PublicKey publicKey;
+ SignatureVerification signatureVerification = new SignatureVerification();
+ signatureVerification.setSignatureValid(false);
+
+ Account[] accounts = accountManager.getAccounts();
+
+ ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver());
+ String arbitraryValue;
+ Gson gson = new Gson();
+ PushConfigurationState pushArbitraryData;
+
+ try {
+ signature = Signature.getInstance("SHA512withRSA");
+ if (accounts.length > 0) {
+ for (Account account : accounts) {
+ if (!TextUtils.isEmpty(arbitraryValue = arbitraryDataProvider.getValue(account, KEY_PUSH))) {
+ pushArbitraryData = gson.fromJson(arbitraryValue, PushConfigurationState.class);
+ if (!pushArbitraryData.isShouldBeDeleted()) {
+ publicKey = (PublicKey) readKeyFromString(true, pushArbitraryData.getUserPublicKey());
+ signature.initVerify(publicKey);
+ signature.update(subjectBytes);
+ if (signature.verify(signatureBytes)) {
+ signatureVerification.setSignatureValid(true);
+ signatureVerification.setAccount(account);
+ return signatureVerification;
+ }
+ }
+ }
+ }
+ }
+ } catch (NoSuchAlgorithmException e) {
+ Log.d(TAG, "No such algorithm");
+ } catch (InvalidKeyException e) {
+ Log.d(TAG, "Invalid key while trying to verify");
+ } catch (SignatureException e) {
+ Log.d(TAG, "Signature exception while trying to verify");
+ }
+
+ return signatureVerification;
+ }
+
+ private static Key readKeyFromString(boolean readPublicKey, String keyString) {
+ String modifiedKey;
+ if (readPublicKey) {
+ modifiedKey = keyString.replaceAll("\\n", "").replace("-----BEGIN PUBLIC KEY-----",
+ "").replace("-----END PUBLIC KEY-----", "");
+ } else {
+ modifiedKey = keyString.replaceAll("\\n", "").replace("-----BEGIN PRIVATE KEY-----",
+ "").replace("-----END PRIVATE KEY-----", "");
+ }
+
+ KeyFactory keyFactory;
+ try {
+ keyFactory = KeyFactory.getInstance("RSA");
+ if (readPublicKey) {
+ X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64.decode(modifiedKey, Base64.DEFAULT));
+ return keyFactory.generatePublic(keySpec);
+ } else {
+ PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.decode(modifiedKey, Base64.DEFAULT));
+ return keyFactory.generatePrivate(keySpec);
+ }
+ } catch (NoSuchAlgorithmException e) {
+ Log.d("TAG", "No such algorithm while reading key from string");
+ } catch (InvalidKeySpecException e) {
+ Log.d("TAG", "Invalid key spec while reading key from string");
+ }
+
+ return null;
+ }
+}
diff --git a/src/themedWhite/java/com/owncloud/android/utils/SecurityUtils.java b/src/themedWhite/java/com/owncloud/android/utils/SecurityUtils.java
new file mode 100644
index 0000000000..f38eedbe3c
--- /dev/null
+++ b/src/themedWhite/java/com/owncloud/android/utils/SecurityUtils.java
@@ -0,0 +1,41 @@
+/**
+ * Nextcloud Android client application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2018 Mario Danic
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) 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.owncloud.android.utils;
+
+import android.content.Intent;
+
+import com.google.android.gms.security.ProviderInstaller;
+import com.owncloud.android.MainApp;
+
+public class SecurityUtils implements ProviderInstaller.ProviderInstallListener {
+ public SecurityUtils() {
+ ProviderInstaller.installIfNeededAsync(MainApp.getAppContext(), this);
+ }
+
+ @Override
+ public void onProviderInstalled() {
+ // Does nothing
+ }
+
+ @Override
+ public void onProviderInstallFailed(int i, Intent intent) {
+ // Does nothing
+ }
+}
diff --git a/src/themedWhite/res/values/setup.xml b/src/themedWhite/res/values/setup.xml
new file mode 100644
index 0000000000..7ec81f47ce
--- /dev/null
+++ b/src/themedWhite/res/values/setup.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <!-- Colors -->
+ <color name="primary">#ffffff</color>
+ <color name="primary_dark">#cccccc</color>
+ <color name="color_accent">#ffffff</color>
+ <color name="login_text_color">#000000</color>
+ <color name="login_text_hint_color">#000000</color>
+
+ <bool name="show_provider_or_own_installation">false</bool>
+</resources>
+
+