Add support for insecure anonymous session, open bridge geo-spoofing

This commit is contained in:
Rahul Kumar Patel
2021-03-29 07:49:10 +05:30
parent d6d1bdca7d
commit ea290fedba
10 changed files with 199 additions and 11 deletions

View File

@@ -0,0 +1,25 @@
/*
* Aurora Store
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.aurora.store.data.model
data class InsecureAuth(
val email: String,
val auth: String
)

View File

@@ -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)

View File

@@ -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()
}
}
}
}

View File

@@ -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)

View File

@@ -0,0 +1,48 @@
/*
* Aurora Store
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
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
}
}
}
}

View File

@@ -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 {