Add javadocs.

This commit is contained in:
akwizgran
2020-01-09 14:17:55 +00:00
parent 4d3c1b4fd2
commit d7b05dcba0
5 changed files with 28 additions and 3 deletions

View File

@@ -132,6 +132,9 @@ public interface CryptoComponent {
* storage. The encryption and authentication keys are derived from the * storage. The encryption and authentication keys are derived from the
* given password. The ciphertext will be decryptable using the same * given password. The ciphertext will be decryptable using the same
* password after the app restarts. * password after the app restarts.
*
* @param keyStoreConfig Configures the use of a stored key to strengthen
* the password-based key. If null, no stored key will be used
*/ */
byte[] encryptWithPassword(byte[] plaintext, String password, byte[] encryptWithPassword(byte[] plaintext, String password,
@Nullable KeyStoreConfig keyStoreConfig); @Nullable KeyStoreConfig keyStoreConfig);
@@ -141,6 +144,10 @@ public interface CryptoComponent {
* storage. The encryption and authentication keys are derived from the * storage. The encryption and authentication keys are derived from the
* given password. Returns null if the ciphertext cannot be decrypted and * given password. Returns null if the ciphertext cannot be decrypted and
* authenticated (for example, if the password is wrong). * authenticated (for example, if the password is wrong).
*
* @param keyStoreConfig Configures the use of a stored key to strengthen
* the password-based key. If null, or if no stored key was used when
* encrypting the ciphertext, then no stored key will be used
*/ */
@Nullable @Nullable
byte[] decryptWithPassword(byte[] ciphertext, String password, byte[] decryptWithPassword(byte[] ciphertext, String password,

View File

@@ -4,12 +4,20 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
/**
* Configures the use of a stored key to strengthen password-based encryption.
* The key may be stored in a hardware security module, but this is not
* guaranteed. See
* {@link CryptoComponent#encryptWithPassword(byte[], String, KeyStoreConfig)}
* and
* {@link CryptoComponent#decryptWithPassword(byte[], String, KeyStoreConfig)}.
*/
@NotNullByDefault @NotNullByDefault
public interface KeyStoreConfig { public interface KeyStoreConfig {
String getKeyStoreType(); String getKeyStoreType();
String getAlias(); String getKeyAlias();
String getProviderName(); String getProviderName();

View File

@@ -10,10 +10,20 @@ import javax.annotation.Nullable;
@NotNullByDefault @NotNullByDefault
public interface DatabaseConfig { public interface DatabaseConfig {
/**
* Returns the directory where the database stores its data.
*/
File getDatabaseDirectory(); File getDatabaseDirectory();
/**
* Returns the directory where the encrypted database key is stored.
*/
File getDatabaseKeyDirectory(); File getDatabaseKeyDirectory();
/**
* Returns a {@link KeyStoreConfig} for strengthening the encryption of the
* database key, or null if no keystore should be used.
*/
@Nullable @Nullable
KeyStoreConfig getKeyStoreConfig(); KeyStoreConfig getKeyStoreConfig();
} }

View File

@@ -383,7 +383,7 @@ class CryptoComponentImpl implements CryptoComponent {
ks.load(null); ks.load(null);
// Load or generate the stored key // Load or generate the stored key
javax.crypto.SecretKey storedKey; javax.crypto.SecretKey storedKey;
Entry e = ks.getEntry(config.getAlias(), null); Entry e = ks.getEntry(config.getKeyAlias(), null);
if (e == null) { if (e == null) {
if (!generateIfMissing) { if (!generateIfMissing) {
LOG.warning("Key not found in keystore"); LOG.warning("Key not found in keystore");

View File

@@ -31,7 +31,7 @@ class AndroidKeyStoreConfig implements KeyStoreConfig {
} }
@Override @Override
public String getAlias() { public String getKeyAlias() {
return "db"; return "db";
} }