diff options
| author | Wiktor Kwapisiewicz <wiktor@metacode.biz> | 2017-11-06 12:41:00 +0100 |
|---|---|---|
| committer | Mohamed Zenadi <zeapo@users.noreply.github.com> | 2017-11-19 11:14:45 +0100 |
| commit | 3d5dd65e306ba3ca560b3c221830ee4cdb4363fb (patch) | |
| tree | 6a417353098a9dc22093568c7e6c1dd505997512 /app/src/main/java/com/zeapo/pwdstore/crypto | |
| parent | 67a7b124eec9178f8539664bf4d2528a111465b2 (diff) | |
| download | HardenedPass-3d5dd65e306ba3ca560b3c221830ee4cdb4363fb.tar.gz HardenedPass-3d5dd65e306ba3ca560b3c221830ee4cdb4363fb.zip | |
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.
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/crypto')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt | 22 |
1 files changed, 22 insertions, 0 deletions
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<View>(R.id.share_password_as_plaintext) == null) |
