From ea290fedba2304bf97264e1ff660e003740fd7d7 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Patel Date: Mon, 29 Mar 2021 07:49:10 +0530 Subject: [PATCH] Add support for insecure anonymous session, open bridge geo-spoofing --- app/build.gradle | 2 +- .../aurora/store/data/model/InsecureAuth.kt | 25 ++++++++ .../java/com/aurora/store/util/Preferences.kt | 2 + .../store/view/ui/commons/BaseActivity.kt | 26 +++++--- .../view/ui/onboarding/OnboardingActivity.kt | 4 ++ .../view/ui/preferences/NetworkPreference.kt | 48 ++++++++++++++ .../store/viewmodel/auth/AuthViewModel.kt | 63 +++++++++++++++++++ app/src/main/res/values/strings.xml | 4 ++ app/src/main/res/xml/preferences_main.xml | 8 +++ app/src/main/res/xml/preferences_network.xml | 28 +++++++++ 10 files changed, 199 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/com/aurora/store/data/model/InsecureAuth.kt create mode 100644 app/src/main/java/com/aurora/store/view/ui/preferences/NetworkPreference.kt create mode 100644 app/src/main/res/xml/preferences_network.xml diff --git a/app/build.gradle b/app/build.gradle index b2e2186b1..dbaa7b893 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -169,7 +169,7 @@ dependencies { implementation "com.github.topjohnwu.libsu:core:${versions.libsu}" //Love <3 - api("com.gitlab.AuroraOSS:gplayapi:fe28788fa0") + api("com.gitlab.AuroraOSS:gplayapi:efb14fa545") } Properties props = new Properties() diff --git a/app/src/main/java/com/aurora/store/data/model/InsecureAuth.kt b/app/src/main/java/com/aurora/store/data/model/InsecureAuth.kt new file mode 100644 index 000000000..990d13c35 --- /dev/null +++ b/app/src/main/java/com/aurora/store/data/model/InsecureAuth.kt @@ -0,0 +1,25 @@ +/* + * Aurora Store + * Copyright (C) 2021, Rahul Kumar Patel + * + * Aurora Store is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Aurora Store 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 Aurora Store. If not, see . + * + */ + +package com.aurora.store.data.model + +data class InsecureAuth( + val email: String, + val auth: String +) diff --git a/app/src/main/java/com/aurora/store/util/Preferences.kt b/app/src/main/java/com/aurora/store/util/Preferences.kt index 0ed646edf..0aed8bf9e 100644 --- a/app/src/main/java/com/aurora/store/util/Preferences.kt +++ b/app/src/main/java/com/aurora/store/util/Preferences.kt @@ -48,6 +48,8 @@ object Preferences { const val PREFERENCE_TOS_READ = "PREFERENCE_TOS_READ" + const val PREFERENCE_INSECURE_ANONYMOUS = "PREFERENCE_INSECURE_ANONYMOUS" + private fun getPrefs(context: Context): SharedPreferences { return PreferenceManager.getDefaultSharedPreferences(context) diff --git a/app/src/main/java/com/aurora/store/view/ui/commons/BaseActivity.kt b/app/src/main/java/com/aurora/store/view/ui/commons/BaseActivity.kt index acf72de0e..05f847b43 100644 --- a/app/src/main/java/com/aurora/store/view/ui/commons/BaseActivity.kt +++ b/app/src/main/java/com/aurora/store/view/ui/commons/BaseActivity.kt @@ -144,26 +144,32 @@ abstract class BaseActivity : AppCompatActivity(), NetworkProvider.NetworkListen task { TimeUnit.SECONDS.sleep(5) } successUi { - val sheet = TOSSheet.newInstance() - sheet.isCancelable = false - sheet.show(supportFragmentManager, TOSSheet.TAG) + if (!supportFragmentManager.isDestroyed) { + val sheet = TOSSheet.newInstance() + sheet.isCancelable = false + sheet.show(supportFragmentManager, TOSSheet.TAG) + } } } - fun showNetworkConnectivitySheet() { runOnUiThread { - supportFragmentManager.beginTransaction() - .add(NetworkDialogSheet.newInstance(), NetworkDialogSheet.TAG) - .commitAllowingStateLoss() + if (!supportFragmentManager.isDestroyed) { + supportFragmentManager.beginTransaction() + .add(NetworkDialogSheet.newInstance(), NetworkDialogSheet.TAG) + .commitAllowingStateLoss() + } } } fun hideNetworkConnectivitySheet() { runOnUiThread { - val fragment = supportFragmentManager.findFragmentByTag(NetworkDialogSheet.TAG) - fragment?.let { - supportFragmentManager.beginTransaction().remove(fragment).commitAllowingStateLoss() + if (!supportFragmentManager.isDestroyed) { + val fragment = supportFragmentManager.findFragmentByTag(NetworkDialogSheet.TAG) + fragment?.let { + supportFragmentManager.beginTransaction().remove(fragment) + .commitAllowingStateLoss() + } } } } diff --git a/app/src/main/java/com/aurora/store/view/ui/onboarding/OnboardingActivity.kt b/app/src/main/java/com/aurora/store/view/ui/onboarding/OnboardingActivity.kt index a4c397496..46792ad6e 100644 --- a/app/src/main/java/com/aurora/store/view/ui/onboarding/OnboardingActivity.kt +++ b/app/src/main/java/com/aurora/store/view/ui/onboarding/OnboardingActivity.kt @@ -36,6 +36,7 @@ import com.aurora.store.util.Preferences.PREFERENCE_DOWNLOAD_ACTIVE import com.aurora.store.util.Preferences.PREFERENCE_DOWNLOAD_EXTERNAL import com.aurora.store.util.Preferences.PREFERENCE_FILTER_FDROID import com.aurora.store.util.Preferences.PREFERENCE_FILTER_GOOGLE +import com.aurora.store.util.Preferences.PREFERENCE_INSECURE_ANONYMOUS import com.aurora.store.util.Preferences.PREFERENCE_INSTALLER_ID import com.aurora.store.util.Preferences.PREFERENCE_INTRO import com.aurora.store.util.Preferences.PREFERENCE_THEME_ACCENT @@ -155,6 +156,9 @@ class OnboardingActivity : BaseActivity() { save(PREFERENCE_DOWNLOAD_ACTIVE, 3) save(PREFERENCE_DOWNLOAD_EXTERNAL, false) + /*Network*/ + save(PREFERENCE_INSECURE_ANONYMOUS, false) + /*Theme*/ save(PREFERENCE_THEME_TYPE, 0) save(PREFERENCE_THEME_ACCENT, 0) diff --git a/app/src/main/java/com/aurora/store/view/ui/preferences/NetworkPreference.kt b/app/src/main/java/com/aurora/store/view/ui/preferences/NetworkPreference.kt new file mode 100644 index 000000000..d3526a853 --- /dev/null +++ b/app/src/main/java/com/aurora/store/view/ui/preferences/NetworkPreference.kt @@ -0,0 +1,48 @@ +/* + * Aurora Store + * Copyright (C) 2021, Rahul Kumar Patel + * + * Aurora Store is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Aurora Store 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 Aurora Store. If not, see . + * + */ + +package com.aurora.store.view.ui.preferences + +import android.os.Bundle +import androidx.preference.Preference +import androidx.preference.PreferenceFragmentCompat +import com.aurora.extensions.runOnUiThread +import com.aurora.extensions.toast +import com.aurora.store.R +import com.aurora.store.util.CommonUtil +import com.aurora.store.util.Preferences + +class NetworkPreference : PreferenceFragmentCompat() { + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + setPreferencesFromResource(R.xml.preferences_network, rootKey) + + val insecureAnonymous: Preference? = + findPreference(Preferences.PREFERENCE_INSECURE_ANONYMOUS) + + insecureAnonymous?.let { + it.onPreferenceClickListener = + Preference.OnPreferenceClickListener { + runOnUiThread { + requireContext().toast(R.string.insecure_anonymous_apply) + } + false + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/aurora/store/viewmodel/auth/AuthViewModel.kt b/app/src/main/java/com/aurora/store/viewmodel/auth/AuthViewModel.kt index 4bcaba652..f1515380d 100644 --- a/app/src/main/java/com/aurora/store/viewmodel/auth/AuthViewModel.kt +++ b/app/src/main/java/com/aurora/store/viewmodel/auth/AuthViewModel.kt @@ -24,11 +24,13 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import com.aurora.Constants import com.aurora.gplayapi.data.models.AuthData +import com.aurora.gplayapi.data.providers.DeviceInfoProvider import com.aurora.gplayapi.helpers.AuthHelper import com.aurora.gplayapi.helpers.AuthValidator import com.aurora.store.AccountType import com.aurora.store.data.AuthState import com.aurora.store.data.RequestState +import com.aurora.store.data.model.InsecureAuth import com.aurora.store.data.network.HttpClient import com.aurora.store.data.providers.AccountProvider import com.aurora.store.data.providers.NativeDeviceInfoProvider @@ -81,6 +83,19 @@ class AuthViewModel(application: Application) : BaseAndroidViewModel(application } fun buildAnonymousAuthData() { + val insecure = Preferences.getBoolean( + getApplication(), + Preferences.PREFERENCE_INSECURE_ANONYMOUS + ) + + if (insecure) { + buildInSecureAnonymousAuthData() + } else { + buildSecureAnonymousAuthData() + } + } + + private fun buildSecureAnonymousAuthData() { updateStatus("Requesting new session") task { @@ -118,6 +133,54 @@ class AuthViewModel(application: Application) : BaseAndroidViewModel(application } } + private fun buildInSecureAnonymousAuthData() { + updateStatus("Requesting new session") + + task { + var properties = NativeDeviceInfoProvider(getApplication()) + .getNativeDeviceProperties() + + if (spoofProvider.isDeviceSpoofEnabled()) + properties = spoofProvider.getSpoofDeviceProperties() + + val playResponse = HttpClient + .getPreferredClient() + .getAuth( + Constants.URL_DISPENSER + ) + + val insecureAuth: InsecureAuth + + if (playResponse.isSuccessful) { + insecureAuth = gson.fromJson( + String(playResponse.responseBytes), + InsecureAuth::class.java + ) + } else { + when (playResponse.code) { + 404 -> throw Exception("Server unreachable") + 429 -> throw Exception("Oops, You are rate limited") + else -> throw Exception(playResponse.errorString) + } + } + + val deviceInfoProvider = DeviceInfoProvider(properties, Locale.getDefault().toString()) + + AuthHelper.buildInsecure( + insecureAuth.email, + insecureAuth.auth, + Locale.getDefault(), + deviceInfoProvider + ) + } success { + //Set AuthData as anonymous + it.isAnonymous = true + verifyAndSaveAuth(it, AccountType.ANONYMOUS) + } fail { + updateStatus(it.message.toString()) + } + } + private fun buildSavedAuthData() { viewModelScope.launch(Dispatchers.IO) { supervisorScope { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f44cd63fc..51c32b19e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -282,6 +282,8 @@ "Filter F-Droid apps" "Removes all Google Apps from search results and category apps" "Filter Google apps" + "Generate GSF ID locally on device" + "Insecure anonymous session" "Apps are installed instantly after download completes" "Auto install APKs after download" "APKs will be deleted by default" @@ -294,6 +296,7 @@ "Installation method" "Select the target profile to install apps to. Only works with the root installation method" "Installation profiles (Experimental)" + "Networking" "Accent" "Black" "Dark" @@ -312,6 +315,7 @@ "Session expired, re-login to obtain new session." "Make sure you re-login to apply the spoof" + "Make sure you re-login and restart app to apply changes." "Categories" "Editor's choice" diff --git a/app/src/main/res/xml/preferences_main.xml b/app/src/main/res/xml/preferences_main.xml index c0f702f19..bc57a6a3a 100644 --- a/app/src/main/res/xml/preferences_main.xml +++ b/app/src/main/res/xml/preferences_main.xml @@ -49,4 +49,12 @@ app:key="pref_download" app:layout="@layout/item_preference" app:title="@string/pref_app_download" /> + + \ No newline at end of file diff --git a/app/src/main/res/xml/preferences_network.xml b/app/src/main/res/xml/preferences_network.xml new file mode 100644 index 000000000..68afb204a --- /dev/null +++ b/app/src/main/res/xml/preferences_network.xml @@ -0,0 +1,28 @@ + + + + + + \ No newline at end of file