getsentry / getsentry/sentry-java

Report app's signature as part of app context

Ouverte
#2,825 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Android Errors Improvement
Langage dominant
Kotlin
Étoiles
1.4k
Forks
478
Merge moyen
2 j 23 h
PR mergées (30 j)
67

Description

### Description

This can be used to understand if strange errors are thrown from reverse-engineered apps or if it's your own app.
This can be sensitive, maybe it should be hidden behind a flag.
If possible, that applies to Apple apps as well.

```
@Suppress("DEPRECATION")
fun Context.getPackageInfoCompat(): PackageInfo =
if (VERSION.SDK_INT >= VERSION_CODES.P) {
packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES)
} else {
packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES)
}

@Suppress("DEPRECATION")
fun Context.getApkSignaturesCompat(): Array =
if (VERSION.SDK_INT >= VERSION_CODES.P) {
getPackageInfoCompat().signingInfo.apkContentsSigners
} else {
getPackageInfoCompat().signatures
}

fun bytesToHex(bytes: ByteArray): String {
val builder = StringBuilder()
bytes.forEachIndexed { index, byte ->
builder.append("%02x".format(Locale.ROOT, byte).uppercase())
if (index < bytes.size - 1) {
builder.append(":")
}
}
return builder.toString()
}

fun getAppSignatureHash(context: Context): String? = kotlin.runCatching {
val md = MessageDigest.getInstance("SHA-256")
val sig = context.getApkSignaturesCompat().firstOrNull() ?: return null
md.update(sig.toByteArray())
val digest = md.digest()
bytesToHex(digest)
}.getOrNull()

//...
val signature = getAppSignatureHash(context)
```

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.