Init SDK
Overview
The SDK has to be initialized before use. First initialization will trigger SDK to register online. Therefore, you have to make sure your device being connected before first initialization.
Methods
MPoCAPI.initSdk
This is a async function including callback. You can use
suspendCoroutineto convert it to a "sync" call mode.
Initializes the MPoC SDK. This method should be called each time the application starts up (for example, in the
Application's onCreate). First call will trigger SDK to do online registration.
Parameters
| Name | Type | Condition | Description |
|---|---|---|---|
license | String | Required | The name of the license file. |
context | Application | Required | The application instance |
autoRegister | Boolean | Optional | Default true. true makes SDK register automatically. false disables online registration and only initializes the SDK. Call registerSdk later to register. |
callback | (MPoCResult<SdkInitResult>) -> Unit | Required | The callback to handle the result of the SDK initialization. |
Returns
| Return Type | Description |
|---|---|
MPoCResult<SdkInitResult> | A wrapped result containing the SDKInitResult. |
data class SdkInitResult(
val isRegistered: Boolean, // true if the SDK is registered
val sdkId: String, // SDK ID, assigned at registration
val sdkBuildModel: String, // build environment, e.g. "SEC" for the production build
val sdkVersion: String, // SDK version number
val licenseId: String, // license ID
val customerId: String, // customer ID
val serverUrl: String, // URL of the MineSec server the SDK connects to
val kekCert: String, // KEK certificate (PEM)
val signCert: String // signing certificate (PEM)
)Usage
suspend fun registerSdk() = suspendCoroutine { continuation ->
MPoCAPI.initSdk(licenseName,this.application) {
when (it) {
is MPoCResult.Failure -> {
Log.d(
"TAG",
"sdk registration fails ${it.code} ${it.message} context=${it.contextual}"
)
continuation.resumeWith(Result.failure<SdkInitResult>(Exception(it.contextual)))
}
is MPoCResult.Success -> {
Log.d("TAG", "register success $it")
continuation.resumeWith(Result.success<SdkInitResult>(it.data))
}
}
}
}
// Success(data=SdkInitResult(isRegistered=true, sdkId=4411be126c0c91b7, sdkBuildModel=SEC,
// sdkVersion=2.01.01.019.101, licenseId=1234567890, customerId=1234567890, serverUrl=..., kekCert=..., signCert=...))MPoCAPI.registerSdk
This is a async function including callback.
Registers the SDK online. Call it after initSdk, for example when you called initSdk with autoRegister = false. If
the SDK is already registered and forceRegister is false, the SDK does not register again and returns the current
SdkInfo.
Parameters
| Name | Type | Condition | Description |
|---|---|---|---|
forceRegister | Boolean | Required | true registers again even if the SDK is already registered. This creates new KEK and signing keys, so kekCert and signCert change. The EMV settings are kept. |
callback | (MPoCResult<SdkInfo>) -> Unit | Required | The callback to handle the result of the registration. |
Returns
| Return Type | Description |
|---|---|
MPoCResult<SdkInfo> | A wrapped result containing the SdkInfo. |
Usage
MPoCAPI.registerSdk(forceRegister = false) {
when (it) {
is MPoCResult.Success -> Log.d("TAG", "registered, sdkId=${it.data.sdkId}")
is MPoCResult.Failure -> Log.d("TAG", "registration fails ${it.code} ${it.message}")
}
}MPoCAPI.getSdkInfo
This is a sync function. It may wait for the SDK service to connect, so do not call it on the main thread.
Returns the current SDK information and status. Call initSdk first.
Returns
| Return Type | Description |
|---|---|
MPoCResult<SdkInfo> | A wrapped result containing the SdkInfo. |
Usage
val info = withContext(Dispatchers.IO) { MPoCAPI.getSdkInfo() }
if (info is MPoCResult.Success) {
Log.d("TAG", "sdk status ${info.data.sdkStatus}")
}SdkInfo
data class SdkInfo(
var sdkId: String, // SDK ID, assigned at registration
var licenseId: String, // license ID
var customerId: String, // customer ID
var emvList: String, // EMV flags of the license
var sdkVersion: String, // SDK version number
var isRegistered: Boolean, // true if the SDK is registered
var kekCert: String, // KEK certificate (PEM)
var signCert: String, // signing certificate (PEM)
var sdkStatus: SdkStatus, // current SDK status, see below
var attestToken: String, // token of the last attestation
var attestTs: String, // time of the last attestation
var serverUrl: String // URL of the MineSec server the SDK connects to
)SdkStatus
| Value | Code | Description |
|---|---|---|
SDK_NOT_INITILIZED | 0 | SDK is not initialized |
SDK_NOT_REGISTERED | 1 | SDK is not registered |
SDK_ENV_CHECKING | 2 | SDK is under attestation checking |
SDK_HEALTH | 3 | SDK is healthy |
SDK_FUNCTIONAL_FLAW | 4 | SDK detects a functional flaw |
SDK_SECURITY_FLAW | 5 | SDK detects a security flaw |
SDK_UNDER_ATTACKING | 6 | SDK detects an attack |
SDK_UNDER_RUNTIME_CRASH | 7 | SDK detects a runtime issue |
SDK_UNDER_BLOCKED | 8 | SDK is blocked (security flaw) |