Skip to content

Commit

Permalink
Revert "Resolved a minor bug in IOS implementation of Face ID"
Browse files Browse the repository at this point in the history
This reverts commit 16c12d8.
  • Loading branch information
therajanmaurya committed Sep 9, 2024
1 parent c336796 commit b685c9f
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 39 deletions.
4 changes: 2 additions & 2 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
DEVELOPMENT_TEAM = N5F88VN4G4;
DEVELOPMENT_TEAM = Z57TWPQ3R6;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = iosApp/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
Expand All @@ -384,7 +384,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
DEVELOPMENT_TEAM = N5F88VN4G4;
DEVELOPMENT_TEAM = Z57TWPQ3R6;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = iosApp/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
Expand Down
9 changes: 4 additions & 5 deletions iosApp/iosApp/Biometric/BiometricUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import shared
import LocalAuthentication

class BiometricUtilIosImpl: BioMetricUtil {

private let cipherUtil = CipherUtilIosImpl()

private var promptDescription: String = "Authenticate"
Expand All @@ -18,7 +17,7 @@ class BiometricUtilIosImpl: BioMetricUtil {

DispatchQueue.main.async {
if success {
completionHandler(self?.generatePublicKey(), nil)
completionHandler(self?.getPublicKey(), nil)
} else {
completionHandler(nil, authenticationError)
}
Expand All @@ -43,9 +42,9 @@ class BiometricUtilIosImpl: BioMetricUtil {
}


func generatePublicKey() -> String? {
let keyPair = try? cipherUtil.generateKeyPair()
return keyPair?.publicKey?.toPemFormat().toBase64()
func generatePublicKey() async throws -> String? {
let keyPair = try cipherUtil.generateKeyPair()
return keyPair.publicKey?.toPemFormat().toBase64()
}

func getPublicKey() -> String? {
Expand Down
8 changes: 4 additions & 4 deletions iosApp/iosApp/Biometric/CipherUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Foundation
import shared

class CipherUtilIosImpl: ICipherUtil {
private let KEY_NAME = "my_biometric_key"
private let tag: Data
private let KEY_NAME = "biometric_key"
private let tag: String

private lazy var key: SecKey? = {
let query: [String: Any] = [
Expand All @@ -19,7 +19,7 @@ class CipherUtilIosImpl: ICipherUtil {
}()

init() {
self.tag = KEY_NAME.data(using: .utf8)!
self.tag = KEY_NAME
}

func generateKeyPair() throws -> CommonKeyPair {
Expand All @@ -35,7 +35,7 @@ class CipherUtilIosImpl: ICipherUtil {
kSecPrivateKeyAttrs as String: [
kSecAttrIsPermanent as String: true,
kSecAttrApplicationTag as String: tag,
kSecAttrAccessControl as String: access,
kSecAttrAccessControl as String: access
]
]

Expand Down
35 changes: 27 additions & 8 deletions iosApp/iosApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,49 @@ import shared

let biometricUtil = BiometricUtilIosImpl()
struct ContentView: View {
let greet = Greeting().greet()
let greet = Greeting().greet()
@State private var path = NavigationPath()

var body: some View {
var body: some View {
ZStack {
ComposeViewController()
ComposeViewController(onNavigateToNextScreen: {
path.append("NextScreen")
})
}
}
.navigationDestination(for: String.self) { value in
if value == "NextScreen" {
NextScreen()
}
}
}
}

struct ComposeViewController: UIViewControllerRepresentable {
@StateObject var biometricAuthorizationViewModel: BiometricAuthorizationViewModel = BiometricAuthorizationViewModel()
var onNavigateToNextScreen: () -> Void

func makeUIViewController(context: Context) -> UIViewController {
return App_iosKt.MainViewController(bioMetricUtil: biometricUtil, biometricViewModel: biometricAuthorizationViewModel)
return App_iosKt.MainViewController(
bioMetricUtil: biometricUtil,
biometricViewModel: biometricAuthorizationViewModel,
onPasscodeConfirm: onNavigateToNextScreen
)
}

func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
struct NextScreen: View {
var body: some View {
Text("Next Screen")
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

extension BiometricAuthorizationViewModel: ObservableObject {}
2 changes: 1 addition & 1 deletion iosApp/iosApp/iOSApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ struct iOSApp: App {
ContentView()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BiometricUtilAndroidImpl(
}

@RequiresApi(Build.VERSION_CODES.O)
override fun generatePublicKey(): String? {
override suspend fun generatePublicKey(): String? {
return cipherUtil.generateKeyPair().public?.encoded?.toBase64Encoded()?.toPemFormat()?.toBase64Encoded()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.mifos.shared

class AndroidPlatform : Platform {
// override val name: String = "Android ${android.os.Build.VERSION.SDK_INT}"
override val name: String = "Android"
override val name: String = "Android ${android.os.Build.VERSION.SDK_INT}"
}

actual fun getPlatform(): Platform = AndroidPlatform()
1 change: 0 additions & 1 deletion shared/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<string name="passcode_do_not_match">Passcode do not match!</string>
<string name="are_you_sure_you_want_to_exit">Are you sure you want to exit?</string>
<string name="use_touchId">Use TouchId</string>
<string name="use_faceId">Use FaceId</string>h
<string name="authentication_failed">Authentication failed</string>
<string name="authentication_not_set">Authentication not set</string>
<string name="authentication_not_available">Feature unavailable</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.mifos.shared.Platform
import com.mifos.shared.getPlatform
import com.mifos.shared.utility.BioMetricUtil
import com.mifos.shared.utility.PreferenceManager
import com.mifos.shared.theme.blueTint
Expand Down Expand Up @@ -120,7 +118,7 @@ fun PasscodeScreen(

LaunchedEffect(true){
if(preferenceManager.hasPasscode)
biometricAuthorizationViewModel.authorizeBiometric(bioMetricUtil)
biometricAuthorizationViewModel.authorizeBiometric(bioMetricUtil)
}

val snackBarHostState = remember {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.mifos.shared.Platform
import com.mifos.shared.getPlatform
import com.mifos.shared.theme.forgotButtonStyle
import com.mifos.shared.theme.skipButtonStyle
import com.mifos.shared.theme.useTouchIdButtonStyle
import com.mifos.shared.resources.Res
import com.mifos.shared.resources.forgot_passcode_login_manually
import com.mifos.shared.resources.skip
import com.mifos.shared.resources.use_faceId
import com.mifos.shared.resources.use_touchId
import org.jetbrains.compose.resources.stringResource

Expand Down Expand Up @@ -82,10 +79,7 @@ fun UseTouchIdButton(
TextButton(
onClick = onClick
) {
if(getPlatform().name == "Android")
Text(text = stringResource(Res.string.use_touchId), style = useTouchIdButtonStyle())
else
Text(text = stringResource(Res.string.use_faceId), style = useTouchIdButtonStyle())
Text(text = stringResource(Res.string.use_touchId), style = useTouchIdButtonStyle())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface BioMetricUtil {
suspend fun setAndReturnPublicKey(): String?
suspend fun authenticate(): AuthenticationResult
fun canAuthenticate(): Boolean
fun generatePublicKey(): String?
suspend fun generatePublicKey(): String?
fun signUserId(ucc: String): String
fun isBiometricSet(): Boolean
fun getPublicKey(): String?
Expand Down
9 changes: 7 additions & 2 deletions shared/src/iosMain/kotlin/com/mifos/shared/App.ios.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ import platform.UIKit.UIViewController

fun MainViewController(
bioMetricUtil: BioMetricUtil,
biometricViewModel: BiometricAuthorizationViewModel): UIViewController = ComposeUIViewController {
biometricViewModel: BiometricAuthorizationViewModel,
onPasscodeConfirm: () -> Unit,
): UIViewController = ComposeUIViewController {
PasscodeScreen(
onPasscodeConfirm = {
onPasscodeConfirm()
},
onSkipButton = {
onPasscodeConfirm()
},
onForgotButton = {},
onPasscodeRejected = {},
bioMetricUtil = bioMetricUtil,
biometricAuthorizationViewModel = biometricViewModel,
onBiometricAuthSuccess = {
}
onPasscodeConfirm()
}
)
}
3 changes: 1 addition & 2 deletions shared/src/iosMain/kotlin/com/mifos/shared/Platform.ios.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package com.mifos.shared
import platform.UIKit.UIDevice

class IOSPlatform: Platform {
// override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
override val name: String = "Ios"
override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
}

actual fun getPlatform(): Platform = IOSPlatform()

0 comments on commit b685c9f

Please sign in to comment.