Allow exporting OTP authenticator secred, for manual provisioning or use in hardware OTP token burning apps
This commit is contained in:
parent
0df3aaccae
commit
b2bd2cafec
3 changed files with 29 additions and 2 deletions
|
@ -1,5 +1,8 @@
|
|||
package info.nightscout.androidaps.plugins.general.smsCommunicator.activities
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
|
@ -16,8 +19,8 @@ import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicato
|
|||
import info.nightscout.androidaps.plugins.general.smsCommunicator.otp.OneTimePassword
|
||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.otp.OneTimePasswordValidationResult
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.ToastUtils
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import kotlinx.android.synthetic.main.activity_smscommunicator_otp.*
|
||||
import net.glxn.qrgen.android.QRCode
|
||||
|
@ -66,9 +69,23 @@ class SmsCommunicatorOtpActivity : NoSplashAppCompatActivity() {
|
|||
Runnable {
|
||||
otp.ensureKey(true)
|
||||
updateGui()
|
||||
ToastUtils.showToastInUiThread(this, R.string.smscommunicator_otp_reset_successful)
|
||||
ToastUtils.Long.infoToast(this, resourceHelper.gs(R.string.smscommunicator_otp_reset_successful))
|
||||
})
|
||||
}
|
||||
|
||||
smscommunicator_otp_provisioning.setOnLongClickListener {
|
||||
OKDialog.showConfirmation(this,
|
||||
resourceHelper.gs(R.string.smscommunicator_otp_export_title),
|
||||
resourceHelper.gs(R.string.smscommunicator_otp_export_prompt),
|
||||
Runnable {
|
||||
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip = ClipData.newPlainText("OTP Secret", otp.provisioningSecret())
|
||||
clipboard.primaryClip = clip
|
||||
ToastUtils.Long.infoToast(this, resourceHelper.gs(R.string.smscommunicator_otp_export_successful))
|
||||
})
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
|
|
|
@ -121,4 +121,10 @@ class OneTimePassword @Inject constructor(
|
|||
fun provisioningURI(): String? =
|
||||
key?.let { "otpauth://totp/AndroidAPS:" + URLEncoder.encode(name(), "utf-8").replace("+", "%20") + "?secret=" + BaseEncoding.base32().encode(it.encoded).replace("=", "") + "&issuer=AndroidAPS" }
|
||||
|
||||
/**
|
||||
* Return secret used to provision Authenticator apps, in Base32 format
|
||||
*/
|
||||
fun provisioningSecret(): String? =
|
||||
key?.let { BaseEncoding.base32().encode(it.encoded).replace("=", "") }
|
||||
|
||||
}
|
|
@ -1376,6 +1376,10 @@
|
|||
<string name="smscommunicator_otp_reset_prompt">Are you sure to reset Authenticator key? It will render all currently configured Authenticators invalid, and you will need to set them up again.</string>
|
||||
<string name="smscommunicator_otp_reset_successful">New Authenticator Key was generated! Please use updated QRCode to provision authenticators.</string>
|
||||
|
||||
<string name="smscommunicator_otp_export_title">Exporting OTP secret</string>
|
||||
<string name="smscommunicator_otp_export_prompt">Are you sure you want to copy OTP secret to clipboard?\n\nYou may only need that if your authenticator app have issues scanning QRCode, you want to enter it manually or you want to configure hardware OTP token using dedicated app.</string>
|
||||
<string name="smscommunicator_otp_export_successful">OTP secret (in Base32 format) exported and copied into clipboard. Paste it into authenticator or hardware OTP burner!</string>
|
||||
|
||||
<string name="smscommunicator_otp_step1_install_header">1. Install Authenticator</string>
|
||||
<string name="smscommunicator_otp_step2_provisioning_header">2. Scan code to setup AndroidAPS OTP codes</string>
|
||||
<string name="smscommunicator_otp_step3_test_header">3. Test One-Time-Password</string>
|
||||
|
|
Loading…
Reference in a new issue