generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PAS-531 | Generate Facet ID for Android (#70)
- Loading branch information
1 parent
fdd15a2
commit 8654f16
Showing
10 changed files
with
63 additions
and
127 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
4 changes: 0 additions & 4 deletions
4
app/src/main/java/dev/passwordless/sampleapp/LoginFragment.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
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
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
43 changes: 43 additions & 0 deletions
43
passwordless/src/main/java/dev/passwordless/android/utils/SignatureService.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,43 @@ | ||
package dev.passwordless.android.utils | ||
|
||
import android.content.Context | ||
import android.content.pm.PackageInfo | ||
import android.content.pm.PackageManager | ||
import android.content.pm.Signature | ||
import dev.passwordless.android.rest.converters.Base64UrlConverter | ||
import java.security.MessageDigest | ||
|
||
class SignatureService { | ||
private val context: Context | ||
private var facetId: String? = null | ||
|
||
constructor(context: Context) { | ||
this.context = context; | ||
} | ||
|
||
fun getFacetId(): String { | ||
if (facetId != null) { | ||
return facetId!! | ||
} | ||
val packageManager = context.packageManager | ||
val packageName = context.packageName | ||
try { | ||
val packageInfo: PackageInfo = packageManager.getPackageInfo( | ||
packageName, | ||
PackageManager.GET_SIGNING_CERTIFICATES) | ||
|
||
val signatures: Array<Signature> = packageInfo.signingInfo.apkContentsSigners | ||
|
||
val signature: ByteArray = signatures[0].toByteArray() | ||
val md: MessageDigest = MessageDigest.getInstance("SHA-256") | ||
val hash: ByteArray = md.digest(signature) | ||
|
||
val shortFacetId = Base64UrlConverter.convert(hash) | ||
this.facetId = "android:apk-key-hash:$shortFacetId" | ||
return facetId!! | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
throw e | ||
} | ||
} | ||
} |
Oops, something went wrong.