-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
12 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
app/unit-tests/resources/META-INF/services/org.commcare.util.IKeyStoreEncryptionKeyProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.commcare.utils.TestKeyStoreEncryptionKeyProvider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/unit-tests/src/org/commcare/utils/TestKeyStoreEncryptionKeyProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.commcare.utils; | ||
|
||
import android.os.Build; | ||
import android.security.keystore.KeyProperties; | ||
|
||
import org.commcare.util.EncryptionHelper; | ||
import org.commcare.util.EncryptionKeyHelper; | ||
import org.commcare.util.IKeyStoreEncryptionKeyProvider; | ||
|
||
import java.security.Key; | ||
|
||
import androidx.annotation.RequiresApi; | ||
|
||
/** | ||
* Class for providing encryption keys backed by Android Keystore for Unit testing | ||
* | ||
* @author avazirna | ||
*/ | ||
public class TestKeyStoreEncryptionKeyProvider implements IKeyStoreEncryptionKeyProvider { | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.M) | ||
private static final String ALGORITHM = KeyProperties.KEY_ALGORITHM_AES; | ||
@RequiresApi(api = Build.VERSION_CODES.M) | ||
private static final String BLOCK_MODE = KeyProperties.BLOCK_MODE_GCM; | ||
@RequiresApi(api = Build.VERSION_CODES.M) | ||
private static final String PADDING = KeyProperties.ENCRYPTION_PADDING_NONE; | ||
|
||
// Generates a cryptrographic key and adds it to the Android KeyStore | ||
@Override | ||
public Key generateCryptographicKeyInKeyStore(String keyAlias, | ||
EncryptionHelper.CryptographicOperation cryptographicOperation) | ||
throws EncryptionKeyHelper.EncryptionKeyException { | ||
throw new EncryptionKeyHelper.EncryptionKeyException("KeyStore encryption key generator provider for testing only"); | ||
} | ||
|
||
@Override | ||
public String getTransformationString() { | ||
return String.format("%s/%s/%s", ALGORITHM, BLOCK_MODE, PADDING); | ||
} | ||
|
||
@Override | ||
public String getKeyStoreName() { | ||
return "AndroidKeyStore"; | ||
} | ||
} |