-
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: Generate ProofOfPosession (#101)
* feat: Create ProofOfPosession structure and amend KeyStoreManager - create KeyStreManager interface - amend KeyStoreManager impl name and availabel functions to allow for signing and verifying Signature for Jwt * refactor: Amend naming to be more accurate * feat: Amend FirebaseClientAttestationManager to enable getting PoP - amend implementation to create sign PoP and create PoP Jwt * test: Fix tests * fix: Change exp time to 3 minutes * test: Remove unused import and add test * feat: Expose ECKeyManager * refactor: Change the integrity package structure - pkg structure based on functionality * test: Amend tests * style: Add Log for the signature verification for QA purpose * refactor: Change names to be more specific
- Loading branch information
1 parent
cc9fce3
commit f8a1b5d
Showing
21 changed files
with
390 additions
and
182 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
65 changes: 0 additions & 65 deletions
65
app/src/androidTest/java/uk/gov/android/authentication/integrity/KeystoreManagerTest.kt
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
...c/androidTest/java/uk/gov/android/authentication/integrity/keymanager/ECKeyManagerTest.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,63 @@ | ||
package uk.gov.android.authentication.integrity.keymanager | ||
|
||
import org.junit.Assert.assertThrows | ||
import uk.gov.android.authentication.integrity.pop.ProofOfPossessionGenerator | ||
import org.junit.Test as JUnitTest | ||
import java.security.KeyStore | ||
import kotlin.io.encoding.ExperimentalEncodingApi | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertTrue | ||
|
||
@OptIn(ExperimentalEncodingApi::class) | ||
class ECKeyManagerTest { | ||
private lateinit var keyStore: KeyStore | ||
private lateinit var ecKeyManager: ECKeyManager | ||
|
||
@BeforeTest | ||
fun setup() { | ||
keyStore = KeyStore.getInstance("AndroidKeyStore").apply { | ||
load(null) | ||
} | ||
ecKeyManager = ECKeyManager() | ||
} | ||
|
||
@Test | ||
fun check_keys_created_on_initialization() { | ||
assertTrue(keyStore.containsAlias("app_check_keys")) | ||
} | ||
|
||
@Test | ||
fun check_getPublicKey() { | ||
val actual = ecKeyManager.getPublicKey() | ||
|
||
assertTrue(checkInputIsBase64(actual.first)) | ||
assertTrue(checkInputIsBase64(actual.second)) | ||
} | ||
|
||
@Test | ||
fun check_sign_success() { | ||
val signature = ecKeyManager.sign("Success".toByteArray()) | ||
|
||
assertTrue(ecKeyManager.verify("Success".toByteArray(), signature)) | ||
} | ||
|
||
|
||
|
||
@JUnitTest | ||
fun check_verify_failure() { | ||
assertThrows(ECKeyManager.SigningError.InvalidSignature::class.java) { | ||
ecKeyManager.verify("Success".toByteArray(), "Success".toByteArray()) | ||
} | ||
} | ||
|
||
@Suppress("SwallowedException") | ||
private fun checkInputIsBase64(input: String): Boolean { | ||
return try { | ||
ProofOfPossessionGenerator.getUrlSafeNoPaddingBase64(input.toByteArray()) | ||
true | ||
} catch (e: IllegalArgumentException) { | ||
false | ||
} | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
app/src/main/java/uk/gov/android/authentication/integrity/ClientAttestationManager.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,9 +1,9 @@ | ||
package uk.gov.android.authentication.integrity | ||
|
||
import uk.gov.android.authentication.integrity.model.AttestationResponse | ||
import uk.gov.android.authentication.integrity.model.SignedResponse | ||
import uk.gov.android.authentication.integrity.appcheck.model.AttestationResponse | ||
import uk.gov.android.authentication.integrity.pop.SignedPoP | ||
|
||
interface ClientAttestationManager { | ||
suspend fun getAttestation(): AttestationResponse | ||
suspend fun signAttestation(attestation: String): SignedResponse | ||
fun generatePoP(iss: String, aud: String): SignedPoP | ||
} |
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
Oops, something went wrong.