Updated on 2026-08-14

This commit is contained in:
Tangem 2020-04-23 12:21:06 +00:00
commit 4955064927
8 changed files with 65 additions and 5 deletions

View file

@ -0,0 +1,14 @@
package com.tangem
import com.tangem.common.extensions.CardType
import java.util.*
/**
* Filter that can be used to limit cards that can be interacted with in TangemSdk.
*
* @property allowedCardTypes Type of cards that are allowed to be interacted with in TangemSdk.
*/
data class CardFilter(
var allowedCardTypes: EnumSet<CardType> = EnumSet.allOf(CardType::class.java)
)

View file

@ -8,6 +8,7 @@ import com.tangem.common.CompletionResult
import com.tangem.common.apdu.CommandApdu
import com.tangem.common.apdu.ResponseApdu
import com.tangem.common.extensions.calculateSha256
import com.tangem.common.extensions.getType
import com.tangem.crypto.EncryptionHelper
import com.tangem.crypto.FastEncryptionHelper
import com.tangem.crypto.StrongEncryptionHelper
@ -136,6 +137,12 @@ class CardSession(
callback(CompletionResult.Failure(SessionError.WrongCard()))
return@run
}
val allowedCardTypes = environment.cardFilter.allowedCardTypes
if (!allowedCardTypes.contains(result.data.getType())) {
stopWithError(SessionError.WrongCardType())
callback(CompletionResult.Failure(SessionError.WrongCardType()))
return@run
}
environment.card = result.data
cardId = receivedCardId
callback(CompletionResult.Success(result.data))

View file

@ -18,16 +18,21 @@ class Config(
the correctness of Terminal_Transaction_Signature using previously stored Terminal_PublicKey
and, if correct, will skip security delay for the current SIGN operation.
*/
val linkedTerminal: Boolean = true,
var linkedTerminal: Boolean = true,
/**
* If not null, it will be used to validate Issuer data and issuer extra data.
* If null, issuerPublicKey from current card will be used.
*/
val issuerPublicKey: ByteArray? = null,
var issuerPublicKey: ByteArray? = null,
/**
* Level of encryption used in communication with a Tangem Card.
*/
val encryptionMode: EncryptionMode = EncryptionMode.NONE
var encryptionMode: EncryptionMode = EncryptionMode.NONE,
/**
* Filter that can be used to limit cards that can be interacted with in TangemSdk.
*/
val cardFilter: CardFilter = CardFilter()
)

View file

@ -20,7 +20,8 @@ data class SessionEnvironment(
val terminalKeys: KeyPair? = null,
var encryptionMode: EncryptionMode = EncryptionMode.NONE,
var encryptionKey: ByteArray? = null,
val cvc: ByteArray? = null
val cvc: ByteArray? = null,
var cardFilter: CardFilter
) {
fun setPin1(pin1: String) {

View file

@ -106,6 +106,13 @@ sealed class SessionError(val code: Int) : Exception() {
*/
class HashSizeMustBeEqual : SessionError(3005)
/**
* This error is returned when a user scans a card of a [com.tangem.common.extensions.CardType]
* that is not specified in [Config.allowedCards].
*/
class WrongCardType : SessionError(3006)
/**
* This error is returned when [com.tangem.TangemSdk] was called with a new [Task],
* while a previous [Task] is still in progress.

View file

@ -367,7 +367,8 @@ class TangemSdk(
private fun buildEnvironment(): SessionEnvironment {
val terminalKeys = if (config.linkedTerminal) terminalKeysService?.getKeys() else null
return SessionEnvironment(
terminalKeys = terminalKeys
terminalKeys = terminalKeys,
cardFilter = config.cardFilter
)
}

View file

@ -0,0 +1,22 @@
package com.tangem.common.extensions
import com.tangem.commands.Card
fun Card.getType(): CardType {
val firmware = this.firmwareVersion ?: return CardType.Unknown
return when {
firmware.endsWith("d SDK") -> {
CardType.Sdk
}
firmware.endsWith("r") -> {
CardType.Release
}
else -> {
CardType.Unknown
}
}
}
enum class CardType {
Sdk, Release, Unknown
}

View file

@ -9,6 +9,7 @@ import com.tangem.TangemSdk
import com.tangem.commands.Card
import com.tangem.commands.CommandResponse
import com.tangem.common.CompletionResult
import com.tangem.common.extensions.CardType
import com.tangem.devkit._arch.SingleLiveEvent
import com.tangem.devkit._arch.structure.Id
import com.tangem.devkit._arch.structure.Payload
@ -20,6 +21,7 @@ import com.tangem.devkit.ucase.resources.ActionType
import com.tangem.devkit.ucase.tunnel.ViewScreen
import com.tangem.devkit.ucase.variants.personalize.converter.ItemTypes
import ru.dev.gbixahue.eu4d.lib.android.global.log.Log
import java.util.*
/**
[REDACTED_AUTHOR]
@ -43,6 +45,7 @@ class ActionViewModel(private val itemsManager: ItemsManager) : ViewModel(), Lif
fun setCardManager(tangemSdk: TangemSdk) {
this.tangemSdk = tangemSdk
this.tangemSdk.config.cardFilter.allowedCardTypes = EnumSet.of(CardType.Sdk)
}
@Deprecated("Events must be send directly from the Widget")