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 1 commit
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
Prev Previous commit
Next Next commit
[api] crypto test
  • Loading branch information
StageGuard committed Apr 13, 2023
commit b5fd8ac8c9ed6267a2f10f25e462abf13a90a8f4
41 changes: 41 additions & 0 deletions mirai-core/src/commonTest/kotlin/utils/crypto/AESTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2019-2023 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/

package net.mamoe.mirai.internal.utils.crypto

import net.mamoe.mirai.utils.currentTimeMillis
import net.mamoe.mirai.utils.getRandomString
import net.mamoe.mirai.utils.toUHexString
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertEquals

internal class AESTest {
@Test
fun `can aes crypto works`() {
val random = Random(currentTimeMillis())
repeat(5) {
val key = getRandomString(16, random).encodeToByteArray()
val iv = getRandomString(16, random).encodeToByteArray()
val currentTime = currentTimeMillis()

val plainText = buildString {
append("Use of this source code is governed by the GNU AGPLv3 license ")
append("that can be found through the following link. ")
append(currentTime)
}

println("AES crypto test #${it + 1}: key = ${key.toUHexString()}, iv = ${iv.toUHexString()}, currentTimeMillis = $currentTime")
StageGuard marked this conversation as resolved.
Show resolved Hide resolved
val encrypted = aesEncrypt(plainText.encodeToByteArray(), iv, key)
val decrypted = aesDecrypt(encrypted, iv, key)

assertEquals(plainText, decrypted.decodeToString())
}
}
}
109 changes: 109 additions & 0 deletions mirai-core/src/commonTest/kotlin/utils/crypto/RSATest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright 2019-2023 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/

package net.mamoe.mirai.internal.utils.crypto

import net.mamoe.mirai.utils.currentTimeMillis
import net.mamoe.mirai.utils.toUHexString
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertEquals

class RSATest {
@Test
fun `can gen rsa key pair`() {
val rsaKeyPair = generateRSAKeyPair(2048)
println(rsaKeyPair.pubPemKey.decodeToString())
println(rsaKeyPair.privPemKey.decodeToString())
}

@Test
fun `can do crypto with generated key`() {

val random = Random(currentTimeMillis())
StageGuard marked this conversation as resolved.
Show resolved Hide resolved
repeat(5) {
StageGuard marked this conversation as resolved.
Show resolved Hide resolved
val keyPair = generateRSAKeyPair(2048)
val currentTime = currentTimeMillis()

val plainText = buildString {
append("Use of this source code is governed by the GNU AGPLv3 license ")
append(currentTime)
}

println(
"RSA crypto test #${it + 1}: pubKey = ${keyPair.pubPemKey.decodeToString()}, " +
StageGuard marked this conversation as resolved.
Show resolved Hide resolved
"privKey = ${keyPair.privPemKey.decodeToString()}, currentTimeMillis = $currentTime"
)
val enc =
rsaEncryptWithX509PubKey(plainText.encodeToByteArray(), keyPair.pubPemKey, random.nextLong(currentTime))
println("rsa encrypt: data=${enc.toUHexString()}")
val decrypted = rsaDecryptWithPKCS8PrivKey(enc, keyPair.privPemKey, random.nextLong(currentTime))
println("rsa decrypt: data=${decrypted.toUHexString()}")

assertEquals(plainText, decrypted.decodeToString())
}
}

@Test
fun `can do crypto with specific key`() {
val pubKey = """
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAr0KIpsWPW2JA7ShJI18o
wPv3Ip3Y6a0OkJOozfVlQDOjjUG6niDcrPIm+OpL7pCAzwc+h8d9sFH5c/7/bY4i
wKK6CpSaOYgQQ03P31KhzmXGJ4LVSxUIV0bhuDYQr+sU5Gu97onF8Ko8MELtWTPw
KP1dfqZ3PrK8QBH6su0GlB8onYFtzDUckr2wCrrJ1cR4L1Dg5f2egE75l1cliAIM
4FH1WFU2musfdEuCo5oPgl8ZPPLrQwp8qm9w7xBvbgbmfPTjPBC0N4gcelVzvdfC
eU8vpIlLP/9W5nkdqF6CWzjE3dIx2btOH4QDDyogDSLRAvcKN5/1EIZeu2FTbw9k
3QIDAQAB
-----END PUBLIC KEY-----
""".trimIndent().encodeToByteArray()

val privKey = """
-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCvQoimxY9bYkDt
KEkjXyjA+/cindjprQ6Qk6jN9WVAM6ONQbqeINys8ib46kvukIDPBz6Hx32wUflz
/v9tjiLAoroKlJo5iBBDTc/fUqHOZcYngtVLFQhXRuG4NhCv6xTka73uicXwqjww
Qu1ZM/Ao/V1+pnc+srxAEfqy7QaUHyidgW3MNRySvbAKusnVxHgvUODl/Z6ATvmX
VyWIAgzgUfVYVTaa6x90S4Kjmg+CXxk88utDCnyqb3DvEG9uBuZ89OM8ELQ3iBx6
VXO918J5Ty+kiUs//1bmeR2oXoJbOMTd0jHZu04fhAMPKiANItEC9wo3n/UQhl67
YVNvD2TdAgMBAAECggEAExREqRcfvJyNIeQ9Vg7xclTbuhaB+ypeSAnzGfzJeXxF
pUaPCNDeBSvVZ0qmWoG7rA4HViO3AJ9j7ydG6kfLa7orU6SKx5GS56jMZOzrdXsp
37pD+wj+n/W08+da2LPYUeeSxSmVdVYq+DwI96mKTwQKDhQULiyqBrWOW7Um/q/Z
JC8kJWKEmlNideDQHJxZViRyOdKvJtiwvoBLe1Jvbx7oMbpZnf20gV8C7UU7U38R
e0BKT6HBUHXuOOp2tFFpX6dySkJqW7Jijv04B/KnDYaSWD8TtaQfPfAhkiEVA17E
Ret04PnPMiYCkSVakO0MEeFpwb01vPca4Z64zgf7EQKBgQDyU6wsO3v8L1OlV7tx
7+T0PuOqeo7MWESSn18LeyOP2Y+fDtHKMUFULeYH1UZaGsZJvW+P+c8Mvyitbcvv
SZPTR0Dg+1HueXWkNTejs8Z2BKpPmIPaVLz5FxhV7hV2hKgII/yhyRoiWrTiawLg
ocOnYSostg+tt6kT8U2QPKhg9QKBgQC5Jho1nZ3pFPVu2rV/o9VvN7bGfn1M2o8k
9PQjLZQYiXJvPP0tNlvAOHk9cAqYecHJ3wDVacZWmLicU8xmNSFmmN6Vs9jj6km4
CWq0/wuTUO/fiH+oHZb6+JM63RXbASWyNK+WwmZtDryNBGRB5zbeCAK8tFsRCJDw
19WQUzljSQKBgCWKkuzTVlTuXA4MdmyjVpwENi8OB5tevVjdudLEg/DgKqDgod2q
Hc3VwoJKJzkEVt3LrEHo2IvH/ZxIm0R56J3dtw5jwQCp7nC/EdyZmFBmTqBAJ4Um
hZQtYMbHOKoAySthr9y8lADofodpPqvgQ7hllCwTFIC8KER/qJ2E2C0VAoGATLUM
hsoWckrMpHDYYVlvQ/TBNNuS7hRe2eDihPCNOt03G/8YpXKv8KN1F48j1KgdMZXC
sqhwE9CSK7JMLMw2WltbXIp2gXa/tA+yteo00YPm3aWfvfcEZlY2KV0PgPyosXxC
gyNnbCd+1q3LG8K/aJ3JBIV0dUonQqEpSfIxBIECgYArO3Iw+LvoePjq4yHheyEM
rz6d6RB+i1Q7ExBK7lbZxN17HmKiOewwI772zEo28IY9sIHugV7rW1vQVs3bnzgk
ExDGjYWZSKHfs+3mvrLNRIx/IsVqqwlXt5oO9TspSh68ASvmXN51dmduxRrSuScq
8a49uOr675SyFCJTIdF/Ag==
-----END PRIVATE KEY-----
""".trimIndent().encodeToByteArray()

val plainText = buildString {
append("Use of this source code is governed by the GNU AGPLv3 license ")
append("that can be found through the following link. ")
}

val enc = rsaEncryptWithX509PubKey(plainText.encodeToByteArray(), pubKey, 0)
val dec = rsaDecryptWithPKCS8PrivKey(enc, privKey, 0)

assertEquals(plainText, dec.decodeToString())

}
}