Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
4c79081b
Commit
4c79081b
authored
Jan 29, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhance c2s
parent
6d2d6bec
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
26 deletions
+20
-26
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/LoginPacket.kt
...ai/qqandroid/network/protocol/packet/login/LoginPacket.kt
+13
-16
mirai-core-qqandroid/src/jvmTest/kotlin/androidPacketTests/clientToServer.kt
...d/src/jvmTest/kotlin/androidPacketTests/clientToServer.kt
+5
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/cryptor/ECDH.kt
...c/commonMain/kotlin/net.mamoe.mirai/utils/cryptor/ECDH.kt
+2
-8
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/LoginPacket.kt
View file @
4c79081b
...
@@ -11,9 +11,12 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.*
...
@@ -11,9 +11,12 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.*
import
net.mamoe.mirai.qqandroid.utils.GuidSource
import
net.mamoe.mirai.qqandroid.utils.GuidSource
import
net.mamoe.mirai.qqandroid.utils.MacOrAndroidIdChangeFlag
import
net.mamoe.mirai.qqandroid.utils.MacOrAndroidIdChangeFlag
import
net.mamoe.mirai.qqandroid.utils.guidFlag
import
net.mamoe.mirai.qqandroid.utils.guidFlag
import
net.mamoe.mirai.utils.*
import
net.mamoe.mirai.utils.MiraiDebugAPI
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
net.mamoe.mirai.utils.cryptor.contentToString
import
net.mamoe.mirai.utils.cryptor.contentToString
import
net.mamoe.mirai.utils.cryptor.decryptBy
import
net.mamoe.mirai.utils.cryptor.decryptBy
import
net.mamoe.mirai.utils.currentTimeMillis
import
net.mamoe.mirai.utils.currentTimeSeconds
import
net.mamoe.mirai.utils.io.*
import
net.mamoe.mirai.utils.io.*
import
net.mamoe.mirai.utils.io.discardExact
import
net.mamoe.mirai.utils.io.discardExact
...
@@ -220,11 +223,12 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
...
@@ -220,11 +223,12 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
sealed
class
LoginPacketResponse
:
Packet
{
sealed
class
LoginPacketResponse
:
Packet
{
object
Success
:
LoginPacketResponse
(){
object
Success
:
LoginPacketResponse
()
{
override
fun
toString
():
String
{
override
fun
toString
():
String
{
return
"LoginPacketResponse.Success"
return
"LoginPacketResponse.Success"
}
}
}
}
data class
Error
(
data class
Error
(
val
title
:
String
,
val
title
:
String
,
val
message
:
String
,
val
message
:
String
,
...
@@ -236,7 +240,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
...
@@ -236,7 +240,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
class
Slider
(
class
Slider
(
val
data
:
IoBuffer
,
val
data
:
IoBuffer
,
val
sign
:
ByteArray
val
sign
:
ByteArray
)
:
Captcha
(){
)
:
Captcha
()
{
override
fun
toString
():
String
{
override
fun
toString
():
String
{
return
"LoginPacketResponse.Captcha.Slider"
return
"LoginPacketResponse.Captcha.Slider"
}
}
...
@@ -245,7 +249,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
...
@@ -245,7 +249,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
class
Picture
(
class
Picture
(
val
data
:
IoBuffer
,
val
data
:
IoBuffer
,
val
sign
:
ByteArray
val
sign
:
ByteArray
)
:
Captcha
(){
)
:
Captcha
()
{
override
fun
toString
():
String
{
override
fun
toString
():
String
{
return
"LoginPacketResponse.Captcha.Picture"
return
"LoginPacketResponse.Captcha.Picture"
}
}
...
@@ -282,7 +286,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
...
@@ -282,7 +286,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
2
->
onSolveLoginCaptcha
(
tlvMap
,
bot
)
2
->
onSolveLoginCaptcha
(
tlvMap
,
bot
)
160
/*-96*/
->
onUnsafeDeviceLogin
(
tlvMap
)
160
/*-96*/
->
onUnsafeDeviceLogin
(
tlvMap
)
204
/*-52*/
->
onSMSVerifyNeeded
(
tlvMap
,
bot
)
204
/*-52*/
->
onSMSVerifyNeeded
(
tlvMap
,
bot
)
else
->
error
(
"unknown login result type: $type"
)
else
->
tlvMap
[
0
x149
]
?.
let
{
bot
.
client
.
analysisTlv149
(
it
)
}
?:
error
(
"unknown login result type: $type"
)
}
}
}
}
...
@@ -314,7 +318,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
...
@@ -314,7 +318,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
@InternalAPI
@InternalAPI
@UseExperimental
(
MiraiDebugAPI
::
class
)
@UseExperimental
(
MiraiDebugAPI
::
class
)
private
fun
onSolveLoginCaptcha
(
tlvMap
:
TlvMap
,
bot
:
QQAndroidBot
):
LoginPacketResponse
.
Captcha
{
private
fun
onSolveLoginCaptcha
(
tlvMap
:
TlvMap
,
bot
:
QQAndroidBot
):
LoginPacketResponse
.
Captcha
{
// val ret = tlvMap[0x104]?.let { println(it.toUHexString()) }
// val ret = tlvMap[0x104]?.let { println(it.toUHexString()) }
println
()
println
()
val
question
=
tlvMap
[
0
x165
]
?:
error
(
"CAPTCHA QUESTION UNKNOWN"
)
val
question
=
tlvMap
[
0
x165
]
?:
error
(
"CAPTCHA QUESTION UNKNOWN"
)
...
@@ -358,7 +362,6 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
...
@@ -358,7 +362,6 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
DebugLogger
.
warning
(
bytes
.
encodeToString
())
DebugLogger
.
warning
(
bytes
.
encodeToString
())
}
}
tlvMap119
[
0
x149
]
?.
let
{
client
.
analysisTlv149
(
it
)
}
tlvMap119
[
0
x130
]
?.
let
{
client
.
analysisTlv130
(
it
)
}
tlvMap119
[
0
x130
]
?.
let
{
client
.
analysisTlv130
(
it
)
}
tlvMap119
[
0
x113
]
?.
let
{
client
.
analysisTlv113
(
it
)
}
tlvMap119
[
0
x113
]
?.
let
{
client
.
analysisTlv113
(
it
)
}
...
@@ -655,22 +658,16 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
...
@@ -655,22 +658,16 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
/**
/**
* 错误消息
* 错误消息
*/
*/
private
fun
QQAndroidClient
.
analysisTlv149
(
t149
:
ByteArray
)
{
private
fun
QQAndroidClient
.
analysisTlv149
(
t149
:
ByteArray
):
LoginPacketResponse
.
Error
{
data class
ErrorMessage
(
val
type
:
Short
,
val
title
:
String
,
val
content
:
String
,
val
otherInfo
:
String
)
t149
.
read
{
return
t149
.
read
{
val
type
:
Short
=
readShort
()
val
type
:
Short
=
readShort
()
val
title
:
String
=
readUShortLVString
()
val
title
:
String
=
readUShortLVString
()
val
content
:
String
=
readUShortLVString
()
val
content
:
String
=
readUShortLVString
()
val
otherInfo
:
String
=
readUShortLVString
()
val
otherInfo
:
String
=
readUShortLVString
()
// do not write class into read{} block. CompilationException!!
// do not write class into read{} block. CompilationException!!
error
(
"Got error message: "
+
ErrorMessage
(
type
,
title
,
content
,
otherInfo
)
)
// nice toString
LoginPacketResponse
.
Error
(
title
=
title
,
message
=
content
,
errorInfo
=
otherInfo
)
// nice toString
}
}
}
}
...
...
mirai-core-qqandroid/src/jvmTest/kotlin/androidPacketTests/clientToServer.kt
View file @
4c79081b
...
@@ -4,7 +4,10 @@ package androidPacketTests
...
@@ -4,7 +4,10 @@ package androidPacketTests
import
kotlinx.io.core.*
import
kotlinx.io.core.*
import
net.mamoe.mirai.qqandroid.network.protocol.packet.PacketLogger
import
net.mamoe.mirai.qqandroid.network.protocol.packet.PacketLogger
import
net.mamoe.mirai.utils.cryptor.*
import
net.mamoe.mirai.utils.cryptor.ECDH
import
net.mamoe.mirai.utils.cryptor.contentToString
import
net.mamoe.mirai.utils.cryptor.decryptBy
import
net.mamoe.mirai.utils.cryptor.initialPublicKey
import
net.mamoe.mirai.utils.io.*
import
net.mamoe.mirai.utils.io.*
import
net.mamoe.mirai.utils.io.discardExact
import
net.mamoe.mirai.utils.io.discardExact
import
net.mamoe.mirai.utils.md5
import
net.mamoe.mirai.utils.md5
...
@@ -205,7 +208,7 @@ fun ByteReadPacket.analysisOneFullPacket(): ByteReadPacket = debugIfFail("Failed
...
@@ -205,7 +208,7 @@ fun ByteReadPacket.analysisOneFullPacket(): ByteReadPacket = debugIfFail("Failed
ECDH
.
calculateShareKey
(
ECDH
.
calculateShareKey
(
loadPrivateKey
(
ecdhPrivateKeyS
),
loadPrivateKey
(
ecdhPrivateKeyS
),
//"04cb366698561e936e80c157e074cab13b0bb68ddeb2824548a1b18dd4fb6122afe12fe48c5266d8d7269d7651a8eb6fe7".chunkedHexToBytes().adjustToPublicKey() // QQ: 04cb366698561e936e80c157e074cab13b0bb68ddeb2824548a1b18dd4fb6122afe12fe48c5266d8d7269d7651a8eb6fe7
//"04cb366698561e936e80c157e074cab13b0bb68ddeb2824548a1b18dd4fb6122afe12fe48c5266d8d7269d7651a8eb6fe7".chunkedHexToBytes().adjustToPublicKey() // QQ: 04cb366698561e936e80c157e074cab13b0bb68ddeb2824548a1b18dd4fb6122afe12fe48c5266d8d7269d7651a8eb6fe7
publicKey
.
adjustToPublicKey
(
)
ECDH
.
constructPublicKey
(
"30 46 30 10 06 07 2A 86 48 CE 3D 02 01 06 05 2B 81 04 00 1F 03 32 00"
.
hexToBytes
()
+
publicKey
)
)
)
}
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/cryptor/ECDH.kt
View file @
4c79081b
...
@@ -66,13 +66,7 @@ private const val constantHead = "3046301006072A8648CE3D020106052B8104001F033200
...
@@ -66,13 +66,7 @@ private const val constantHead = "3046301006072A8648CE3D020106052B8104001F033200
private
val
byteArray_04
=
byteArrayOf
(
0
x04
)
private
val
byteArray_04
=
byteArrayOf
(
0
x04
)
fun
ByteArray
.
adjustToPublicKey
():
ECDHPublicKey
{
fun
ByteArray
.
adjustToPublicKey
():
ECDHPublicKey
{
val
key
=
if
(
this
[
0
].
toInt
()
==
0
x02
)
{
// from server
val
head
=
if
(
this
.
size
<
30
)
"302E301006072A8648CE3D020106052B8104001F031A00"
else
"3046301006072A8648CE3D020106052B8104001F03320004"
commonHeadFor02
+
this
}
else
if
(!
this
.
toUHexString
(
""
).
startsWith
(
constantHead
))
{
commonHeadForNot02
+
if
(
this
[
0
].
toInt
()
==
0
x04
)
this
else
(
byteArray_04
+
this
)
}
else
this
return
ECDH
.
constructPublicKey
(
key
)
return
ECDH
.
constructPublicKey
(
(
head
+
this
.
toUHexString
(
""
)).
chunkedHexToBytes
()
)
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment