Skip to content

Commit

Permalink
Fix showing message on different buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
martenrebane committed Aug 28, 2024
1 parent 69b706f commit 74ecbfe
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
import ee.ria.DigiDoc.android.ApplicationApp;
import ee.ria.DigiDoc.android.accessibility.AccessibilityUtils;
import ee.ria.DigiDoc.android.signature.update.mobileid.MobileIdResponse;
import ee.ria.DigiDoc.android.signature.update.smartid.SmartIdResponse;
import ee.ria.DigiDoc.android.signature.update.nfc.NFCDialog;
import ee.ria.DigiDoc.android.signature.update.nfc.NFCResponse;
import ee.ria.DigiDoc.android.signature.update.smartid.SmartIdResponse;
import ee.ria.DigiDoc.android.utils.DateUtil;
import ee.ria.DigiDoc.android.utils.ToastUtil;
import ee.ria.DigiDoc.android.utils.ViewDisposables;
Expand Down Expand Up @@ -587,10 +587,14 @@ public void render(ViewState state) {

if (signatureAddResponse instanceof NFCResponse) {
NFCResponse nfcResponse = (NFCResponse) signatureAddResponse;
Timber.log(Log.DEBUG, "NFC:SignatureUpdateView.render, status %s", nfcResponse.status().toString());
if (nfcResponse.status() != null) {
Timber.log(Log.DEBUG, "NFC:SignatureUpdateView.render, status %s", nfcResponse.status().toString());
}
nfcDialog.showStatus(nfcResponse);
nfcDialog.show();
}
} else {
nfcDialog.dismiss();
}

setupAccessibilityTabs();
Expand Down Expand Up @@ -741,15 +745,19 @@ private void sendMethodSelectionAccessibilityEvent(int method) {
if (signatureMethod.equalsIgnoreCase(getResources().getString(R.string.signature_update_signature_add_method_mobile_id))) {
AccessibilityUtils.sendAccessibilityEvent(getContext(), TYPE_WINDOW_STATE_CHANGED,
getResources().getString(R.string.signature_update_signature_chosen_method_mobile_id));
AccessibilityUtils.sendAccessibilityEvent(getContext(), TYPE_ANNOUNCEMENT, getResources().getString(R.string.signature_update_signature_selected_method_mobile_id, 1, 4));
} else if (signatureMethod.equalsIgnoreCase(getResources().getString(R.string.signature_update_signature_add_method_smart_id))) {
AccessibilityUtils.sendAccessibilityEvent(getContext(), TYPE_WINDOW_STATE_CHANGED,
getResources().getString(R.string.signature_update_signature_chosen_method_smart_id));
AccessibilityUtils.sendAccessibilityEvent(getContext(), TYPE_ANNOUNCEMENT, getResources().getString(R.string.signature_update_signature_selected_method_smart_id, 2, 4));
} else if (signatureMethod.equalsIgnoreCase(getResources().getString(R.string.signature_update_signature_add_method_id_card))) {
AccessibilityUtils.sendAccessibilityEvent(getContext(), TYPE_WINDOW_STATE_CHANGED,
getResources().getString(R.string.signature_update_signature_chosen_method_id_card));
AccessibilityUtils.sendAccessibilityEvent(getContext(), TYPE_ANNOUNCEMENT, getResources().getString(R.string.signature_update_signature_selected_method_id_card, 3, 4));
} else if (signatureMethod.equalsIgnoreCase(getResources().getString(R.string.signature_update_signature_add_method_nfc))) {
AccessibilityUtils.sendAccessibilityEvent(getContext(), TYPE_WINDOW_STATE_CHANGED,
getResources().getString(R.string.signature_update_signature_chosen_method_nfc));
AccessibilityUtils.sendAccessibilityEvent(getContext(), TYPE_ANNOUNCEMENT, getResources().getString(R.string.signature_update_signature_selected_method_nfc, 4, 4));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,18 @@ public void subscribe(ObservableEmitter<NFCResponse> emitter) {
emitter.onNext(NFCResponse.createWithStatus(SessionStatusResponse.ProcessStatus.OK, navigator.activity().getString(R.string.signature_update_nfc_detected)));
NFCResponse response = onTagDiscovered(adapter, tag);
Timber.log(Log.DEBUG, "NFC::completed");
emitter.onNext((response != null) ? response : NFCResponse.success(container));
emitter.onComplete();
if (response != null) {
if (response.status() != SessionStatusResponse.ProcessStatus.OK) {
Timber.log(Log.ERROR, String.format("NFC status: %s", response.status()));
emitter.onError(new NFC.NFCException(response.message()));
} else {
emitter.onNext(response);
emitter.onComplete();
}
} else {
emitter.onNext(NFCResponse.success(container));
emitter.onComplete();
}
}, NfcAdapter.FLAG_READER_NFC_A, null);
}
}
Expand Down Expand Up @@ -94,14 +104,14 @@ private NFCResponse onTagDiscovered(NfcAdapter adapter, Tag tag) {
byte[] certificate = nfc.readCertificate();
if (certificate == null) {
Timber.log(Log.ERROR, "Failed to read certificate. Certificate is null");
throw new RuntimeException("Unable to read certificate for NFC");
throw new RuntimeException(navigator.activity().getString(R.string.signature_update_nfc_technical_error));
}
Timber.log(Log.DEBUG, "CERT:%s", Hex.toHexString(certificate));
Timber.log(Log.DEBUG, "CERT: %s", Hex.toHexString(certificate));
Certificate cert = Certificate.create(ByteString.of(certificate, 0, certificate.length));

// Step 2 - verify PIN2
NFC.Result r = nfc.communicateSecure(SEL_QSCD_CMD, SEL_QSCD);
Timber.log(Log.DEBUG, "Select QSCD AID:%x %s", r.code, Hex.toHexString(r.data));
Timber.log(Log.DEBUG, "Select QSCD AID: %x %s", r.code, Hex.toHexString(r.data));

// pad the PIN and use the chip for verification
byte[] paddedPIN = Hex.decode("ffffffffffffffffffffffff");
Expand All @@ -110,19 +120,20 @@ private NFCResponse onTagDiscovered(NfcAdapter adapter, Tag tag) {
if (null != pin2 && pin2.length > 0) {
Arrays.fill(pin2, (byte) 0);
}
Timber.log(Log.DEBUG, "Verify PIN2:%x %s", r.code, Hex.toHexString(r.data));
Timber.log(Log.DEBUG, "Verify PIN2: %x %s", r.code, Hex.toHexString(r.data));
if (r.code != 0x9000) {
if (r.code == 0x6983) {
throw new RuntimeException(navigator.activity().getString(R.string.signature_update_id_card_sign_pin2_locked));
} else if ((r.code & 0xfff0) == 0x63c0) {
throw new RuntimeException(String.format(navigator.activity().getString(R.string.signature_update_id_card_sign_pin2_invalid), r.code & 0xf));
} else {
throw new RuntimeException("Verification error");
Timber.log(Log.ERROR, "PIN2 verification error");
throw new RuntimeException(navigator.activity().getString(R.string.signature_update_nfc_technical_error));
}
}

r = nfc.communicateSecure(CMD_SET_ENV_SIGN, SET_ENV_SIGN);
Timber.log(Log.DEBUG, "Set ENV:%x %s", r.code, Hex.toHexString(r.data));
Timber.log(Log.DEBUG, "Set ENV: %x %s", r.code, Hex.toHexString(r.data));

container.sign(cert.data(),
signData -> ByteString.of(nfc.calculateSignature(signData.toByteArray())), role);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

import com.google.auto.value.AutoValue;

import ee.ria.DigiDoc.android.model.idcard.IdCardDataResponse;
import ee.ria.DigiDoc.android.model.idcard.IdCardSignResponse;
import ee.ria.DigiDoc.android.signature.update.SignatureAddResponse;
import ee.ria.DigiDoc.android.signature.update.smartid.SmartIdResponse;
import ee.ria.DigiDoc.sign.SignedContainer;
import ee.ria.DigiDoc.smartid.dto.response.SessionStatusResponse;

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
<string name="signature_update_signature_selected_method_mobile_id">Signing option Mobile-ID, tab %1$d of %2$d</string>
<string name="signature_update_signature_selected_method_smart_id">Signing option Smart-ID, tab %1$d of %2$d</string>
<string name="signature_update_signature_selected_method_id_card">Signing option ID-card, tab %1$d of %2$d</string>
<string name="signature_update_signature_selected_method_nfc">Signing option NFC, tab %1$d / %2$d</string>
<string name="signature_update_signature_selected_method_nfc">Signing option NFC, tab %1$d of %2$d</string>

<string name="signature_update_signature_chosen_method_mobile_id">Signing method Mobile-ID, selected</string>
<string name="signature_update_signature_chosen_method_smart_id">Signing method Smart-ID, selected</string>
Expand Down Expand Up @@ -303,7 +303,7 @@
<string name="signature_update_nfc_message">Enter your ID-card access number (CAN) and PIN2 code to sign with ID-card</string>
<string name="signature_update_nfc_can">ID-card access number (CAN)</string>
<string name="signature_update_nfc_pin2">PIN2 code</string>
<string name="signature_update_nfc_adapter_missing">This device does not support NFC</string>
<string name="signature_update_nfc_adapter_missing">This device does not support contactless connection or NFC is turned off </string>
<string name="signature_update_nfc_tag_lost">NFC connection lost</string>
<string name="signature_update_nfc_technical_error">Technical error</string>
<string name="signature_update_nfc_hold">Hold your phone near the ID-card</string>
Expand Down

0 comments on commit 74ecbfe

Please sign in to comment.