Skip to content

Commit

Permalink
AND-9595 hidden sensitive info in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kozarezvlad committed Dec 27, 2024
1 parent 89a3829 commit 7de36ea
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.tangem.common.apdu.ResponseApdu
import com.tangem.common.core.CompletionCallback
import com.tangem.common.core.TagType
import com.tangem.common.core.TangemSdkError
import com.tangem.common.extensions.toHexString
import com.tangem.common.nfc.CardReader
import com.tangem.common.nfc.ReadingActiveListener
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -148,7 +147,6 @@ class NfcReader : CardReader {

override fun transceiveRaw(apduData: ByteArray, callback: CompletionCallback<ByteArray?>) {
val rawResponse: ByteArray? = try {
Log.nfc { "transceiveRaw: " + apduData.toHexString() }
transcieveAndLog(apduData)
} catch (exception: TagLostException) {
Log.nfc { "ERROR transceiving data TagLostException: $exception" }
Expand All @@ -166,13 +164,10 @@ class NfcReader : CardReader {

private fun transcieveAndLog(apduData: ByteArray): ByteArray? {
Log.nfc { "transcieve..." }
val startTime = System.currentTimeMillis()
val isExtendedLengthApduSupported = nfcTag?.isoDep?.isExtendedLengthApduSupported
Log.nfc { "isExtendedLengthApduSupported $isExtendedLengthApduSupported" }
Log.nfc { "transcieveAndLog: isoDep isConnected = " + nfcTag?.isoDep?.isConnected }
val rawResponse = nfcTag?.isoDep?.transceive(apduData)
val finishTime = System.currentTimeMillis()
Log.nfc { "transcieve success: [${finishTime - startTime}] ms" }
return rawResponse
}

Expand Down
7 changes: 6 additions & 1 deletion tangem-sdk-core/src/main/java/com/tangem/common/tlv/Tlv.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ class Tlv {
.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
val tagFullName = "TAG_$tagName"
val size = String.format("%02d", value.size)
return "$tagFullName [0x$tagRaw:$size]: ${value.toHexString()}"
val tagContent = if (!tag.shouldMask) {
"[0x$tagRaw:$size]: ${value.toHexString()}"
} else {
"*****"
}
return "$tagFullName $tagContent"
}

companion object {
Expand Down
16 changes: 8 additions & 8 deletions tangem-sdk-core/src/main/java/com/tangem/common/tlv/TlvTag.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ enum class TlvValueType {
/**
* Contains all TLV tags, with their code and descriptive name.
*/
enum class TlvTag(val code: Int) {
enum class TlvTag(val code: Int, val shouldMask: Boolean = false) {
Unknown(code = 0x00),
CardId(code = 0x01),
Status(code = 0x02),
Expand All @@ -45,10 +45,10 @@ enum class TlvTag(val code: Int) {
CreateWalletAtPersonalize(code = 0x0E),
Health(code = 0x0F),

Pin(code = 0x10),
Pin2(code = 0x11),
NewPin(code = 0x12),
NewPin2(code = 0x13),
Pin(code = 0x10, shouldMask = true),
Pin2(code = 0x11, shouldMask = true),
NewPin(code = 0x12, shouldMask = true),
NewPin2(code = 0x13, shouldMask = true),
PublicKeyChallenge(code = 0x14),
PublicKeySalt(code = 0x15),
Challenge(code = 0x16),
Expand All @@ -59,7 +59,7 @@ enum class TlvTag(val code: Int) {
SessionKeyA(code = 0x1A),
SessionKeyB(code = 0x1B),
Pause(code = 0x1C),
NewPin3(code = 0x1E),
NewPin3(code = 0x1E, shouldMask = true),
CrExKey(code = 0x1F),

Uid(code = 0x0B),
Expand Down Expand Up @@ -94,7 +94,7 @@ enum class TlvTag(val code: Int) {
PinIsDefault(code = 0x5A),
Pin2IsDefault(code = 0x59),

WalletPublicKey(code = 0x60),
WalletPublicKey(code = 0x60, shouldMask = true),
WalletSignature(code = 0x61),
WalletRemainingSignatures(code = 0x62),
WalletSignedHashes(code = 0x63),
Expand All @@ -106,7 +106,7 @@ enum class TlvTag(val code: Int) {

WalletHDPath(code = 0x6A),
WalletHDChain(code = 0x6B),
WalletPrivateKey(code = 0x6F),
WalletPrivateKey(code = 0x6F, shouldMask = true),

Firmware(code = 0x80),
BatchId(code = 0x81),
Expand Down

0 comments on commit 7de36ea

Please # to comment.