aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/utils
diff options
context:
space:
mode:
authorHarsh Shandilya <msfjarvis@gmail.com>2020-07-25 14:37:16 +0530
committerGitHub <noreply@github.com>2020-07-25 14:37:16 +0530
commit62dbc183d52d93860228316b209ec5aa15f16a08 (patch)
tree93af36ab8e7ef7a0b4740233b03b814c46442149 /app/src/main/java/com/zeapo/pwdstore/utils
parente3cf73885c112bc553d6a0cc01d594a87728f448 (diff)
downloadHardenedPass-62dbc183d52d93860228316b209ec5aa15f16a08.tar.gz
HardenedPass-62dbc183d52d93860228316b209ec5aa15f16a08.zip
Properly handle files without passwords (#969)
* Properly handle files without passwords Fixes #967 Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * Fix tests Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * Only look for TOTP URI Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/utils')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/UriTotpFinder.kt17
1 files changed, 12 insertions, 5 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/UriTotpFinder.kt b/app/src/main/java/com/zeapo/pwdstore/utils/UriTotpFinder.kt
index 57c8f580..aab72d38 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/UriTotpFinder.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/UriTotpFinder.kt
@@ -14,10 +14,10 @@ class UriTotpFinder : TotpFinder {
override fun findSecret(content: String): String? {
content.split("\n".toRegex()).forEach { line ->
- if (line.startsWith("otpauth://totp/")) {
+ if (line.startsWith(TOTP_FIELDS[0])) {
return Uri.parse(line).getQueryParameter("secret")
}
- if (line.startsWith("totp:", ignoreCase = true)) {
+ if (line.startsWith(TOTP_FIELDS[1], ignoreCase = true)) {
return line.split(": *".toRegex(), 2).toTypedArray()[1]
}
}
@@ -26,7 +26,7 @@ class UriTotpFinder : TotpFinder {
override fun findDigits(content: String): String {
content.split("\n".toRegex()).forEach { line ->
- if (line.startsWith("otpauth://totp/") &&
+ if (line.startsWith(TOTP_FIELDS[0]) &&
Uri.parse(line).getQueryParameter("digits") != null) {
return Uri.parse(line).getQueryParameter("digits")!!
}
@@ -36,7 +36,7 @@ class UriTotpFinder : TotpFinder {
override fun findPeriod(content: String): Long {
content.split("\n".toRegex()).forEach { line ->
- if (line.startsWith("otpauth://totp/") &&
+ if (line.startsWith(TOTP_FIELDS[0]) &&
Uri.parse(line).getQueryParameter("period") != null) {
val period = Uri.parse(line).getQueryParameter("period")!!.toLongOrNull()
if (period != null && period > 0)
@@ -48,11 +48,18 @@ class UriTotpFinder : TotpFinder {
override fun findAlgorithm(content: String): String {
content.split("\n".toRegex()).forEach { line ->
- if (line.startsWith("otpauth://totp/") &&
+ if (line.startsWith(TOTP_FIELDS[0]) &&
Uri.parse(line).getQueryParameter("algorithm") != null) {
return Uri.parse(line).getQueryParameter("algorithm")!!
}
}
return "sha1"
}
+
+ companion object {
+ val TOTP_FIELDS = arrayOf(
+ "otpauth://totp",
+ "totp:"
+ )
+ }
}