diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/EncryptMethod.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/EncryptMethod.kt index 7684a8a4c..80d0d6141 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/EncryptMethod.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/EncryptMethod.kt @@ -19,9 +19,6 @@ import net.mamoe.mirai.utils.cryptor.ECDHKeyPair import net.mamoe.mirai.utils.io.encryptAndWrite import net.mamoe.mirai.utils.io.writeShortLVByteArray -/** - * Encryption method to be used for packet body. - */ @UseExperimental(ExperimentalUnsignedTypes::class) internal interface EncryptMethod { val id: Int @@ -34,16 +31,6 @@ internal interface EncryptMethodSessionKey : EncryptMethod { val currentLoginState: Int val sessionKey: ByteArray - /** - * buildPacket{ - * byte 1 - * byte if (currentLoginState == 2) 3 else 2 - * fully key - * short 258 - * short 0 - * fully encrypted - * } - */ override fun makeBody(client: QQAndroidClient, body: BytePacketBuilder.() -> Unit): ByteReadPacket = buildPacket { require(currentLoginState == 2 || currentLoginState == 3) { "currentLoginState must be either 2 or 3" } @@ -87,16 +74,6 @@ internal interface EncryptMethodECDH : EncryptMethod { val ecdh: ECDH - /** - * **Packet Structure** - * byte 1 - * byte 1 - * byte[] [ECDH.privateKey] - * short 258 - * short [ECDH.publicKey].size - * byte[] [ECDH.publicKey] - * byte[] encrypted `body()` by [ECDH.shareKey] - */ override fun makeBody(client: QQAndroidClient, body: BytePacketBuilder.() -> Unit): ByteReadPacket = buildPacket { writeByte(1) // const @@ -104,19 +81,14 @@ internal interface EncryptMethodECDH : EncryptMethod { writeFully(client.randomKey) writeShort(258) // const - // writeShortLVByteArray("04 CB 36 66 98 56 1E 93 6E 80 C1 57 E0 74 CA B1 3B 0B B6 8D DE B2 82 45 48 A1 B1 8D D4 FB 61 22 AF E1 2F E4 8C 52 66 D8 D7 26 9D 76 51 A8 EB 6F E7".hexToBytes()) - if (ecdh.keyPair === ECDHKeyPair.DefaultStub) { writeShortLVByteArray(ECDHKeyPair.DefaultStub.defaultPublicKey) encryptAndWrite(ECDHKeyPair.DefaultStub.defaultShareKey, body) } else { writeShortLVByteArray(ecdh.keyPair.publicKey.getEncoded().drop(23).take(49).toByteArray().also { - // it.toUHexString().debugPrint("PUBLIC KEY") check(it[0].toInt() == 0x04) { "Bad publicKey generated. Expected first element=0x04, got${it[0]}" } - //check(ecdh.calculateShareKeyByPeerPublicKey(it.adjustToPublicKey()).contentEquals(ecdh.keyPair.shareKey)) { "PublicKey Validation failed" } }) - // encryptAndWrite("26 33 BA EC 86 EB 79 E6 BC E0 20 06 5E A9 56 6C".hexToBytes(), body) encryptAndWrite(ecdh.keyPair.initialShareKey, body) } }