mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-03 15:22:27 -08:00
fix: Cleartext PRF output #2813
This commit is contained in:
4 files changed
+39
-22
No files matched your search
+11
-10
@@ -38,19 +38,20 @@ class AuthenticatorAssertionResponse(
|
||||
) : AuthenticatorExtensionResponse {
|
||||
|
||||
override var clientJson = JSONObject()
|
||||
private var authenticatorData: ByteArray = AuthenticatorData.buildAuthenticatorData(
|
||||
relyingPartyId = requestOptions.rpId.toByteArray(),
|
||||
userPresent = userPresent,
|
||||
userVerified = userVerified,
|
||||
backupEligibility = backupEligibility,
|
||||
backupState = backupState,
|
||||
extensionsPresent = clientExtensionResults?.prf != null
|
||||
).let {
|
||||
private var authenticatorData: ByteArray = run {
|
||||
val prfAuthData = clientExtensionResults?.toAuthDataCbor(isRegistration = false)
|
||||
val authData = AuthenticatorData.buildAuthenticatorData(
|
||||
relyingPartyId = requestOptions.rpId.toByteArray(),
|
||||
userPresent = userPresent,
|
||||
userVerified = userVerified,
|
||||
backupEligibility = backupEligibility,
|
||||
backupState = backupState,
|
||||
extensionsPresent = prfAuthData != null
|
||||
)
|
||||
if (prfAuthData != null) {
|
||||
it + Cbor().encode(prfAuthData)
|
||||
authData + Cbor().encode(prfAuthData)
|
||||
} else {
|
||||
it
|
||||
authData
|
||||
}
|
||||
}
|
||||
private var signature: ByteArray = byteArrayOf()
|
||||
|
||||
+2
-2
@@ -47,6 +47,7 @@ class AuthenticatorAttestationResponse(
|
||||
}
|
||||
|
||||
private fun buildAuthData(): ByteArray {
|
||||
val prfAuthData = clientExtensionResults?.toAuthDataCbor(isRegistration = true)
|
||||
val authData = AuthenticatorData.buildAuthenticatorData(
|
||||
relyingPartyId = requestOptions.relyingPartyEntity.id.toByteArray(),
|
||||
userPresent = userPresent,
|
||||
@@ -54,13 +55,12 @@ class AuthenticatorAttestationResponse(
|
||||
backupEligibility = backupEligibility,
|
||||
backupState = backupState,
|
||||
attestedCredentialData = true,
|
||||
extensionsPresent = clientExtensionResults?.prf != null
|
||||
extensionsPresent = prfAuthData != null
|
||||
) + AAGUID +
|
||||
//credIdLen
|
||||
byteArrayOf((credentialId.size shr 8).toByte(), credentialId.size.toByte()) +
|
||||
credentialId +
|
||||
credentialPublicKey
|
||||
val prfAuthData = clientExtensionResults?.toAuthDataCbor(isRegistration = true)
|
||||
return if (prfAuthData != null) {
|
||||
authData + Cbor().encode(prfAuthData)
|
||||
} else {
|
||||
|
||||
+2
-10
@@ -254,13 +254,6 @@ data class AuthenticationExtensionsPRFValues(
|
||||
return json
|
||||
}
|
||||
|
||||
fun toAuthDataCbor(): Map<Int, Any> {
|
||||
val map = mutableMapOf<Int, Any>()
|
||||
map[1] = first
|
||||
second?.let { map[2] = it }
|
||||
return map
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val FIRST = "first"
|
||||
private const val SECOND = "second"
|
||||
@@ -341,9 +334,6 @@ data class AuthenticationExtensionsPRFOutputs(
|
||||
|
||||
fun toAuthDataCbor(isRegistration: Boolean): Map<Int, Any> {
|
||||
val map = mutableMapOf<Int, Any>()
|
||||
results?.let {
|
||||
map[2] = it.toAuthDataCbor() // results
|
||||
}
|
||||
if (isRegistration) {
|
||||
map[1] = true // enabled
|
||||
} else if (results == null) {
|
||||
@@ -369,6 +359,8 @@ data class AuthenticationExtensionsClientOutputs(
|
||||
|
||||
fun toAuthDataCbor(isRegistration: Boolean): Map<String, Any>? {
|
||||
val prfAuthData = prf?.toAuthDataCbor(isRegistration) ?: return null
|
||||
if (prfAuthData.isEmpty())
|
||||
return null
|
||||
val map = mutableMapOf<String, Any>()
|
||||
map[PRF] = prfAuthData
|
||||
return map
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package com.kunzisoft.keepass.credentialprovider.passkey
|
||||
|
||||
import com.kunzisoft.encrypt.HashManager
|
||||
import com.kunzisoft.keepass.credentialprovider.passkey.data.AuthenticationExtensionsClientOutputs
|
||||
import com.kunzisoft.keepass.credentialprovider.passkey.data.AuthenticationExtensionsPRFOutputs
|
||||
import com.kunzisoft.keepass.credentialprovider.passkey.data.AuthenticationExtensionsPRFValues
|
||||
import com.kunzisoft.keepass.credentialprovider.passkey.util.PasskeyHelper
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
import java.util.Base64
|
||||
|
||||
@@ -87,4 +93,22 @@ class PrfTestVectors {
|
||||
|
||||
assertArrayEquals("Registration PRF output should match SHA-256(IKM || 0x01)", expectedRegistrationResult, actualResult)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCleartextPrf() {
|
||||
val prfValues = AuthenticationExtensionsPRFValues(
|
||||
first = hex("f54746b8cf04bf43e873c262d4bc213d53879a6db62f7eae8dd691a3f7ba3026")
|
||||
)
|
||||
val prfOutputs = AuthenticationExtensionsPRFOutputs(results = prfValues)
|
||||
val clientOutputs = AuthenticationExtensionsClientOutputs(prf = prfOutputs)
|
||||
|
||||
// For assertion (isRegistration = false): authData CBOR MUST NOT contain PRF results
|
||||
val authDataCborAssertion = clientOutputs.toAuthDataCbor(isRegistration = false)
|
||||
assertNull("Authenticator extension outputs MUST NOT contain cleartext PRF outputs during assertion", authDataCborAssertion)
|
||||
|
||||
// For registration (isRegistration = true): authData CBOR contains enabled flag only
|
||||
val authDataCborRegistration = clientOutputs.toAuthDataCbor(isRegistration = true)
|
||||
assertNotNull("Registration authData CBOR should be present", authDataCborRegistration)
|
||||
assertEquals(mapOf("prf" to mapOf(1 to true)), authDataCborRegistration)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user