Updated on 2026-08-14
This commit is contained in:
commit
0ce9d71a2a
4 changed files with 17 additions and 11 deletions
|
|
@ -208,7 +208,7 @@ class CardSession(
|
|||
when (result) {
|
||||
is CompletionResult.Success -> {
|
||||
val uid = result.data.uid
|
||||
val protocolKey = environment.pin1.calculateSha256().pbkdf2Hash(uid, 50)
|
||||
val protocolKey = environment.pin1.pbkdf2Hash(uid, 50)
|
||||
val secret = encryptionHelper.generateSecret(result.data.sessionKeyB)
|
||||
val sessionKey = (secret + protocolKey).calculateSha256()
|
||||
environment.encryptionKey = sessionKey
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ import com.tangem.crypto.CryptoUtils.generatePublicKey
|
|||
* @property terminalKeys generated terminal keys used in Linked Terminal feature.
|
||||
*/
|
||||
data class SessionEnvironment(
|
||||
val pin1: String = DEFAULT_PIN,
|
||||
val pin2: String = DEFAULT_PIN2,
|
||||
var pin1: ByteArray = DEFAULT_PIN.calculateSha256(),
|
||||
var pin2: ByteArray = DEFAULT_PIN2.calculateSha256(),
|
||||
var card: Card? = null,
|
||||
val terminalKeys: KeyPair? = null,
|
||||
var encryptionMode: EncryptionMode = EncryptionMode.NONE,
|
||||
|
|
@ -23,6 +23,14 @@ data class SessionEnvironment(
|
|||
val cvc: ByteArray? = null
|
||||
) {
|
||||
|
||||
fun setPin1(pin1: String) {
|
||||
this.pin1 = pin1.calculateSha256()
|
||||
}
|
||||
|
||||
fun setPin2(pin2: String) {
|
||||
this.pin2 = pin2.calculateSha256()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val DEFAULT_PIN = "000000"
|
||||
const val DEFAULT_PIN2 = "000"
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ enum class TlvTag(val code: Int) {
|
|||
fun valueType(): TlvValueType {
|
||||
return when (this) {
|
||||
CardId, Batch, CrExKey -> TlvValueType.HexString
|
||||
Pin, Pin2, NewPin, NewPin2, NewPin3 -> TlvValueType.HexStringToHash
|
||||
NewPin, NewPin2, NewPin3 -> TlvValueType.HexStringToHash
|
||||
ManufactureId, Firmware, IssuerId, BlockchainId, TokenSymbol, TokenContractAddress ->
|
||||
TlvValueType.Utf8String
|
||||
CurveId -> TlvValueType.EllipticCurve
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
package com.tangem.common.apdu
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.tangem.common.extensions.calculateSha256
|
||||
import com.tangem.common.extensions.toHexString
|
||||
import com.tangem.common.tlv.Tlv
|
||||
import com.tangem.SessionEnvironment
|
||||
import com.tangem.common.tlv.TlvBuilder
|
||||
import com.tangem.common.tlv.TlvTag
|
||||
import org.junit.Test
|
||||
|
|
@ -13,9 +11,9 @@ class CommandApduTest {
|
|||
|
||||
@Test
|
||||
fun `simple READ command to bytes`() {
|
||||
val pin = "000000"
|
||||
val sessionEnvironment = SessionEnvironment()
|
||||
val tlvBuilder = TlvBuilder()
|
||||
tlvBuilder.append(TlvTag.Pin, pin)
|
||||
tlvBuilder.append(TlvTag.Pin, sessionEnvironment.pin1)
|
||||
val commandApdu = CommandApdu(
|
||||
Instruction.Read,
|
||||
tlvBuilder.serialize()
|
||||
|
|
@ -30,13 +28,13 @@ class CommandApduTest {
|
|||
|
||||
@Test
|
||||
fun `READ with terminal key to bytes`() {
|
||||
val pin = "000000"
|
||||
val sessionEnvironment = SessionEnvironment()
|
||||
val terminalPublicKey = byteArrayOf(4, 80, -122, 58, -42, 74, -121, -82, -118, 47, -24, 60,
|
||||
26, -15, -88, 64, 60, -75, 63, 83, -28, -122, -40, 81, 29, -83, -118, 4, -120, 126,
|
||||
91, 35, 82, 44, -44, 112, 36, 52, 83, -94, -103, -6, -98, 119, 35, 119, 22, 16, 58,
|
||||
-68, 17, -95, -33, 56, -123, 94, -42, -14, -18, 24, 126, -100, 88, 43, -90)
|
||||
val tlvBuilder = TlvBuilder()
|
||||
tlvBuilder.append(TlvTag.Pin, pin)
|
||||
tlvBuilder.append(TlvTag.Pin, sessionEnvironment.pin1)
|
||||
tlvBuilder.append(TlvTag.TerminalPublicKey, terminalPublicKey)
|
||||
val commandApdu = CommandApdu(
|
||||
Instruction.Read,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue