diff --git a/mirai-core/src/commonMain/kotlin/network/auth/DefaultBotAuthorizationFactoryImpl.kt b/mirai-core/src/commonMain/kotlin/network/auth/DefaultBotAuthorizationFactoryImpl.kt index 354332851..dbe04f8b7 100644 --- a/mirai-core/src/commonMain/kotlin/network/auth/DefaultBotAuthorizationFactoryImpl.kt +++ b/mirai-core/src/commonMain/kotlin/network/auth/DefaultBotAuthorizationFactoryImpl.kt @@ -24,13 +24,17 @@ internal class DefaultBotAuthorizationFactoryImpl : net.mamoe.mirai.auth.DefaultBotAuthorizationFactory { override fun byPassword(passwordMd5: ByteArray): BotAuthorization { val buffer = EscapedByteBuffer(passwordMd5) + return byPassword(buffer) // Avoid referring passwordMd5(ByteArray) + } + + private fun byPassword(buffer: EscapedByteBuffer): BotAuthorization { return object : BotAuthorizationWithSecretsProtection() { override fun calculateSecretsKeyImpl(bot: BotAuthInfo): EscapedByteBuffer = buffer override suspend fun authorize( session: BotAuthSessionInternal, bot: BotAuthInfo - ): BotAuthResult = session.authByPassword(passwordMd5) + ): BotAuthResult = session.authByPassword(buffer) override fun toString(): String = "BotAuthorization.byPassword()" } diff --git a/mirai-core/src/commonMain/kotlin/network/components/SsoProcessor.kt b/mirai-core/src/commonMain/kotlin/network/components/SsoProcessor.kt index 8de88b44e..4590d00fc 100644 --- a/mirai-core/src/commonMain/kotlin/network/components/SsoProcessor.kt +++ b/mirai-core/src/commonMain/kotlin/network/components/SsoProcessor.kt @@ -20,6 +20,7 @@ import net.mamoe.mirai.internal.network.QQAndroidClient import net.mamoe.mirai.internal.network.QRCodeLoginData import net.mamoe.mirai.internal.network.WLoginSigInfo import net.mamoe.mirai.internal.network.auth.BotAuthSessionInternal +import net.mamoe.mirai.internal.network.auth.BotAuthorizationWithSecretsProtection import net.mamoe.mirai.internal.network.component.ComponentKey import net.mamoe.mirai.internal.network.handler.NetworkHandler import net.mamoe.mirai.internal.network.handler.logger @@ -182,9 +183,11 @@ internal class SsoProcessorImpl( if (authControl == null) { ssoContext.bot.account.let { account -> if (account.accountSecretsKeyBuffer == null) { - account.accountSecretsKeyBuffer = SecretsProtection.EscapedByteBuffer( - account.authorization.calculateSecretsKey(botAuthInfo) - ) + + account.accountSecretsKeyBuffer = when (val authorization = account.authorization) { + is BotAuthorizationWithSecretsProtection -> authorization.calculateSecretsKeyImpl(botAuthInfo) + else -> SecretsProtection.EscapedByteBuffer(authorization.calculateSecretsKey(botAuthInfo)) + } } } @@ -248,16 +251,21 @@ internal class SsoProcessorImpl( authControl!!.actComplete() authControl = null } catch (exception: Throwable) { - authControl0.exceptionCollector.collectException(exception) + if (exception is SelectorRequireReconnectException) { + + if (nextAuthMethod is AuthMethod.DirectError) { // @TestOnly + authControl0.actResume() + } + + throw exception + } ssoContext.bot.network.logger.warning({ "Failed with auth method: $nextAuthMethod" }, exception) if (nextAuthMethod is AuthMethod.DirectError) { // @TestOnly authControl0.actResume() - } else if (nextAuthMethod !is AuthMethod.Error) { - if (exception !is SelectorRequireReconnectException) { // login not done - authControl0.actFailed(exception) - } + } else if (nextAuthMethod !is AuthMethod.Error && nextAuthMethod != null) { + authControl0.actFailed(exception) } if (exception is NetworkException) {