Get Cipher back from FingerprintManager,CryptoObject after auth

This commit is contained in:
Alexander Bakker 2019-04-04 18:09:59 +02:00
parent 14fa493ac9
commit 4365a693f2
3 changed files with 15 additions and 12 deletions

View file

@ -39,7 +39,7 @@ public class AuthActivity extends AegisActivity implements FingerprintUiHelper.C
private SlotList _slots; private SlotList _slots;
private FingerprintUiHelper _fingerHelper; private FingerprintUiHelper _fingerHelper;
private Cipher _fingerCipher; private FingerprintManager.CryptoObject _fingerCryptoObj;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -84,7 +84,8 @@ public class AuthActivity extends AegisActivity implements FingerprintUiHelper.C
invalidated = true; invalidated = true;
continue; continue;
} }
_fingerCipher = slot.createDecryptCipher(key); Cipher cipher = slot.createDecryptCipher(key);
_fingerCryptoObj = new FingerprintManager.CryptoObject(cipher);
_fingerHelper = new FingerprintUiHelper(manager, imgFingerprint, textFingerprint, this); _fingerHelper = new FingerprintUiHelper(manager, imgFingerprint, textFingerprint, this);
boxFingerprint.setVisibility(View.VISIBLE); boxFingerprint.setVisibility(View.VISIBLE);
invalidated = false; invalidated = false;
@ -142,7 +143,7 @@ public class AuthActivity extends AegisActivity implements FingerprintUiHelper.C
super.onResume(); super.onResume();
if (_fingerHelper != null) { if (_fingerHelper != null) {
_fingerHelper.startListening(new FingerprintManager.CryptoObject(_fingerCipher)); _fingerHelper.startListening(_fingerCryptoObj);
} }
} }
@ -157,7 +158,7 @@ public class AuthActivity extends AegisActivity implements FingerprintUiHelper.C
@Override @Override
public void onAuthenticated() { public void onAuthenticated() {
trySlots(FingerprintSlot.class, _fingerCipher); trySlots(FingerprintSlot.class, _fingerCryptoObj.getCipher());
} }
@Override @Override

View file

@ -178,7 +178,7 @@ public class Dialogs {
TextView textFingerprint = view.findViewById(R.id.text_fingerprint); TextView textFingerprint = view.findViewById(R.id.text_fingerprint);
SwirlView imgFingerprint = view.findViewById(R.id.img_fingerprint); SwirlView imgFingerprint = view.findViewById(R.id.img_fingerprint);
Cipher cipher; FingerprintManager.CryptoObject obj;
FingerprintSlot slot; FingerprintSlot slot;
final AtomicReference<FingerprintUiHelper> helper = new AtomicReference<>(); final AtomicReference<FingerprintUiHelper> helper = new AtomicReference<>();
FingerprintManager manager = FingerprintHelper.getManager(activity); FingerprintManager manager = FingerprintHelper.getManager(activity);
@ -186,7 +186,8 @@ public class Dialogs {
try { try {
slot = new FingerprintSlot(); slot = new FingerprintSlot();
SecretKey key = new KeyStoreHandle().generateKey(slot.getUUID().toString()); SecretKey key = new KeyStoreHandle().generateKey(slot.getUUID().toString());
cipher = Slot.createEncryptCipher(key); Cipher cipher = Slot.createEncryptCipher(key);
obj = new FingerprintManager.CryptoObject(cipher);
} catch (KeyStoreHandleException | SlotException e) { } catch (KeyStoreHandleException | SlotException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -203,7 +204,7 @@ public class Dialogs {
helper.set(new FingerprintUiHelper(manager, imgFingerprint, textFingerprint, new FingerprintUiHelper.Callback() { helper.set(new FingerprintUiHelper(manager, imgFingerprint, textFingerprint, new FingerprintUiHelper.Callback() {
@Override @Override
public void onAuthenticated() { public void onAuthenticated() {
listener.onSlotResult(slot, cipher); listener.onSlotResult(slot, obj.getCipher());
dialog.dismiss(); dialog.dismiss();
} }
@ -213,7 +214,7 @@ public class Dialogs {
} }
})); }));
helper.get().startListening(new FingerprintManager.CryptoObject(cipher)); helper.get().startListening(obj);
showSecureDialog(dialog); showSecureDialog(dialog);
} }

View file

@ -41,7 +41,7 @@ public class CustomAuthenticatedSlide extends Fragment implements FingerprintUiH
private FingerprintUiHelper _fingerHelper; private FingerprintUiHelper _fingerHelper;
private KeyStoreHandle _storeHandle; private KeyStoreHandle _storeHandle;
private FingerprintSlot _fingerSlot; private FingerprintSlot _fingerSlot;
private Cipher _fingerCipher; private FingerprintManager.CryptoObject _fingerCryptoObj;
private boolean _fingerAuthenticated; private boolean _fingerAuthenticated;
@Override @Override
@ -71,7 +71,7 @@ public class CustomAuthenticatedSlide extends Fragment implements FingerprintUiH
} }
public Cipher getFingerCipher() { public Cipher getFingerCipher() {
return _fingerCipher; return _fingerCryptoObj.getCipher();
} }
public FingerprintSlot getFingerSlot() { public FingerprintSlot getFingerSlot() {
@ -111,11 +111,12 @@ public class CustomAuthenticatedSlide extends Fragment implements FingerprintUiH
} }
try { try {
_fingerCipher = Slot.createEncryptCipher(key); Cipher cipher = Slot.createEncryptCipher(key);
_fingerCryptoObj = new FingerprintManager.CryptoObject(cipher);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
_fingerHelper.startListening(new FingerprintManager.CryptoObject(_fingerCipher)); _fingerHelper.startListening(_fingerCryptoObj);
break; break;
default: default:
throw new RuntimeException(); throw new RuntimeException();