MPoC SDK
API Reference
Init SDK

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 suspendCoroutine to 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

NameTypeConditionDescription
licenseStringRequiredThe name of the license file.
contextApplicationRequiredThe application instance
autoRegisterBooleanOptionalDefault true. true makes SDK register automatically.
false disables online registration and only initializes the SDK. Call registerSdk later to register.
callback(MPoCResult<SdkInitResult>) -> UnitRequiredThe callback to handle the result of the SDK initialization.

Returns

Return TypeDescription
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

NameTypeConditionDescription
forceRegisterBooleanRequiredtrue 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>) -> UnitRequiredThe callback to handle the result of the registration.

Returns

Return TypeDescription
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 TypeDescription
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

ValueCodeDescription
SDK_NOT_INITILIZED0SDK is not initialized
SDK_NOT_REGISTERED1SDK is not registered
SDK_ENV_CHECKING2SDK is under attestation checking
SDK_HEALTH3SDK is healthy
SDK_FUNCTIONAL_FLAW4SDK detects a functional flaw
SDK_SECURITY_FLAW5SDK detects a security flaw
SDK_UNDER_ATTACKING6SDK detects an attack
SDK_UNDER_RUNTIME_CRASH7SDK detects a runtime issue
SDK_UNDER_BLOCKED8SDK is blocked (security flaw)