【问题标题】:Sirikit : Touch Id and increasing securitySirikit : Touch Id 和提高安全性
【发布时间】:2016-07-18 03:17:10
【问题描述】:

试图了解以下内容:

  1. https://developer.apple.com/videos/play/wwdc2016/225/ 提到 sendPayments 意图默认是 IntentsRestrictedWhileLocked,但是如果我们想提高安全性以便用户需要使用 Touch Id(本地身份验证)进行批准,那么这将如何完成?这在设备被锁定/解锁时都需要。我假设扩展程序需要在“确认”阶段以某种方式显示本地身份验证 UI?

  2. 他们还提到可以提高安全性,但如果这样做的机制只是 IntentsRestrictedWhileLocked 扩展属性,则只需要确认?或者有没有办法指定需要触摸 id 身份验证?

【问题讨论】:

  • 好问题,我正在研究类似的用例..
  • @inforeqd 请查看我的回答,如果有帮助请接受。 :) 谢谢。

标签: security touch-id sirikit


【解决方案1】:

要回答这两个问题,是的,您可以使用 Touch ID 提高支付的安全性,这是我在 Apple 的示例代码 here 上实现它的方法,我在 SendPaymentIntentHandler.swift 中添加了以下函数:

func authenticate(successAuth: @escaping () -> Void, failure: @escaping (NSError?) -> Void) {
    // 1. Create a authentication context
    let authenticationContext = LAContext()
    var error:NSError?
    guard authenticationContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else {
        failure(error)
        return
    }
    // 3. Check the fingerprint
    authenticationContext.evaluatePolicy(
        .deviceOwnerAuthenticationWithBiometrics,
        localizedReason: "Unlock to send the money",
        reply: { [unowned self] (success, error) -> Void in

            if( success ) {
                successAuth()

            }else {
                let message = self.errorMessageForLAErrorCode(errorCode: (error! as NSError).code)
                print(message)
                failure(error! as NSError)
            }

        })

}

func errorMessageForLAErrorCode( errorCode:Int ) -> String{

    var message = ""

    switch errorCode {

    case LAError.appCancel.rawValue:
        message = "Authentication was cancelled by application"

    case LAError.authenticationFailed.rawValue:
        message = "The user failed to provide valid credentials"

    case LAError.invalidContext.rawValue:
        message = "The context is invalid"

    case LAError.passcodeNotSet.rawValue:
        message = "Passcode is not set on the device"

    case LAError.systemCancel.rawValue:
        message = "Authentication was cancelled by the system"

    case LAError.touchIDLockout.rawValue:
        message = "Too many failed attempts."

    case LAError.touchIDNotAvailable.rawValue:
        message = "TouchID is not available on the device"

    case LAError.userCancel.rawValue:
        message = "The user did cancel"

    case LAError.userFallback.rawValue:
        message = "The user chose to use the fallback"

    default:
        message = "Did not find error code on LAError object"

    }

    return message

}

然后在handle方法中调用函数authenticate,结果是我的app在确认支付后要求进行Touch ID认证,然后用户自己认证后才成功发送支付。

【讨论】:

  • 我没有收到屏幕,但我收到了来自 siri 的声音,因为请进行身份验证...我认为呈现 UI 时存在问题
【解决方案2】:

听起来您希望有一种内置的方式来发送支付扩展来调用本地身份验证。就像可能在 plist 中指定一个键来表示您想要触摸 ID 身份验证?我认为情况并非如此。

对于我正在处理的发送付款扩展,我们在确认阶段实例化了一个LAContext,并同时调用canEvaluatePolicy(_:error:)evaluatePolicy(_:localizedReason:reply:)。当他们说支持本地身份验证时,我认为他们只是意味着您可以在扩展程序中触发它,并且 UI 将由 Siri 显示。

【讨论】:

    【解决方案3】:

    如果 IntentsRestrictedWhileLocked 中列出了指定的 Intent,则在屏幕锁定时,Siri 无法调用它。只有当设备通过密码或触摸 ID 解锁时才能调用它。据我所知,无法区分设备是如何解锁的。

    【讨论】:

    • 我明白了.. 参考我的 pt#2,您知道这是否可行以及如何实现?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 2013-04-09
    • 1970-01-01
    • 2021-07-10
    • 2021-07-30
    相关资源
    最近更新 更多