feat(desktop): 支持粘贴配对并修复串流与设备切换
- 支持 Ctrl+V 粘贴配对文本和二维码图片,预览确认后识别校验 - 修复控制发送阻塞、TLS 读写争锁、设备切换沿用旧连接及串流误关窗 - 优化媒体加密上下文、UDP 接收缓冲和异步诊断日志 - 安装器按路径停止主控与信令进程,统一递增版本、打包和清理旧产物 - 发布 0.1.3+4,通过三端编译、20 项 Flutter 测试和 58 项 Rust 单元测试
This commit is contained in:
1 parent
f6b7730684
commit
3cd72d70e1
38 files changed
+1173
-196
No files matched your search
+7
@@ -27,6 +27,13 @@ class MediaProtocolInstrumentation : Instrumentation() {
|
||||
check(packet.size == payload.size + MediaPackets.OVERHEAD)
|
||||
check(decrypt(packet, key).contentEquals(payload))
|
||||
check(!MediaPackets.encode(payload, 42, 1, key).contentEquals(packet))
|
||||
// Exercise cached Cipher reinitialization and alternating audio/video keys.
|
||||
val otherKey = ByteArray(32) { (it + 1).toByte() }
|
||||
repeat(200) { index ->
|
||||
val activeKey = if (index % 2 == 0) key else otherKey
|
||||
val encoded = MediaPackets.encode(payload, index.toLong(), 1, activeKey)
|
||||
check(decrypt(encoded, activeKey).contentEquals(payload))
|
||||
}
|
||||
val tampered = packet.clone().apply { this[lastIndex] = (this[lastIndex].toInt() xor 1).toByte() }
|
||||
check(runCatching { decrypt(tampered,key) }.isFailure)
|
||||
check(runCatching { decrypt(packet,ByteArray(32)) }.isFailure)
|
||||
|
||||
+18
-4
@@ -28,6 +28,15 @@ object MediaPackets {
|
||||
const val FRAGMENT_PAYLOAD_SIZE = 1152
|
||||
private const val HEADER_SIZE = 37
|
||||
|
||||
// 视频与音频各在线程内复用密码上下文;每个包仍使用全局唯一 nonce。
|
||||
// 避免每个 1152 字节分片都执行 HKDF 和 JCA provider 查找。
|
||||
private class Encoder {
|
||||
var sessionKey: ByteArray? = null
|
||||
var packetKey: SecretKeySpec? = null
|
||||
val cipher: Cipher = Cipher.getInstance("AES/GCM/NoPadding")
|
||||
}
|
||||
private val encoders = ThreadLocal.withInitial { Encoder() }
|
||||
|
||||
fun encode(payload: ByteArray, pts: Long, flags: Int, sessionKey: ByteArray,
|
||||
frameId: Long = nextFrameId(), fragmentIndex: Int = 0, fragmentCount: Int = 1): ByteArray {
|
||||
require(payload.size <= FRAGMENT_PAYLOAD_SIZE && fragmentCount in 1..8192 && fragmentIndex in 0 until fragmentCount && frameId > 0)
|
||||
@@ -47,10 +56,15 @@ object MediaPackets {
|
||||
put("and2".toByteArray(Charsets.US_ASCII)); putLong(sequence)
|
||||
}.array()
|
||||
// Domain separation from the outer relay-media AES-GCM key.
|
||||
val prk = hmac("ttstdconnect-v1".toByteArray(Charsets.UTF_8), sessionKey)
|
||||
val key = hmac(prk, "lancast/media/packet/v2".toByteArray(Charsets.UTF_8) + byteArrayOf(1))
|
||||
val cipher = Cipher.getInstance("AES/GCM/NoPadding").apply {
|
||||
init(Cipher.ENCRYPT_MODE, SecretKeySpec(key, "AES"), GCMParameterSpec(128, nonce))
|
||||
val encoder = encoders.get()!!
|
||||
if (encoder.sessionKey?.contentEquals(sessionKey) != true) {
|
||||
val prk = hmac("ttstdconnect-v1".toByteArray(Charsets.UTF_8), sessionKey)
|
||||
val key = hmac(prk, "lancast/media/packet/v2".toByteArray(Charsets.UTF_8) + byteArrayOf(1))
|
||||
encoder.packetKey = SecretKeySpec(key, "AES")
|
||||
encoder.sessionKey = sessionKey.copyOf()
|
||||
}
|
||||
val cipher = encoder.cipher.apply {
|
||||
init(Cipher.ENCRYPT_MODE, encoder.packetKey, GCMParameterSpec(128, nonce))
|
||||
updateAAD(header)
|
||||
}
|
||||
return header + nonce + cipher.doFinal(payload)
|
||||
|
||||
Reference in new issue
Block a user