Skip to content

Commit

Permalink
Show meaningful error message when no valid challenge was passed
Browse files Browse the repository at this point in the history
pp3345 committed Oct 4, 2018
1 parent cd90092 commit 5b7b52c
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ public class ChallengeResponseActivity extends Activity implements ConnectionMan
private SlotPreferenceManager slotPreferenceManager;
private Slot selectedSlot;
private String purpose;
private byte[] challenge;

@Override
protected void onCreate(final Bundle savedInstanceState) {
@@ -43,6 +44,13 @@ protected void onCreate(final Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(R.layout.activity_challenge_response);

this.challenge = this.getIntent().getByteArrayExtra("challenge");
if (this.challenge == null || this.challenge.length == 0) {
this.showError();
((TextView) ChallengeResponseActivity.this.findViewById(R.id.info)).setText(R.string.invalid_challenge);
return;
}

switch (this.connectionManager.getSupportedConnectionMethods()) {
case ConnectionManager.CONNECTION_METHOD_USB | ConnectionManager.CONNECTION_METHOD_NFC:
((TextView) this.findViewById(R.id.info)).setText(R.string.attach_or_swipe_yubikey);
@@ -91,7 +99,7 @@ public void onYubiKeyConnected(final YubiKey yubiKey) {
@Override
protected byte[] doInBackground(final Void... nothing) {
try {
return yubiKey.challengeResponse(ChallengeResponseActivity.this.selectedSlot, ChallengeResponseActivity.this.getIntent().getByteArrayExtra("challenge"));
return yubiKey.challengeResponse(ChallengeResponseActivity.this.selectedSlot, ChallengeResponseActivity.this.challenge);
} catch (final Exception e) {
this.executionException = e;
return null;
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
@@ -11,4 +11,5 @@
<item>Slot 1</item>
<item>Slot 2</item>
</string-array>
<string name="invalid_challenge">Es wurde keine gültige Challenge übergeben. Sollte das Problem bestehen bleiben, kontaktiere bitte den Entwickler der App, mit der du ykDroid benutzen möchtest.</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
<string name="no_supported_connection_method">Your device supports neither USB host mode nor NFC. YubiKeys can not be used.</string>
<string name="press_button">Please press the button on your YubiKey.</string>
<string name="unplug_yubikey">An error has occurred. Please unplug your YubiKey.</string>
<string name="invalid_challenge">An invalid challenge was passed. If this problem persists, please contact the vendor of the app you are trying to use ykDroid with.</string>
<string-array name="slots">
<item>Slot 1</item>
<item>Slot 2</item>

0 comments on commit 5b7b52c

Please sign in to comment.