-
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.
Update libs.versions.toml to remove the GDS networking library dependency Update build.gradle.kts to remove usage of the GDS networking dependency Add AttestationClient to use in place of GenericHttpClient Add JWK object to hold the relevant details for the attestation JWK Swap from GenericHttpClient to AttestationClient Update tests Resolves: 10311
- Loading branch information
1 parent
61409e9
commit b9f16c0
Showing
9 changed files
with
96 additions
and
60 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
5 changes: 2 additions & 3 deletions
5
app/src/main/java/uk/gov/android/authentication/integrity/model/AppIntegrityConfiguration.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,10 +1,9 @@ | ||
package uk.gov.android.authentication.integrity.model | ||
|
||
import uk.gov.android.authentication.integrity.appcheck.AppChecker | ||
import uk.gov.android.network.client.GenericHttpClient | ||
import uk.gov.android.authentication.integrity.usecase.AttestationClient | ||
|
||
data class AppIntegrityConfiguration( | ||
val httpClient: GenericHttpClient, | ||
val attestationUrl: String, | ||
val attestationClient: AttestationClient, | ||
val appChecker: AppChecker | ||
) |
33 changes: 14 additions & 19 deletions
33
app/src/main/java/uk/gov/android/authentication/integrity/usecase/AttestationApiCall.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,31 +1,26 @@ | ||
package uk.gov.android.authentication.integrity.usecase | ||
|
||
import uk.gov.android.network.api.ApiRequest | ||
import uk.gov.android.network.api.ApiResponse | ||
import uk.gov.android.network.client.GenericHttpClient | ||
|
||
internal fun interface AttestationApiCaller { | ||
suspend fun call( | ||
firebaseToken: String, | ||
backendUrl: String | ||
signedProofOfPossession: String, | ||
jwkX: String, | ||
jwkY: String | ||
): String | ||
} | ||
|
||
internal class AttestationApiCallerImpl ( | ||
private val httpClient: GenericHttpClient | ||
private val client: AttestationClient | ||
) : AttestationApiCaller { | ||
override suspend fun call(firebaseToken: String, backendUrl: String): String { | ||
val request = ApiRequest.Get( | ||
url = backendUrl, | ||
headers = listOf( | ||
"X-Firebase-Token" to firebaseToken | ||
) | ||
) | ||
val response = httpClient.makeRequest(request) | ||
return if (response is ApiResponse.Success<*>) { | ||
response.response.toString() | ||
} else { | ||
(response as ApiResponse.Failure).error.message ?: "Error" | ||
|
||
override suspend fun call( | ||
signedProofOfPossession: String, | ||
jwkX: String, | ||
jwkY: String | ||
): String { | ||
val result = client.attest(signedProofOfPossession, JWK.makeJWK(jwkX, jwkY)) | ||
return when { | ||
result.isSuccess -> result.getOrNull()?.jwt ?: "Empty" | ||
else -> result.exceptionOrNull()?.message ?: "Error" | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/uk/gov/android/authentication/integrity/usecase/AttestationClient.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,14 @@ | ||
package uk.gov.android.authentication.integrity.usecase | ||
|
||
import org.jose4j.jwk.JsonWebKey | ||
|
||
fun interface AttestationClient { | ||
suspend fun attest(popJWT: String, request: JsonWebKey): Result<Response> | ||
|
||
data class Response(val jwt: String, val expiresIn: Long) | ||
|
||
companion object { | ||
@Suppress("unused") | ||
protected const val FIREBASE_HEADER = "X-Firebase-AppCheck" | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/uk/gov/android/authentication/integrity/usecase/JWK.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,25 @@ | ||
package uk.gov.android.authentication.integrity.usecase | ||
|
||
import org.jose4j.jwk.JsonWebKey | ||
|
||
@Suppress("MemberVisibilityCanBePrivate") | ||
object JWK { | ||
const val keyType = "kty" | ||
const val use = "use" | ||
const val curve = "crv" | ||
const val x = "x" | ||
const val y = "y" | ||
private const val keyTypeValue = "EC" | ||
private const val useValue = "sig" | ||
private const val curveValue = "P-256" | ||
|
||
fun makeJWK(x: String, y: String): JsonWebKey = JsonWebKey.Factory.newJwk( | ||
mapOf( | ||
keyType to keyTypeValue, | ||
use to useValue, | ||
curve to curveValue, | ||
JWK.x to x, | ||
JWK.y to y | ||
) | ||
) | ||
} |
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
18 changes: 18 additions & 0 deletions
18
app/src/test/java/uk/gov/android/authentication/integrity/usecase/JWKTest.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,18 @@ | ||
package uk.gov.android.authentication.integrity.usecase | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class JWKTest { | ||
@Test | ||
fun `makeJWK sets defaults`() { | ||
val actual = JWK.makeJWK(X, Y) | ||
assertEquals(expected = "EC", actual = actual.keyType) | ||
assertEquals(expected = "sig", actual = actual.use) | ||
} | ||
|
||
companion object { | ||
const val X = "18wHLeIgW9wVN6VD1Txgpqy2LszYkMf6J8njVAibvhM" | ||
const val Y = "-V4dS4UaLMgP_4fY4j8ir7cl1TXlFdAgcx55o7TkcSA" | ||
} | ||
} |
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