From 3d5dd65e306ba3ca560b3c221830ee4cdb4363fb Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Mon, 6 Nov 2017 12:41:00 +0100 Subject: Display TOTP code if entry contains OTP secret TOTP is calculated on display and on copy to clipboard from secret embedded in entry (either in password or in extra) and the current time. --- .../java/com/zeapo/pwdstore/crypto/PgpActivity.kt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'app/src/main/java/com/zeapo/pwdstore/crypto') diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt index db2acfac..905f37bf 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt @@ -20,6 +20,7 @@ import com.zeapo.pwdstore.PasswordEntry import com.zeapo.pwdstore.R import com.zeapo.pwdstore.UserPreference import com.zeapo.pwdstore.pwgenDialogFragment +import com.zeapo.pwdstore.utils.Totp import kotlinx.android.synthetic.main.decrypt_layout.* import kotlinx.android.synthetic.main.encrypt_layout.* import org.apache.commons.io.FileUtils @@ -32,6 +33,7 @@ import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.io.File import java.nio.charset.Charset +import java.util.Date class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { private val clipboard: ClipboardManager by lazy { @@ -231,6 +233,20 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { } } + if (entry.hasTotp()) { + crypto_totp_show.visibility = View.VISIBLE + crypto_totp_show_label.visibility = View.VISIBLE + crypto_copy_totp.visibility = View.VISIBLE + + crypto_copy_totp.setOnClickListener { copyTotpToClipBoard(Totp.calculateCode(entry.totpSecret, Date().time / 1000)) } + crypto_totp_show.typeface = monoTypeface + crypto_totp_show.text = Totp.calculateCode(entry.totpSecret, Date().time / 1000); + } else { + crypto_totp_show.visibility = View.GONE + crypto_totp_show_label.visibility = View.GONE + crypto_copy_totp.visibility = View.GONE + } + if (settings.getBoolean("copy_on_decrypt", true)) { copyPasswordToClipBoard() } @@ -460,6 +476,12 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { showToast(resources.getString(R.string.clipboard_username_toast_text)) } + private fun copyTotpToClipBoard(code: String) { + val clip = ClipData.newPlainText("pgp_handler_result_pm", code) + clipboard.primaryClip = clip + showToast(resources.getString(R.string.clipboard_totp_toast_text)) + } + private fun shareAsPlaintext() { if (findViewById(R.id.share_password_as_plaintext) == null) -- cgit v1.2.3