From 804cb8b12dd710c0c5dac7b0746f7e92c557c3e3 Mon Sep 17 00:00:00 2001 From: Karlatemp <kar@kasukusakura.com> Date: Thu, 29 Jun 2023 01:20:29 +0800 Subject: [PATCH] [core] Service alert --- .../commonMain/kotlin/spi/EncryptService.kt | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/mirai-core/src/commonMain/kotlin/spi/EncryptService.kt b/mirai-core/src/commonMain/kotlin/spi/EncryptService.kt index 67b9ee0c7..303406b7d 100644 --- a/mirai-core/src/commonMain/kotlin/spi/EncryptService.kt +++ b/mirai-core/src/commonMain/kotlin/spi/EncryptService.kt @@ -86,8 +86,31 @@ public interface EncryptService : BaseService { public companion object { private val loader = SpiServiceLoader(EncryptService::class) + private val warningAlert: Unit by lazy { + val log = MiraiLogger.Factory.create(EncryptService::class, "EncryptService.alert") + + val serviceUsed = loader.service + + if (serviceUsed != null) { + val serviceClass = serviceUsed.javaClass + log.warning { "Encrypt service was loaded: $serviceUsed" } + log.warning { "All outgoing message may be leaked by this service." } + log.warning { "Use this service if and only if you trusted this service and the service provider." } + log.warning { "Service details:" } + log.warning { " `- Jvm Class: $serviceClass" } + log.warning { " `- ClassLoader: " + serviceClass.classLoader } + log.warning { " `- Source: " + serviceClass.protectionDomain?.codeSource?.location } + log.warning { " `- Protected Domain: " + serviceClass.protectionDomain } + } + + } + @GlobalEncryptServiceUsage - internal val instance: EncryptService? get() = loader.service + internal val instance: EncryptService? + get() { + warningAlert + return loader.service + } } }