-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[updates] Merge remote-tracking branch 'origin/feature/google-play-in…
…tegrity' into feature/updates # Conflicts: # gradle.properties
- Loading branch information
Showing
5 changed files
with
20 additions
and
13 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
24 changes: 15 additions & 9 deletions
24
...m/src/androidMain/kotlin/ch/dreipol/dreiattest/multiplatform/GoogleAttestationProvider.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 |
---|---|---|
@@ -1,24 +1,30 @@ | ||
package ch.dreipol.dreiattest.multiplatform | ||
|
||
import android.content.Context | ||
import android.util.Base64 | ||
import ch.dreipol.dreiattest.multiplatform.api.dto.Attestation | ||
import ch.dreipol.dreiattest.multiplatform.utils.DeviceSystemInfo | ||
import ch.dreipol.dreiattest.multiplatform.utils.Hash | ||
import ch.dreipol.dreiattest.multiplatform.utils.SystemInfo | ||
import com.google.android.gms.common.ConnectionResult | ||
import com.google.android.gms.common.GoogleApiAvailability | ||
import com.google.android.gms.safetynet.SafetyNet | ||
import com.google.android.play.core.integrity.IntegrityManagerFactory | ||
import com.google.android.play.core.integrity.IntegrityTokenRequest | ||
import kotlinx.coroutines.tasks.await | ||
|
||
internal const val platformDriver = "google" | ||
internal const val platformDriver = "google_play_integrity_api" | ||
|
||
public class GoogleAttestationProvider(private val context: Context, private val apiKey: String) : AttestationProvider { | ||
class GoogleAttestationProvider(private val context: Context, private val cloudProjectNumber: Long? = null) : AttestationProvider { | ||
private val integrityManager by lazy { | ||
IntegrityManagerFactory.create(context) | ||
} | ||
override val systemInfo: SystemInfo = DeviceSystemInfo(context) | ||
override val isSupported: Boolean = | ||
GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS | ||
override val isSupported: Boolean = true | ||
|
||
|
||
public override suspend fun getAttestation(nonce: Hash, publicKey: String): Attestation { | ||
val deviceAttestation = SafetyNet.getClient(context).attest(nonce, apiKey).await().jwsResult!! | ||
override suspend fun getAttestation(nonce: Hash, publicKey: String): Attestation { | ||
val requestBuilder = IntegrityTokenRequest.builder() | ||
.setNonce(Base64.encodeToString(nonce, Base64.URL_SAFE or Base64.NO_WRAP)) | ||
cloudProjectNumber?.let { requestBuilder.setCloudProjectNumber(it) } | ||
val deviceAttestation = integrityManager.requestIntegrityToken(requestBuilder.build()).await().token() | ||
return Attestation(publicKey = publicKey, attestation = deviceAttestation, driver = platformDriver) | ||
} | ||
} |
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