-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
app: generate key using SAK when available
Signed-off-by: BlackMesa123 <[email protected]>
- Loading branch information
1 parent
2dd9cb0
commit 67437d6
Showing
3 changed files
with
89 additions
and
3 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
60 changes: 60 additions & 0 deletions
60
app/src/main/java/io/github/vvb2060/keyattestation/util/SamsungUtils.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,60 @@ | ||
package io.github.vvb2060.keyattestation.util | ||
|
||
import android.content.pm.PackageManager | ||
import android.os.SystemProperties | ||
import android.util.Log | ||
import androidx.core.content.ContextCompat | ||
import io.github.vvb2060.keyattestation.AppApplication | ||
|
||
object SamsungUtils { | ||
private const val SAMSUNG_KEYSTORE_PERMISSION = | ||
"com.samsung.android.security.permission.SAMSUNG_KEYSTORE_PERMISSION" | ||
|
||
fun isSecAttestationSupported(): Boolean { | ||
if (!isSamsungKeystoreLibrarySupported()) { | ||
Log.w(AppApplication.TAG, "This device has no samsungkeystoreutils library, " + | ||
"skipping SAK.") | ||
return false | ||
} | ||
|
||
if (!isSAKSupported()) { | ||
Log.w(AppApplication.TAG, "This device has no SAK support, " + | ||
"skipping SAK.") | ||
return false | ||
} | ||
|
||
if (!isKeystorePermissionGranted()) { | ||
Log.e(AppApplication.TAG, "SAMSUNG_KEYSTORE_PERMISSION has not been granted to the app, " + | ||
"skipping SAK.") | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
private fun isSamsungKeystoreLibrarySupported(): Boolean { | ||
val pm: PackageManager = AppApplication.app.packageManager | ||
val systemSharedLibraries = pm.systemSharedLibraryNames | ||
|
||
if (systemSharedLibraries != null) { | ||
for (lib in systemSharedLibraries) { | ||
if (lib != null && lib.lowercase() == "samsungkeystoreutils") { | ||
return true | ||
} | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
private fun isSAKSupported(): Boolean { | ||
return SystemProperties.get("ro.security.keystore.keytype", "").lowercase() | ||
.contains("sak") | ||
} | ||
|
||
private fun isKeystorePermissionGranted(): Boolean{ | ||
return ContextCompat.checkSelfPermission( | ||
AppApplication.app, SAMSUNG_KEYSTORE_PERMISSION) == | ||
PackageManager.PERMISSION_GRANTED | ||
} | ||
} |