Update to 8.4.18

This commit is contained in:
Him188 2020-12-16 21:56:20 +08:00
parent 0888cd3f5b
commit c478f24db0
7 changed files with 56 additions and 33 deletions

View File

@ -215,7 +215,7 @@ public open class BotConfiguration { // open for Java
/** /**
* Android 手机. * Android 手机.
*/ */
ANDROID_PHONE(537062845), ANDROID_PHONE(537066439),
/** /**
* Android 平板. * Android 平板.

View File

@ -29,7 +29,6 @@ import net.mamoe.mirai.internal.utils.cryptor.TEA
import net.mamoe.mirai.network.LoginFailedException import net.mamoe.mirai.network.LoginFailedException
import net.mamoe.mirai.network.NoServerAvailableException import net.mamoe.mirai.network.NoServerAvailableException
import net.mamoe.mirai.utils.* import net.mamoe.mirai.utils.*
import kotlin.jvm.Volatile
import kotlin.random.Random import kotlin.random.Random
internal val DeviceInfo.guid: ByteArray get() = generateGuid(androidId, macAddress) internal val DeviceInfo.guid: ByteArray get() = generateGuid(androidId, macAddress)
@ -158,8 +157,8 @@ internal open class QQAndroidClient(
var openAppId: Long = 715019303L var openAppId: Long = 715019303L
val apkVersionName: ByteArray get() = "8.4.8".toByteArray() val apkVersionName: ByteArray get() = "8.4.18".toByteArray()
val buildVer: String get() = "8.4.8.4810" // 8.2.0.1296 // 8.4.8.4810 // 8.2.7.4410 val buildVer: String get() = "8.4.18.4810" // 8.2.0.1296 // 8.4.8.4810 // 8.2.7.4410
private val messageSequenceId: AtomicInt = atomic(22911) private val messageSequenceId: AtomicInt = atomic(22911)
internal fun atomicNextMessageSequenceId(): Int = messageSequenceId.getAndAdd(2) internal fun atomicNextMessageSequenceId(): Int = messageSequenceId.getAndAdd(2)

View File

@ -59,7 +59,7 @@ internal class EncryptMethodECDH135(override val ecdh: ECDH) :
internal class EncryptMethodECDH7(override val ecdh: ECDH) : internal class EncryptMethodECDH7(override val ecdh: ECDH) :
EncryptMethodECDH { EncryptMethodECDH {
override val id: Int get() = 7 override val id: Int get() = 7 // 135
} }
internal interface EncryptMethodECDH : EncryptMethod { internal interface EncryptMethodECDH : EncryptMethod {
@ -73,18 +73,26 @@ internal interface EncryptMethodECDH : EncryptMethod {
val ecdh: ECDH val ecdh: ECDH
override fun makeBody(client: QQAndroidClient, body: BytePacketBuilder.() -> Unit): ByteReadPacket = override fun makeBody(client: QQAndroidClient, body: BytePacketBuilder.() -> Unit): ByteReadPacket = buildPacket {
buildPacket { /* //new curve p-256
writeByte(1) // const writeByte(2) // const
writeByte(1) // const writeByte(1) // const
writeFully(client.randomKey) writeFully(client.randomKey)
writeShort(258) // const writeShort(0x0131) // const
writeShort(0x0001)
*/
writeByte(1) // version
writeByte(1) // const
writeFully(client.randomKey)
writeShort(0x0102)
if (ecdh.keyPair === ECDHKeyPair.DefaultStub) { if (ecdh.keyPair === ECDHKeyPair.DefaultStub) {
writeShortLVByteArray(ECDHKeyPair.DefaultStub.defaultPublicKey) writeShortLVByteArray(ECDHKeyPair.DefaultStub.defaultPublicKey)
encryptAndWrite(ECDHKeyPair.DefaultStub.defaultShareKey, body) encryptAndWrite(ECDHKeyPair.DefaultStub.defaultShareKey, body)
} else { } else {
writeShortLVByteArray(ecdh.keyPair.publicKey.getEncoded().drop(23).take(49).toByteArray().also { // for p-256, drop(26). // but not really sure.
writeShortLVByteArray(ecdh.keyPair.publicKey.getEncoded().drop(23).toByteArray().also {
check(it[0].toInt() == 0x04) { "Bad publicKey generated. Expected first element=0x04, got${it[0]}" } check(it[0].toInt() == 0x04) { "Bad publicKey generated. Expected first element=0x04, got${it[0]}" }
}) })

View File

@ -103,7 +103,7 @@ internal fun BytePacketBuilder.t106(
encryptAndWrite(MiraiPlatformUtils.md5(passwordMd5 + ByteArray(4) + (salt.takeIf { it != 0L } ?: uin).toInt().toByteArray())) { encryptAndWrite(MiraiPlatformUtils.md5(passwordMd5 + ByteArray(4) + (salt.takeIf { it != 0L } ?: uin).toInt().toByteArray())) {
writeShort(4)//TGTGTVer writeShort(4)//TGTGTVer
writeInt(Random.nextInt()) writeInt(Random.nextInt())
writeInt(5)//ssoVer writeInt(13)//ssoVer
writeInt(appId.toInt()) writeInt(appId.toInt())
writeInt(appClientVersion) writeInt(appClientVersion)

View File

@ -160,7 +160,7 @@ internal class WtLogin {
*/ */
t116(client.miscBitMap, client.subSigMap) t116(client.miscBitMap, client.subSigMap)
t100(appId, client.subAppId, client.appClientVersion) t100(appId, client.subAppId, client.appClientVersion)
t107(0) t107(6)
// t108(byteArrayOf()) // t108(byteArrayOf())
// ignored: t104() // ignored: t104()
@ -312,6 +312,7 @@ internal class WtLogin {
discardExact(2) discardExact(2)
val tlvMap: TlvMap = this._readTLVMap() val tlvMap: TlvMap = this._readTLVMap()
// tlvMap.printTLVMap() // tlvMap.printTLVMap()
tlvMap[0x161]?.let { bot.client.analysisTlv161(it) }
return when (type.toInt()) { return when (type.toInt()) {
0 -> onLoginSuccess(tlvMap, bot) 0 -> onLoginSuccess(tlvMap, bot)
2 -> onSolveLoginCaptcha(tlvMap, bot) 2 -> onSolveLoginCaptcha(tlvMap, bot)

View File

@ -76,13 +76,24 @@ internal expect class ECDH(keyPair: ECDHKeyPair) {
@Suppress("FunctionName") @Suppress("FunctionName")
internal expect fun ECDH(): ECDH internal expect fun ECDH(): ECDH
// gen by p-256
//3059301306072A8648CE3D020106082A8648CE3D03010703420004FA540CB3F755D0A6572338777A4D0BEAFA86664D53040B27331CBF1B7F3C226CE8A1C05EFA9028F85510B103D8175172895C9F9FE4C80A47894BCA2BE569BFCB
//3059301306072A8648CE3D020106082A8648CE3D03010703420004949D41D7C14B92F0CB94B6232FB87BA51B0D5AB661FBAF95599A97472FFC4F50BC8CEC5865E79DB3782459A6E9A2298954CD198A25274CEEA8F925342D763D62
/*
// p-256
get() = ECDH.constructPublicKey(
("3059301306072A8648CE3D020106082A8648CE3D03010703420004" +
"EBCA94D733E399B2DB96EACDD3F69A8BB0F74224E2B44E3357812211D2E62EFB" +
"C91BB553098E25E33A799ADC7F76FEB208DA7C6522CDB0719A305180CC54A82E"
).chunkedHexToBytes()
)
* */
// this is for old curve
internal val initialPublicKey internal val initialPublicKey
get() = ECDH.constructPublicKey("3046301006072A8648CE3D020106052B8104001F03320004928D8850673088B343264E0C6BACB8496D697799F37211DEB25BB73906CB089FEA9639B4E0260498B51A992D50813DA8".chunkedHexToBytes()) get() = ECDH.constructPublicKey("3046301006072A8648CE3D020106052B8104001F03320004928D8850673088B343264E0C6BACB8496D697799F37211DEB25BB73906CB089FEA9639B4E0260498B51A992D50813DA8".chunkedHexToBytes())
private val commonHeadFor02 = "302E301006072A8648CE3D020106052B8104001F031A00".chunkedHexToBytes()
private val commonHeadForNot02 = "3046301006072A8648CE3D020106052B8104001F033200".chunkedHexToBytes()
private const val constantHead = "3046301006072A8648CE3D020106052B8104001F03320004"
private val byteArray_04 = byteArrayOf(0x04)
private val head1 = "302E301006072A8648CE3D020106052B8104001F031A00".chunkedHexToBytes() private val head1 = "302E301006072A8648CE3D020106052B8104001F031A00".chunkedHexToBytes()
private val head2 = "3046301006072A8648CE3D020106052B8104001F03320004".chunkedHexToBytes() private val head2 = "3046301006072A8648CE3D020106052B8104001F03320004".chunkedHexToBytes()

View File

@ -28,8 +28,7 @@ internal actual class ECDHKeyPairImpl(
override val privateKey: ECDHPrivateKey get() = delegate.private override val privateKey: ECDHPrivateKey get() = delegate.private
override val publicKey: ECDHPublicKey get() = delegate.public override val publicKey: ECDHPublicKey get() = delegate.public
override val initialShareKey: ByteArray = override val initialShareKey: ByteArray by lazy { ECDH.calculateShareKey(privateKey, initialPublicKey) }
ECDH.calculateShareKey(privateKey, initialPublicKey)
} }
@Suppress("FunctionName") @Suppress("FunctionName")
@ -38,6 +37,8 @@ internal actual fun ECDH() =
internal actual class ECDH actual constructor(actual val keyPair: ECDHKeyPair) { internal actual class ECDH actual constructor(actual val keyPair: ECDHKeyPair) {
actual companion object { actual companion object {
private const val curveName = "secp192k1" // p-256
actual val isECDHAvailable: Boolean actual val isECDHAvailable: Boolean
init { init {
@ -45,7 +46,7 @@ internal actual class ECDH actual constructor(actual val keyPair: ECDHKeyPair) {
fun testECDH() { fun testECDH() {
ECDHKeyPairImpl( ECDHKeyPairImpl(
KeyPairGenerator.getInstance("ECDH") KeyPairGenerator.getInstance("ECDH")
.also { it.initialize(ECGenParameterSpec("secp192k1")) } .also { it.initialize(ECGenParameterSpec(curveName)) }
.genKeyPair()).let { .genKeyPair()).let {
calculateShareKey(it.privateKey, it.publicKey) calculateShareKey(it.privateKey, it.publicKey)
} }
@ -60,6 +61,8 @@ internal actual class ECDH actual constructor(actual val keyPair: ECDHKeyPair) {
} }
Security.addProvider(BouncyCastleProvider()) Security.addProvider(BouncyCastleProvider())
testECDH() testECDH()
}.onFailure {
it.printStackTrace()
}.isSuccess }.isSuccess
} }
@ -67,8 +70,9 @@ internal actual class ECDH actual constructor(actual val keyPair: ECDHKeyPair) {
if (!isECDHAvailable) { if (!isECDHAvailable) {
return ECDHKeyPair.DefaultStub return ECDHKeyPair.DefaultStub
} }
return ECDHKeyPairImpl(KeyPairGenerator.getInstance("ECDH") return ECDHKeyPairImpl(
.also { it.initialize(ECGenParameterSpec("secp192k1")) } KeyPairGenerator.getInstance("ECDH")
.also { it.initialize(ECGenParameterSpec(curveName)) }
.genKeyPair()) .genKeyPair())
} }