-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
511afe8
commit 1b04f4b
Showing
27 changed files
with
1,833 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
play-services-droidguard/src/main/kotlin/org/microg/gms/droidguard/HandleProxy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.microg.gms.droidguard | ||
|
||
import android.content.Context | ||
import android.os.Parcelable | ||
|
||
class HandleProxy(private val handle: Any, val vmKey: String) { | ||
constructor(clazz: Class<*>, context: Context, vmKey: String, data: Parcelable) : this(kotlin.runCatching { | ||
clazz.getDeclaredConstructor(Context::class.java, Parcelable::class.java).newInstance(context, data) | ||
}.getOrElse { | ||
throw it | ||
}, vmKey | ||
) | ||
|
||
fun init(): Boolean { | ||
try { | ||
return handle.javaClass.getDeclaredMethod("init").invoke(handle) as Boolean | ||
} catch (e: Exception) { | ||
throw e | ||
} | ||
} | ||
|
||
fun close() { | ||
try { | ||
handle.javaClass.getDeclaredMethod("close").invoke(handle) | ||
} catch (e: Exception) { | ||
throw e | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
play-services-droidguard/src/main/kotlin/org/microg/gms/droidguard/HandleProxyFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.microg.gms.droidguard | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.os.ParcelFileDescriptor | ||
import dalvik.system.DexClassLoader | ||
import java.io.File | ||
import java.io.IOException | ||
import java.util.UUID | ||
|
||
class HandleProxyFactory(private val context: Context) { | ||
private fun getTheApkFile(vmKey: String) = File(getCacheDir(vmKey), "the.apk") | ||
private fun getCacheDir() = context.getDir(CACHE_FOLDER_NAME, Context.MODE_PRIVATE) | ||
private fun getCacheDir(vmKey: String) = File(getCacheDir(), vmKey) | ||
private fun getOptDir(vmKey: String) = File(getCacheDir(vmKey), "opt") | ||
private fun isValidCache(vmKey: String) = getTheApkFile(vmKey).isFile && getOptDir(vmKey).isDirectory | ||
|
||
private fun updateCacheTimestamp(vmKey: String) { | ||
try { | ||
val timestampFile = File(getCacheDir(vmKey), "t") | ||
if (!timestampFile.exists() && !timestampFile.createNewFile()) { | ||
throw Exception("Failed to touch last-used file for $vmKey.") | ||
} | ||
if (!timestampFile.setLastModified(System.currentTimeMillis())) { | ||
throw Exception("Failed to update last-used timestamp for $vmKey.") | ||
} | ||
} catch (e: IOException) { | ||
throw Exception("Failed to touch last-used file for $vmKey.") | ||
} | ||
} | ||
|
||
private fun verifyApkSignature(apk: File): Boolean { | ||
return true | ||
} | ||
|
||
private fun copyTheApk(pfd: ParcelFileDescriptor, vmKey: String) { | ||
if (!isValidCache(vmKey)) { | ||
val auIs = ParcelFileDescriptor.AutoCloseInputStream(pfd) | ||
val temp = File(getCacheDir(), "${UUID.randomUUID()}.apk") | ||
temp.parentFile!!.mkdirs() | ||
temp.writeBytes(auIs.readBytes()) | ||
auIs.close() | ||
getOptDir(vmKey).mkdirs() | ||
temp.renameTo(getTheApkFile(vmKey)) | ||
updateCacheTimestamp(vmKey) | ||
if (!isValidCache(vmKey)) { | ||
getCacheDir(vmKey).deleteRecursively() | ||
throw IllegalStateException("unknown except") | ||
} | ||
} | ||
} | ||
|
||
fun createHandle(vmKey: String, pfd: ParcelFileDescriptor, extras: Bundle): HandleProxy { | ||
copyTheApk(pfd, vmKey) | ||
val clazz = loadClass(vmKey) | ||
return HandleProxy(clazz, context, vmKey, extras) | ||
} | ||
|
||
private fun loadClass(vmKey: String): Class<*> { | ||
val clazz = classMap[vmKey] | ||
if (clazz != null) { | ||
updateCacheTimestamp(vmKey) | ||
return clazz | ||
} else { | ||
if (!isValidCache(vmKey)) { | ||
throw RuntimeException("VM key $vmKey not found in cache") | ||
} | ||
if (!verifyApkSignature(getTheApkFile(vmKey))) { | ||
getCacheDir(vmKey).deleteRecursively() | ||
throw ClassNotFoundException("APK signature verification failed") | ||
} | ||
val loader = DexClassLoader( | ||
getTheApkFile(vmKey).absolutePath, getOptDir(vmKey).absolutePath, null, context.classLoader | ||
) | ||
val clazz = loader.loadClass(CLASS_NAME) | ||
classMap[vmKey] = clazz | ||
return clazz | ||
} | ||
} | ||
|
||
companion object { | ||
const val CLASS_NAME = "com.google.ccc.abuse.droidguard.DroidGuard" | ||
const val CACHE_FOLDER_NAME = "cache_dg" | ||
val classMap = hashMapOf<String, Class<*>>() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...c/main/aidl/com/google/android/play/core/integrity/protocol/IExpressIntegrityService.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.google.android.play.core.integrity.protocol; | ||
|
||
import com.google.android.play.core.integrity.protocol.IExpressIntegrityServiceCallback; | ||
import com.google.android.play.core.integrity.protocol.IRequestDialogCallback; | ||
|
||
interface IExpressIntegrityService { | ||
void warmUpIntegrityToken(in Bundle bundle, in IExpressIntegrityServiceCallback callback) = 1; | ||
void requestExpressIntegrityToken(in Bundle bundle, in IExpressIntegrityServiceCallback callback) = 2; | ||
void requestAndShowDialog(in Bundle bundle, in IRequestDialogCallback callback) = 5; | ||
} |
12 changes: 12 additions & 0 deletions
12
...idl/com/google/android/play/core/integrity/protocol/IExpressIntegrityServiceCallback.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.google.android.play.core.integrity.protocol; | ||
|
||
interface IExpressIntegrityServiceCallback { | ||
void OnWarmUpIntegrityTokenCallback(in Bundle bundle) = 1; | ||
void onRequestExpressIntegrityToken(in Bundle bundle) = 2; | ||
void onRequestIntegrityToken(in Bundle bundle) = 3; | ||
} |
14 changes: 14 additions & 0 deletions
14
...-app/src/main/aidl/com/google/android/play/core/integrity/protocol/IIntegrityService.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.google.android.play.core.integrity.protocol; | ||
|
||
import com.google.android.play.core.integrity.protocol.IIntegrityServiceCallback; | ||
import com.google.android.play.core.integrity.protocol.IRequestDialogCallback; | ||
|
||
interface IIntegrityService { | ||
void requestDialog(in Bundle bundle, in IRequestDialogCallback callback) = 0; | ||
void requestIntegrityToken(in Bundle request, in IIntegrityServiceCallback callback) = 1; | ||
} |
10 changes: 10 additions & 0 deletions
10
.../main/aidl/com/google/android/play/core/integrity/protocol/IIntegrityServiceCallback.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.google.android.play.core.integrity.protocol; | ||
|
||
interface IIntegrityServiceCallback { | ||
void onResult(in Bundle bundle) = 1; | ||
} |
10 changes: 10 additions & 0 deletions
10
...src/main/aidl/com/google/android/play/core/integrity/protocol/IRequestDialogCallback.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.google.android.play.core.integrity.protocol; | ||
|
||
interface IRequestDialogCallback { | ||
void onRequestAndShowDialog(in Bundle bundle); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.