Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Remove app-own crypto implementation and add kmp-advcrypto as dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Cach30verfl0w committed Jun 15, 2024
1 parent c8641ec commit cf43817
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 450 deletions.
7 changes: 5 additions & 2 deletions cash3fl0w-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ kotlin {
}
}

listOf(
/*listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
Expand All @@ -26,7 +26,7 @@ kotlin {
baseName = "Cash3Fl0w"
isStatic = true
}
}
}*/

sourceSets {

Expand All @@ -41,6 +41,9 @@ kotlin {
iosMain.dependencies {
}
commonMain.dependencies {
// Add kmp-advcrypto
implementation(project(":kmp-advcrypto"))

// Compose and decompose
implementation(compose.runtime)
implementation(compose.foundation)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,12 @@ import android.view.WindowManager.LayoutParams
import androidx.biometric.BiometricManager
import androidx.biometric.BiometricManager.Authenticators
import de.cacheoverflow.cashflow.MainActivity
import de.cacheoverflow.cashflow.security.cryptography.AESCryptoProvider
import de.cacheoverflow.cashflow.security.cryptography.IAsymmetricCryptoProvider
import de.cacheoverflow.cashflow.security.cryptography.ISymmetricCryptoProvider
import de.cacheoverflow.cashflow.security.cryptography.RSACryptoProvider
import de.cacheoverflow.cashflow.utils.DI
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.flow
import okio.FileSystem
import okio.Path
import java.io.IOException
import java.security.KeyFactory
import java.security.KeyStore
import java.security.spec.PKCS8EncodedKeySpec
import java.security.spec.X509EncodedKeySpec
import java.util.ArrayList
import javax.crypto.spec.SecretKeySpec

/**
* This is the Android-specific implementation of the security manager. This security manager
Expand All @@ -44,55 +32,13 @@ import javax.crypto.spec.SecretKeySpec
* @author Cedric Hammes
* @since 03/06/2024
*
* @see KeyStore
* @see LayoutParams
* @see KeyguardManager
*/
class AndroidSecurityProvider(private val pathProvider: (Path) -> Path): ISecurityProvider {
internal val keyStore = KeyStore.getInstance(KEY_STORE).apply { load(null) }
val isAuthenticated = MutableStateFlow(false)
private var screenshotDisabled = false

override fun getSymmetricCryptoProvider(usePadding: Boolean): ISymmetricCryptoProvider {
return AESCryptoProvider(this, usePadding)
}

override fun getAsymmetricCryptoProvider(usePadding: Boolean): IAsymmetricCryptoProvider {
return RSACryptoProvider(this, usePadding)
}

/**
* This method reads the specified file from the file system specified in the constructor to
* extract a key from the file.
*
* @param file The relative path to the file being read
* @param algorithm The key's algorithm
* @param privateKey Whether the key is a private key or not (ignored on symmetric algorithms)
*
* @author Cedric Hammes
* @since 05/06/2024
*/
override fun readKeyFromFile(
file: Path,
algorithm: ISecurityProvider.EnumAlgorithm,
privateKey: Boolean,
usePadding: Boolean
): Flow<IKey> = flow {
FileSystem.SYSTEM.read(pathProvider(file)) {
emit(AndroidKey(when(algorithm) {
ISecurityProvider.EnumAlgorithm.AES -> SecretKeySpec(readByteArray(), "AES")
ISecurityProvider.EnumAlgorithm.RSA -> {
val keyFactory = KeyFactory.getInstance("RSA")
when(privateKey) {
false -> keyFactory.generatePrivate(PKCS8EncodedKeySpec(readByteArray()))
true -> keyFactory.generatePublic(X509EncodedKeySpec(readByteArray()))
}
}
}!!, usePadding))
close()
}
}

/**
* This method returns the authentication methods supported by this system. This is used to
* reduce the amount of settings based on the authentication schemes available.
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit cf43817

Please sign in to comment.