Skip to content

Commit

Permalink
Update wwwverifier to Recent CD Consultation (#357)
Browse files Browse the repository at this point in the history
Modified build scripts to make wwwverifier a subproject of the
Identity Credential project to reduce copy-pasted code. Updated
OriginInfo to match 18013-7 recent CD consultation.

Tested appholder changes manually with unattended presentations
via the wwwverifier as well as attended presentations with
appverifier.
  • Loading branch information
suzannajiwani authored Sep 19, 2023
1 parent 3c824b1 commit 034099e
Show file tree
Hide file tree
Showing 34 changed files with 582 additions and 5,375 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
.idea/
fastlane/report.xml
/mdl-ref-server/mdl-server-db.sqlite3
/version*
/version*
wwwverifier/build/*
6 changes: 4 additions & 2 deletions appholder/src/main/java/com/android/mdl/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import androidx.navigation.ui.NavigationUI
import androidx.navigation.ui.NavigationUI.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.android.identity.mdoc.origininfo.OriginInfo
import com.android.identity.mdoc.origininfo.OriginInfoWebsite
import com.android.identity.mdoc.origininfo.OriginInfoReferrerUrl
import com.android.mdl.app.databinding.ActivityMainBinding
import com.android.mdl.app.util.log
import com.android.mdl.app.util.logError
Expand Down Expand Up @@ -105,7 +105,9 @@ class MainActivity : AppCompatActivity() {
// TODO: maybe bail in the future if this isn't set.
} else {
logInfo("referrer: $mdocReferrerUri")
originInfos.add(OriginInfoWebsite(1, mdocReferrerUri))
originInfos.add(
OriginInfoReferrerUrl(mdocReferrerUri)
)
}

viewModel.startPresentationReverseEngagement(mdocUri, originInfos)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.android.identity.mdoc.origininfo.OriginInfo
import com.android.identity.mdoc.origininfo.OriginInfoQr
import com.android.mdl.app.databinding.FragmentReverseEngagementBinding
import com.android.mdl.app.util.log
import com.android.mdl.app.util.logWarning
Expand Down Expand Up @@ -53,9 +52,7 @@ class ReverseEngagementFragment : Fragment() {
log("qrText: $qrText")
val uri = Uri.parse(qrText)
if (uri.scheme.equals("mdoc")) {
val originInfos = ArrayList<OriginInfo>()
originInfos.add(OriginInfoQr(1))
vm.startPresentationReverseEngagement(qrText, originInfos)
vm.startPresentationReverseEngagement(qrText, emptyList<OriginInfo>())
findNavController().navigate(
ReverseEngagementFragmentDirections.actionReverseEngagementFragmentToTransferDocumentFragment()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import java.security.KeyPair;
import java.security.PublicKey;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.OptionalLong;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class EngagementGenerator {
private static final String TAG = "EngagementGenerator";
private final String mVersion;
final private PublicKey mESenderKey;
private ArrayBuilder<CborBuilder> mConnectionMethodsArrayBuilder;
private ArrayBuilder<CborBuilder> mDeviceRetrievalMethodsArrayBuilder;
private ArrayBuilder<CborBuilder> mOriginInfoArrayBuilder;

public static final String ENGAGEMENT_VERSION_1_0 = "1.0";
Expand Down Expand Up @@ -75,9 +75,9 @@ public EngagementGenerator(@NonNull PublicKey ESenderKey,
*/
public @NonNull
EngagementGenerator setConnectionMethods(@NonNull List<ConnectionMethod> connectionMethods) {
mConnectionMethodsArrayBuilder = new CborBuilder().addArray();
mDeviceRetrievalMethodsArrayBuilder = new CborBuilder().addArray();
for (ConnectionMethod connectionMethod : connectionMethods) {
mConnectionMethodsArrayBuilder.add(Util.cborDecode(connectionMethod.toDeviceEngagement()));
mDeviceRetrievalMethodsArrayBuilder.add(Util.cborDecode(connectionMethod.toDeviceEngagement()));
}
return this;
}
Expand Down Expand Up @@ -118,8 +118,8 @@ byte[] generate() {
MapBuilder<CborBuilder> map = builder.addMap();
map.put(0, mVersion);
map.put(new UnsignedInteger(1), securityDataItem);
if (mConnectionMethodsArrayBuilder != null) {
map.put(new UnsignedInteger(2), mConnectionMethodsArrayBuilder.end().build().get(0));
if (mDeviceRetrievalMethodsArrayBuilder != null) {
map.put(new UnsignedInteger(2), mDeviceRetrievalMethodsArrayBuilder.end().build().get(0));
}
if (mOriginInfoArrayBuilder != null) {
map.put(new UnsignedInteger(5), mOriginInfoArrayBuilder.end().build().get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.security.PublicKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -305,7 +306,7 @@ void parse(byte[] encodedMobileSecurityObject) {
}

mDigestAlgorithm = Util.cborMapExtractString(mso, "digestAlgorithm");
final List<String> allowableDigestAlgorithms = List.of("SHA-256", "SHA-384", "SHA-512");
final List<String> allowableDigestAlgorithms = Arrays.asList("SHA-256", "SHA-384", "SHA-512");
if (!allowableDigestAlgorithms.contains(mDigestAlgorithm)) {
throw new IllegalArgumentException("Given digest algorithm '" + mDigestAlgorithm +
"' one of " + allowableDigestAlgorithms);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import com.android.identity.internal.Util;

import java.security.cert.X509Certificate;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,7 @@
public abstract class OriginInfo {
private static final String TAG = "OriginInfo";

/**
* The constant used to specify how the current engagement structure is delivered.
*/
public static final long CAT_DELIVERY = 0;

/**
* The constant used to specify how the other party engagement structure has been received.
*/
public static final long CAT_RECEIVE = 1;

/**
* Specifies whether the OriginInfoOptions are about this engagement or the one
* received previously
*
* @return one of {@link #CAT_DELIVERY} or {@link #CAT_RECEIVE}.
*/
public abstract long getCat();
protected static final long CAT = 1;

public abstract @NonNull DataItem encode();

Expand All @@ -56,12 +40,10 @@ public abstract class OriginInfo {
}
long type = Util.cborMapExtractNumber(oiDataItem, "type");
switch ((int) type) {
case OriginInfoQr.TYPE:
return OriginInfoQr.decode(oiDataItem);
case OriginInfoNfc.TYPE:
return OriginInfoNfc.decode(oiDataItem);
case OriginInfoWebsite.TYPE:
return OriginInfoWebsite.decode(oiDataItem);
case OriginInfoReferrerUrl.TYPE:
return OriginInfoReferrerUrl.decode(oiDataItem);
case OriginInfoBaseUrl.TYPE:
return OriginInfoBaseUrl.decode(oiDataItem);
}
Logger.w(TAG, "Unsupported type " + type);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,54 +23,47 @@

import co.nstant.in.cbor.CborBuilder;
import co.nstant.in.cbor.model.DataItem;
import co.nstant.in.cbor.model.SimpleValue;
import co.nstant.in.cbor.model.UnicodeString;
import com.android.identity.util.Logger;
import co.nstant.in.cbor.model.Map;

public class OriginInfoQr extends OriginInfo {
private static final String TAG = "OriginInfoQr";
public class OriginInfoBaseUrl extends OriginInfo {
private static final String TAG = "OriginInfoBaseUrl";

static final int TYPE = 2;
private final long mCat;
private final String mUrl;

public OriginInfoQr(long cat) {
mCat = cat;
public OriginInfoBaseUrl(String url) {
mUrl = url;
}

/**
* Specifies whether the OriginInfoOptions are about this engagement or the one
* received previously
*
* @return one of {@link #CAT_DELIVERY} or {@link #CAT_RECEIVE}.
*/
@Override
public long getCat() {
return mCat;
public String getUrl() {
return mUrl;
}

@NonNull
@Override
public DataItem encode() {
return new CborBuilder()
.addMap()
.put("cat", mCat)
.put("cat", CAT)
.put("type", TYPE)
.put(new UnicodeString("Details"), SimpleValue.NULL)
.put("details", mUrl)
.end()
.build().get(0);
}

@Nullable
public static OriginInfoQr decode(@NonNull DataItem oiDataItem) {
if (!(oiDataItem instanceof co.nstant.in.cbor.model.Map)) {
public static OriginInfoBaseUrl decode(@NonNull DataItem oiDataItem) {
if (!(oiDataItem instanceof Map)) {
throw new IllegalArgumentException("Top-level CBOR is not an map");
}
long cat = Util.cborMapExtractNumber(oiDataItem, "cat");
long type = Util.cborMapExtractNumber(oiDataItem, "type");
if (type != TYPE) {
Logger.w(TAG, "Unexpected type " + type);
return null;
int type = (int) Util.cborMapExtractNumber(oiDataItem, "type");
if (!(cat == 1 && type == 2)) {
throw new IllegalArgumentException(String.format("This CBOR object has the wrong " +
"category or type. Expected cat = 1, type = 2 for baseURL type but got " +
"cat = %d, type = %d", cat, type));
}
return new OriginInfoQr(cat);
String url = Util.cborMapExtractString(oiDataItem, "details");
return new OriginInfoBaseUrl(url);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,54 +23,47 @@

import co.nstant.in.cbor.CborBuilder;
import co.nstant.in.cbor.model.DataItem;
import co.nstant.in.cbor.model.SimpleValue;
import co.nstant.in.cbor.model.UnicodeString;
import com.android.identity.util.Logger;
import co.nstant.in.cbor.model.Map;

public class OriginInfoNfc extends OriginInfo {
private static final String TAG = "OriginInfoNfc";
public class OriginInfoReferrerUrl extends OriginInfo {
private static final String TAG = "OriginInfoReferrerUrl";

static final int TYPE = 3;
private final long mCat;
static final int TYPE = 1;
private final String mUrl;

public OriginInfoNfc(long cat) {
mCat = cat;
public OriginInfoReferrerUrl(String url) {
mUrl = url;
}

/**
* Specifies whether the OriginInfoOptions are about this engagement or the one
* received previously
*
* @return one of {@link #CAT_DELIVERY} or {@link #CAT_RECEIVE}.
*/
@Override
public long getCat() {
return mCat;
public String getUrl() {
return mUrl;
}

@NonNull
@Override
public DataItem encode() {
return new CborBuilder()
.addMap()
.put("cat", mCat)
.put("cat", CAT)
.put("type", TYPE)
.put(new UnicodeString("Details"), SimpleValue.NULL)
.put("details", mUrl)
.end()
.build().get(0);
}

@Nullable
public static OriginInfoNfc decode(@NonNull DataItem oiDataItem) {
if (!(oiDataItem instanceof co.nstant.in.cbor.model.Map)) {
public static OriginInfoReferrerUrl decode(@NonNull DataItem oiDataItem) {
if (!(oiDataItem instanceof Map)) {
throw new IllegalArgumentException("Top-level CBOR is not an map");
}
long cat = Util.cborMapExtractNumber(oiDataItem, "cat");
long type = Util.cborMapExtractNumber(oiDataItem, "type");
if (type != TYPE) {
Logger.w(TAG, "Unexpected type " + type);
return null;
int type = (int) Util.cborMapExtractNumber(oiDataItem, "type");
if (!(cat == 1 && type == 1)) {
throw new IllegalArgumentException(String.format("This CBOR object has the wrong " +
"category or type. Expected cat = 1, type = 1 for baseURL type but got " +
"cat = %d, type = %d", cat, type));
}
return new OriginInfoNfc(cat);
String url = Util.cborMapExtractString(oiDataItem, "details");
return new OriginInfoReferrerUrl(url);
}
}

This file was deleted.

Loading

0 comments on commit 034099e

Please sign in to comment.