Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing a new KeyStoreManager to handle BRKeyStore related #291

Merged
merged 9 commits into from
Dec 19, 2024

Conversation

andhikayuana
Copy link
Contributor

Overview

To get better understanding of the codebase, we are need to refactor the BRKeyStore into separate class, it can be easier for maintaining the codebase. Now, we are introducing a new KeyStoreManager that aim to replace the BRKeyStore. currently it only called from BRKeyStore._getData.

Key Classes

  • com.loafwallet.util.cryptography.CipherBox: this will be responsible to encrypt/decrypt the data
  • com.loafwallet.util.cryptography.CipherStorage: which location the encrypted data can will be stored
  • com.loafwallet.util.cryptography.KeyStoreKeyGenerator: to generate the secret key
  • com.loafwallet.util.cryptography.KeyStoreManager: this will be used as a replacement for BRKeyStore later

Next Plan

  • Add remote config?
  • Add Unit Test?

@andhikayuana andhikayuana self-assigned this Dec 8, 2024
@andhikayuana andhikayuana requested review from kcw-grunt and josikie and removed request for kcw-grunt December 8, 2024 09:58
@@ -45,6 +34,8 @@ public class BreadApp extends Application {
public static long backgroundedTime;
private static Activity currentActivity;

public static KeyStoreManager keyStoreManager;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now we just use this, maybe in the future we can use dependency injection like koin

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets. Feel free to add a spike issue in litewallet-engineering for us to study Koin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, will add Koin later


try {
lock.lock();
return BreadApp.keyStoreManager.getDataBlocking(new AliasObject(alias, alias_file, alias_iv));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calling new method from KeyStoreManager

@andhikayuana andhikayuana marked this pull request as ready for review December 8, 2024 10:04
@andhikayuana andhikayuana changed the title Introducting KeyStoreManager to handle BRKeyStore related Introducing a new KeyStoreManager to handle BRKeyStore related Dec 8, 2024
return BreadApp.keyStoreManager.getDataBlocking(new AliasObject(alias, alias_file, alias_iv));
} catch (UserNotAuthenticatedException e) {
Timber.e(e, "timber:_getData: showAuthenticationScreen: %s", alias);
showAuthenticationScreen(context, request_code, alias);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have questions @kcw-grunt, our Android app will still need user's pin lock screen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still thinking about this how to migrate without the device lock, since the key (for phrase and canary) that created before need to do device unlock first. related with link above

ref:

Copy link
Contributor

@kcw-grunt kcw-grunt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM just need rebase / resolve conflicts.
Also, @andhikayuana please confirm this is no-op at this time

@@ -45,6 +34,8 @@ public class BreadApp extends Application {
public static long backgroundedTime;
private static Activity currentActivity;

public static KeyStoreManager keyStoreManager;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets. Feel free to add a spike issue in litewallet-engineering for us to study Koin

@@ -55,16 +46,23 @@ public void onCreate() {
AnalyticsManager.init(this);
AnalyticsManager.logCustomEvent(BRConstants._20191105_AL);

if(BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this the linter or Andhika manual @andhikayuana ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do manually before commit

Screenshot 2024-12-13 at 17 05 18
Screenshot 2024-12-13 at 17 05 35

Copy link
Contributor

@josikie josikie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good you want to separate the classes so will be easy to maintain

return BreadApp.keyStoreManager.getDataBlocking(new AliasObject(alias, alias_file, alias_iv));
} catch (UserNotAuthenticatedException e) {
Timber.e(e, "timber:_getData: showAuthenticationScreen: %s", alias);
showAuthenticationScreen(context, request_code, alias);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have questions @kcw-grunt, our Android app will still need user's pin lock screen?

Copy link
Contributor

@kcw-grunt kcw-grunt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just holding until pairing

@kcw-grunt
Copy link
Contributor

@josikie We ultimately want to completely remove the device PIN...then later let user choose from Biometric or app 6 digit PIN

@josikie
Copy link
Contributor

josikie commented Dec 19, 2024

Ok, noted! @kcw-grunt

Does it mean when user choose biometric they should already have biometric lock in their phone?

I think we've tried to implement biometric in the past for our new Android UI. When we wanted to implement biometric on our new UI Android, Android phone need user to set their biometric in their phone first, then they can use it in our new UI Android

@kcw-grunt
Copy link
Contributor

Ok, noted! @kcw-grunt

Does it mean when user choose biometric they should already have biometric lock in their phone?

I think we've tried to implement biometric in the past for our new Android UI. When we wanted to implement biometric on our new UI Android, Android phone need user to set their biometric in their phone first, then they can use it in our new UI Android

@andhikayuana matched the logic of iOS 👍

@kcw-grunt kcw-grunt merged commit 59540fb into develop Dec 19, 2024
0 of 2 checks passed
@kcw-grunt kcw-grunt deleted the bugfix/288 branch December 19, 2024 14:56
losh11 pushed a commit that referenced this pull request Feb 7, 2025
* chore: remove forgot_seed_phrase_or_pin_text text at activity_pin.xml

* fix: [#288] catch all exception and return null

* chore: wip keystore related

* chore: wip keystore related for CipherBox

* chore: wip keystore related for CipherBox

* feat: add new CipherBox, CipherStorage, KeyStoreKeyGenerator and KeyStoreManager to handle keystore related

* feat: add keyStoreManager to BreadApp and change _getData method at BRKeyStore

* Revert "chore: remove forgot_seed_phrase_or_pin_text text at activity_pin.xml"

This reverts commit 04b02ac.

* chore: resolve conflict and implement toggle for new KeyStoreManager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants