[6.3.0] add func of security down load and add caller

This commit is contained in:
EmArrow
2024-03-06 18:21:31 +08:00
parent fd32c452ed
commit 40cc7b72f0
13 changed files with 174 additions and 196 deletions

View File

@@ -65,8 +65,6 @@ 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()

View File

@@ -8,7 +8,6 @@ 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 {
@@ -22,17 +21,12 @@ class DataCenterProvider: IDataCenterProvider {
MoGoLocationDispatcher.initListener()
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()

View File

@@ -1,86 +0,0 @@
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()
}
}
}
}
}

View File

@@ -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()

View File

@@ -21,8 +21,6 @@ import com.mogo.commons.storage.SharedPrefsMgr
import com.mogo.commons.utils.MogoAnalyticUtils
import com.mogo.eagle.core.data.config.FunctionBuildConfig
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_CODE_CLOUD_INIT
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_CODE_CLOUD_PASSPORT_AUTH_FAILED
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_CODE_CLOUD_PASSPORT_AUTH_OK
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_CODE_CLOUD_PASSPORT_TOKEN
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_CODE_CLOUD_RECONNECT
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_CODE_HTTP_DNS_ERROR_REASON
@@ -30,12 +28,12 @@ import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_SOURCE_
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_TYPE_STATUS
import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener
import com.mogo.eagle.core.function.api.cloud.IMoGoCloudListener
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager
import com.mogo.eagle.core.function.call.cloud.CallerCloudCertManager
import com.mogo.eagle.core.function.call.cloud.CallerCloudListenerManager
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager
import com.mogo.eagle.core.function.startup.stageone.secret.IPassportSecret
import com.mogo.eagle.core.function.startup.stageone.secret.PassPortSecret
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_MAIN
import com.mogo.eagle.core.utilcode.util.AppUtils
@@ -47,7 +45,7 @@ import com.rousetime.android_startup.AndroidStartup
import com.zhjt.service.chain.ChainLog
import kotlin.properties.Delegates
class HttpDnsStartUp : AndroidStartup<Boolean>() {
class HttpDnsStartUp : AndroidStartup<Boolean>(), IMoGoCloudListener {
companion object {
private const val TAG = "HttpDnsStartUp"
@@ -108,6 +106,8 @@ class HttpDnsStartUp : AndroidStartup<Boolean>() {
}
private fun preparePassportEnvironment() {
//监听cert文件下载
CallerCloudListenerManager.addListener(TAG,this)
// 设置网络环境HTTP_DNS_ENV_QA、HTTP_DNS_ENV_RELEASE、HTTP_DNS_ENV_DEV
when (DebugConfig.getNetMode()) {
DebugConfig.NET_MODE_DEV -> clientConfig.netMode =
@@ -229,8 +229,8 @@ class HttpDnsStartUp : AndroidStartup<Boolean>() {
if (!gotToken) {
CallerLogger.d("$M_MAIN$TAG", "onTokenGot token : $token , sn :$sn")
CallerCloudListenerManager.invokeCloudTokenGot(token, sn)
// 异步初始化NetConfig
asyncInit(sn)
// 开启cert download && 异步初始化NetConfig
asyncInit()
startSocketService(sn)
// 开启每5s/次定位上报
uploadLocPerFiveSecond()
@@ -248,7 +248,11 @@ class HttpDnsStartUp : AndroidStartup<Boolean>() {
/**
* 异步初始化
*/
private fun asyncInit(sn: String) {
private fun asyncInit() {
// cert file下载
CallerCloudCertManager.certFileDownLoad{
logError(getPrReason("PassPortSecret-onFailed , $it"))
}
ThreadPoolService.execute {
// 初始化网络配置
NetConfigUtils.init()
@@ -259,65 +263,13 @@ class HttpDnsStartUp : AndroidStartup<Boolean>() {
mStartParams["app_flavor"] = DebugConfig.getProductFlavor()
mStartParams["app_identity_mode"] = FunctionBuildConfig.appIdentityMode
MogoAnalyticUtils.track("app_start_time", mStartParams)
}
}
if (FunctionBuildConfig.isSecure) {
context?.let {
val authStatus =
SharedPrefsMgr.getInstance()
.getBoolean("securityKeyStatus-${DebugConfig.getNetMode()}", false)
if (authStatus) {
// clientConfig设置auth值并带入header
clientConfig.authPubKey = SharedPrefsMgr.getInstance()
.getString("securityKey-${DebugConfig.getNetMode()}", "")
return@let
}
// 安全校验
try {
PassPortSecret.getInstance().init(sn, it.filesDir.path, object :
IPassportSecret {
@ChainLog(
linkChainLog = CHAIN_TYPE_STATUS,
linkCode = CHAIN_SOURCE_CLOUD,
nodeAliasCode = CHAIN_CODE_CLOUD_PASSPORT_AUTH_OK,
paramIndexes = [0,1]
)
override fun onSuccess(securityKey: String, rootKey: String) {
CallerLogger.d(
"$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 = CHAIN_TYPE_STATUS,
linkCode = CHAIN_SOURCE_CLOUD,
nodeAliasCode = 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()
}
}
}
override fun authCrtFile(device: String, root: String) {
super.authCrtFile(device, root)
handler.post {
clientConfig.securityKey = device
}
}

View File

@@ -0,0 +1,114 @@
package com.mogo.eagle.core.function.startup.stageone.secret
import android.content.Context
import com.alibaba.android.arouter.facade.annotation.Route
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.constants.MogoServicePaths
import com.mogo.eagle.core.data.deva.chain.ChainConstant
import com.mogo.eagle.core.function.api.cloud.IMoGoCertProvider
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.mogo.eagle.core.utilcode.util.ThreadPoolService
import com.zhjt.service.chain.ChainLog
import java.util.concurrent.atomic.AtomicBoolean
@Route(path = MogoServicePaths.PATH_CERT_DOWN_LOAD_PROVIDER)
class CertFileManager : IMoGoCertProvider {
private var context: Context? = null
private val securityKeyTAG = "securityKey-${DebugConfig.getNetMode()}"
private val securityRootTAG = "securityRoot-${DebugConfig.getNetMode()}"
private val securityKeyStatus = "securityKeyStatus-${DebugConfig.getNetMode()}"
private val certStatus = AtomicBoolean(false)
@Volatile
private var deviceCrtFile: String? = null
@Volatile
private var rootCrtFile: String? = null
companion object {
private const val TAG = "CertFileManager"
}
override fun init(context: Context?) {
this.context = context
}
override fun certificateDownLoad(onError: ((String) -> Unit)?) {
if (FunctionBuildConfig.isSecure) {
context?.let {
val authStatus = SharedPrefsMgr.getInstance().getBoolean(securityKeyStatus, false)
if (authStatus) {
deviceCrtFile = SharedPrefsMgr.getInstance().getString(securityKeyTAG, "")
rootCrtFile = SharedPrefsMgr.getInstance().getString(securityRootTAG, "")
CallerCloudListenerManager.invokeCloudCrtFile(deviceCrtFile!!, rootCrtFile!!)
return@let
}
if (certStatus.get()) {
onError?.invoke("正在下载证书,请稍后再试")
return@let
}
// 安全校验
try {
ThreadPoolService.execute {
PassPortSecret.getInstance()
.init(SharedPrefsMgr.getInstance().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_D_C}$TAG",
"onSuccess securityKey:$securityKey , thread:${Thread.currentThread().name}"
)
certStatus.set(true)
deviceCrtFile = securityKey
rootCrtFile = rootKey
SharedPrefsMgr.getInstance().putString(securityKeyTAG, securityKey)
SharedPrefsMgr.getInstance().putString(securityRootTAG, rootKey)
SharedPrefsMgr.getInstance().putBoolean(securityKeyStatus, 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) {
CallerLogger.d("${SceneConstant.M_D_C}$TAG", "onFailed code:$errorCode, msg:$errorMsg")
certStatus.set(true)
onError?.invoke("证书下载失败, code:$errorCode, msg:$errorMsg")
}
})
}
} catch (e: Exception) {
e.printStackTrace()
}
}
} else {
onError?.invoke("当前环境id:${FunctionBuildConfig.urlJson.secureProductId} 不支持密钥下载")
}
}
override fun getDeviceCrtF(): String? {
return deviceCrtFile?:SharedPrefsMgr.getInstance().getString(securityKeyTAG, "")
}
override fun getRootCrtF(): String? {
return rootCrtFile?:SharedPrefsMgr.getInstance().getString(securityRootTAG, "")
}
}

View File

@@ -97,6 +97,8 @@ public class MogoServicePaths {
@Keep
public static final String PATH_DATA_CENTER_MODULE = "/data_center/api";
@Keep
public static final String PATH_CERT_DOWN_LOAD_PROVIDER = "/cert_file/api";
@Keep
public static final String PATH_VISUAL_ANGLE = "/map/angle_change";

View File

@@ -0,0 +1,11 @@
package com.mogo.eagle.core.function.api.cloud
import com.alibaba.android.arouter.facade.template.IProvider
interface IMoGoCertProvider:IProvider {
fun certificateDownLoad(onError: ((String) -> Unit)? = null)
fun getDeviceCrtF():String?
fun getRootCrtF(): String?
}

View File

@@ -3,7 +3,7 @@ package com.mogo.eagle.core.function.api.cloud
import com.mogo.eagle.core.data.v2x.V2XEvent
interface IMoGoCloudListener{
//单独线程
fun authCrtFile(device:String, root:String){}
fun tokenGot(token: String, sn: String){}

View File

@@ -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)
}

View File

@@ -1,17 +0,0 @@
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<IDataCenterProvider>() {
fun certificate(callback: (String, String) -> Unit) {
M_LISTENERS.forEach {
val listener = it.value
listener.certificateDownLoad { s1, s2 ->
callback.invoke(s1, s2)
}
}
}
}

View File

@@ -0,0 +1,26 @@
package com.mogo.eagle.core.function.call.cloud
import com.mogo.eagle.core.data.constants.MogoServicePaths
import com.mogo.eagle.core.function.api.cloud.IMoGoCertProvider
import com.mogo.eagle.core.function.call.base.CallerBase
object CallerCloudCertManager {
private val certProviderApi: IMoGoCertProvider
get() = CallerBase.getApiInstance(
IMoGoCertProvider::class.java,
MogoServicePaths.PATH_CERT_DOWN_LOAD_PROVIDER
)
fun certFileDownLoad(onError: ((String) -> Unit)? = null) {
certProviderApi.certificateDownLoad(onError)
}
fun getDeviceCrtF(): String? {
return certProviderApi.getDeviceCrtF()
}
fun getRootCrtF(): String? {
return certProviderApi.getRootCrtF()
}
}

View File

@@ -12,12 +12,6 @@ object CallerCloudListenerManager : CallerBase<IMoGoCloudListener>() {
@Volatile
private var sn: String? = null
@Volatile
private var deviceCrtFile: String? = null
@Volatile
private var rootCrtFile: String? = null
override fun doSomeAfterAddListener(tag: String, listener: IMoGoCloudListener) {
super.doSomeAfterAddListener(tag, listener)
if (!token.isNullOrEmpty() && !sn.isNullOrEmpty()) {
@@ -25,17 +19,7 @@ object CallerCloudListenerManager : CallerBase<IMoGoCloudListener>() {
}
}
fun getRootCrtF(): String? {
return rootCrtFile
}
fun getDeviceCrtF(): String? {
return deviceCrtFile
}
fun invokeCloudCrtFile(deviceCrtFile: String, rootCrtFile: String) {
this.deviceCrtFile = deviceCrtFile
this.rootCrtFile = rootCrtFile
M_LISTENERS.forEach {
val listener = it.value
listener.authCrtFile(deviceCrtFile, rootCrtFile)