aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt
diff options
context:
space:
mode:
authorFabian Henneke <FabianHenneke@users.noreply.github.com>2020-09-01 10:12:27 +0200
committerGitHub <noreply@github.com>2020-09-01 13:42:27 +0530
commitcbb96397d1f5cffef7984b08a426646aaea93e5b (patch)
treeda11f9d477758f69f7349dea56bfcee3a92b2446 /app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt
parent55d64fb73710d8dcadd28089ab233cd543830184 (diff)
downloadHardenedPass-cbb96397d1f5cffef7984b08a426646aaea93e5b.tar.gz
HardenedPass-cbb96397d1f5cffef7984b08a426646aaea93e5b.zip
Add Keystore backend for SSH public key authentication (#1070)
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt62
1 files changed, 18 insertions, 44 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt b/app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt
index 109ebd01..bfa7e1c8 100644
--- a/app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt
@@ -4,61 +4,35 @@
*/
package com.zeapo.pwdstore.sshkeygen
-import android.annotation.SuppressLint
import android.app.Dialog
-import android.content.ClipData
+import android.content.Intent
import android.os.Bundle
-import android.view.View
-import android.widget.TextView
-import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R
-import com.zeapo.pwdstore.utils.clipboard
-import java.io.File
+import com.zeapo.pwdstore.git.sshj.SshKey
class ShowSshKeyFragment : DialogFragment() {
- private lateinit var builder: MaterialAlertDialogBuilder
- private lateinit var publicKey: TextView
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- builder = MaterialAlertDialogBuilder(requireActivity())
- }
-
- @SuppressLint("InflateParams")
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val activity = requireActivity()
- val view = activity.layoutInflater.inflate(R.layout.fragment_show_ssh_key, null)
- publicKey = view.findViewById(R.id.public_key)
- readKeyFromFile()
- createMaterialDialog(view)
- val ad = builder.create()
- ad.setOnShowListener {
- val b = ad.getButton(AlertDialog.BUTTON_POSITIVE)
- b.setOnClickListener {
- val clipboard = activity.clipboard ?: return@setOnClickListener
- val clip = ClipData.newPlainText("public key", publicKey.text.toString())
- clipboard.setPrimaryClip(clip)
+ val publicKey = SshKey.sshPublicKey
+ return MaterialAlertDialogBuilder(requireActivity()).run {
+ setMessage(getString(R.string.ssh_keygen_message, publicKey))
+ setTitle(R.string.your_public_key)
+ setNegativeButton(R.string.ssh_keygen_later) { _, _ ->
+ (activity as? SshKeyGenActivity)?.finish()
}
- }
- return ad
- }
-
- private fun createMaterialDialog(view: View) {
- builder.setView(view)
- builder.setTitle(getString(R.string.your_public_key))
- builder.setNegativeButton(R.string.dialog_ok) { _, _ -> requireActivity().finish() }
- builder.setPositiveButton(R.string.ssh_keygen_copy, null)
- }
-
- private fun readKeyFromFile() {
- val file = File(requireActivity().filesDir.toString() + "/.ssh_key.pub")
- try {
- publicKey.text = file.readText()
- } catch (e: Exception) {
- e.printStackTrace()
+ setPositiveButton(R.string.ssh_keygen_share) { _, _ ->
+ val sendIntent = Intent().apply {
+ action = Intent.ACTION_SEND
+ type = "text/plain"
+ putExtra(Intent.EXTRA_TEXT, publicKey)
+ }
+ startActivity(Intent.createChooser(sendIntent, null))
+ (activity as? SshKeyGenActivity)?.finish()
+ }
+ create()
}
}
}