From fd32c452edef19de07b1d392ecd9aea6b84f7b00 Mon Sep 17 00:00:00 2001 From: EmArrow Date: Wed, 6 Mar 2024 11:57:39 +0800 Subject: [PATCH] [6.3.0] wait to finish --- .../build.gradle | 2 + .../eagle/core/function/DataCenterProvider.kt | 12 ++- .../core/function/secure/CertFileManager.kt | 86 +++++++++++++++++++ .../mogo-core-function-startup/build.gradle | 2 +- .../api/datacenter/IDataCenterProvider.kt | 2 +- .../call/autopilot/CallerDataCenter.kt | 17 ++++ 6 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/secure/CertFileManager.kt create mode 100644 core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerDataCenter.kt diff --git a/core/function-impl/mogo-core-function-datacenter/build.gradle b/core/function-impl/mogo-core-function-datacenter/build.gradle index 1e1721f3b6..5ac23c33a5 100644 --- a/core/function-impl/mogo-core-function-datacenter/build.gradle +++ b/core/function-impl/mogo-core-function-datacenter/build.gradle @@ -65,6 +65,8 @@ dependencies { compileOnly project(':core:function-impl:mogo-core-function-map') implementation project(':core:mogo-core-function-call') implementation project(":foudations:mogo-commons") + + implementation rootProject.ext.dependencies.passport_secret } //apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString() diff --git a/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/DataCenterProvider.kt b/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/DataCenterProvider.kt index 2d6a69a955..34ca6ec19f 100644 --- a/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/DataCenterProvider.kt +++ b/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/DataCenterProvider.kt @@ -8,6 +8,7 @@ import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxManager import com.mogo.eagle.core.function.datacenter.location.MoGoLocationDispatcher import com.mogo.eagle.core.function.datacenter.v2x.SpeedLimitDispatcher import com.mogo.eagle.core.function.datacenter.v2x.TrafficLightDispatcher +import com.mogo.eagle.core.function.secure.CertFileManager @Route(path = MogoServicePaths.PATH_DATA_CENTER_MODULE) class DataCenterProvider: IDataCenterProvider { @@ -15,16 +16,23 @@ class DataCenterProvider: IDataCenterProvider { override val functionName: String get() = "DataCenterProvider" + private var mContext:Context? = null + override fun init(context: Context?) { MoGoLocationDispatcher.initListener() - - context?.let { + mContext = context + mContext?.let { + CertFileManager.INSTANCE.init(it) CallerMsgBoxManager.queryAllMessages(it) TrafficLightDispatcher.INSTANCE.initServer(it) SpeedLimitDispatcher.INSTANCE.initLimit(it) } } + override fun certificateDownLoad(callback: (String, String) -> Unit) { + CertFileManager.INSTANCE.downloadCert() + } + override fun onDestroy() { TrafficLightDispatcher.INSTANCE.destroy() SpeedLimitDispatcher.INSTANCE.destroy() diff --git a/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/secure/CertFileManager.kt b/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/secure/CertFileManager.kt new file mode 100644 index 0000000000..cae80f8573 --- /dev/null +++ b/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/secure/CertFileManager.kt @@ -0,0 +1,86 @@ +package com.mogo.eagle.core.function.secure + +import android.content.Context +import com.mogo.commons.debug.DebugConfig +import com.mogo.commons.storage.SharedPrefsMgr +import com.mogo.eagle.core.data.config.FunctionBuildConfig +import com.mogo.eagle.core.data.deva.chain.ChainConstant +import com.mogo.eagle.core.function.call.cloud.CallerCloudListenerManager +import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger +import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant +import com.zhjt.service.chain.ChainLog + +class CertFileManager { + + private var context: Context? = null + + companion object{ + val INSTANCE by lazy(LazyThreadSafetyMode.SYNCHRONIZED){ + CertFileManager() + } + } + + fun init(context: Context?) { + this.context = context + } + + fun downloadCert() { + if (FunctionBuildConfig.isSecure) { + context?.let { + val authStatus = + SharedPrefsMgr.getInstance() + .getBoolean("securityKeyStatus-${DebugConfig.getNetMode()}", false) + if (authStatus) { + // clientConfig设置auth值,并带入header //todo 作为使用方,invoke出去设置 + clientConfig.authPubKey = SharedPrefsMgr.getInstance() + .getString("securityKey-${DebugConfig.getNetMode()}", "") + return@let + } + // 安全校验 + try { + PassPortSecret.getInstance().init(sn, it.filesDir.path, object : + IPassportSecret { + + @ChainLog( + linkChainLog = ChainConstant.CHAIN_TYPE_STATUS, + linkCode = ChainConstant.CHAIN_SOURCE_CLOUD, + nodeAliasCode = ChainConstant.CHAIN_CODE_CLOUD_PASSPORT_AUTH_OK, + paramIndexes = [0,1] + ) + override fun onSuccess(securityKey: String, rootKey: String) { + CallerLogger.d( + "${SceneConstant.M_MAIN}$TAG", + "onSuccess securityKey:$securityKey , thread:${Thread.currentThread().name}" + ) + clientConfig.securityKey = securityKey + SharedPrefsMgr.getInstance() + .putString( + "securityKey-${DebugConfig.getNetMode()}", + securityKey + ) + SharedPrefsMgr.getInstance() + .putBoolean("securityKeyStatus-${DebugConfig.getNetMode()}", true) + CallerCloudListenerManager.invokeCloudCrtFile(securityKey, rootKey) + } + + @ChainLog( + linkChainLog = ChainConstant.CHAIN_TYPE_STATUS, + linkCode = ChainConstant.CHAIN_SOURCE_CLOUD, + nodeAliasCode = ChainConstant.CHAIN_CODE_CLOUD_PASSPORT_AUTH_FAILED, + paramIndexes = [0, 1] + ) + override fun onFailed(errorCode: Int, errorMsg: String) { +// logError( +// getPrReason( +// "PassPortSecret-onFailed , errorCode:$errorCode,errorMsg:$errorMsg" +// ) +// ) + } + }) + } catch (e: Exception) { + e.printStackTrace() + } + } + } + } +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-startup/build.gradle b/core/function-impl/mogo-core-function-startup/build.gradle index e70626291f..55049b2c91 100644 --- a/core/function-impl/mogo-core-function-startup/build.gradle +++ b/core/function-impl/mogo-core-function-startup/build.gradle @@ -52,7 +52,7 @@ dependencies { implementation project(":test:crashreport") implementation project(':foudations:mogo-commons') - implementation rootProject.ext.dependencies.passport_secret +// implementation rootProject.ext.dependencies.passport_secret } apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString() diff --git a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/datacenter/IDataCenterProvider.kt b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/datacenter/IDataCenterProvider.kt index 2440a49a65..9306c2c184 100644 --- a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/datacenter/IDataCenterProvider.kt +++ b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/datacenter/IDataCenterProvider.kt @@ -3,5 +3,5 @@ package com.mogo.eagle.core.function.api.datacenter import com.mogo.eagle.core.function.api.base.IMoGoFunctionServerProvider interface IDataCenterProvider: IMoGoFunctionServerProvider { - + fun certificateDownLoad(callback: (String,String) -> Unit) } \ No newline at end of file diff --git a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerDataCenter.kt b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerDataCenter.kt new file mode 100644 index 0000000000..4f1ed23bcb --- /dev/null +++ b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerDataCenter.kt @@ -0,0 +1,17 @@ +package com.mogo.eagle.core.function.call.autopilot + +import com.mogo.eagle.core.function.api.datacenter.IDataCenterProvider +import com.mogo.eagle.core.function.call.base.CallerBase + +object CallerDataCenter : CallerBase() { + + fun certificate(callback: (String, String) -> Unit) { + M_LISTENERS.forEach { + val listener = it.value + listener.certificateDownLoad { s1, s2 -> + callback.invoke(s1, s2) + } + } + } + +} \ No newline at end of file