perf(keygen): replace Gaussian RTT normalization with 15ms floor fence
The old Gaussian sleep (mean=55ms, stddev=12ms) triggered detection on Chunqiu Native Check 2.8. A flat 15ms floor satisfies the minimum RTT threshold without creating a detectable delay pattern — both attested and non-attested paths get identical treatment, keeping the D50 ratio at ~1.0 while staying above the >=15ms requirement.
This commit is contained in:
+2
-10
@@ -350,7 +350,7 @@ class KeyMintSecurityLevelInterceptor(
|
|||||||
)
|
)
|
||||||
|
|
||||||
val elapsedMs = (System.nanoTime() - startNs) / 1_000_000
|
val elapsedMs = (System.nanoTime() - startNs) / 1_000_000
|
||||||
val delayMs = sampleTeeLatencyMs() - elapsedMs
|
val delayMs = TEE_LATENCY_FLOOR_MS - elapsedMs
|
||||||
if (delayMs > 0) Thread.sleep(delayMs)
|
if (delayMs > 0) Thread.sleep(delayMs)
|
||||||
|
|
||||||
return InterceptorUtils.createTypedObjectReply(response.metadata)
|
return InterceptorUtils.createTypedObjectReply(response.metadata)
|
||||||
@@ -541,15 +541,12 @@ class KeyMintSecurityLevelInterceptor(
|
|||||||
private const val MAX_ALIAS_LENGTH = 256 * 1024
|
private const val MAX_ALIAS_LENGTH = 256 * 1024
|
||||||
private const val KEYMINT_INVALID_INPUT_LENGTH = -21
|
private const val KEYMINT_INVALID_INPUT_LENGTH = -21
|
||||||
private const val RESPONSE_INVALID_ARGUMENT = 20
|
private const val RESPONSE_INVALID_ARGUMENT = 20
|
||||||
|
private const val TEE_LATENCY_FLOOR_MS = 15L
|
||||||
private const val KEYMINT_CANNOT_ATTEST_IDS = -66
|
private const val KEYMINT_CANNOT_ATTEST_IDS = -66
|
||||||
private const val MAX_CONCURRENT_HW_KEYGEN_PER_UID = 2
|
private const val MAX_CONCURRENT_HW_KEYGEN_PER_UID = 2
|
||||||
// Sliding window: max hardware keygen permits per UID within the burst window
|
// Sliding window: max hardware keygen permits per UID within the burst window
|
||||||
private const val MAX_HW_KEYGEN_PER_WINDOW = 2
|
private const val MAX_HW_KEYGEN_PER_WINDOW = 2
|
||||||
private const val BURST_WINDOW_MS = 30_000L
|
private const val BURST_WINDOW_MS = 30_000L
|
||||||
private const val TEE_LATENCY_MEAN_MS = 55.0
|
|
||||||
private const val TEE_LATENCY_STDDEV_MS = 12.0
|
|
||||||
private const val TEE_LATENCY_FLOOR_MS = 15L
|
|
||||||
|
|
||||||
private val uidHardwareKeygenCount = ConcurrentHashMap<Int, AtomicInteger>()
|
private val uidHardwareKeygenCount = ConcurrentHashMap<Int, AtomicInteger>()
|
||||||
private val hardwareKeygenTxIds = ConcurrentHashMap.newKeySet<Long>()
|
private val hardwareKeygenTxIds = ConcurrentHashMap.newKeySet<Long>()
|
||||||
private val uidKeygenTimestamps = ConcurrentHashMap<Int, MutableList<Long>>()
|
private val uidKeygenTimestamps = ConcurrentHashMap<Int, MutableList<Long>>()
|
||||||
@@ -577,11 +574,6 @@ class KeyMintSecurityLevelInterceptor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sampleTeeLatencyMs(): Long {
|
|
||||||
val sample = TEE_LATENCY_MEAN_MS + secureRandom.nextGaussian() * TEE_LATENCY_STDDEV_MS
|
|
||||||
return sample.toLong().coerceAtLeast(TEE_LATENCY_FLOOR_MS)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val GENERATE_KEY_TRANSACTION =
|
private val GENERATE_KEY_TRANSACTION =
|
||||||
InterceptorUtils.getTransactCode(IKeystoreSecurityLevel.Stub::class.java, "generateKey")
|
InterceptorUtils.getTransactCode(IKeystoreSecurityLevel.Stub::class.java, "generateKey")
|
||||||
private val IMPORT_KEY_TRANSACTION =
|
private val IMPORT_KEY_TRANSACTION =
|
||||||
|
|||||||
Reference in New Issue
Block a user