Use Android keystore for encrypting DB key.

Only for new accounts on API 23+.
This commit is contained in:
akwizgran
2020-01-09 14:06:42 +00:00
parent 8a6e886d09
commit 4d3c1b4fd2
12 changed files with 222 additions and 37 deletions

View File

@@ -133,7 +133,8 @@ public interface CryptoComponent {
* given password. The ciphertext will be decryptable using the same
* password after the app restarts.
*/
byte[] encryptWithPassword(byte[] plaintext, String password);
byte[] encryptWithPassword(byte[] plaintext, String password,
@Nullable KeyStoreConfig keyStoreConfig);
/**
* Decrypts and authenticates the given ciphertext that has been read from
@@ -142,7 +143,8 @@ public interface CryptoComponent {
* authenticated (for example, if the password is wrong).
*/
@Nullable
byte[] decryptWithPassword(byte[] ciphertext, String password);
byte[] decryptWithPassword(byte[] ciphertext, String password,
@Nullable KeyStoreConfig keyStoreConfig);
/**
* Encrypts the given plaintext to the given public key.

View File

@@ -0,0 +1,19 @@
package org.briarproject.bramble.api.crypto;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.security.spec.AlgorithmParameterSpec;
@NotNullByDefault
public interface KeyStoreConfig {
String getKeyStoreType();
String getAlias();
String getProviderName();
String getMacAlgorithmName();
AlgorithmParameterSpec getParameterSpec();
}

View File

@@ -1,13 +1,19 @@
package org.briarproject.bramble.api.db;
import org.briarproject.bramble.api.crypto.KeyStoreConfig;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.io.File;
import javax.annotation.Nullable;
@NotNullByDefault
public interface DatabaseConfig {
File getDatabaseDirectory();
File getDatabaseKeyDirectory();
@Nullable
KeyStoreConfig getKeyStoreConfig();
}