Source:
public void attestationTest() throws Exception { Context appContext = InstrumentationRegistry.getTargetContext(); IdentityCredentialStore store = IdentityCredentialStore.getInstance(appContext); SecureRandom random = new SecureRandom(); int challengeLength = 16 + random.nextInt(16); byte[] challenge = new byte[challengeLength]; random.nextBytes(challenge); String credentialName = "test"; store.deleteCredentialByName(credentialName); Collection<X509Certificate> certChain = ProvisioningTest.createCredential(store, credentialName); store.deleteCredentialByName("test"); assertTrue(verifyCertificateChain(certChain)); X509Certificate cert = certChain.iterator().next(); ParsedAttestationRecord record = new ParsedAttestationRecord(cert); assertTrue(record.getAttestationVersion() >= 3); ParsedAttestationRecord.SecurityLevel asl = record.getAttestationSecurityLevel(); assertTrue(asl == ParsedAttestationRecord.SecurityLevel.TRUSTED_ENVIRONMENT || asl == ParsedAttestationRecord.SecurityLevel.STRONG_BOX); ParsedAttestationRecord.SecurityLevel kmsl = record.getKeymasterSecurityLevel(); assertTrue(kmsl == ParsedAttestationRecord.SecurityLevel.TRUSTED_ENVIRONMENT || kmsl == ParsedAttestationRecord.SecurityLevel.STRONG_BOX); assertTrue(record.getKeymasterVersion() >= 10); assertArrayEquals(challenge, record.getAttestationChallenge()); Optional<byte[]> attestationApplicationId = record.getSoftwareAuthorizationByteString(KM_TAG_ATTESTATION_APPLICATION_ID); assertTrue(attestationApplicationId.isPresent()); String appId = appContext.getPackageName(); assertTrue(Bytes.indexOf(attestationApplicationId.get(), appId.getBytes()) != -1); boolean isIdentityCredentialKey = record.getTeeAuthorizationBoolean(KM_TAG_IDENTITY_CREDENTIAL_KEY); assertTrue(isIdentityCredentialKey); }

Target:
public void attestationTest() throws Exception { Context appContext = InstrumentationRegistry.getTargetContext(); IdentityCredentialStore store = IdentityCredentialStore.getInstance(appContext); SecureRandom random = new SecureRandom(); int challengeLength = 16 + random.nextInt(16); byte[] challenge = new byte[challengeLength]; random.nextBytes(challenge); String credentialName = "test"; store.deleteCredentialByName(credentialName); Collection<X509Certificate> certChain = ProvisioningTest.createCredentialWithChallenge( store, credentialName, challenge); store.deleteCredentialByName("test"); assertTrue(verifyCertificateChain(certChain)); X509Certificate cert = certChain.iterator().next(); ParsedAttestationRecord record = new ParsedAttestationRecord(cert); assertTrue(record.getAttestationVersion() >= 3); assertTrue(record.getKeymasterVersion() >= 10); assertTrue(record.getKeymasterVersion() < 40); assertArrayEquals(challenge, record.getAttestationChallenge()); Optional<byte[]> attestationApplicationId = record.getSoftwareAuthorizationByteString(KM_TAG_ATTESTATION_APPLICATION_ID); assertTrue(attestationApplicationId.isPresent()); String appId = appContext.getPackageName(); assertTrue(Bytes.indexOf(attestationApplicationId.get(), appId.getBytes()) != -1); boolean isIdentityCredentialKey = record.getTeeAuthorizationBoolean(KM_TAG_IDENTITY_CREDENTIAL_KEY); assertTrue(isIdentityCredentialKey); }