Skip to content

Commit

Permalink
Fix identity-android unit tests.
Browse files Browse the repository at this point in the history
These tests haven't compiled for a while. Fix this.

Test: Verify identity and identity-android unit tests pass.
  • Loading branch information
davidz25 committed Oct 27, 2023
1 parent b4e1051 commit 24e47ec
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import androidx.test.filters.LargeTest;

import com.android.identity.internal.Util;
import com.android.identity.securearea.SecureArea;
import com.android.identity.util.Constants;

import org.junit.Test;
Expand Down Expand Up @@ -200,7 +201,7 @@ public void dynamicAuthTest() throws Exception {
+ "}",
pretty);

KeyPair readerEphemeralKeyPair = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair readerEphemeralKeyPair = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);

credential = store.getCredentialByName(credentialName,
IdentityCredentialStore.CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256);
Expand Down Expand Up @@ -647,7 +648,7 @@ public void dynamicAuthWithExpirationTest() throws Exception {
IdentityCredential tc = store.getCredentialByName(credentialName,
IdentityCredentialStore.CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256);
KeyPair ekp = tc.createEphemeralKeyPair();
KeyPair rekp = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair rekp = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
tc.setReaderEphemeralPublicKey(rekp.getPublic());
tc.setSessionTranscript(Util.buildSessionTranscript(ekp));
Map<String, Collection<String>> etr = new LinkedHashMap<>();
Expand Down Expand Up @@ -676,7 +677,7 @@ public void dynamicAuthWithExpirationTest() throws Exception {
IdentityCredential tc = store.getCredentialByName(credentialName,
IdentityCredentialStore.CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256);
KeyPair ekp = tc.createEphemeralKeyPair();
KeyPair rekp = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair rekp = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
tc.setReaderEphemeralPublicKey(rekp.getPublic());
tc.setSessionTranscript(Util.buildSessionTranscript(ekp));
Map<String, Collection<String>> etr = new LinkedHashMap<>();
Expand Down Expand Up @@ -704,7 +705,7 @@ public void dynamicAuthWithExpirationTest() throws Exception {
IdentityCredentialStore.CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256);
tc.setAllowUsingExpiredKeys(true); // <-- this is the call that makes the difference!
KeyPair ekp = tc.createEphemeralKeyPair();
KeyPair rekp = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair rekp = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
tc.setReaderEphemeralPublicKey(rekp.getPublic());
tc.setSessionTranscript(Util.buildSessionTranscript(ekp));
Map<String, Collection<String>> etr = new LinkedHashMap<>();
Expand Down Expand Up @@ -776,7 +777,7 @@ public void dynamicAuthMinValidTimeTest() throws Exception {
IdentityCredential tc = store.getCredentialByName(credentialName,
IdentityCredentialStore.CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256);
KeyPair ekp = tc.createEphemeralKeyPair();
KeyPair rekp = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair rekp = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
tc.setReaderEphemeralPublicKey(rekp.getPublic());
tc.setSessionTranscript(Util.buildSessionTranscript(ekp));
Map<String, Collection<String>> etr = new LinkedHashMap<>();
Expand Down Expand Up @@ -808,7 +809,7 @@ public void dynamicAuthMinValidTimeTest() throws Exception {
IdentityCredential tc = store.getCredentialByName(credentialName,
IdentityCredentialStore.CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256);
KeyPair ekp = tc.createEphemeralKeyPair();
KeyPair rekp = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair rekp = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
tc.setReaderEphemeralPublicKey(rekp.getPublic());
tc.setSessionTranscript(Util.buildSessionTranscript(ekp));
Map<String, Collection<String>> etr = new LinkedHashMap<>();
Expand Down Expand Up @@ -857,7 +858,7 @@ public void dynamicAuthMinValidTimeTest() throws Exception {
IdentityCredential tc = store.getCredentialByName(credentialName,
IdentityCredentialStore.CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256);
KeyPair ekp = tc.createEphemeralKeyPair();
KeyPair rekp = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair rekp = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
tc.setReaderEphemeralPublicKey(rekp.getPublic());
tc.setSessionTranscript(Util.buildSessionTranscript(ekp));
Map<String, Collection<String>> etr = new LinkedHashMap<>();
Expand Down Expand Up @@ -888,7 +889,7 @@ public void dynamicAuthMinValidTimeTest() throws Exception {
IdentityCredential tc = store.getCredentialByName(credentialName,
IdentityCredentialStore.CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256);
KeyPair ekp = tc.createEphemeralKeyPair();
KeyPair rekp = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair rekp = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
tc.setReaderEphemeralPublicKey(rekp.getPublic());
tc.setSessionTranscript(Util.buildSessionTranscript(ekp));
Map<String, Collection<String>> etr = new LinkedHashMap<>();
Expand Down Expand Up @@ -916,7 +917,7 @@ public void dynamicAuthMinValidTimeTest() throws Exception {
IdentityCredentialStore.CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256);
tc.setAllowUsingExpiredKeys(true); // <-- this is the call that makes the difference!
KeyPair ekp = tc.createEphemeralKeyPair();
KeyPair rekp = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair rekp = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
tc.setReaderEphemeralPublicKey(rekp.getPublic());
tc.setSessionTranscript(Util.buildSessionTranscript(ekp));
Map<String, Collection<String>> etr = new LinkedHashMap<>();
Expand Down Expand Up @@ -1040,7 +1041,7 @@ public void dynamicAuthMultipleGetEntries() throws Exception {
Map<String, Collection<String>> entriesToRequest = new LinkedHashMap<>();
entriesToRequest.put("org.iso.18013-5.2019", Arrays.asList("First name", "Last name"));
KeyPair ephemeralKeyPair = credential.createEphemeralKeyPair();
KeyPair readerEphemeralKeyPair = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair readerEphemeralKeyPair = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
byte[] sessionTranscript = Util.buildSessionTranscript(ephemeralKeyPair);
credential.setReaderEphemeralPublicKey(readerEphemeralKeyPair.getPublic());
credential.setSessionTranscript(sessionTranscript);
Expand Down Expand Up @@ -1101,7 +1102,7 @@ public void dynamicAuthNoUsageCountIncrement() throws Exception {
Map<String, Collection<String>> entriesToRequest = new LinkedHashMap<>();
entriesToRequest.put("org.iso.18013-5.2019", Arrays.asList("First name", "Last name"));
KeyPair ephemeralKeyPair = credential.createEphemeralKeyPair();
KeyPair readerEphemeralKeyPair = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair readerEphemeralKeyPair = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
byte[] sessionTranscript = Util.buildSessionTranscript(ephemeralKeyPair);
credential.setReaderEphemeralPublicKey(readerEphemeralKeyPair.getPublic());
credential.setSessionTranscript(sessionTranscript);
Expand All @@ -1124,7 +1125,7 @@ public void dynamicAuthNoUsageCountIncrement() throws Exception {
credential = store.getCredentialByName(credentialName,
IdentityCredentialStore.CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256);
ephemeralKeyPair = credential.createEphemeralKeyPair();
readerEphemeralKeyPair = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
readerEphemeralKeyPair = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
sessionTranscript = Util.buildSessionTranscript(ephemeralKeyPair);
credential.setReaderEphemeralPublicKey(readerEphemeralKeyPair.getPublic());
credential.setSessionTranscript(sessionTranscript);
Expand All @@ -1145,7 +1146,7 @@ public void dynamicAuthNoUsageCountIncrement() throws Exception {
credential = store.getCredentialByName(credentialName,
IdentityCredentialStore.CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256);
ephemeralKeyPair = credential.createEphemeralKeyPair();
readerEphemeralKeyPair = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
readerEphemeralKeyPair = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
sessionTranscript = Util.buildSessionTranscript(ephemeralKeyPair);
credential.setReaderEphemeralPublicKey(readerEphemeralKeyPair.getPublic());
credential.setSessionTranscript(sessionTranscript);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.content.Context;

import com.android.identity.internal.Util;
import com.android.identity.securearea.SecureArea;
import com.android.identity.util.Constants;

import org.junit.Test;
Expand Down Expand Up @@ -207,7 +208,7 @@ public void multipleDocuments() throws Exception {
IdentityCredentialStore.CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256);

KeyPair ephemeralKeyPair = session.getEphemeralKeyPair();
KeyPair readerEphemeralKeyPair = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair readerEphemeralKeyPair = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
session.setReaderEphemeralPublicKey(readerEphemeralKeyPair.getPublic());
byte[] sessionTranscript = Util.buildSessionTranscript(ephemeralKeyPair);
session.setSessionTranscript(sessionTranscript);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.android.identity.android.legacy.Utility;
import com.android.identity.android.legacy.WritableIdentityCredential;
import com.android.identity.internal.Util;
import com.android.identity.securearea.SecureArea;
import com.android.identity.util.Constants;

import org.junit.Test;
Expand Down Expand Up @@ -601,7 +602,7 @@ public void testProvisionAndRetrieveMultipleTimes() throws IdentityCredentialExc
}

KeyPair ephemeralKeyPair = credential.createEphemeralKeyPair();
KeyPair readerEphemeralKeyPair = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair readerEphemeralKeyPair = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
credential.setReaderEphemeralPublicKey(readerEphemeralKeyPair.getPublic());
byte[] sessionTranscript = Util.buildSessionTranscript(ephemeralKeyPair);

Expand All @@ -621,7 +622,7 @@ public void testProvisionAndRetrieveMultipleTimes() throws IdentityCredentialExc

// Now try with a different (but still valid) sessionTranscript - this should fail with
// a RuntimeException
KeyPair otherEphemeralKeyPair = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair otherEphemeralKeyPair = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
byte[] otherSessionTranscript = Util.buildSessionTranscript(otherEphemeralKeyPair);
try {
credential.setSessionTranscript(otherSessionTranscript);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.android.identity.mdoc.response.DeviceResponseGenerator;
import com.android.identity.mdoc.response.DeviceResponseParser;
import com.android.identity.mdoc.sessionencryption.SessionEncryption;
import com.android.identity.securearea.SecureArea;
import com.android.identity.util.Constants;
import com.android.identity.internal.Util;
import com.android.identity.util.Logger;
Expand Down Expand Up @@ -221,7 +222,7 @@ public void onError(@NonNull Throwable error) {
byte[] encodedDeviceEngagement = qrHelper.getDeviceEngagement();

DataItem handover = SimpleValue.NULL;
KeyPair eReaderKeyPair = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair eReaderKeyPair = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
byte[] encodedEReaderKeyPub = Util.cborEncode(Util.cborBuildCoseKey(eReaderKeyPair.getPublic()));
byte[] encodedSessionTranscript = Util.cborEncode(new CborBuilder()
.addArray()
Expand Down Expand Up @@ -502,7 +503,7 @@ public void onError(@NonNull Throwable error) {
byte[] encodedDeviceEngagement = qrHelper.getDeviceEngagement();

DataItem handover = SimpleValue.NULL;
KeyPair eReaderKeyPair = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair eReaderKeyPair = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
byte[] encodedEReaderKeyPub = Util.cborEncode(Util.cborBuildCoseKey(eReaderKeyPair.getPublic()));
byte[] encodedSessionTranscript = Util.cborEncode(new CborBuilder()
.addArray()
Expand Down Expand Up @@ -679,7 +680,7 @@ public void onError(@NonNull Throwable error) {
byte[] encodedDeviceEngagement = qrHelper.getDeviceEngagement();

DataItem handover = SimpleValue.NULL;
KeyPair eReaderKeyPair = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair eReaderKeyPair = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
byte[] encodedEReaderKeyPub = Util.cborEncode(Util.cborBuildCoseKey(eReaderKeyPair.getPublic()));
byte[] encodedSessionTranscript = Util.cborEncode(new CborBuilder()
.addArray()
Expand Down Expand Up @@ -860,7 +861,7 @@ public void onError(@NonNull Throwable error) {
byte[] encodedDeviceEngagement = qrHelper.getDeviceEngagement();

byte[] encodedHandover = Util.cborEncode(SimpleValue.NULL);
KeyPair eReaderKeyPair = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair eReaderKeyPair = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);
byte[] encodedEReaderKeyPub = Util.cborEncode(Util.cborBuildCoseKey(eReaderKeyPair.getPublic()));
byte[] encodedSessionTranscript = Util.cborEncode(new CborBuilder()
.addArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.android.identity.android.legacy.Utility;
import com.android.identity.android.legacy.WritableIdentityCredential;
import com.android.identity.mdoc.mso.StaticAuthDataParser;
import com.android.identity.securearea.SecureArea;
import com.android.identity.util.CborUtil;
import com.android.identity.util.Constants;
import com.android.identity.internal.Util;
Expand Down Expand Up @@ -244,7 +245,7 @@ public void testDeviceResponseGenerator() throws Exception {
Arrays.asList("given_name", "family_name", "some_number", "raw_cbor_1", "raw_cbor_2"));
issuerSignedEntriesToRequest.put(AAMVA_NAMESPACE, Collections.singletonList("real_id"));

KeyPair readerEphemeralKeyPair = Util.createEphemeralKeyPair(Constants.EC_CURVE_P256);
KeyPair readerEphemeralKeyPair = Util.createEphemeralKeyPair(SecureArea.EC_CURVE_P256);

PresentationSession session = store.createPresentationSession(
IdentityCredentialStore.CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256);
Expand Down

0 comments on commit 24e47ec

Please sign in to comment.