Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] update login protocol #2613

Merged
merged 62 commits into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
81e9fea
[core] update protocol
Apr 8, 2023
d1846b4
[core] fix t106 decryption key
Apr 9, 2023
cdf88c7
[core] handle t543
Apr 9, 2023
3818438
[core] revert t106
Apr 9, 2023
d0ef92d
[core] revert native test pow data
Apr 9, 2023
ac7407e
[core] split build version and apk version name
Apr 9, 2023
7987473
[core] pass time to t1 instead of time diff
Apr 10, 2023
d52ddea
[core] remove unused t106 writer & rename param ip to ipv4 of t1 and …
Apr 10, 2023
39f13bc
[core] implement qimei for t545
Apr 10, 2023
434db6e
[core] fix base64 decode for android in rsa
Apr 11, 2023
e2440f3
[core] fix unix timestamp parsing on native and add more tests
Apr 11, 2023
61b7006
[api] DeviceInfo move `androidId` to main constructor and adjust test.
Apr 11, 2023
db8bbab
[api] do not request qimei when protocol is neither ANDROID_PHONE no…
Apr 11, 2023
ef2e980
[api] implement aes crypto for native target
Apr 11, 2023
388165e
[api] rsa crypto for multi-platform
Apr 13, 2023
b5fd8ac
[api] crypto test
Apr 13, 2023
2fd3e25
[api] move freePointer util
Apr 13, 2023
db7e931
[api] openssl api compatibility
Apr 13, 2023
a6b4fee
[core] add explicit `androidId` param
Apr 13, 2023
3cd9c0e
[core] remove unused `tlvCount`
Apr 13, 2023
153082f
[core] optimize crypto
Apr 13, 2023
a1d4dd7
[core] move Qimei to network package
Apr 13, 2023
79d34d7
[core] move appId to protocol
Apr 13, 2023
184932a
[core] lazily initialize qimeiLogger
Apr 13, 2023
e8f709c
[core] write byte array to BIO mem
Apr 13, 2023
54976ed
[core] move qimei to client, add direct serializer for DeviceInfo
Apr 14, 2023
0e368b3
[core] optimize DeviceInfoDelegateSerializer
Apr 14, 2023
1088054
[core] real user-agent when requesting qimei
Apr 14, 2023
804677f
[core] use `DeviceInfo.version.release`
Apr 15, 2023
ae06319
[core] remove unused wtlogin packet
Apr 15, 2023
749b8d8
[core] do what constructor serializer should do
Apr 15, 2023
de3c6ab
[core] fix endless cache validation caused by not upgrading device in…
Apr 15, 2023
6c5d2b8
[core] request qimei before fast-login
Apr 15, 2023
d0bfbbf
[core] tlv order
Apr 15, 2023
e81873b
[core] remove wrong tests and print more detail when deserialize failed.
Apr 15, 2023
dda3e89
[core] device info upgrade for native
Apr 15, 2023
b2fe32b
[core] request qimei after validating cache
Apr 15, 2023
96c53e4
Merge remote-tracking branch 'mamoe/dev' into dev
Apr 16, 2023
d0ad083
[core] DeviceInfo compatibility
Apr 16, 2023
5a3f459
[core] DeviceInfo test name
Apr 16, 2023
909767d
[core] compatibility serializer
Apr 16, 2023
ea7040f
Merge remote-tracking branch 'mamoe/dev' into protocol
May 4, 2023
128858e
[core] disable rsa crypto test on android unit test
May 5, 2023
209dfac
[core] move rsa impl to jvmBase
May 6, 2023
632e654
action
May 6, 2023
f862578
Merge branch 'dev' into dev
StageGuard May 6, 2023
0a43f8b
import
May 6, 2023
09f3250
api dump
May 6, 2023
436ff0f
api dump
May 6, 2023
5471a28
Merge branch 'dev' into dev
StageGuard May 6, 2023
c926c4d
revert wrong api dumps
May 7, 2023
1a163aa
[core] Deprecate DeviceInfo constructor and serializer, provide `seri…
Him188 May 8, 2023
86298a0
rerun ci
Him188 May 8, 2023
f090916
optimize
May 7, 2023
9cd9ef5
use serializer directly
May 8, 2023
6fc32ea
optimize test
May 8, 2023
4ee05ff
revert
May 8, 2023
c275dd1
[core] CacheValidator use `DeviceInfo.serializeToString()` instead of…
May 10, 2023
832267f
Remove `println` in `DeviceInfoManager`
Him188 May 20, 2023
89c3d1a
Add legacy deserialize overload for ABI compatibility
Him188 May 20, 2023
60a8537
Remove uncompleted docs for DeviceInfo
Him188 May 20, 2023
271a5e0
Suppress DeviceInfo deprecation warnings for internal usages
Him188 May 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5584,8 +5584,9 @@ public final class net/mamoe/mirai/utils/BotConfiguration$MiraiProtocol : java/l

public final class net/mamoe/mirai/utils/DeviceInfo {
public static final field Companion Lnet/mamoe/mirai/utils/DeviceInfo$Companion;
public synthetic fun <init> (I[B[B[B[B[B[B[B[B[B[B[BLnet/mamoe/mirai/utils/DeviceInfo$Version;[B[B[B[B[B[BLjava/lang/String;[BLkotlinx/serialization/internal/SerializationConstructorMarker;)V
public synthetic fun <init> (I[B[B[B[B[B[B[B[B[B[B[BLnet/mamoe/mirai/utils/DeviceInfo$Version;[B[B[B[B[B[BLjava/lang/String;[B[BLkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> ([B[B[B[B[B[B[B[B[B[B[BLnet/mamoe/mirai/utils/DeviceInfo$Version;[B[B[B[B[B[BLjava/lang/String;[B)V
public fun <init> ([B[B[B[B[B[B[B[B[B[B[BLnet/mamoe/mirai/utils/DeviceInfo$Version;[B[B[B[B[B[BLjava/lang/String;[B[B)V
public fun equals (Ljava/lang/Object;)Z
public static final fun from (Ljava/io/File;)Lnet/mamoe/mirai/utils/DeviceInfo;
public static final fun from (Ljava/io/File;Lkotlinx/serialization/json/Json;)Lnet/mamoe/mirai/utils/DeviceInfo;
Expand All @@ -5608,13 +5609,17 @@ public final class net/mamoe/mirai/utils/DeviceInfo {
public final fun getOsType ()[B
public final fun getProcVersion ()[B
public final fun getProduct ()[B
public final fun getQimei16 ()Ljava/lang/String;
public final fun getQimei36 ()Ljava/lang/String;
public final fun getSimInfo ()[B
public final fun getVersion ()Lnet/mamoe/mirai/utils/DeviceInfo$Version;
public final fun getWifiBSSID ()[B
public final fun getWifiSSID ()[B
public fun hashCode ()I
public static final fun random ()Lnet/mamoe/mirai/utils/DeviceInfo;
public static final fun random (Lkotlin/random/Random;)Lnet/mamoe/mirai/utils/DeviceInfo;
public final fun setQimei16 (Ljava/lang/String;)V
public final fun setQimei36 (Ljava/lang/String;)V
public static final fun write$Self (Lnet/mamoe/mirai/utils/DeviceInfo;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

Expand Down
7 changes: 6 additions & 1 deletion mirai-core-api/compatibility-validation/jvm/api/jvm.api
Original file line number Diff line number Diff line change
Expand Up @@ -5584,8 +5584,9 @@ public final class net/mamoe/mirai/utils/BotConfiguration$MiraiProtocol : java/l

public final class net/mamoe/mirai/utils/DeviceInfo {
public static final field Companion Lnet/mamoe/mirai/utils/DeviceInfo$Companion;
public synthetic fun <init> (I[B[B[B[B[B[B[B[B[B[B[BLnet/mamoe/mirai/utils/DeviceInfo$Version;[B[B[B[B[B[BLjava/lang/String;[BLkotlinx/serialization/internal/SerializationConstructorMarker;)V
public synthetic fun <init> (I[B[B[B[B[B[B[B[B[B[B[BLnet/mamoe/mirai/utils/DeviceInfo$Version;[B[B[B[B[B[BLjava/lang/String;[B[BLkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> ([B[B[B[B[B[B[B[B[B[B[BLnet/mamoe/mirai/utils/DeviceInfo$Version;[B[B[B[B[B[BLjava/lang/String;[B)V
public fun <init> ([B[B[B[B[B[B[B[B[B[B[BLnet/mamoe/mirai/utils/DeviceInfo$Version;[B[B[B[B[B[BLjava/lang/String;[B[B)V
public fun equals (Ljava/lang/Object;)Z
public static final fun from (Ljava/io/File;)Lnet/mamoe/mirai/utils/DeviceInfo;
public static final fun from (Ljava/io/File;Lkotlinx/serialization/json/Json;)Lnet/mamoe/mirai/utils/DeviceInfo;
Expand All @@ -5608,13 +5609,17 @@ public final class net/mamoe/mirai/utils/DeviceInfo {
public final fun getOsType ()[B
public final fun getProcVersion ()[B
public final fun getProduct ()[B
public final fun getQimei16 ()Ljava/lang/String;
public final fun getQimei36 ()Ljava/lang/String;
public final fun getSimInfo ()[B
public final fun getVersion ()Lnet/mamoe/mirai/utils/DeviceInfo$Version;
public final fun getWifiBSSID ()[B
public final fun getWifiSSID ()[B
public fun hashCode ()I
public static final fun random ()Lnet/mamoe/mirai/utils/DeviceInfo;
public static final fun random (Lkotlin/random/Random;)Lnet/mamoe/mirai/utils/DeviceInfo;
public final fun setQimei16 (Ljava/lang/String;)V
public final fun setQimei36 (Ljava/lang/String;)V
public static final fun write$Self (Lnet/mamoe/mirai/utils/DeviceInfo;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

Expand Down
128 changes: 117 additions & 11 deletions mirai-core-api/src/commonMain/kotlin/utils/DeviceInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,40 @@ public expect class DeviceInfo(
wifiSSID: ByteArray,
imsiMd5: ByteArray,
imei: String,
apn: ByteArray
apn: ByteArray,
androidId: ByteArray,
StageGuard marked this conversation as resolved.
Show resolved Hide resolved
) {
@Deprecated(
"This DeviceInfo constructor may randomize field `androidId` without your random instance. " +
"It is better to specify `androidId` explicitly.",
replaceWith = ReplaceWith(
"net.mamoe.mirai.utils.DeviceInfo(display, product, device, board, brand, model, " +
"bootloader, fingerprint, bootId, procVersion, baseBand, version, simInfo, osType, " +
"macAddress, wifiBSSID, wifiSSID, imsiMd5, imei, apn, )"
)
)
StageGuard marked this conversation as resolved.
Show resolved Hide resolved
public constructor(
display: ByteArray,
product: ByteArray,
device: ByteArray,
board: ByteArray,
brand: ByteArray,
model: ByteArray,
bootloader: ByteArray,
fingerprint: ByteArray,
bootId: ByteArray,
procVersion: ByteArray,
baseBand: ByteArray,
version: Version,
simInfo: ByteArray,
osType: ByteArray,
macAddress: ByteArray,
wifiBSSID: ByteArray,
wifiSSID: ByteArray,
imsiMd5: ByteArray,
imei: String,
apn: ByteArray,
)

public val display: ByteArray
public val product: ByteArray
Expand All @@ -69,14 +101,22 @@ public expect class DeviceInfo(
public val imsiMd5: ByteArray
public val imei: String
public val apn: ByteArray

public val androidId: ByteArray

public val ipAddress: ByteArray

@Transient
@MiraiInternalApi
public val guid: ByteArray

@Transient
@MiraiInternalApi
public var qimei16: String?

@Transient
@MiraiInternalApi
public var qimei36: String?


// @Serializable: use DeviceInfoVersionSerializer in commonMain.
public class Version(
Expand Down Expand Up @@ -160,7 +200,8 @@ internal object DeviceInfoCommonImpl {
wifiSSID = "<unknown ssid>".toByteArray(),
imsiMd5 = getRandomByteArray(16, random).md5(),
imei = "86${getRandomIntString(12, random)}".let { it + luhn(it) },
apn = "wifi".toByteArray()
apn = "wifi".toByteArray(),
androidId = getRandomByteArray(8, random).toUHexString("").lowercase().encodeToByteArray()
)

/**
Expand All @@ -187,6 +228,8 @@ internal object DeviceInfoCommonImpl {
if (deviceInfo === other) return true
if (!isSameType(this, other)) return false

// also remember to add equal compare to JvmDeviceInfoTest.`can read legacy v1`
// when adding new field compare here.
if (!display.contentEquals(other.display)) return false
if (!product.contentEquals(other.product)) return false
if (!device.contentEquals(other.device)) return false
Expand All @@ -208,6 +251,9 @@ internal object DeviceInfoCommonImpl {
if (imei != other.imei) return false
if (!apn.contentEquals(other.apn)) return false
if (!guid.contentEquals(other.guid)) return false
if (!androidId.contentEquals(other.androidId)) return false
if (qimei16 != other.qimei16) return false
if (qimei36 != other.qimei36) return false

return true
}
Expand Down Expand Up @@ -235,6 +281,9 @@ internal object DeviceInfoCommonImpl {
result = 31 * result + imei.hashCode()
result = 31 * result + apn.contentHashCode()
result = 31 * result + guid.contentHashCode()
result = 31 * result + androidId.contentHashCode()
result = 31 * result + qimei16.hashCode()
result = 31 * result + qimei36.hashCode()
return result
}
}
Expand Down Expand Up @@ -355,7 +404,8 @@ internal object DeviceInfoManager {
wifiSSID = wifiSSID,
imsiMd5 = imsiMd5,
imei = imei,
apn = apn
apn = apn,
androidId = getRandomByteArray(8).toUHexString("").lowercase().encodeToByteArray()
)
}
}
Expand Down Expand Up @@ -404,7 +454,58 @@ internal object DeviceInfoManager {
this.wifiSSID.toByteArray(),
this.imsiMd5.data,
this.imei,
this.apn.toByteArray()
this.apn.toByteArray(),
androidId = getRandomByteArray(8).toUHexString("").lowercase().encodeToByteArray()
)
}


@Serializable
class V3(
val display: String,
val product: String,
val device: String,
val board: String,
val brand: String,
val model: String,
val bootloader: String,
val fingerprint: String,
val bootId: String,
val procVersion: String,
val baseBand: HexString,
val version: Version,
val simInfo: String,
val osType: String,
val macAddress: String,
val wifiBSSID: String,
val wifiSSID: String,
val imsiMd5: HexString,
val imei: String,
val apn: String,
val androidId: String,
) : Info {
override fun toDeviceInfo(): DeviceInfo = DeviceInfo(
this.display.toByteArray(),
this.product.toByteArray(),
this.device.toByteArray(),
this.board.toByteArray(),
this.brand.toByteArray(),
this.model.toByteArray(),
this.bootloader.toByteArray(),
this.fingerprint.toByteArray(),
this.bootId.toByteArray(),
this.procVersion.toByteArray(),
this.baseBand.data,
this.version.trans(),
this.simInfo.toByteArray(),
this.osType.toByteArray(),
this.macAddress.toByteArray(),
this.wifiBSSID.toByteArray(),
this.wifiSSID.toByteArray(),
this.imsiMd5.data,
this.imei,
this.apn.toByteArray(),
this.androidId.toByteArray()
)
}

Expand All @@ -426,7 +527,7 @@ internal object DeviceInfoManager {
}
}

fun DeviceInfo.toCurrentInfo(): V2 = V2(
fun DeviceInfo.toCurrentInfo(): V3 = V3(
display.decodeToString(),
product.decodeToString(),
device.decodeToString(),
Expand All @@ -446,7 +547,8 @@ internal object DeviceInfoManager {
wifiSSID.decodeToString(),
HexString(imsiMd5),
imei,
apn.decodeToString()
apn.decodeToString(),
androidId.decodeToString(),
)

internal val format = Json {
Expand All @@ -467,21 +569,25 @@ internal object DeviceInfoManager {
* @since 2.9
*/
2 -> format.decodeFromJsonElement(Wrapper.serializer(V2.serializer()), element).data
/**
* @since 2.15
*/
3 -> format.decodeFromJsonElement(Wrapper.serializer(V3.serializer()), element).data
else -> throw IllegalArgumentException("Unsupported deviceInfoVersion: $version")
}.toDeviceInfo()
}

fun serialize(info: DeviceInfo, format: Json = this.format): String {
return format.encodeToString(
Wrapper.serializer(V2.serializer()),
Wrapper(2, info.toCurrentInfo())
Wrapper.serializer(V3.serializer()),
Wrapper(3, info.toCurrentInfo())
)
}

fun toJsonElement(info: DeviceInfo, format: Json = this.format): JsonElement {
return format.encodeToJsonElement(
Wrapper.serializer(V2.serializer()),
Wrapper(2, info.toCurrentInfo())
Wrapper.serializer(V3.serializer()),
Wrapper(3, info.toCurrentInfo())
)
}
}
Expand Down
StageGuard marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CommonDeviceInfoTest {
*/

val element = DeviceInfoManager.toJsonElement(device)
assertEquals(2, element.jsonObject["deviceInfoVersion"]!!.jsonPrimitive.content.toInt())
assertEquals(3, element.jsonObject["deviceInfoVersion"]!!.jsonPrimitive.content.toInt())

val imsiMd5 = element.jsonObject["data"]!!.jsonObject["imsiMd5"]!!.jsonPrimitive.content
assertEquals(
Expand Down
51 changes: 48 additions & 3 deletions mirai-core-api/src/jvmBaseMain/kotlin/utils/DeviceInfo.kt
Him188 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.io.File
import kotlin.random.Random

@Serializable
public actual class DeviceInfo actual constructor(
public actual class DeviceInfo public actual constructor(
public actual val display: ByteArray,
public actual val product: ByteArray,
public actual val device: ByteArray,
Expand All @@ -36,9 +36,46 @@ public actual class DeviceInfo actual constructor(
public actual val wifiSSID: ByteArray,
public actual val imsiMd5: ByteArray,
public actual val imei: String,
public actual val apn: ByteArray
public actual val apn: ByteArray,
public actual val androidId: ByteArray,
) {
public actual val androidId: ByteArray get() = display
@Deprecated(
"This DeviceInfo constructor may randomize field `androidId` without your random instance. " +
"It is better to specify `android` id explicitly.",
replaceWith = ReplaceWith(
"net.mamoe.mirai.utils.DeviceInfo(display, product, device, board, brand, model, " +
"bootloader, fingerprint, bootId, procVersion, baseBand, version, simInfo, osType, " +
"macAddress, wifiBSSID, wifiSSID, imsiMd5, imei, apn, )"
)
)
public actual constructor(
display: ByteArray,
product: ByteArray,
device: ByteArray,
board: ByteArray,
brand: ByteArray,
model: ByteArray,
bootloader: ByteArray,
fingerprint: ByteArray,
bootId: ByteArray,
procVersion: ByteArray,
baseBand: ByteArray,
version: Version,
simInfo: ByteArray,
osType: ByteArray,
macAddress: ByteArray,
wifiBSSID: ByteArray,
wifiSSID: ByteArray,
imsiMd5: ByteArray,
imei: String,
apn: ByteArray
) : this(
display, product, device, board, brand, model, bootloader,
fingerprint, bootId, procVersion, baseBand, version, simInfo,
osType, macAddress, wifiBSSID, wifiSSID, imsiMd5, imei, apn,
androidId = getRandomByteArray(8).toUHexString("").lowercase().encodeToByteArray()
StageGuard marked this conversation as resolved.
Show resolved Hide resolved
)

public actual val ipAddress: ByteArray get() = byteArrayOf(192.toByte(), 168.toByte(), 1, 123)

init {
Expand All @@ -49,6 +86,14 @@ public actual class DeviceInfo actual constructor(
@MiraiInternalApi
public actual val guid: ByteArray = generateGuid(androidId, macAddress)

@MiraiInternalApi
@Transient
public actual var qimei16: String? = null

@MiraiInternalApi
@Transient
public actual var qimei36: String? = null

StageGuard marked this conversation as resolved.
Show resolved Hide resolved
@Serializable
public actual class Version actual constructor(
public actual val incremental: ByteArray,
Expand Down
Loading