This commit is contained in:
Adam Velebil 2022-09-02 17:01:28 +02:00
commit 5b927221d8
No known key found for this signature in database
GPG Key ID: AC6D6B9D715FC084
4 changed files with 25 additions and 25 deletions

View File

@ -4,10 +4,10 @@ import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel
class FlutterLog(messenger: BinaryMessenger) { class FlutterLog(messenger: BinaryMessenger) {
private var _channel = MethodChannel(messenger, "android.log.redirect") private var channel = MethodChannel(messenger, "android.log.redirect")
init { init {
_channel.setMethodCallHandler { call, result -> channel.setMethodCallHandler { call, result ->
when (call.method) { when (call.method) {
"log" -> { "log" -> {

View File

@ -13,11 +13,11 @@ object Log {
ERROR ERROR
} }
const val MAX_BUFFER_SIZE = 1000 private const val MAX_BUFFER_SIZE = 1000
private val _buffer = arrayListOf<String>() private val buffer = arrayListOf<String>()
fun getBuffer() : List<String> { fun getBuffer() : List<String> {
return _buffer return buffer
} }
private var level = if (BuildConfig.DEBUG) { private var level = if (BuildConfig.DEBUG) {
@ -59,12 +59,12 @@ object Log {
return return
} }
if (_buffer.size > MAX_BUFFER_SIZE) { if (buffer.size > MAX_BUFFER_SIZE) {
_buffer.removeAt(0) buffer.removeAt(0)
} }
val logMessage = "[$loggerName] ${level.name}: $message".also { val logMessage = "[$loggerName] ${level.name}: $message".also {
_buffer.add(it) buffer.add(it)
} }
when (level) { when (level) {
@ -77,7 +77,7 @@ object Log {
error?.let { error?.let {
Log.e(TAG, "[$loggerName] ${level.name}(details): $error".also { Log.e(TAG, "[$loggerName] ${level.name}(details): $error".also {
_buffer.add(it) buffer.add(it)
}) })
} }
} }

View File

@ -41,13 +41,13 @@ class OathManager(
const val NFC_DATA_CLEANUP_DELAY = 30L * 1000; // 30s const val NFC_DATA_CLEANUP_DELAY = 30L * 1000; // 30s
} }
private val _dispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher() private val dispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
private val coroutineScope = CoroutineScope(SupervisorJob() + _dispatcher) private val coroutineScope = CoroutineScope(SupervisorJob() + dispatcher)
private val oathChannel = MethodChannel(messenger, "android.oath.methods") private val oathChannel = MethodChannel(messenger, "android.oath.methods")
private val _memoryKeyProvider = ClearingMemProvider() private val memoryKeyProvider = ClearingMemProvider()
private val _keyManager = KeyManager(KeyStoreProvider(), _memoryKeyProvider) private val keyManager = KeyManager(KeyStoreProvider(), memoryKeyProvider)
private var pendingAction: OathAction? = null private var pendingAction: OathAction? = null
private var refreshJob: Job? = null private var refreshJob: Job? = null
@ -198,11 +198,11 @@ class OathManager(
// Clear in-memory password for any previous device // Clear in-memory password for any previous device
if (it.transport == Transport.NFC && previousId != null) { if (it.transport == Transport.NFC && previousId != null) {
_memoryKeyProvider.removeKey(previousId) memoryKeyProvider.removeKey(previousId)
} }
// Update the OATH state // Update the OATH state
oathViewModel.setSessionState(oath.model(_keyManager.isRemembered(oath.deviceId))) oathViewModel.setSessionState(oath.model(keyManager.isRemembered(oath.deviceId)))
if (!oath.isLocked) { if (!oath.isLocked) {
oathViewModel.updateCredentials( oathViewModel.updateCredentials(
calculateOathCodes(oath).model(oath.deviceId) calculateOathCodes(oath).model(oath.deviceId)
@ -243,7 +243,7 @@ class OathManager(
useOathSession("Reset YubiKey") { useOathSession("Reset YubiKey") {
// note, it is ok to reset locked session // note, it is ok to reset locked session
it.reset() it.reset()
_keyManager.removeKey(it.deviceId) keyManager.removeKey(it.deviceId)
oathViewModel.setSessionState(it.model(false)) oathViewModel.setSessionState(it.model(false))
} }
return NULL return NULL
@ -252,10 +252,10 @@ class OathManager(
private suspend fun unlock(password: String, remember: Boolean): String = private suspend fun unlock(password: String, remember: Boolean): String =
useOathSession("Unlocking") { useOathSession("Unlocking") {
val accessKey = it.deriveAccessKey(password.toCharArray()) val accessKey = it.deriveAccessKey(password.toCharArray())
_keyManager.addKey(it.deviceId, accessKey, remember) keyManager.addKey(it.deviceId, accessKey, remember)
val unlocked = tryToUnlockOathSession(it) val unlocked = tryToUnlockOathSession(it)
val remembered = _keyManager.isRemembered(it.deviceId) val remembered = keyManager.isRemembered(it.deviceId)
if (unlocked) { if (unlocked) {
oathViewModel.setSessionState(it.model(remembered)) oathViewModel.setSessionState(it.model(remembered))
oathViewModel.updateCredentials(calculateOathCodes(it).model(it.deviceId)) oathViewModel.updateCredentials(calculateOathCodes(it).model(it.deviceId))
@ -280,7 +280,7 @@ class OathManager(
} }
val accessKey = session.deriveAccessKey(newPassword.toCharArray()) val accessKey = session.deriveAccessKey(newPassword.toCharArray())
session.setAccessKey(accessKey) session.setAccessKey(accessKey)
_keyManager.addKey(session.deviceId, accessKey, false) keyManager.addKey(session.deviceId, accessKey, false)
oathViewModel.setSessionState(session.model(false)) oathViewModel.setSessionState(session.model(false))
Log.d(TAG, "Successfully set password") Log.d(TAG, "Successfully set password")
NULL NULL
@ -292,7 +292,7 @@ class OathManager(
// test current password sent by the user // test current password sent by the user
if (session.unlock(currentPassword.toCharArray())) { if (session.unlock(currentPassword.toCharArray())) {
session.deleteAccessKey() session.deleteAccessKey()
_keyManager.removeKey(session.deviceId) keyManager.removeKey(session.deviceId)
oathViewModel.setSessionState(session.model(false)) oathViewModel.setSessionState(session.model(false))
Log.d(TAG, "Successfully unset password") Log.d(TAG, "Successfully unset password")
return@useOathSession NULL return@useOathSession NULL
@ -302,7 +302,7 @@ class OathManager(
} }
private suspend fun forgetPassword(): String { private suspend fun forgetPassword(): String {
_keyManager.clearAll() keyManager.clearAll()
Log.d(TAG, "Cleared all keys.") Log.d(TAG, "Cleared all keys.")
oathViewModel.sessionState.value?.let { oathViewModel.sessionState.value?.let {
oathViewModel.setSessionState( oathViewModel.setSessionState(
@ -416,7 +416,7 @@ class OathManager(
} }
val deviceId = session.deviceId val deviceId = session.deviceId
val accessKey = _keyManager.getKey(deviceId) val accessKey = keyManager.getKey(deviceId)
?: return false // we have no access key to unlock the session ?: return false // we have no access key to unlock the session
val unlockSucceed = session.unlock(accessKey) val unlockSucceed = session.unlock(accessKey)
@ -425,7 +425,7 @@ class OathManager(
return true return true
} }
_keyManager.removeKey(deviceId) // remove invalid access keys from [KeyManager] keyManager.removeKey(deviceId) // remove invalid access keys from [KeyManager]
return false // the unlock did not work, session is locked return false // the unlock did not work, session is locked
} }

View File

@ -56,7 +56,7 @@ typealias BarcodeAnalyzerListener = (Result<String>) -> Unit
internal class QRScannerView( internal class QRScannerView(
context: Context, context: Context,
id: Int, @Suppress("UNUSED_PARAMETER") id : Int,
binaryMessenger: BinaryMessenger, binaryMessenger: BinaryMessenger,
private val permissionsResultRegistrar: PermissionsResultRegistrar, private val permissionsResultRegistrar: PermissionsResultRegistrar,
creationParams: Map<String?, Any?>? creationParams: Map<String?, Any?>?
@ -149,7 +149,7 @@ internal class QRScannerView(
bindUseCases(context) bindUseCases(context)
} }
methodChannel.setMethodCallHandler { call, result -> methodChannel.setMethodCallHandler { call, _ ->
if (call.method =="requestCameraPermissions") { if (call.method =="requestCameraPermissions") {
requestPermissionsFromUser(context) requestPermissionsFromUser(context)