diff --git a/app/src/main/java/com/kunzisoft/keepass/credentialprovider/passkey/data/PublicKeyCredentialCreationOptions.kt b/app/src/main/java/com/kunzisoft/keepass/credentialprovider/passkey/data/PublicKeyCredentialCreationOptions.kt index e58e37a7d..66fa14152 100644 --- a/app/src/main/java/com/kunzisoft/keepass/credentialprovider/passkey/data/PublicKeyCredentialCreationOptions.kt +++ b/app/src/main/java/com/kunzisoft/keepass/credentialprovider/passkey/data/PublicKeyCredentialCreationOptions.kt @@ -1,17 +1,21 @@ /* - * Copyright 2023 The Android Open Source Project + * Copyright 2025 Jeremy Jamet / Kunzisoft. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * This file is part of KeePassDX. * - * http://www.apache.org/licenses/LICENSE-2.0 + * KeePassDX is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KeePassDX is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KeePassDX. If not, see . * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. */ package com.kunzisoft.keepass.credentialprovider.passkey.data @@ -19,7 +23,10 @@ import android.util.Log import com.kunzisoft.keepass.credentialprovider.passkey.util.Base64Helper import org.json.JSONObject -class PublicKeyCredentialCreationOptions(requestJson: String) { +class PublicKeyCredentialCreationOptions( + requestJson: String, + var clientDataHash: ByteArray? +) { val json: JSONObject = JSONObject(requestJson) val relyingPartyEntity: PublicKeyCredentialRpEntity @@ -60,13 +67,17 @@ class PublicKeyCredentialCreationOptions(requestJson: String) { authenticatorSelection = AuthenticatorSelectionCriteria("platform", "required") attestation = json.optString("attestation", "none") - Log.i("WebAuthn", "Challenge $challenge()") - Log.i("WebAuthn", "rp $relyingPartyEntity") - Log.i("WebAuthn", "user $userEntity") - Log.i("WebAuthn", "pubKeyCredParams $pubKeyCredParams") - Log.i("WebAuthn", "timeout $timeout") - Log.i("WebAuthn", "excludeCredentials $excludeCredentials") - Log.i("WebAuthn", "authenticatorSelection $authenticatorSelection") - Log.i("WebAuthn", "attestation $attestation") + Log.i(TAG, "challenge $challenge()") + Log.i(TAG, "rp $relyingPartyEntity") + Log.i(TAG, "user $userEntity") + Log.i(TAG, "pubKeyCredParams $pubKeyCredParams") + Log.i(TAG, "timeout $timeout") + Log.i(TAG, "excludeCredentials $excludeCredentials") + Log.i(TAG, "authenticatorSelection $authenticatorSelection") + Log.i(TAG, "attestation $attestation") + } + + companion object { + private val TAG = PublicKeyCredentialCreationOptions::class.simpleName } } diff --git a/app/src/main/java/com/kunzisoft/keepass/credentialprovider/passkey/util/OriginManager.kt b/app/src/main/java/com/kunzisoft/keepass/credentialprovider/passkey/util/OriginManager.kt index e743f9eac..65dcb7414 100644 --- a/app/src/main/java/com/kunzisoft/keepass/credentialprovider/passkey/util/OriginManager.kt +++ b/app/src/main/java/com/kunzisoft/keepass/credentialprovider/passkey/util/OriginManager.kt @@ -43,24 +43,12 @@ class OriginManager( webOrigin = callingAppInfo?.getOrigin(privilegedAllowlist)?.removeSuffix("/") } - private fun isPrivilegedApp(): Boolean { - return webOrigin != null - && webOrigin == (DEFAULT_PROTOCOL + relyingParty) - } - // TODO isPrivileged app fun checkPrivilegedApp( clientDataHash: ByteArray? ) { - val isPrivilegedApp = isPrivilegedApp() && clientDataHash != null - Log.d(TAG, "isPrivilegedApp = $isPrivilegedApp") - if (!isPrivilegedApp) { - AppRelyingPartyRelation.isRelationValid(relyingParty, apkSigningCertificate) - } - } - - fun checkPrivilegedApp() { - val isPrivilegedApp = isPrivilegedApp() + val isPrivilegedApp = webOrigin != null + && webOrigin == (DEFAULT_PROTOCOL + relyingParty) && clientDataHash != null Log.d(TAG, "isPrivilegedApp = $isPrivilegedApp") if (!isPrivilegedApp) { AppRelyingPartyRelation.isRelationValid(relyingParty, apkSigningCertificate) diff --git a/app/src/main/java/com/kunzisoft/keepass/credentialprovider/passkey/util/PasskeyHelper.kt b/app/src/main/java/com/kunzisoft/keepass/credentialprovider/passkey/util/PasskeyHelper.kt index fa3ea0ce1..a26a59738 100644 --- a/app/src/main/java/com/kunzisoft/keepass/credentialprovider/passkey/util/PasskeyHelper.kt +++ b/app/src/main/java/com/kunzisoft/keepass/credentialprovider/passkey/util/PasskeyHelper.kt @@ -222,8 +222,10 @@ object PasskeyHelper { if (request.callingRequest !is CreatePublicKeyCredentialRequest) { throw CreateCredentialUnknownException("callingRequest is of wrong type: ${request.callingRequest.type}") } + val createPublicKeyCredentialRequest = request.callingRequest as CreatePublicKeyCredentialRequest return PublicKeyCredentialCreationOptions( - (request.callingRequest as CreatePublicKeyCredentialRequest).requestJson + requestJson = createPublicKeyCredentialRequest.requestJson, + clientDataHash = createPublicKeyCredentialRequest.clientDataHash ) } @@ -255,9 +257,10 @@ object PasskeyHelper { val username = creationOptions.userEntity.name val userHandle = creationOptions.userEntity.id val pubKeyCredParams = creationOptions.pubKeyCredParams + val clientDataHash = creationOptions.clientDataHash val originManager = OriginManager(callingAppInfo, assetManager, relyingParty) - originManager.checkPrivilegedApp() + originManager.checkPrivilegedApp(clientDataHash) val credentialId = KeePassDXRandom.generateCredentialId() @@ -280,12 +283,16 @@ object PasskeyHelper { publicKeyCredentialCreationOptions = creationOptions, credentialId = credentialId, signatureKey = Pair(keyPair, keyTypeId), - clientDataResponse = ClientDataNotDefinedResponse( - type = ClientDataNotDefinedResponse.Type.CREATE, - challenge = creationOptions.challenge, - origin = originManager.origin, - packageName = packageName - ) + clientDataResponse = clientDataHash?.let { + ClientDataDefinedResponse(clientDataHash) + } ?: run { + ClientDataNotDefinedResponse( + type = ClientDataNotDefinedResponse.Type.CREATE, + challenge = creationOptions.challenge, + origin = originManager.origin, + packageName = packageName + ) + } ) ) }