Skip to content

Commit 2ac75d3

Browse files
author
Elis Elliott
committed
Add option to use a custom attestation challenge
When generating a private/public key pair a text box now appears asking for a custom challenge (in Base64) under the checkbox "Include key attestation challenge". The default challenge is 'abc' ('YWJj' in Base64). Bug: 159901371 Change-Id: I0b275205eb53f92cd58792892d861a3666947b0a
1 parent 0f2af88 commit 2ac75d3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import android.telephony.TelephonyManager;
6565
import android.text.InputType;
6666
import android.text.TextUtils;
67+
import android.util.Base64;
6768
import android.util.Log;
6869
import android.util.SparseIntArray;
6970
import android.view.LayoutInflater;
@@ -2777,6 +2778,10 @@ private void showPromptForGeneratedKeyAlias(String alias) {
27772778
R.id.use_individual_attestation);
27782779
useIndividualAttestationCheckbox.setEnabled(Util.SDK_INT >= VERSION_CODES.R);
27792780

2781+
// Custom Challenge input
2782+
final EditText customChallengeInput = aliasNamingView.findViewById(
2783+
R.id.custom_challenge_input);
2784+
27802785
new AlertDialog.Builder(getActivity())
27812786
.setTitle(getString(R.string.certificate_alias_prompt_title))
27822787
.setView(aliasNamingView)
@@ -2789,7 +2794,11 @@ public void onClick(DialogInterface dialog, int which) {
27892794
paramsBuilder.setIsUserSelectable(userSelectableCheckbox.isChecked());
27902795

27912796
if (includeAttestationChallengeCheckbox.isChecked()) {
2792-
paramsBuilder.setAttestationChallenge(new byte[] {0x61, 0x62, 0x63});
2797+
String customChallenge = customChallengeInput.getText().toString()
2798+
.trim();
2799+
byte[] decodedChallenge = Base64.decode(customChallenge,
2800+
Base64.DEFAULT);
2801+
paramsBuilder.setAttestationChallenge(decodedChallenge);
27932802
}
27942803

27952804
int idAttestationFlags = 0;

app/src/main/res/layout/key_generation_prompt.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@
6464
android:layout_height="wrap_content"
6565
android:text="@string/key_attestation_checkbox"/>
6666

67+
<EditText
68+
android:id="@+id/custom_challenge_input"
69+
android:layout_width="fill_parent"
70+
android:layout_height="wrap_content"
71+
android:lines="1"
72+
android:maxLines="1"
73+
android:scrollHorizontally="true"
74+
android:ellipsize="end"
75+
android:inputType="text"
76+
android:text="YWJj"
77+
android:hint="Custom Challenge (Base64)"/>
78+
6779
<TextView
6880
android:layout_width="fill_parent"
6981
android:layout_height="wrap_content"

0 commit comments

Comments
 (0)