Repository navigation
Description
Here's an outline of what we should do:
- Some information about private keys will have to go into a database
- Create a class to encrypt secrets using the KeyStore, call it something like
KeyStoreEncryption - look up private keys
1: Database
You should have a table called something like key. The table should have roughly the following structure:
CREATE TABLE IF NOT EXISTS `key` (
`longid` VARCHAR(16) NOT NULL,
`source` VARCHAR(20) NOT NULL,
`public` BLOB NOT NULL,
`private` BLOB NOT NULL,
`passphrase` varchar(100) DEFAULT NULL,
PRIMARY KEY(longid)
);Explaining each column:
longid: get this when recovering the key withjs.crypto_key_longid()source: any of following strings: "backup", "new", "import". For now, will always bebackuppublic: armored public key. get withkey.toPublic().armor()private: armored private key, that was first encrypted using KeyStoreEncryption. Something like:String KeyStoreEncryption.encrypt(String normalized_armored_private_key);passphrase: also encrypted egString KeyStoreEncryption.encrypt(String passphrase);. This column may stay empty (a null). For now though, you will always fill it with the encrypted pass phrase.
2: KeyStoreEncryption
Unfortunately, KeyStore cannot just store any string and encrypt it - we have to do it ourselves and use KeyStore to do it.
Basically, we will create a new keypair in KeyStore and then use that keypair to encrypt and decrypt sensitive information. When creating the keypair, you will have to assign a an alias to it. You can probably pick something static like "flowcrypt_main".
The details are outlined here: http://www.androidauthority.com/use-android-keystore-store-passwords-sensitive-information-623779/
KeyStore specs if you need them: https://developer.android.com/training/articles/keystore.html
This functionality should be put as methods into a class, something like:
class KeyStoreEncryption {
private String alias = "flowcrypt_main";
public String encrypt(String plain_data);
public String decrypt(String encrypted_data);
}The details of how you structure this is of course up to you. The result will be that private and passphrase fields in the database will be encrypted using the KeyStore keypair, and therefore protected by user's Android passcode.
Anytime you save or load the private key from database, you'll need to use that class.
3: Look up private keys
This will make it possible to connect this to SecurityStorageConnector and look up private keys and pass phrases based on longid as originally intended
Activity
tomholub commentedon May 10, 2017
This is what I believe we should do based on my understanding of Android so far, but I may have missed something. Let me know if you have any feedback.
DenBond7 commentedon May 11, 2017
For me http://www.androidauthority.com/where-is-the-best-place-to-store-a-password-in-your-android-app-597197/
DenBond7 commentedon May 11, 2017
For reference: The Keystore itself is encrypted using the user’s own lockscreen pin/password, hence, when the device screen is locked the Keystore is unavailable. Keep this in mind if you have a background service that could need to access your application secrets.
tomholub commentedon May 11, 2017
DenBond7 commentedon May 11, 2017
Yes, because we will use the decrypt function only when showing message when the device is active.
tomholub commentedon May 11, 2017
DenBond7 commentedon May 12, 2017
6795d08
DenBond7 commentedon May 15, 2017
8a1dd47
DenBond7 commentedon May 16, 2017
For me https://tozny.com/blog/encrypting-strings-in-android-lets-make-better-mistakes/
Completed work on Issue #17. Ended work on private key saving, struct…
DenBond7 commentedon May 16, 2017
I completed this task. Now the keys are stored in the database in encrypted form. The current build of apk file will work with the new algorithm.
tomholub commentedon May 20, 2017
Just tested it, working well on my end. Closing this