File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
app/src/main/java/com/ismartcoding/plain/web Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ import io.ktor.server.plugins.origin
7676import io.ktor.server.plugins.partialcontent.PartialContent
7777import io.ktor.server.request.header
7878import io.ktor.server.request.receiveMultipart
79+ import io.ktor.server.request.receive
7980import io.ktor.server.request.receiveText
8081import io.ktor.server.response.header
8182import 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 {
You can’t perform that action at this time.
0 commit comments