diff options
| author | Harsh Shandilya <msfjarvis@gmail.com> | 2020-05-28 22:42:13 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-28 22:42:13 +0530 |
| commit | e7463ec24c929860f0a7311b558f496919d54d20 (patch) | |
| tree | eb460f7e49e1a71acaceaec305e511bb4c0a9d45 /app/src/main/java/com/zeapo/pwdstore/crypto | |
| parent | ffcbabc2f4ef9766271be5335cec1869fe634646 (diff) | |
| download | HardenedPass-e7463ec24c929860f0a7311b558f496919d54d20.tar.gz HardenedPass-e7463ec24c929860f0a7311b558f496919d54d20.zip | |
Remove HOTP/TOTP support (#806)
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/crypto')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt | 158 |
1 files changed, 4 insertions, 154 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 89399031..d9027230 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt @@ -21,14 +21,12 @@ import android.text.InputType import android.text.TextUtils import android.text.format.DateUtils import android.text.method.PasswordTransformationMethod -import android.view.LayoutInflater import android.view.Menu import android.view.MenuItem import android.view.MotionEvent import android.view.View import android.view.WindowManager import android.widget.Button -import android.widget.CheckBox import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.constraintlayout.widget.ConstraintLayout @@ -41,7 +39,6 @@ import androidx.preference.PreferenceManager import com.github.ajalt.timberkt.Timber.e import com.github.ajalt.timberkt.Timber.i import com.github.ajalt.timberkt.Timber.tag -import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar import com.zeapo.pwdstore.ClipboardService import com.zeapo.pwdstore.PasswordEntry @@ -51,15 +48,11 @@ import com.zeapo.pwdstore.autofill.oreo.AutofillPreferences import com.zeapo.pwdstore.autofill.oreo.DirectoryStructure import com.zeapo.pwdstore.ui.dialogs.PasswordGeneratorDialogFragment import com.zeapo.pwdstore.ui.dialogs.XkPasswordGeneratorDialogFragment -import com.zeapo.pwdstore.utils.Otp import kotlinx.android.synthetic.main.decrypt_layout.crypto_container_decrypt -import kotlinx.android.synthetic.main.decrypt_layout.crypto_copy_otp import kotlinx.android.synthetic.main.decrypt_layout.crypto_copy_username import kotlinx.android.synthetic.main.decrypt_layout.crypto_extra_show import kotlinx.android.synthetic.main.decrypt_layout.crypto_extra_show_layout import kotlinx.android.synthetic.main.decrypt_layout.crypto_extra_toggle_show -import kotlinx.android.synthetic.main.decrypt_layout.crypto_otp_show -import kotlinx.android.synthetic.main.decrypt_layout.crypto_otp_show_label import kotlinx.android.synthetic.main.decrypt_layout.crypto_password_category_decrypt import kotlinx.android.synthetic.main.decrypt_layout.crypto_password_file import kotlinx.android.synthetic.main.decrypt_layout.crypto_password_last_changed @@ -93,7 +86,6 @@ 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 by lazy { getSystemService<ClipboardManager>() } @@ -284,7 +276,6 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { } override fun onDestroy() { - checkAndIncrementHotp() super.onDestroy() mServiceConnection?.unbindFromService() } @@ -304,23 +295,12 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - android.R.id.home -> { - if (passwordEntry?.hotpIsIncremented() == false) { - setResult(RESULT_CANCELED) - } - finish() - } + R.id.crypto_cancel_add, android.R.id.home -> finish() R.id.copy_password -> copyPasswordToClipBoard() R.id.share_password_as_plaintext -> shareAsPlaintext() R.id.edit_password -> editPassword() R.id.crypto_confirm_add -> encrypt() R.id.crypto_confirm_add_and_copy -> encrypt(true) - R.id.crypto_cancel_add -> { - if (passwordEntry?.hotpIsIncremented() == false) { - setResult(RESULT_CANCELED) - } - finish() - } else -> return super.onOptionsItemSelected(item) } return true @@ -463,84 +443,6 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { } } - if (entry.hasTotp() || entry.hasHotp()) { - crypto_extra_show_layout.visibility = View.VISIBLE - crypto_extra_show.typeface = monoTypeface - crypto_extra_show.text = entry.extraContent - - crypto_otp_show.visibility = View.VISIBLE - crypto_otp_show_label.visibility = View.VISIBLE - crypto_copy_otp.visibility = View.VISIBLE - - if (entry.hasTotp()) { - crypto_copy_otp.setOnClickListener { - copyOtpToClipBoard( - Otp.calculateCode( - entry.totpSecret, - Date().time / (1000 * entry.totpPeriod), - entry.totpAlgorithm, - entry.digits) - ) - } - crypto_otp_show.text = - Otp.calculateCode( - entry.totpSecret, - Date().time / (1000 * entry.totpPeriod), - entry.totpAlgorithm, - entry.digits) - } else { - // we only want to calculate and show HOTP if the user requests it - crypto_copy_otp.setOnClickListener { - if (settings.getBoolean("hotp_remember_check", false)) { - if (settings.getBoolean("hotp_remember_choice", false)) { - calculateAndCommitHotp(entry) - } else { - calculateHotp(entry) - } - } else { - // show a dialog asking permission to update the HOTP counter in the entry - val checkInflater = LayoutInflater.from(this@PgpActivity) - val checkLayout = checkInflater.inflate(R.layout.otp_confirm_layout, null) - val rememberCheck: CheckBox = - checkLayout.findViewById(R.id.hotp_remember_checkbox) - val dialogBuilder = MaterialAlertDialogBuilder(this@PgpActivity) - dialogBuilder.setView(checkLayout) - dialogBuilder.setMessage(R.string.dialog_update_body) - .setCancelable(false) - .setPositiveButton(R.string.dialog_update_positive) { _, _ -> - run { - calculateAndCommitHotp(entry) - if (rememberCheck.isChecked) { - settings.edit { - putBoolean("hotp_remember_check", true) - putBoolean("hotp_remember_choice", true) - } - } - } - } - .setNegativeButton(R.string.dialog_update_negative) { _, _ -> - run { - calculateHotp(entry) - settings.edit { - putBoolean("hotp_remember_check", true) - putBoolean("hotp_remember_choice", false) - } - } - } - val updateDialog = dialogBuilder.create() - updateDialog.setTitle(R.string.dialog_update_title) - updateDialog.show() - } - } - crypto_otp_show.setText(R.string.hotp_pending) - } - crypto_otp_show.typeface = monoTypeface - } else { - crypto_otp_show.visibility = View.GONE - crypto_otp_show_label.visibility = View.GONE - crypto_copy_otp.visibility = View.GONE - } - if (settings.getBoolean("copy_on_decrypt", true)) { copyPasswordToClipBoard() } @@ -559,12 +461,9 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { * Encrypts the password and the extra content */ private fun encrypt(copy: Boolean = false) { - // if HOTP was incremented, we leave fields as is; they have already been set - if (intent.getStringExtra("OPERATION") != "INCREMENT") { - editName = crypto_password_file_edit.text.toString().trim() - editPass = crypto_password_edit.text.toString() - editExtra = crypto_extra_edit.text.toString() - } + editName = crypto_password_file_edit.text.toString().trim() + editPass = crypto_password_edit.text.toString() + editExtra = crypto_extra_edit.text.toString() if (editName?.isEmpty() == true) { showSnackbar(resources.getString(R.string.file_toast_text)) @@ -688,43 +587,6 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { } /** - * Writes updated HOTP counter to edit fields and encrypts - */ - private fun checkAndIncrementHotp() { - // we do not want to increment the HOTP counter if the user has edited the entry or has not - // generated an HOTP code - if (intent.getStringExtra("OPERATION") != "EDIT" && passwordEntry?.hotpIsIncremented() == true) { - editName = name.trim() - editPass = passwordEntry?.password - editExtra = passwordEntry?.extraContent - - val data = Intent(this, PgpActivity::class.java) - data.putExtra("OPERATION", "INCREMENT") - data.putExtra("fromDecrypt", true) - intent = data - encrypt() - } - } - - private fun calculateHotp(entry: PasswordEntry) { - copyOtpToClipBoard(Otp.calculateCode(entry.hotpSecret, entry.hotpCounter!! + 1, "sha1", entry.digits)) - crypto_otp_show.text = Otp.calculateCode(entry.hotpSecret, entry.hotpCounter + 1, "sha1", entry.digits) - crypto_extra_show.text = entry.extraContent - } - - private fun calculateAndCommitHotp(entry: PasswordEntry) { - calculateHotp(entry) - entry.incrementHotp() - // we must set the result before encrypt() is called, since in - // some cases it is called during the finish() sequence - val returnIntent = Intent() - returnIntent.putExtra("NAME", name.trim()) - returnIntent.putExtra("OPERATION", "INCREMENT") - returnIntent.putExtra("needCommit", true) - setResult(RESULT_OK, returnIntent) - } - - /** * Get the Key ids from OpenKeychain */ private fun getKeyIds(receivedIntent: Intent? = null) { @@ -861,13 +723,6 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { showSnackbar(resources.getString(R.string.clipboard_username_toast_text)) } - private fun copyOtpToClipBoard(code: String) { - val clipboard = clipboard ?: return - val clip = ClipData.newPlainText("pgp_handler_result_pm", code) - clipboard.setPrimaryClip(clip) - showSnackbar(resources.getString(R.string.clipboard_otp_toast_text)) - } - private fun shareAsPlaintext() { if (findViewById<View>(R.id.share_password_as_plaintext) == null) return @@ -957,13 +812,8 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { fun doOnPostExecute() { if (skip) return - checkAndIncrementHotp() if (crypto_password_show != null) { - // clear password; if decrypt changed to encrypt layout via edit button, no need - if (passwordEntry?.hotpIsIncremented() == false) { - setResult(RESULT_CANCELED) - } passwordEntry = null crypto_password_show.text = "" crypto_extra_show.text = "" |
