代码之家  ›  专栏  ›  技术社区  ›  Brett Sutton

android fido-SECURITY_ERR传入请求无法验证

  •  0
  • Brett Sutton  · 技术社区  · 1 年前

    我正在构建一个演示android应用程序(从技术上讲是flutter,但这段代码在本地java代码中)。

    应用程序的目的是演示使用fido登录应用程序。

    我的问题是在fido注册过程中。 它正在返回错误:

    SECURITY_ERR无法验证传入请求

    我正在尝试在本地系统上完全测试该应用程序。

    为此,我为域'squarephone.biz'创建了一个指向10.0.2.2的/etc/hosts条目。

    android/flatter应用程序能够连接到我的本地fido服务器。

    本地fido服务器承载assetslinks.json文件。

    我猜问题出在应用程序没有访问assetslinks.json文件上,因为我没有看到任何对该文件的请求。

    你可以在这里看到fido客户端: https://github.com/onepub-dev/fido-client

    客户端使用第三方插头,所有fido交互都发生在该插头上:

    https://github.com/onepub-dev/contrib-fido2-flutter-lib

    Android目录是所有有趣的部分所在的地方。

    我目前的猜测是,要么你不能使用本地fido服务器进行测试(但本地/etc/hosts应该可以绕过这一点),要么我的一个配置文件不正确。

    这是一个失败的呼叫:

    关键参数为:

    rp域:squarephone.biz

    coseAlgoValue:-7

     private fun initiateRegistration(
            result: Result, challenge: String, userId: String, username: String,
            rpDomain: String, rpName: String, coseAlgoValue: List<Int>, excludeCredentials: List<String>
        ) {
            val rpEntity = PublicKeyCredentialRpEntity(rpDomain, rpName, null)
            val options = PublicKeyCredentialCreationOptions.Builder()
                .setRp(rpEntity)
                .setUser(
                    PublicKeyCredentialUserEntity(
                        userId.to(),
                        userId,
                        null,
                        username
                    )
                )
                .setChallenge(challenge.decodeBase64())
                .setParameters(
                    coseAlgoValue.map {
                        PublicKeyCredentialParameters(
                            PublicKeyCredentialType.PUBLIC_KEY.toString(),
                            it
                        )
                    }
                )
                .setExcludeList(
                    excludeCredentials.map {
                        PublicKeyCredentialDescriptor(
                            PublicKeyCredentialType.PUBLIC_KEY.toString(),
                            it.decodeBase64(),
                            null
                        )
                    }
                )
                .setAuthenticatorSelection(
                    AuthenticatorSelectionCriteria.Builder().setAttachment(Attachment.PLATFORM).build()
                )
                .build()
    
            val fidoClient = Fido.getFido2ApiClient(activity)
            val registerIntent = fidoClient.getRegisterPendingIntent(options)
            registerIntent.addOnFailureListener {
                val errCode = "FAILED_TO_GET_REGISTER_INTENT"
                result.error(errCode, it.message, null);
            }
            registerIntent.addOnSuccessListener { pendingIntent ->
                if (pendingIntent != null) {
                    // Start a FIDO2 registration request.
                    activity?.startIntentSenderForResult(
                        pendingIntent.intentSender,
                        REGISTER_REQUEST_CODE,
                        null,
                        0,
                        0,
                        0
                    )
                } else {
                    val errCode = "FAILED_TO_GET_REGISTER_INTENT"
                    result.error(errCode, "An error occurred", null);
                }
            }
        }
    

    问题是,我看不出任何方法可以从android中获得任何诊断信息。 我真的在寻找一个关于android正在做什么和失败的日志。

    以下是关键文件:

    AndroidManifest.xml

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="dev.onepub.fido.client">
       <application
            android:label="fido_client"
            android:name="${applicationName}"
            android:icon="@mipmap/ic_launcher">
            <activity
                android:name=".MainActivity"
                android:exported="true"
                android:launchMode="singleTop"
                android:theme="@style/LaunchTheme"
                android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
                android:hardwareAccelerated="true"
                android:windowSoftInputMode="adjustResize">
                <!-- Specifies an Android theme to apply to this Activity as soon as
                     the Android process has started. This theme is visible to the user
                     while the Flutter UI initializes. After that, this theme continues
                     to determine the Window background behind the Flutter UI. -->
                <meta-data
                  android:name="io.flutter.embedding.android.NormalTheme"
                  android:resource="@style/NormalTheme"
                  />
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
            </activity>
            <!-- Don't delete the meta-data below.
                 This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
            <meta-data
                android:name="flutterEmbedding"
                android:value="2" />
            <!-- required by FIDO links to res/values/strings.xml-->
            <meta-data android:name="asset_statements" android:resource="@string/asset_statements" />
        </application>
    </manifest>
    

    字符串.xml

    <resources>
            <string name="asset_statements" translatable="false">
        [{
                \"include\": \"http://squarephone.biz:8080/.well-known/assetlinks.json\"
        }]
            </string>
    </resources>
    

    我已经包含了assetlinks.json文件,但它并没有发挥作用,因为它不能从服务器访问。

    assetlinks.json

    [
        {
          "relation" : [
            "delegate_permission/common.handle_all_urls",
            "delegate_permission/common.get_login_creds"
          ],
          "target" : {
            "namespace" : "web",
            "site" : "http://squarephone.biz:8080"
          }
        },
        {
          "relation" : [
            "delegate_permission/common.handle_all_urls",
            "delegate_permission/common.get_login_creds"
          ],
          "target" : {
            "namespace" : "android_app",
            "package_name" : "dev.onepub.fido.client",
            "sha256_cert_fingerprints" : [
               "XXXX:XXXX"
            ]
          }
        }
      ]
    

    这里有一个指向fido服务器的链接,然而,我不认为它在问题中起了作用。

    https://github.com/onepub-dev/fido-server

    0 回复  |  直到 1 年前
        1
  •  0
  •   Brett Sutton    1 年前

    所以最终发现了问题。

    assetlinks.json文件必须托管在谷歌服务器可以访问的公共web服务器上。

    在身份验证过程中,您的手机会向谷歌发送一个验证资产的请求。

    Google服务器从strings.xml文件中的asset_statement获取assetslinks.json文件。

    如果谷歌服务器无法获取文件,则会出现上述错误:

    SECURITY_ERR无法验证传入请求