Updated on 2026-08-14

This commit is contained in:
Tangem 2018-12-18 18:33:57 +03:00
parent cfebd18d17
commit f8b2a70086
11 changed files with 101 additions and 87 deletions

View file

@ -35,8 +35,12 @@ object Constant {
// PinRequestActivity
const val EXTRA_MODE = "mode"
const val KEY_ALIAS = "pinKey"
const val KEYSTORE = "AndroidKeyStore"
// PinSwapActivity
const val EXTRA_CONFIRM_PIN = "confirmPIN"
const val EXTRA_CONFIRM_PIN_2 = "confirmPIN2"
const val EXTRA_NEW_PIN = "newPIN"
const val EXTRA_NEW_PIN_2 = "newPIN2"

View file

@ -8,6 +8,7 @@ import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyPermanentlyInvalidatedException;
import android.security.keystore.KeyProperties;
import com.tangem.Constant;
import com.tangem.tangemcard.android.data.PINStorage;
import com.tangem.presentation.activity.PinRequestActivity;
@ -88,7 +89,7 @@ public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
pinRequestActivity.doLog("Getting keystore...");
try {
keyStore = KeyStore.getInstance(PinRequestActivity.KEYSTORE);
keyStore = KeyStore.getInstance(Constant.KEYSTORE);
keyStore.load(null); // Create empty keystore
return true;
} catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | IOException e) {
@ -105,12 +106,12 @@ public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
pinRequestActivity.doLog("Creating new key...");
try {
if (forceCreate)
keyStore.deleteEntry(PinRequestActivity.KEY_ALIAS);
keyStore.deleteEntry(Constant.KEY_ALIAS);
if (!keyStore.containsAlias(PinRequestActivity.KEY_ALIAS)) {
KeyGenerator generator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, PinRequestActivity.KEYSTORE);
if (!keyStore.containsAlias(Constant.KEY_ALIAS)) {
KeyGenerator generator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, Constant.KEYSTORE);
generator.init(new KeyGenParameterSpec.Builder(PinRequestActivity.KEY_ALIAS,
generator.init(new KeyGenParameterSpec.Builder(Constant.KEY_ALIAS,
KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
@ -152,7 +153,7 @@ public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
pinRequestActivity.doLog("Initializing cipher...");
try {
keyStore.load(null);
SecretKey keyspec = (SecretKey) keyStore.getKey(PinRequestActivity.KEY_ALIAS, null);
SecretKey keyspec = (SecretKey) keyStore.getKey(Constant.KEY_ALIAS, null);
if (mode == Cipher.ENCRYPT_MODE) {
cipher.init(mode, keyspec);

View file

@ -24,12 +24,28 @@ class Navigator {
context.startActivityForResult(PinRequestActivity.callingIntent(context, mode), Constant.REQUEST_CODE_ENTER_PIN_ACTIVITY)
}
fun showPinRequestRequestPin(context: Activity, mode: String, ctx: TangemContext, newPin: String) {
context.startActivityForResult(PinRequestActivity.callingIntentRequestPin(context, mode, ctx, newPin), Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN)
}
fun showPinRequestRequestPin2(context: Activity, mode: String, ctx: TangemContext, newPin2: String) {
context.startActivityForResult(PinRequestActivity.callingIntentRequestPin2(context, mode, ctx, newPin2), Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN)
}
fun showPinRequestConfirmNewPin(context: Activity, mode: String, newPin: String) {
context.startActivityForResult(PinRequestActivity.callingIntentConfirmPin(context, mode, newPin), Constant.REQUEST_CODE_ENTER_NEW_PIN)
}
fun showPinRequestConfirmNewPin2(context: Activity, mode: String, newPin2: String) {
context.startActivityForResult(PinRequestActivity.callingIntentConfirmPin2(context, mode, newPin2), Constant.REQUEST_CODE_ENTER_NEW_PIN2)
}
fun showLoadedWallet(context: Activity, lastTag: Tag, ctx: TangemContext) {
context.startActivityForResult(LoadedWalletActivity.callingIntent(context, lastTag, ctx), Constant.REQUEST_CODE_SHOW_CARD_ACTIVITY)
}
fun showEmptyWallet(context: Activity, ctx: TangemContext) {
context.startActivity(EmptyWalletActivity.callingIntent(context ,ctx))
context.startActivity(EmptyWalletActivity.callingIntent(context, ctx))
}
fun showVerifyCard(context: Activity, ctx: TangemContext) {

View file

@ -284,18 +284,14 @@ class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoco
public override fun onPause() {
nfcManager.onPause()
if (readCardInfoTask != null) {
readCardInfoTask!!.cancel(true)
}
readCardInfoTask?.cancel(true)
super.onPause()
}
public override fun onStop() {
// dismiss enable NFC dialog
nfcManager.onStop()
if (readCardInfoTask != null) {
readCardInfoTask!!.cancel(true)
}
readCardInfoTask?.cancel(true)
super.onStop()
}
@ -329,7 +325,8 @@ class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoco
val ctx = TangemContext(card)
when {
card.status == TangemCard.Status.Loaded -> lastTag?.let {
val engineCoin = CoinEngineFactory.create(ctx) ?: throw CardProtocol.TangemException("Can't create CoinEngine!")
val engineCoin = CoinEngineFactory.create(ctx)
?: throw CardProtocol.TangemException("Can't create CoinEngine!")
engineCoin.defineWallet()
//mCard.setWallet(Blockchain.calculateWalletAddress(mCard, pkUncompressed));

View file

@ -23,6 +23,7 @@ import com.tangem.Constant
import com.tangem.data.fingerprint.StartFingerprintReaderTask
import com.tangem.tangemcard.android.reader.NfcManager
import com.tangem.data.fingerprint.FingerprintHelper
import com.tangem.domain.wallet.TangemContext
import com.tangem.tangemcard.android.data.PINStorage
import com.tangem.tangemcard.data.TangemCard
import com.tangem.tangemcard.data.loadFromBundle
@ -36,14 +37,39 @@ import java.io.IOException
class PinRequestActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, FingerprintHelper.FingerprintHelperListener {
companion object {
const val KEY_ALIAS = "pinKey"
const val KEYSTORE = "AndroidKeyStore"
fun callingIntent(context: Activity, mode: String): Intent {
val intent = Intent(context, PinRequestActivity::class.java)
intent.putExtra(Constant.EXTRA_MODE, mode)
return intent
}
fun callingIntentRequestPin(context: Activity, mode: String, ctx: TangemContext, newPIN: String): Intent {
val intent = Intent(context, PinRequestActivity::class.java)
intent.putExtra(Constant.EXTRA_MODE, mode)
ctx.saveToIntent(intent)
return intent
}
fun callingIntentRequestPin2(context: Activity, mode: String, ctx: TangemContext, newPIN2: String): Intent {
val intent = Intent(context, PinRequestActivity::class.java)
intent.putExtra(Constant.EXTRA_MODE, mode)
ctx.saveToIntent(intent)
return intent
}
fun callingIntentConfirmPin(context: Activity, mode: String, newPIN: String): Intent {
val intent = Intent(context, PinRequestActivity::class.java)
intent.putExtra(Constant.EXTRA_NEW_PIN, newPIN)
intent.putExtra(Constant.EXTRA_MODE, mode)
return intent
}
fun callingIntentConfirmPin2(context: Activity, mode: String, newPin2: String): Intent {
val intent = Intent(context, PinRequestActivity::class.java)
intent.putExtra(Constant.EXTRA_NEW_PIN_2, newPin2)
intent.putExtra(Constant.EXTRA_MODE, mode)
return intent
}
}
lateinit var mode: Mode
@ -63,8 +89,6 @@ class PinRequestActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Finge
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_pin_request)
// MainActivity.commonInit(applicationContext)
nfcManager = NfcManager(this, this)
mode = Mode.valueOf(intent.getStringExtra("mode"))

View file

@ -167,7 +167,7 @@ class PinSaveActivity : AppCompatActivity(), FingerprintHelper.FingerprintHelper
fun getKeyStore(): Boolean {
try {
keyStore = KeyStore.getInstance(PinRequestActivity.KEYSTORE)
keyStore = KeyStore.getInstance(Constant.KEYSTORE)
// create empty keystore
keyStore!!.load(null)
return true
@ -188,12 +188,12 @@ class PinSaveActivity : AppCompatActivity(), FingerprintHelper.FingerprintHelper
fun createNewKey(forceCreate: Boolean): Boolean {
try {
if (forceCreate)
keyStore!!.deleteEntry(PinRequestActivity.KEY_ALIAS)
keyStore!!.deleteEntry(Constant.KEY_ALIAS)
if (!keyStore!!.containsAlias(PinRequestActivity.KEY_ALIAS)) {
val generator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, PinRequestActivity.KEYSTORE)
if (!keyStore!!.containsAlias(Constant.KEY_ALIAS)) {
val generator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, Constant.KEYSTORE)
generator.init(KeyGenParameterSpec.Builder(PinRequestActivity.KEY_ALIAS,
generator.init(KeyGenParameterSpec.Builder(Constant.KEY_ALIAS,
KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
@ -229,7 +229,7 @@ class PinSaveActivity : AppCompatActivity(), FingerprintHelper.FingerprintHelper
fun initCipher(mode: Int): Boolean {
try {
keyStore!!.load(null)
val keyspec = keyStore!!.getKey(PinRequestActivity.KEY_ALIAS, null) as SecretKey
val keyspec = keyStore!!.getKey(Constant.KEY_ALIAS, null) as SecretKey
if (mode == Cipher.ENCRYPT_MODE) {
cipher!!.init(mode, keyspec)

View file

@ -43,8 +43,6 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_prepare_payment)
// MainActivity.commonInit(applicationContext)
nfcManager = NfcManager(this, this)
ctx = TangemContext.loadFromBundle(this, intent.extras)

View file

@ -44,8 +44,6 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
nfcManager = NfcManager(this, this)
// MainActivity.commonInit(applicationContext)
ctx = TangemContext.loadFromBundle(this, intent.extras)
tvCardID.text = ctx.card!!.cidDescription

View file

@ -116,8 +116,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
srl.setOnRefreshListener { refresh() }
btnLookup.setOnClickListener {
val engine = CoinEngineFactory.create(ctx)
val browserIntent = Intent(Intent.ACTION_VIEW, engine?.shareWalletUriExplorer)
startActivity(browserIntent)
startActivity(Intent(Intent.ACTION_VIEW, engine?.shareWalletUriExplorer))
}
btnCopy.setOnClickListener { doShareWallet(false) }
tvWallet.setOnClickListener { doShareWallet(false) }
@ -183,7 +182,6 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
}
btnDetails.setOnClickListener {
if (cardProtocol != null)
// openVerifyCard(cardProtocol!!)
(activity as LoadedWalletActivity).navigator.showVerifyCard(context as Activity, ctx)
else
showSingleToast(R.string.need_attach_card_again)
@ -191,18 +189,14 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
btnScanAgain.setOnClickListener { (activity as LoadedWalletActivity).navigator.showMain(context as Activity) }
btnExtract.setOnClickListener {
val engine = CoinEngineFactory.create(ctx)
if (UtilHelper.isOnline(context as Activity)) {
if (UtilHelper.isOnline(context as Activity))
if (!engine!!.isExtractPossible)
showSingleToast(ctx.message)
else if (ctx.card!!.remainingSignatures == 0)
showSingleToast(R.string.card_has_no_remaining_signature)
else {
else
(activity as LoadedWalletActivity).navigator.showPreparePayment(context as Activity, ctx)
// val intent = Intent(activity, PreparePaymentActivity::class.java)
// ctx.saveToIntent(intent)
// startActivityForResult(intent, Constant.REQUEST_CODE_SEND_PAYMENT)
}
} else
else
Toast.makeText(activity, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
}
@ -496,48 +490,29 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
var data = data
// var data = data
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
Constant.REQUEST_CODE_VERIFY_CARD ->
// action when erase wallet
if (resultCode == Activity.RESULT_OK) {
if (activity != null)
activity?.finish()
}
// action after erase wallet
if (resultCode == Activity.RESULT_OK)
activity?.finish()
Constant.REQUEST_CODE_ENTER_NEW_PIN -> if (resultCode == Activity.RESULT_OK)
if (data != null)
if (data.extras != null && data.extras!!.containsKey(Constant.EXTRA_CONFIRM_PIN))
(activity as LoadedWalletActivity).navigator.showPinRequestRequestPin(context as Activity, PinRequestActivity.Mode.RequestPIN.toString(), ctx, data.getStringExtra(Constant.EXTRA_NEW_PIN))
else
(activity as LoadedWalletActivity).navigator.showPinRequestConfirmNewPin(context as Activity, PinRequestActivity.Mode.ConfirmNewPIN.toString(), data.getStringExtra(Constant.EXTRA_NEW_PIN))
Constant.REQUEST_CODE_ENTER_NEW_PIN2 -> if (resultCode == Activity.RESULT_OK)
if (data != null)
if (data.extras != null && data.extras!!.containsKey(Constant.EXTRA_CONFIRM_PIN_2))
(activity as LoadedWalletActivity).navigator.showPinRequestRequestPin2(context as Activity, PinRequestActivity.Mode.RequestPIN2.toString(), ctx, data.getStringExtra(Constant.EXTRA_NEW_PIN_2))
else
(activity as LoadedWalletActivity).navigator.showPinRequestConfirmNewPin2(context as Activity, PinRequestActivity.Mode.ConfirmNewPIN2.toString(), data.getStringExtra(Constant.EXTRA_NEW_PIN_2))
Constant.REQUEST_CODE_ENTER_NEW_PIN -> if (resultCode == Activity.RESULT_OK) {
if (data != null) {
if (data.extras != null && data.extras!!.containsKey("confirmPIN")) {
val intent = Intent(activity, PinRequestActivity::class.java)
intent.putExtra("mode", PinRequestActivity.Mode.RequestPIN2.toString())
ctx.saveToIntent(intent)
newPIN = data.getStringExtra("newPIN")
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN)
} else {
val intent = Intent(activity, PinRequestActivity::class.java)
intent.putExtra("newPIN", data.getStringExtra("newPIN"))
intent.putExtra("mode", PinRequestActivity.Mode.ConfirmNewPIN.toString())
startActivityForResult(intent, Constant.REQUEST_CODE_ENTER_NEW_PIN)
}
}
}
Constant.REQUEST_CODE_ENTER_NEW_PIN2 -> if (resultCode == Activity.RESULT_OK) {
if (data != null) {
if (data.extras != null && data.extras!!.containsKey("confirmPIN2")) {
val intent = Intent(activity, PinRequestActivity::class.java)
intent.putExtra("mode", PinRequestActivity.Mode.RequestPIN2.toString())
ctx.saveToIntent(intent)
newPIN2 = data.getStringExtra("newPIN2")
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN)
} else {
val intent = Intent(activity, PinRequestActivity::class.java)
intent.putExtra("newPIN2", data.getStringExtra("newPIN2"))
intent.putExtra("mode", PinRequestActivity.Mode.ConfirmNewPIN2.toString())
startActivityForResult(intent, Constant.REQUEST_CODE_ENTER_NEW_PIN2)
}
}
}
Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN -> if (resultCode == Activity.RESULT_OK) {
if (newPIN == "")
newPIN = ctx.card!!.pin
@ -558,9 +533,8 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
Constant.REQUEST_CODE_SWAP_PIN -> if (resultCode == Activity.RESULT_OK) {
if (data == null) {
data = Intent()
ctx.saveToIntent(data)
data.putExtra(Constant.EXTRA_MODIFICATION, "delete")
data?.putExtra(Constant.EXTRA_MODIFICATION, "delete")
} else
data.putExtra(Constant.EXTRA_MODIFICATION, "update")
@ -586,16 +560,17 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
}
}
}
Constant.REQUEST_CODE_REQUEST_PIN2_FOR_PURGE -> if (resultCode == Activity.RESULT_OK) {
val intent = Intent(activity, PurgeActivity::class.java)
ctx.saveToIntent(intent)
startActivityForResult(intent, Constant.REQUEST_CODE_PURGE)
}
Constant.REQUEST_CODE_PURGE -> if (resultCode == Activity.RESULT_OK) {
if (data == null) {
data = Intent()
ctx.saveToIntent(data)
data.putExtra(Constant.EXTRA_MODIFICATION, "delete")
data?.putExtra(Constant.EXTRA_MODIFICATION, "delete")
} else {
data.putExtra(Constant.EXTRA_MODIFICATION, "update")
}
@ -623,6 +598,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
}
updateViews()
}
Constant.REQUEST_CODE_SEND_PAYMENT, Constant.REQUEST_CODE_RECEIVE_PAYMENT -> {
if (resultCode == Activity.RESULT_OK) {
ctx.coinData?.clearInfo()
@ -733,11 +709,11 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
}
if (ctx.hasError()) {
tvError.visibility = View.VISIBLE
tvError.text = ctx.error
tvError?.visibility = View.VISIBLE
tvError?.text = ctx.error
} else {
tvError.visibility = View.GONE
tvError.text = ""
tvError?.visibility = View.GONE
tvError?.text = ""
}
if (ctx.message == null || ctx.message.isEmpty()) {

View file

@ -207,7 +207,7 @@ class VerifyCard : Fragment(), NfcAdapter.ReaderCallback {
updateViews()
}
// TODO unused block
// TODO unused block, need check and remove it
// Constant.REQUEST_CODE_SEND_PAYMENT -> {
// if (resultCode == Activity.RESULT_OK) {
// srlVerifyCard.isRefreshing = true

View file

@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.10'
ext.kotlin_version = '1.3.11'
repositories {
google()
jcenter()