Skip to content

Commit

Permalink
fix: Require Android 6 or newer (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
LilianaFaustinoDev authored Jun 7, 2023
1 parent ecb6eca commit 8def0f7
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 6 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ android.jetifier.blacklist = bcprov-jdk15on-1.*.jar

The items below summarize the security and privacy considerations specific to this app. For a more general overview of the security considerations in Awala, please refer to [RS-019](https://specs.awala.network/RS-019).

### No encryption at rest on Android 5

We use the [Android Keystore system](https://developer.android.com/training/articles/keystore) to protect sensitive cryptographic material, such as long-term and ephemeral keys. Unfortunately, [Android 5 doesn't actually encrypt anything at rest](https://github.com/relaycorp/relaynet-gateway-android/issues/247).

### External communication

This library exclusively communicates with the private gateway installed on the device. It does not communicate with other apps or any Internet host.
Expand Down
2 changes: 1 addition & 1 deletion lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 21
minSdkVersion 23
targetSdkVersion 33
versionCode 1
versionName "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ package tech.relaycorp.awaladroid
import java.io.File
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import tech.relaycorp.awala.keystores.file.FileKeystoreRoot
import tech.relaycorp.awaladroid.test.FakeAndroidKeyStore
import tech.relaycorp.relaynet.testing.pki.KeyPairSet
import tech.relaycorp.relaynet.testing.pki.PDACertPath

@RunWith(RobolectricTestRunner::class)
public class AndroidPrivateKeyStoreTest {

@Before
public fun setUp() {
FakeAndroidKeyStore.setup
}

@Test
public fun saveAndRetrieve(): Unit = runTest {
val androidContext = RuntimeEnvironment.getApplication()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright 2023 Relaycorp, Inc.
* Copyright 2020 Appmattus Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package tech.relaycorp.awaladroid.test

import java.io.InputStream
import java.io.OutputStream
import java.security.Key
import java.security.KeyStore
import java.security.KeyStoreSpi
import java.security.Provider
import java.security.SecureRandom
import java.security.Security
import java.security.cert.Certificate
import java.security.spec.AlgorithmParameterSpec
import java.util.Date
import java.util.Enumeration
import javax.crypto.KeyGenerator
import javax.crypto.KeyGeneratorSpi
import javax.crypto.SecretKey

// Source: https://proandroiddev.com/testing-jetpack-security-with-robolectric-9f9cf2aa4f61
public object FakeAndroidKeyStore {

public val setup: Int by lazy {
Security.addProvider(object : Provider("AndroidKeyStore", 1.0, "") {
init {
put("KeyStore.AndroidKeyStore", FakeKeyStore::class.java.name)
put("KeyGenerator.AES", FakeAesKeyGenerator::class.java.name)
}
})
}

@Suppress("unused")
public class FakeKeyStore : KeyStoreSpi() {
private val wrapped = KeyStore.getInstance(KeyStore.getDefaultType())

override fun engineIsKeyEntry(alias: String?): Boolean = wrapped.isKeyEntry(alias)
override fun engineIsCertificateEntry(alias: String?): Boolean =
wrapped.isCertificateEntry(alias)

override fun engineGetCertificate(alias: String?): Certificate =
wrapped.getCertificate(alias)

override fun engineGetCreationDate(alias: String?): Date = wrapped.getCreationDate(alias)
override fun engineDeleteEntry(alias: String?): Unit = wrapped.deleteEntry(alias)
override fun engineSetKeyEntry(
alias: String?,
key: Key?,
password: CharArray?,
chain: Array<out Certificate>?
): Unit =
wrapped.setKeyEntry(alias, key, password, chain)

override fun engineSetKeyEntry(
alias: String?,
key: ByteArray?,
chain: Array<out Certificate>?
): Unit = wrapped.setKeyEntry(alias, key, chain)

override fun engineStore(stream: OutputStream?, password: CharArray?): Unit =
wrapped.store(stream, password)

override fun engineSize(): Int = wrapped.size()
override fun engineAliases(): Enumeration<String> = wrapped.aliases()
override fun engineContainsAlias(alias: String?): Boolean = wrapped.containsAlias(alias)
override fun engineLoad(stream: InputStream?, password: CharArray?): Unit =
wrapped.load(stream, password)

override fun engineGetCertificateChain(alias: String?): Array<Certificate> =
wrapped.getCertificateChain(alias)

override fun engineSetCertificateEntry(alias: String?, cert: Certificate?): Unit =
wrapped.setCertificateEntry(alias, cert)

override fun engineGetCertificateAlias(cert: Certificate?): String =
wrapped.getCertificateAlias(cert)

override fun engineGetKey(alias: String?, password: CharArray?): Key? =
wrapped.getKey(alias, password)
}

@Suppress("unused")
public class FakeAesKeyGenerator : KeyGeneratorSpi() {
private val wrapped = KeyGenerator.getInstance("AES")

override fun engineInit(random: SecureRandom?): Unit = Unit
override fun engineInit(params: AlgorithmParameterSpec?, random: SecureRandom?): Unit = Unit
override fun engineInit(keysize: Int, random: SecureRandom?): Unit = Unit
override fun engineGenerateKey(): SecretKey = wrapped.generateKey()
}
}
2 changes: 1 addition & 1 deletion lib/src/test/resources/robolectric.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sdk=21
sdk=23

0 comments on commit 8def0f7

Please sign in to comment.