Skip to content

Commit 422ed72

Browse files
committed
Enhance login check
1 parent 884b9dd commit 422ed72

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

app/src/main/java/com/ismartcoding/plain/web/HttpModule.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import io.ktor.server.plugins.origin
7676
import io.ktor.server.plugins.partialcontent.PartialContent
7777
import io.ktor.server.request.header
7878
import io.ktor.server.request.receiveMultipart
79+
import io.ktor.server.request.receive
7980
import io.ktor.server.request.receiveText
8081
import io.ktor.server.response.header
8182
import io.ktor.server.response.respond
@@ -666,6 +667,20 @@ object HttpModule {
666667
return@post
667668
}
668669
HttpServerManager.clientIpCache[clientId] = call.request.origin.remoteAddress
670+
// If request body is not empty, try to decrypt with the token corresponding to c-id.
671+
// If decrypt succeeds, return 200; otherwise continue with the original handling.
672+
val bodyBytes = runCatching { call.receive<ByteArray>() }.getOrNull()
673+
if (bodyBytes != null && bodyBytes.isNotEmpty()) {
674+
val token = HttpServerManager.tokenCache[clientId]
675+
if (token != null) {
676+
val decryptedBytes = CryptoHelper.chaCha20Decrypt(token, bodyBytes)
677+
if (decryptedBytes != null) {
678+
call.respond(HttpStatusCode.OK)
679+
return@post
680+
}
681+
}
682+
}
683+
669684
if (PasswordTypePreference.getValueAsync(MainApp.instance) == PasswordType.NONE) {
670685
call.respondText(HttpServerManager.resetPasswordAsync())
671686
} else {

0 commit comments

Comments
 (0)