forked from Displax/safetynet-fix
-
Notifications
You must be signed in to change notification settings - Fork 6
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
0283018
commit 4079142
Showing
2 changed files
with
25 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,10 @@ class ProxyKeyStoreSpi private constructor( | |
// Avoid breaking other, legitimate uses of key attestation in Google Play Services, e.g. | ||
// - com.google.android.gms.auth.cryptauth.register.ReEnrollmentChimeraService | ||
// - tk_trace.129-RegisterForKeyPairOperation | ||
private fun isCallerSafetyNet() = Thread.currentThread().stackTrace.any { | ||
private fun isCallerDeniedOrSafetyNet(): Boolean { | ||
var isGMS = false | ||
|
||
// SafetyNet stack trace example: | ||
// a.a.engineGetCertificateChain(Unknown Source:15) | ||
// java.security.KeyStore.getCertificateChain(KeyStore.java:1087) | ||
// com.google.ccc.abuse.droidguard.DroidGuard.initNative(Native Method) | ||
|
@@ -33,14 +36,25 @@ class ProxyKeyStoreSpi private constructor( | |
// dzx.onTransact(:com.google.android.gms@[email protected] (190400-387928701):8) | ||
// android.os.Binder.execTransactInternal(Binder.java:1179) | ||
// android.os.Binder.execTransact(Binder.java:1143) | ||
logDebug("Stack trace element: $it") | ||
it.className.contains("DroidGuard", ignoreCase = true) | ||
for (it in Thread.currentThread().stackTrace) { | ||
logDebug("Stack trace element: $it") | ||
|
||
if (it.className.contains("DroidGuard", ignoreCase = true)) { | ||
return true | ||
} | ||
|
||
if (!isGMS && it.className.contains("com.google.android.gms", ignoreCase = true)) { | ||
isGMS = true | ||
} | ||
} | ||
|
||
return !isGMS | ||
} | ||
|
||
override fun engineGetCertificateChain(alias: String?): Array<Certificate>? { | ||
logDebug("Proxy key store: get certificate chain") | ||
|
||
if (isCallerSafetyNet()) { | ||
if (isCallerDeniedOrSafetyNet()) { | ||
logDebug("Blocking call") | ||
throw UnsupportedOperationException() | ||
} else { | ||
|
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