-
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.
feat: Add functionality for mobile-backend/client-attestation call (#98)
* feat: Add functionality for mobile-backend/client-attestation call - update AttestationCaller interface to enable use of firebase token and jwk - update jwk to a custom impl (JWK provided by jose4.jwt was not serializable) to enable use in the backend call - update FirebaseClientAttestationManager to add logic for the attestation call once firebase call is successful - update keystore manager to enable getting the public key in the required format * fix: Fix detekt issue in test file * style: Remove unused import * test: Amend tests with the correct impl * refactor: Amend AttestationCaller and AttestationResponse - simplify the result returned from the attestation caller - update attestation response to meet requirements from backend * style: Remove unnecessary lint supression
- Loading branch information
1 parent
bcd5c1d
commit 0fb4ce9
Showing
8 changed files
with
123 additions
and
27 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
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
13 changes: 12 additions & 1 deletion
13
app/src/main/java/uk/gov/android/authentication/integrity/model/AttestationResponse.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,6 +1,17 @@ | ||
package uk.gov.android.authentication.integrity.model | ||
|
||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.json.JsonNames | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
sealed class AttestationResponse { | ||
data class Success(val attestationJwt: String) : AttestationResponse() | ||
@Serializable | ||
data class Success( | ||
@JsonNames("client_attestation") | ||
val attestationJwt: String, | ||
@JsonNames("expires_in") | ||
val expiresIn: String | ||
) : AttestationResponse() | ||
data class Failure(val reason: String, val error: Throwable? = null) : AttestationResponse() | ||
} |
13 changes: 7 additions & 6 deletions
13
app/src/main/java/uk/gov/android/authentication/integrity/usecase/AttestationCaller.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,16 +1,17 @@ | ||
package uk.gov.android.authentication.integrity.usecase | ||
|
||
import uk.gov.android.authentication.integrity.model.AttestationResponse | ||
|
||
@Suppress("unused") | ||
fun interface AttestationCaller { | ||
suspend fun call( | ||
signedProofOfPossession: String, | ||
jwkX: String, | ||
jwkY: String | ||
): Result<Response> | ||
|
||
data class Response(val jwt: String, val expiresIn: Long) | ||
firebaseToken: String, | ||
jwk: JWK.JsonWebKey | ||
): AttestationResponse | ||
|
||
companion object { | ||
const val FIREBASE_HEADER = "X-Firebase-AppCheck" | ||
const val CONTENT_TYPE = "Content-type" | ||
const val CONTENT_TYPE_VALUE = "application/json" | ||
} | ||
} |
35 changes: 22 additions & 13 deletions
35
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 |
---|---|---|
@@ -1,25 +1,34 @@ | ||
package uk.gov.android.authentication.integrity.usecase | ||
|
||
import org.jose4j.jwk.JsonWebKey | ||
import kotlinx.serialization.Serializable | ||
|
||
@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 | ||
fun makeJWK(x: String, y: String): JsonWebKey = JsonWebKey( | ||
jwk = JsonWebKeyFormat( | ||
keyTypeValue, | ||
useValue, | ||
curveValue, | ||
x, | ||
y | ||
) | ||
) | ||
|
||
@Serializable | ||
data class JsonWebKey( | ||
val jwk: JsonWebKeyFormat | ||
) | ||
|
||
@Serializable | ||
data class JsonWebKeyFormat( | ||
val kty: String, | ||
val use: String, | ||
val crv: String, | ||
val x: String, | ||
val y: String | ||
) | ||
} |
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