aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/PasswordEntry.kt
diff options
context:
space:
mode:
authorHarsh Shandilya <msfjarvis@gmail.com>2020-05-28 22:42:13 +0530
committerGitHub <noreply@github.com>2020-05-28 22:42:13 +0530
commite7463ec24c929860f0a7311b558f496919d54d20 (patch)
treeeb460f7e49e1a71acaceaec305e511bb4c0a9d45 /app/src/main/java/com/zeapo/pwdstore/PasswordEntry.kt
parentffcbabc2f4ef9766271be5335cec1869fe634646 (diff)
downloadHardenedPass-e7463ec24c929860f0a7311b558f496919d54d20.tar.gz
HardenedPass-e7463ec24c929860f0a7311b558f496919d54d20.zip
Remove HOTP/TOTP support (#806)
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/PasswordEntry.kt')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordEntry.kt104
1 files changed, 2 insertions, 102 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordEntry.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordEntry.kt
index 32f671be..d9168d39 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordEntry.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordEntry.kt
@@ -4,26 +4,18 @@
*/
package com.zeapo.pwdstore
-import android.net.Uri
import java.io.ByteArrayOutputStream
import java.io.UnsupportedEncodingException
/**
* A single entry in password store.
*/
-class PasswordEntry(private val content: String) {
+class PasswordEntry(content: String) {
val password: String
val username: String?
- val digits: String
- val totpSecret: String?
- val totpPeriod: Long
- val totpAlgorithm: String
- val hotpSecret: String?
- val hotpCounter: Long?
var extraContent: String
private set
- private var isIncremented = false
@Throws(UnsupportedEncodingException::class)
constructor(os: ByteArrayOutputStream) : this(os.toString("UTF-8"))
@@ -31,12 +23,6 @@ class PasswordEntry(private val content: String) {
init {
val passContent = content.split("\n".toRegex(), 2).toTypedArray()
password = passContent[0]
- digits = findOtpDigits(content)
- totpSecret = findTotpSecret(content)
- totpPeriod = findTotpPeriod(content)
- totpAlgorithm = findTotpAlgorithm(content)
- hotpSecret = findHotpSecret(content)
- hotpCounter = findHotpCounter(content)
extraContent = findExtraContent(passContent)
username = findUsername()
}
@@ -49,27 +35,6 @@ class PasswordEntry(private val content: String) {
return username != null
}
- fun hasTotp(): Boolean {
- return totpSecret != null
- }
-
- fun hasHotp(): Boolean {
- return hotpSecret != null && hotpCounter != null
- }
-
- fun hotpIsIncremented(): Boolean {
- return isIncremented
- }
-
- fun incrementHotp() {
- content.split("\n".toRegex()).forEach { line ->
- if (line.startsWith("otpauth://hotp/")) {
- extraContent = extraContent.replaceFirst("counter=[0-9]+".toRegex(), "counter=${hotpCounter!! + 1}")
- isIncremented = true
- }
- }
- }
-
val extraContentWithoutUsername by lazy {
var usernameFound = false
extraContent.splitToSequence("\n").filter { line ->
@@ -93,73 +58,8 @@ class PasswordEntry(private val content: String) {
return null
}
- private fun findTotpSecret(decryptedContent: String): String? {
- decryptedContent.split("\n".toRegex()).forEach { line ->
- if (line.startsWith("otpauth://totp/")) {
- return Uri.parse(line).getQueryParameter("secret")
- }
- if (line.startsWith("totp:", ignoreCase = true)) {
- return line.split(": *".toRegex(), 2).toTypedArray()[1]
- }
- }
- return null
- }
-
- private fun findOtpDigits(decryptedContent: String): String {
- decryptedContent.split("\n".toRegex()).forEach { line ->
- if ((line.startsWith("otpauth://totp/") ||
- line.startsWith("otpauth://hotp/")) &&
- Uri.parse(line).getQueryParameter("digits") != null) {
- return Uri.parse(line).getQueryParameter("digits")!!
- }
- }
- return "6"
- }
-
- private fun findTotpPeriod(decryptedContent: String): Long {
- decryptedContent.split("\n".toRegex()).forEach { line ->
- if (line.startsWith("otpauth://totp/") &&
- Uri.parse(line).getQueryParameter("period") != null) {
- return java.lang.Long.parseLong(Uri.parse(line).getQueryParameter("period")!!)
- }
- }
- return 30
- }
-
- private fun findTotpAlgorithm(decryptedContent: String): String {
- decryptedContent.split("\n".toRegex()).forEach { line ->
- if (line.startsWith("otpauth://totp/") &&
- Uri.parse(line).getQueryParameter("algorithm") != null) {
- return Uri.parse(line).getQueryParameter("algorithm")!!
- }
- }
- return "sha1"
- }
-
- private fun findHotpSecret(decryptedContent: String): String? {
- decryptedContent.split("\n".toRegex()).forEach { line ->
- if (line.startsWith("otpauth://hotp/")) {
- return Uri.parse(line).getQueryParameter("secret")
- }
- }
- return null
- }
-
- private fun findHotpCounter(decryptedContent: String): Long? {
- decryptedContent.split("\n".toRegex()).forEach { line ->
- if (line.startsWith("otpauth://hotp/")) {
- return java.lang.Long.parseLong(Uri.parse(line).getQueryParameter("counter")!!)
- }
- }
- return null
- }
-
private fun findExtraContent(passContent: Array<String>): String {
- val extraContent = if (passContent.size > 1) passContent[1] else ""
- // if there is a HOTP URI, we must return the extra content with the counter incremented
- return if (hasHotp()) {
- extraContent.replaceFirst("counter=[0-9]+".toRegex(), "counter=" + (hotpCounter!!).toString())
- } else extraContent
+ return if (passContent.size > 1) passContent[1] else ""
}
companion object {