patrickfav / armadillo

A shared preference implementation for confidential data in Android. Per default uses AES-GCM, BCrypt and HKDF as cryptographic primitives. Uses the concept of device fingerprinting combined with optional user provided passwords and strong password hashes.
https://favr.dev/opensource/armadillo
Apache License 2.0
280 stars 52 forks source link

Check password during initialisation #24

Closed davidmigloz closed 6 years ago

davidmigloz commented 6 years ago

Currently, if you are using a user-provided password you don't know if the password is correct until you try to decrypt some value and you get an exception. It would be nice to know it when you are getting the Armadillo instance.

We could store some dummy value and try to decrypt it during the initialisation to check that the password is correct. What do you think?

patrickfav commented 6 years ago

That's generally a good idea, but I wouldn't do it automatically since the key stretching might take seconds which would make the initialization unnecessary complicated (waiting for a callback or using Observables).

Also I'm not sure I want to pollute the user encryption data with too much meta data (the user should be able to keep it as clean as possible.

This feature can be trivially implemented by a user, he/she only has to add the dummy value and try to read it after initialization. So I dont want the users to force to have this dummy check value if they don't need it (also migration would be a hassle again)

davidmigloz commented 6 years ago

I see your point.

Maybe It could be an additional parameter in the builder and a separate method to check it. So it would be totally optional to use it. Something like:

// Initialise Armadillo
ArmadilloSharedPreferences preferences = Armadillo.create(context, "myCustomPreferences")
        .password(pass, /* support password validation */ true)
        .build();
// Check validity of the password in background
if(preferences.isValidPassword()) {
        ...
} else {
        ....
}
patrickfav commented 6 years ago

I see your use case, a user might want to immediately check if a password is correct for an internal login. We just have to be careful with the magic value key.

I will add a v0.7.0 milestone.

davidmigloz commented 6 years ago

Exactly, that's the use case I have in mind.

patrickfav commented 6 years ago

PR merged