From 3d5dd65e306ba3ca560b3c221830ee4cdb4363fb Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Mon, 6 Nov 2017 12:41:00 +0100 Subject: Display TOTP code if entry contains OTP secret TOTP is calculated on display and on copy to clipboard from secret embedded in entry (either in password or in extra) and the current time. --- .../main/java/com/zeapo/pwdstore/PasswordEntry.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'app/src/main/java/com/zeapo/pwdstore/PasswordEntry.java') diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordEntry.java b/app/src/main/java/com/zeapo/pwdstore/PasswordEntry.java index d4d3fe81..ba689fe9 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordEntry.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordEntry.java @@ -1,5 +1,7 @@ package com.zeapo.pwdstore; +import android.net.Uri; + import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; @@ -13,6 +15,7 @@ public class PasswordEntry { private final String extraContent; private final String password; private final String username; + private final String totpSecret; public PasswordEntry(final ByteArrayOutputStream os) throws UnsupportedEncodingException { this(os.toString("UTF-8")); @@ -23,6 +26,7 @@ public class PasswordEntry { password = passContent[0]; extraContent = passContent.length > 1 ? passContent[1] : ""; username = findUsername(); + totpSecret = findTotpSecret(decryptedContent); } public String getPassword() { @@ -37,6 +41,10 @@ public class PasswordEntry { return username; } + public String getTotpSecret() { + return totpSecret; + } + public boolean hasExtraContent() { return extraContent.length() != 0; } @@ -45,6 +53,8 @@ public class PasswordEntry { return username != null; } + public boolean hasTotp() { return totpSecret != null; } + private String findUsername() { final String[] extraLines = extraContent.split("\n"); for (String line : extraLines) { @@ -56,4 +66,13 @@ public class PasswordEntry { } return null; } + + private String findTotpSecret(String decryptedContent) { + for (String line : decryptedContent.split("\n")) { + if (line.startsWith("otpauth://totp/")) { + return Uri.parse(line).getQueryParameter("secret"); + } + } + return null; + } } -- cgit v1.2.3